/*
//	
//	Sphera Lightbox 1.2
//
*/


$(document).ready(function(){
	$('#close_popup').click(function(){
		$("div#div_sovrapposto").toggle();
		$("div#div_trasparenza").hide();
		$('.no_print').removeClass('no_print');
	})
});

function OpenLightbox(pageOrUrl, height, width, post_data){

		var data;
		var content = $("div#div_content");
		
		content.html("");
		
		width = width ? width : 500;
		$('#main').addClass('no_print');
		$('#close_popup').addClass('no_print');
		
		var sovrapposto = $("div#div_sovrapposto");
		
		//if (isPage != "") isPage = true;
		if (height != null){
			sovrapposto.css("overflow","auto");
		}
		
		var marg_left = ($(document).width()/2) - (width/2);
		
		// Retieve scroll height
		/* Taken from: (http://www.jr.pl/www.quirksmode.org/viewport/compatibility.html) */
		var x_scroll;
		var y_scroll;
		if (self.pageYOffset) // all except Explorer
		{
			x_scroll = self.pageXOffset;
			y_scroll = self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop)
			// Explorer 6 Strict
		{
			x_scroll = document.documentElement.scrollLeft;
			y_scroll = document.documentElement.scrollTop;
		}
		else if (document.body) // all other Explorers
		{
			x_scroll = document.body.scrollLeft;
			y_scroll = document.body.scrollTop;
		}
		
		// Retrieve window width / height
		var x_window;
		var y_window;
		if (self.innerHeight) // all except Explorer
		{
			x_window = self.innerWidth;
			y_window = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
		{
			x_window = document.documentElement.clientWidth;
			y_window = document.documentElement.clientHeight;
		}
		else if (document.body) // other Explorers
		{
			x_window = document.body.clientWidth;
			y_window = document.body.clientHeight;
		}
		
		// Set width, height, top, left
		var top = (parseInt(y_window)/2)-(parseInt(height)/2)+parseInt(y_scroll);
		
		sovrapposto.css("left", marg_left).css("width", width);
		if( top>0 ){
			sovrapposto.css("top", top);
		}
		if ( height ) sovrapposto.css("height", height);
			else sovrapposto.css("height", "auto");
			
		$("div#div_trasparenza")
			.css("height",$(document).height())
			.css("width",$(document).width()).show();
			
		sovrapposto.show();
		
		//content.html("<div style='margin: 150px auto;text-align: center;' class='ie-center'><img src='img/elem/loading.gif'></div>");
		
		if(!pageOrUrl.match(/\.php/)){
			content.hide().html(pageOrUrl).show();
		}
		else{
			$.post('./'+pageOrUrl, post_data, function(data){
				//check_ajax_state( data );			
				content.hide().html( data ).show();
				
			});
		}
		

		return 0;
}

function CloseLightbox(){
	$("div#div_sovrapposto").toggle();
	$("div#div_trasparenza").hide();
	$('.no_print').removeClass('no_print');
}

