//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){
		$("#popupBg").css({
			"opacity": "0.7"
		});
		$("#popupBg").fadeIn("slow");
		$("#popup").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#popupBg").fadeOut("slow");
		$("#popup").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	//var windowWidth = document.documentElement.clientWidth;
	//var windowHeight = document.documentElement.clientHeight;
	//var windowWidth = self.innerWidth;
	//var windowHeight = self.innerHeight;
	var windowWidth = document.body.clientWidth;
	var windowHeight = document.body.clientHeight;
	var popupHeight = $("#popup").height();
	var popupWidth = $("#popup").width();
	//centering
	$("#popup").css({
		"position": "absolute",
		"top": "0",
		"left": "0",
		"margin-top": windowHeight/2-popupHeight/2,
		"margin-left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#popupBg").css({
		"height": windowHeight,
		"width": windowWidth
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#main_submenu a").click(function(){
		$("iframe").css({
			"height": 440,
			"width": 600
		});
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#popupBg").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	
	//SHOWREELS
	//Hover animate
	$("#in30Sec").hover(function(){
		$("#submenu_expand").addClass("in30Sec");
	},function(){
		$("#submenu_expand").removeClass("in30Sec");
	});
	
	$("#rmb").hover(function(){
		$("#submenu_expand").addClass("rmb");
	},function(){
		$("#submenu_expand").removeClass("rmb");
	});
	
	$("#tvAds").hover(function(){
		$("#submenu_expand").addClass("tvAds");
	},function(){
		$("#submenu_expand").removeClass("tvAds");
	});
	
	$("#attvShowreel").hover(function(){
		$("#submenu_expand").addClass("attvShowreel");
	},function(){
		$("#submenu_expand").removeClass("attvShowreel");
	});
	
	$("#jewellery").hover(function(){
		$("#submenu_expand").addClass("jewellery");
	},function(){
		$("#submenu_expand").removeClass("jewellery");
	});
	
	$("#pharmaceutical").hover(function(){
		$("#submenu_expand").addClass("pharmaceutical");
	},function(){
		$("#submenu_expand").removeClass("pharmaceutical");
	});
	
	$("#training").hover(function(){
		$("#submenu_expand").addClass("training");
	},function(){
		$("#submenu_expand").removeClass("training");
	});
	
	$("#industrial").hover(function(){
		$("#submenu_expand").addClass("industrial");
	},function(){
		$("#submenu_expand").removeClass("industrial");
	});
	
	$("#wordStory1").hover(function(){
		$("#submenu_expand").addClass("wordStory1");
	},function(){
		$("#submenu_expand").removeClass("wordStory1");
	});
	
	$("#wordStory2").hover(function(){
		$("#submenu_expand").addClass("wordStory2");
	},function(){
		$("#submenu_expand").removeClass("wordStory2");
	});
	
	$("#graphics").hover(function(){
		$("#submenu_expand").addClass("graphics");
	},function(){
		$("#submenu_expand").removeClass("graphics");
	});
	
	$("#liveEvents").hover(function(){
		$("#submenu_expand").addClass("liveEvents");
	},function(){
		$("#submenu_expand").removeClass("liveEvents");
	});

});
/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/
