/***************************/
//@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 EGO Management: 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.8"
		});
		$("#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 windowWidth = document.body.clientWidth;
	//var windowHeight = document.body.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...
	var topScrollerPosition = document.documentElement.scrollTop;


	//centering
	$("#popupSpotlight").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		//"top": parseInt((windowHeight-popupHeight)/2) + topScrollerPosition,
		//"top": topScrollerPosition + 40,
		"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!
	
	/*
	$("#buttonSpotlight").click(function() {
		//centering with css
		centerPopupSpotlight();
		//load popup
		loadPopupSpotlight();
	});
	*/
				
	//CLOSING POPUP
	//Click the x event!
	$("#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();
		}
	});

	$(".popupSpotlightArrowsHolder .arrow_left").click(function() {
		$(".popupSpotlightContent .arrow_left").click();
	});
	
	$(".popupSpotlightArrowsHolder .arrow_right").click(function() {
		$(".popupSpotlightContent .arrow_right").click();
	});
	
});


function spotlightPopup(index)
{

	loadPopupSpotlight();
	centerPopupSpotlight();
	if (!($("div.popupSpotlightContent").is('.js'))) {
		$("div.popupSpotlightContent").carousel({ pagination: true,
				nextBtn: " <a href='javascript:void(0);' class='arrow_right'><img src='/img/clear.gif' width='11' height='15' alt='' title='' /></a>",
						prevBtn: "<a href='javascript:void(0);' class='arrow_left'><img src='/img/clear.gif' width='11' height='15' alt='' title='' /></a>",
				nextBtnInsert: "appendTo", prevBtnInsert: "appendTo"});
	}
	$("#spotlightPopupArtists").css("left", -634 * index);
	$(".popupSpotlightContent .carousel-pagination a:eq(" + index + ")").click();
	
	return true;
}