﻿/***************************/
//@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;


var videos = [ "<iframe width='640' height='390' src='http://www.youtube.com/embed/-SukMtoBu9g' frameborder='0' allowfullscreen></iframe>" ,
			  "<iframe width='640' height='390' src='http://www.youtube.com/embed/fndPILj3mnE' frameborder='0' allowfullscreen></iframe>" ,
			  "<iframe width='640' height='390' src='http://www.youtube.com/embed/4_0c8FMVMUs' frameborder='0' allowfullscreen></iframe>" ,
			  "<iframe width='640' height='390' src='http://www.youtube.com/embed/felz59RU1-0' frameborder='0' allowfullscreen></iframe>" ,
			  "<iframe width='640' height='390' src='http://www.youtube.com/embed/Q68k3mqkNXs' frameborder='0' allowfullscreen></iframe>" ,
			  "<iframe width='640' height='390' src='http://www.youtube.com/embed/niM7qtMc77E' frameborder='0' allowfullscreen></iframe>" ,
			  "<iframe width='640' height='390' src='http://www.youtube.com/embed/-kd9_lXtob0' frameborder='0' allowfullscreen></iframe>" ,
			  "<iframe width='640' height='390' src='http://www.youtube.com/embed/mV5OeSKcFnc' frameborder='0' allowfullscreen></iframe>" ,];



//loading popup with jQuery magic!
function loadPopup(video){
	//alert( videos[video]);
	$('#videoArea').html( videos[video]);
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#videoArea").height();
	var popupWidth = $("#videoArea").width();
	//centering
	$('#videoArea').css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#videoArea").fadeIn("slow");
		popupStatus = 1;
	}
}

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


}



// set menu background color per page
function setMenuBkg(bkgColor,bodyColor){
	//disables popup only if it is enabled
	$("#headerNav").css({
		"width": document.documentElement.clientWidth,
		"background": bkgColor
	});
	$("#bodyContainer").css({
		"background": bodyColor
	});
	if(document.documentElement.clientWidth<=1200){
		$("#headerNav").css({
			"width": 1200
		});
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#"+targetItem).height();
	var popupWidth = $("#"+targetItem).width();
	//centering
	$("#videoArea").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(){
	
	$(window).resize(function() {
 		$("#headerNav").css({
			"width": "100%"
		});
		$("#navIcons").css({
			"left": document.documentElement.clientWidth-$("#navIcons").width()
		});
		$("#bodyContainer").css({
			"background": bodyColor
		});
		if(document.documentElement.clientWidth<=1200){
			$("#headerNav").css({
			"width": 1200
		});
	}
	});
	//LOADING POPUP
	//Click the button event!
	//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();
		}
	});

});
