
var popupStatus = 0;

function setGalleryFrame(value){	
	var uri = "http://www.clopaydoor.com/"
	var src =  uri + value + ".html";	
	loadIframe('GalleryFrame', src);
	}

function setDisFrame(values){

if(values == "start"){
	var uri = "http://www.clopaydoor.com/dis/shell-entry.html"
	var src =  uri
	loadIframe('entryDisFrame', src);
}
else{
	var uri = "http://www.clopaydoor.com/dis/shell-entry.html?autoStart=ENTRY&config="
	var src =  uri +values;
	loadIframe('entryDisFrame', src);
}
	}

function loadIframe(iframeName, url) {    
	var $iframe = $('#' + iframeName);    
		if ( $iframe.length ) {        
			$iframe.attr('src',url);           
				return false;    
				}    
		return true;}


function loadPopup(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupBox").fadeIn("slow");
		$("body").append($("#popupBox"))
		popupStatus = 1;
	}
}
function loadPopup1(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupBox1").fadeIn("slow");
		$("body").append($("#popupBox1"))
		popupStatus = 1;
	}
}
function loadPopup2(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupBox2").fadeIn("slow");
		$("body").append($("#popupBox2"))
		popupStatus = 1;
	}
}
function loadPopup3(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupBox3").fadeIn("slow");
		$("body").append($("#popupBox3"))
		popupStatus = 1;
	}
}
function loadPopup4(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupBox4").fadeIn("slow");
		$("body").append($("#popupBox4"))
		popupStatus = 1;
	}
}
function loadPopup5(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupBox5").fadeIn("slow");
		$("body").append($("#popupBox5"))
		popupStatus = 1;
	}
}
function loadPopup6(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupBox6").fadeIn("slow");
		$("body").append($("#popupBox6"))
		popupStatus = 1;
	}
}
function loadPopup7(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupBox7").fadeIn("slow");
		$("body").append($("#popupBox7"))
		popupStatus = 1;
	}
}
function loadPopup8(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupBox8").fadeIn("slow");
		$("body").append($("#popupBox8"))
		popupStatus = 1;
	}
}
function loadPopup9(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupBox9").fadeIn("slow");
		$("body").append($("#popupBox9"))
		popupStatus = 1;
	}
}
function loadPopup10(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupBox10").fadeIn("slow");
		$("body").append($("#popupBox10"))
		popupStatus = 1;
	}
}
function loadPopup11(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupBox11").fadeIn("slow");
		$("body").append($("#popupBox11"))
		popupStatus = 1;
	}
}

function loadPopup12(){
	if(popupStatus==0){
		$("#backgroundPopup").css({"opacity": "0.7"});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupBox12").fadeIn("slow");
		$("body").append($("#popupBox12"))
		popupStatus = 1;
	}
}


function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupBox").fadeOut("slow");
		$("#popupBox1").fadeOut("slow");
		$("#popupBox2").fadeOut("slow");
		$("#popupBox3").fadeOut("slow");
		$("#popupBox4").fadeOut("slow");
		$("#popupBox5").fadeOut("slow");
		$("#popupBox6").fadeOut("slow");
		$("#popupBox7").fadeOut("slow");
		$("#popupBox8").fadeOut("slow");
		$("#popupBox9").fadeOut("slow");
		$("#popupBox10").fadeOut("slow");
		$("#popupBox11").fadeOut("slow");
		$("#popupBox12").fadeOut("slow");		
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupBox").height();
	var popupWidth = $("#popupBox").width();
	$("#popupBox").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
function centerPopup1(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupBox1").height();
	var popupWidth = $("#popupBox1").width();
	$("#popupBox1").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
function centerPopup2(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupBox2").height();
	var popupWidth = $("#popupBox2").width();
	$("#popupBox2").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
function centerPopup3(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupBox3").height();
	var popupWidth = $("#popupBox3").width();
	$("#popupBox3").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
function centerPopup4(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupBox4").height();
	var popupWidth = $("#popupBox4").width();
	$("#popupBox4").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
function centerPopup5(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupBox5").height();
	var popupWidth = $("#popupBox5").width();
	$("#popupBox5").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
function centerPopup6(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupBox6").height();
	var popupWidth = $("#popupBox6").width();
	$("#popupBox6").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
function centerPopup7(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupBox7").height();
	var popupWidth = $("#popupBox7").width();
	$("#popupBox7").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
function centerPopup8(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupBox8").height();
	var popupWidth = $("#popupBox8").width();
	$("#popupBox8").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
function centerPopup9(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupBox9").height();
	var popupWidth = $("#popupBox9").width();
	$("#popupBox9").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
function centerPopup10(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupBox10").height();
	var popupWidth = $("#popupBox10").width();
	$("#popupBox10").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
function centerPopup11(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupBox11").height();
	var popupWidth = $("#popupBox11").width();
	$("#popupBox11").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}

function centerPopup12(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupBox12").height();
	var popupWidth = $("#popupBox12").width();
	$("#popupBox12").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//Click the button event!
	$('#popBtn').click(function(){
		//centering with css
		centerPopup();
		loadPopup();
	});
	
	
	for( i=0; i < (25); i++){ 
	$('#popBtn-'+i).click(function(){
		//centering with css
		centerPopup();
		loadPopup();
	});
	}
	
	
//Click the button event!
	$("#popBtn1").click(function(){
		centerPopup1();
		loadPopup1();
	});
	$("#popBtn2").click(function(){
		centerPopup2();
		loadPopup2();
	});
	$("#popBtn3").click(function(){
		centerPopup3();
		loadPopup3();
	});
	$("#popBtn4").click(function(){
		centerPopup4();
		loadPopup4();
	});
	$("#popBtn5").click(function(){
		centerPopup5();
		loadPopup5();
	});
	$("#popBtn6").click(function(){
		centerPopup6();
		loadPopup6();
	});
	$("#popBtn7").click(function(){
		centerPopup7();
		loadPopup7();
	});
	$("#popBtn8").click(function(){
		centerPopup8();
		loadPopup8();
	});
	$("#popBtn9").click(function(){
		centerPopup9();
		loadPopup9();
	});
	$("#popBtn10").click(function(){
		centerPopup10();
		loadPopup10();
	});
	$("#popBtn11").click(function(){
		centerPopup11();
		loadPopup11();
	});	
	$("#popBtn12").click(function(){
		centerPopup12();
		loadPopup12();
	});	
	
	//Click the x event!
	$("#popupBoxClose").click(function(){
		disablePopup();
	});
$(".popupBoxClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});

	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
