/***************************/
//@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");
		$("#popupContact_vote").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");
		$("#popupContact_vote").fadeOut("slow");
		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": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
	var popupHeight = $("#popupContact_vote").height();
	var popupWidth = $("#popupContact_vote").width();
	$("#popupContact_vote").css({
		"position": "fixed",
		"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(){
	
	//LOADING POPUP
	//Click the button event!
	$("#pg-icon").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});

	//Click the button event!
	$("#btn-gt1").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
//		con
	});

	//Click the button event!
	$("#video_clip").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
//		con
		var div = $('#contactArea_vote');
		div.html('<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/bpjyv0tFtDQ&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/bpjyv0tFtDQ&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>');
		var div1 = $('#popheading');
		div1.html('Visit Kumarakom here');
	});
	
	//Click the button event!
	$("#btn-gt").click(function(){
		var correctAns = $("input#answer").val();
		var sel_val = $("input[name='radio']:checked").val();
		if(sel_val == undefined) { alert("Please select a option!"); return false; }
		var ans_yes = $("input#ans_yes").val();
		var ans_no = $("input#ans_no").val();
//		if(correctAns == sel_val) { alert("Correct Answer"); } else { alert("Wrong Answer"); }
//		alert(correctAns +" - "+ sel_val);
//		alert(ans_yes +" - "+ ans_no)
		var div = $('#contactArea_vote');
		if(correctAns == sel_val) {
			div.html(ans_yes);
		} else {
			div.html(ans_no);
		}
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
//		con
	});

				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	$("#popupContactClose_vote").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
	//	disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
		//	disablePopup();
		}
	});

});
