﻿/***************************/
//@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 menuStatus = 0;
var imageselectorStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}	

function imageselector(obj){


	//loads popup only if it is disabled
	if(imageselectorStatus==0){
		$("#imageselectorbg").css({
			"opacity": "0.7"
		});
		$("#imageselectorbg").fadeIn("slow");
		$("#imageselector").fadeIn("slow");
		imageselectorStatus = 1;
	}

//centering popup

	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#imageselector").height();
	var popupWidth = $("#imageselector").width();
	//centering
	$("#imageselector").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#imageselectorbg").css({
		"height": windowHeight
	});
	
//placing imagepage into imageselectorbox
ajaxpage('imageselector.php?file=image&obj=' + obj, 'imageselectorArea');	

}

function downloadselector(obj){


	//loads popup only if it is disabled
	if(imageselectorStatus==0){
		$("#imageselectorbg").css({
			"opacity": "0.7"
		});
		$("#imageselectorbg").fadeIn("slow");
		$("#imageselector").fadeIn("slow");
		imageselectorStatus = 1;
	}

//centering popup

	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#imageselector").height();
	var popupWidth = $("#imageselector").width();
	//centering
	$("#imageselector").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#imageselectorbg").css({
		"height": windowHeight
	});
	
//placing imagepage into imageselectorbox
ajaxpage('imageselector.php?file=download&obj=' + obj, 'imageselectorArea');	

}

function ShowQuickviewer(){
	
		//loads popup only if it is disabled
	if(popupStatus==0){
		//document.getElementById('quickviewer').style.visibility='visible';
		//$("#quickviewer").fadeIn("slow");
		$("#quickviewer").fadeTo(400,1) ;
		popupStatus = 1;
	}
	else if(popupStatus==1){
	$("#quickviewer").fadeTo(400,0) ;
		popupStatus = 0;
	}
	
}

function HideQuickviewer(){
	
		//loads popup only if it is disabled
	if(popupStatus==1){
		$("#quickviewer").fadeTo(400,0) ;
		popupStatus = 0;
	}
	
}

//disabling popup with jQuery magic!
function ximageselector(){
	//disables popup only if it is enabled
	if(imageselectorStatus==1){
		$("#imageselectorbg").fadeOut("slow");
		$("#imageselector").fadeOut("slow");
		imageselectorStatus = 0;
	}
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("kjhkjh").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#imageselectorClose").click(function(){
		ximageselector();
	});
	//Click out event!
	$("#imageselectorbg").click(function(){
		ximageselector();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && imageselectorStatus==1){
			ximageselector();
		}
	});

});
