/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
//
//@implementing and optimizing for Talent Banque: Alex Baskov, 2009
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatusSpotlight = 0;


//loading popup with jQuery magic!
function loadPopupSpotlight()
{
	//loads popup only if it is disabled
	if(popupStatusSpotlight == 0)
	{
		$("#popupSpotlightBackground").css({
			"opacity": "0.5" // set to zero, if you don't want to have a background
		});
		$("#popupSpotlightBackground").fadeIn("slow");
		$("#popupSpotlight").fadeIn("slow");
		popupStatusSpotlight = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupSpotlight()
{
	//disables popup only if it is enabled
	if(popupStatusSpotlight == 1)
	{
		$("#popupSpotlightBackground").fadeOut("slow");
		$("#popupSpotlight").fadeOut("slow");
		popupStatusSpotlight = 0;
	}
}

//centering popup
function centerPopupSpotlight()
{
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupSpotlight").height();
	var popupWidth = $("#popupSpotlight").width();

	//
	// we need here to emulate fixed position... so we use offsetHeight and offsetWidth instead
	// (c) Alex Baskov
	//
	var topScrollerPosition = 0;
	
	// we may just scroll to top and see nice popup
	//scroll(0,0);

	// center vertically in the visible area...
	if ($.browser.msie) {
		topScrollerPosition = document.body.scrollTop;
	}
	else {
		topScrollerPosition = window.pageYOffset;
	}

	//centering
	$("#popupSpotlight").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		//"top": parseInt((windowHeight-popupHeight)/2) + topScrollerPosition,
		//"top": topScrollerPosition + 60,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#popupSpotlightBackground").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {
	
	//LOADING POPUP
	//Click the button event!
	
	$(".linkSpotlight").click(function() {

		$("#popupSpotlight .title").html($(this).parent().parent().find(".title").html());
		$("#popupSpotlight .spotlight_desc").html($(this).parent().parent().find(".full_desc").html());

		var imgSrc = $(this).attr("img");
		if (imgSrc != "") {
			$("#popup_artist_image").attr("src", imgSrc);
			$("#popup_artist_image").parent().show();
		}
		else {
			$("#popup_news_image").parent().hide();
		}
		
		//centering with css
		centerPopupSpotlight();
		//load popup
		loadPopupSpotlight();
	});
				
	//CLOSING POPUP
	$("#popupSpotlightClose").click(function() {
		disablePopupSpotlight();
	});
	
	//Click out event!
	$("#popupSpotlightBackground").click(function() {
		disablePopupSpotlight();
	});
	
	//Press Escape event!
	$(document).keypress(function(e) {
		if(e.keyCode == 27 && popupStatusSpotlight == 1) {
			disablePopupSpotlight();
		}
	});

});


