﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
        $("#popup_message").hide();
        // $("#contact_send_btn").show();
        $("#contactArea").show();
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

    $("ul#twitter_update_list > li").hide()

    $("ul#twitter_update_list > li").liquidCanvas("[shadow] => roundedRect");
    // $('ul#twitter_update_list > li').corner('transparent');
    // $('ul#twitter_update_list > li').corner();
	
	$("ul#twitter_update_list > li").show()
	
	//LOADING POPUP
	//Click the button event!
	$("#popup").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
    
});



$(function() {

    $('.error').hide();
    $('#popup_message').hide();

    $('input.text-input').css({backgroundColor:"#FFFFFF"});
    $('input.text-input').focus(function(){
        $(this).css({backgroundColor:"#CCC"});
    });
    $('input.text-input').blur(function(){
        $(this).css({backgroundColor:"#FFFFFF"});
    });

    $(".button").click(function() {
        // validate and process form
        // first hide any error messages
        $('.error').hide();

        var name = $("input#name").val();
        if (name == "") {
            $("label#name_error").show();
            $("input#name").focus();
            return false;
        }
        var email = $("input#email").val();
        if (email == "") {
            $("label#email_error").show();
            $("input#email").focus();
            return false;
        }
        // NOTE: this funky syntax in order to fetch textarea value using jquery
        var msg = $('[name="msg"]').val();
        if (msg == "") {
            $("label#msg_error").show();
            $("input#msg").focus();
            return false;
        }
		
		var dataString = 'name='+ name + '&email=' + email + '&msg=' + msg;
        // alert (dataString);return false;
		
		$.ajax({
            type: "POST",
            url: "/do_contact",
            data: dataString,
            success: function() {
                $('#popup_message').fadeIn(1500);
                
                $("input#name").val("");
                $("input#email").val("");
                $("[name='msg']").val("");
                
                // $("#contact_send_btn").hide();
                $("#contactArea").hide();
                
                
                // $('#contact').html("<div id='message'></div>");
                // $('#message').html("<h2>Contact Form Submitted!</h2>")
                // .append("<p>We will be in touch soon.</p>")
                // .hide()
                // .fadeIn(1500, function() {
                    // $('#message').append("<img id='popupDone' src='images/check.png' />");
                // });
            }
        });
        
    return false;
    });
});

// runOnLoad(function(){
//   $("input#name").select().focus();
// });
