$(document).ready(function(){

	$("#watch_video").click(function(){
		document.getElementById('video_PopUp').innerHTML = "<div id=\"video_close\"><img onclick=\"video_DisablePopUp()\" src=\"/img/close.png\"></img></div><iframe id=\"video_frame\" width='385px' height='315px' src='/vids/vid01.jsp' scrolling='no' frameborder='0'></iframe>";
		video_CenterPopUp();
		video_LoadPopUp();
	});
	
	$("#video_close").click(function(){
		video_DisablePopUp();
	});
	

	
	$("#signup_btn").click(function(e){
		Chatfe.signupPopUp('signup_form',e.pageX,e.pageY);
		
	});

//	jason's hackz
	
	$("#closeSignUp").click(function(){
		
		$("#" + "signup_form").fadeOut("slow");
		signup_popupStatus = 0; 	
	});
	
	var signUpBtn = document.getElementById('signup_btn');
	signUpBtn.onclick = function(){
		return false;	
	}	
	
	
});


//0 means disabled; 1 means enabled;
var video_popupStatus = 0;
var signup_popupStatus = 0;

//centering popup
function video_CenterPopUp(){

	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#video_PopUp").height();
	var popupWidth = $("#video_PopUp").width();
	//centering
	$("#video_PopUp").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#video_GreyOutBg").css({
		"height": windowHeight
	});
	
}

//loading popup 
function video_LoadPopUp(){
	//loads popup only if it is disabled
	if(video_popupStatus==0){
		$("#video_GreyOutBg").css({
			"opacity": "0.7"
		});
		$("#video_GreyOutBg").fadeIn("fast");
		$("#video_PopUp").fadeIn("slow");
		video_popupStatus = 1;
	}
}

//disabling popup 
function video_DisablePopUp(){
	//disables popup only if it is enabled
	if(video_popupStatus==1){
		$("#video_GreyOutBg").fadeOut("slow");
		$("#video_PopUp").fadeOut("slow");
		document.getElementById('video_PopUp').innerHTML = "";
		video_popupStatus = 0;
	}
}


/* start jason's code*/


Chatfe = {
	
	signupPopUp: function(id,xPos,yPos){

		var xPosShift = ($("#" + id).outerWidth())/2;
		var yPostShift = ($("#" + id).outerHeight())/2;
		
		if(signup_popupStatus==0){
			$("#" + id).animate(
				{
					opacity: 0,
	   			    left: xPos + 50,
					top: yPos -175
	
				},1, function(){
					$("#" + id).fadeIn("fast"); 
					$("#" + id).animate(
						{
							opacity: 1,
			   			    left: xPos + 20,
			   			    top: yPos -175
	
						},200, function(){
//							$("#" + id).fadeIn("slow"); 
							signup_popupStatus = 1;
						});				
					
					
			}); 
		}else if (signup_popupStatus==1){

			$("#" + id).fadeOut("slow"); 
			signup_popupStatus = 0;
			
		}else {
			signup_popupStatus = 0;
		}
		
		
		
	}
};




