/*
	Layer IE7 Workaround
*/

function workaround(obj)
{
	if($('div#rocket_overlay').css('display')!="block")
	{
		showRocketOverlayBackground();
	}
	
	obj.prependTo('#overlay_content')
	//$('#overlay_content').html(obj)
	
	$('#overlay_content').css('display', 'block');
	$('#overlay_content').height(600); 
	
	$('#overlay_content').width('600')
	if(navigator.appName=="Netscape")
	{
	$('#overlay_content').width(parseInt(obj.css('width')));
	}
	
	$('#overlay_content').css("left", (document.body.clientWidth / 2) - ($('#overlay_content').width() / 2));
	//$('#overlay_content').css("top", (document.body.clientWidth / 2) - ($('#overlay_content').height() / 2));
			/*iframe = document.createElement("iframe");
			iframeid = document.createAttribute("id");
			iframesrc = document.createAttribute("src");
			iframeid.nodeValue = "ie6_overlay_content";
			iframesrc.nodeValue = "https:///img/blank.gif";
			iframe.setAttributeNode(iframeid);
			
			
			$('#overlay_content').before(iframe);*/
	ie6 = navigator.appVersion.search(/MSIE 6.0/)
	if(navigator.appName == "Microsoft Internet Explorer" && ie6>=0)
		{
			$('#ie6_overlay_content').css("left", (document.body.clientWidth / 2) - ($('#overlay_content').width() / 2));
			$('#ie6_overlay_content').width('600')

			$('#ie6_overlay_content').css("display", "block");
			
		}

	$('#overlay_content').css("display", "block");
	//$('#overlay_content').css("position", "absolute");
	//$('#overlay_content').css("overflow-x", "hidden");
	
}

function closeOverlay()
{
	hideRocketOverlayBackground();

	$('#overlay_content').css("display", "none");
	ie6 = navigator.appVersion.search(/MSIE 6.0/)
	if(navigator.appName == "Microsoft Internet Explorer" && ie6>=0)
		{$('#ie6_overlay_content').css("display", "none");
		}
	
	
	
}

/* * * * * * * * * * * * * 
 * Layer Functions
 * * * * * * * * * * * * */
function addMerkliste(produktid, lang){
	
	if(!lang){ lang ="de"; }
	url = '/'+lang+'/japi/produkt_merkliste/'+ produktid;

	$('#produkt-merkliste').load(url);
	$('#produkt-merkliste').css('display', 'block');
	workaround($('#produkt-merkliste'))
}

function showPackstuecke(produktid, sort)
{
	url = '/'+lang+'/japi/produkt_packstuecke/'+ produktid +'?sort='+ sort;

	$('#packstueck_layer').load(url);
	$('#packstueck_layer').css('display', 'block');
	workaround($('#packstueck_layer'))
}

function showHalfstep()
{
	url = '/'+lang+'/japi/show_halfstep/';
	$('#packstueck_layer').load(url);
	$('#packstueck_layer').css('display', 'block');
	workaround($('#packstueck_layer'))
}


function showLandingpagelogin()
{	
	url = '/'+lang+'/japi/landingpage_login/';
	 
	$('#packstueck_layer').load(url);
	$('#packstueck_layer').css('display', 'block');
	workaround($('#packstueck_layer'))
}

function showLandingpagewka(sessionid)
{
	url = '/'+lang+'/japi/landingpagewka/';

	$('#packstueck_layer').load(url);
	$('#packstueck_layer').css('display', 'block');
	workaround($('#packstueck_layer'))
}


function showArtikelGroessen(produktid, sort)
{
	url = '/'+lang+'/japi/produkt_groessen/'+ produktid +'?sort='+ sort;
	
	$('#packstueck_layer').load(url);
	$('#packstueck_layer').css('display', 'block');
	workaround($('#packstueck_layer'))
}

function showPleaseWait()
{
	url = '/'+lang+'/japi/generate_pdf';

	$('#generate_pdf_layer').load(url);
	$('#generate_pdf_layer').css('display', 'block');
	workaround($('#generate_pdf_layer'))
}

function changeadl()
{
	url = '/'+lang+'/japi/changeadl/';
	
	$('#changeadl-layer').load(url);
	$('#changeadl-layer').css('display', 'block');
	workaround($('#changeadl-layer'))
}
function changeLanguage()
{
	document.location = document.getElementById('language').value;
}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function showOverlay(url)
{
	showRocketOverlayBackground();

	var overlay_content = $("#overlay_content");
	overlay_content.empty();
	
	if(url.indexOf('?') > -1) {
		url+= '&overlay=true';
	} else {
		url+= '?overlay=true';
	}
	
	overlay_content.load(url, null, function() {
		var overlay_height = parseInt($("#overlay_main").css('height'));
		var overlay_width = parseInt($("#overlay_main").css('width'));
		
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		
		var overlay_content = $("#overlay_content");
		overlay_content.css("display", "block");
		overlay_content.css("top", (arrayPageScroll[1] + ((arrayPageSize[3] - 120 - overlay_height) / 2) + 'px'));
		overlay_content.css("left", (((arrayPageSize[0] - 20 - overlay_width) / 2) + 'px'));
	});	
}

function hideOverlay()
{
	var overlay_content = $("#overlay_content");
	overlay_content.css("display", "none");
	
	hideRocketOverlayBackground();
}