﻿/***************************/
//@Author: Steve Ariss - Elevations Marketing
//@website: www.elevaitons.ca
//@email: info@elevations.ca				
/***************************/

$(document).ready(function(){

	//VARIABLES
	var popupStatus = 0;		//0 means disabled; 1 means enabled;
	var popupDiv = $("#popup");	//Styled Container to use as popup
	var screenDim = $("#backgroundPopup");
	var prizesNav = $("#prizeMenu li"); 
	
	//INITIALIZE POPUP
	function popup_init (myDiv){
	
		//set opacity for background Dim
		$(screenDim).css({
			"opacity": "0.7"
		});
		
		//request data for centering
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = $(myDiv).height();
		var popupWidth = $(myDiv).width();
		
		//centering
		$(myDiv).css({
			"position": "absolute",
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
		//only need force for IE6
		$(screenDim).css({
			"height": windowHeight
		});
	};
	popup_init(popupDiv);
		
	//OPEN POPUP
	function loadPopup() {
		//loads popup only if it is disabled
		if(popupStatus==0){		
			screenDim.fadeIn("slow");
			popupDiv.fadeIn("fast");	
			popupDiv.empty();		//clear popup contents		
			popupStatus = 1;
		};
	};
	
	//DISABLE POPUP
	function disablePopup(){
		//Remove Events
			$(".XButton").die("click");
			
		//disables popup only if it is enabled
		if(popupStatus==1){
			screenDim.fadeOut("slow");
			popupDiv.fadeOut("fast");
			popupDiv.empty();		
			popupStatus = 0;
		}
	}
	
	//LOADING ANIMATION
	function showLoading(){
		$("#popupLoading")
			.css({visibility:"visible"})  
	    	.css({opacity:"1"})
	    	.css({display:"block"});
	}
	
/////////////////////////////////////////////////////////////////////////////////
////// POPUP CLICK EVENTS ///////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

	
	//FAQ'S POPUP
	$("#openNom").click(function(){
		loadPopup();
		popupDiv.load("winning-nomination.html", function() { 
			//Page descisions
			xClose(); //Binds close button event	

			$('#list1b').accordion({
				autoheight: false
			});
						
			// bind to change event of select to control first and seconds accordion
			// similar to tab's plugin triggerTab(), without an extra method
			var accordions = $('#list1b');
			
			$('#switch select').change(function() {
				accordions.accordion("activate", this.selectedIndex-1 );
			});
			$('#close').click(function() {
				accordions.accordion("activate", -1);
			});
			$('#switch2').change(function() {
				accordions.accordion("activate", this.value);
			});
			$('#enable').click(function() {
				accordions.accordion("enable");
			});
			$('#disable').click(function() {
				accordions.accordion("disable");
			});
			$('#remove').click(function() {
				accordions.accordion("destroy");
				wizardButtons.unbind("click");
			});
		});
	});
	
	
	//RE-BIND NESTED EVENTS
	//CLOSE ICON ON POPUPS
	function xClose () {
		$(".XButton").live("click", function (event) {
			//alert("close me");
			disablePopup();
		});
	};
		
	//CLOSING POPUP
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		};
	});
});