﻿/***************************/
//@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(triggerid){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.2"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#"+triggerid).fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#showbanner").fadeOut("slow");
		$("#quicklogin").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(triggerid){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#"+triggerid).height();
	var popupWidth = $("#"+triggerid).width();
	//centering
	var position = "fixed";
	$.each(jQuery.browser, function(i, val) {
		if(($.browser.msie)&&(val == '6.0')){
			position = "absolute";
		}
		
 	});
	//alert(position);
	$("#"+triggerid).css({
		
		"position": position,
		"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!
	$("#popgallery").click(function(){
		//centering with css
		centerPopup('popupContact');
		//load popup
		loadPopup('popupContact');
	});
	$(".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();
		}
	});

});

$(document).ready(function(){
		var left 	= $('.leftmenu').height();
		var right 	= $('.rightcontent').height();
		if(left >= right){
			$('.leftmenu').attr('style','border-right:1px solid #ccc;padding-right:10px;');
			$('.rightcontent').attr('style','border:none;padding-left:5px;');
			//alert(left + " - " + right )
		}
		$('#login').click(function(){
			$('#errmsgpop').addClass('ferror');
			$('#errmsgpop').html("Please wait..");
			var email 		= $('#email').val();
			var password 	= $('#password').val();;
			$.post("postloginregistration.php", { "login": email,"password": password,"type": "login"},
			function(data){
				
				if(data.message == 'studentlogin'){
					disablePopup();
					}else if(data.message == 'userlogin'){
						disablePopup();
						}else{
							$('#errmsgpop').addClass('ferror');
							$('#errmsgpop').html(data.message);
						}
			}, "json");	
		});
		
		/*$('#register').click(function(){
			$('#errmsgpop').addClass('ferror');
			$('#errmsgpop').html("Please wait..");
			var cname 		= $('#cname').val();
			var cmobile		= $('#cmobile').val();
			var iama 		= $('#iama').val();
			var cemail 		= $('#cemail').val();
			var cpassword 	= $('#cpassword').val();;
			var crepassword = $('#crepassword').val();
			if(cname == ''){
					$('#errmsgpop').html('Please enter your full name');
					$('#cname').focus();
				}
			else if(cemail == ''){
					$('#errmsgpop').html('Please enter your valid Email Id. Your Email Id is your UserId');
					$('#cemail').focus();
				}
			else if(cpassword == ''){
					$('#errmsgpop').html('Please enter Password');
					$('#cpassword').focus();
				}
			else if(crepassword == ''){
					$('#errmsgpop').html('Please enter Re-Password');
					$('#crepassword').focus();
				}
			else if(crepassword != cpassword){
					$('#errmsgpop').html('Password and Re-Password does not match please try again!');
					$('#crepassword').focus();
				}
			else{
				$.post("postloginregistration.php", { "cname": cname,"cmobile": cmobile,"cemail": cemail,"cpassword": cpassword,"iama": iama,"type": "register"},
				function(data){
					if(data.msgarea == '1'){
						$('#errmsgpop').removeClass('ferror');
						$('#errmsgpop').html('');
						$('#registerfree').addClass('ferror');
						$('#registerfree').attr('style','margin-bottom:180px;');
						$('#registerfree').html(data.message);
					}
					else{
					$('#errmsgpop').html(data.message);
					}
				}, "json");	
			}
		});*/
		$('.closebox').click(function (){
			window.location.href = 'index.php';
		});
		$('a.ans').click(function(event) {
			var id = this.id.replace('ans_', "");
			$("#liking"+id).html("<img src='images/spinner.gif' border='0' />");
			$.get("postliking.php?ul="+id, function(data){cb(data,id)});
		});
	});
function cb(data,id){
//converts the JSON string to a JavaScript object
eval("myTweets="+data); 
document.getElementById("liking"+id).innerHTML =  myTweets.liking;
}
