
//document.onload = setupZoom();

var showroomImgActive = new Image();
showroomImgActive.src = "SYSTEM/images/showroom_active.gif";
var showroomImg = "SYSTEM/images/showroom.gif";


// Print

var truePrint = false;

function PrintOrNot() {
 		var myPrint = location.search;
 		if (myPrint.indexOf("print=true") > -1) {
   		truePrint = true;
 		}
}
PrintOrNot();

if (truePrint == true) {
	document.write('<style type="text/css" media="screen">@import url(SYSTEM/css/print.css);</style>');
}

var printLink = location.href.indexOf("-") ? location.href + "?" : location.href + "&";



jQuery(document).ready(function(){


// Printbutton
$("a.printbutton").attr("href",printLink + "print=true");
$("a.printbutton").attr("target","_blank");

if (truePrint) return;


// Navigation
	var timeout   = null;
	var animating = false;
	$("#nav a.header").click(function() {
		$("ul#nav ul:visible").slideUp("slow");
		$(this).next("ul:hidden").slideDown("slow");
		if (animating === true){return;}
		if (timeout) clearTimeout(timeout);
		animating = true;
		timeout = window.setTimeout(function() {
			$("ul#nav ul:visible").slideUp("slow");
			$("ul#nav ul.current").slideDown("slow");
			animating = false;
		}, 5000);
	}); //.next().hide();



/*

	$("#nav a.header").click(function() {
		$("ul#nav ul:visible:not(.current)").slideUp("slow");
		$(this).next("ul:hidden").slideDown("slow");
	}); //.next().hide();
*/



// backButton
	$("a.backbutton").click(function() {
		history.go(-2);
	}); 



//Language
   $("div#langLabel a").toggle(function(){
     $("div#langOptions").slideDown('slow',"easeOutExpo");
   },function(){
     $("div#langOptions").slideUp('slow',"easeInOutExpo");
   });



//Showroom
	$("#showroom a").not(".current").mouseover(function() {
		$("#showroom a img").attr("src",showroomImgActive.src);;
	});

	$("#showroom a").not(".current").mouseout(function() {
		$("#showroom a img").attr("src",showroomImg);;
	});





//Pager

	var pages = $("div.page").length;
	if (pages > 1) {
		var clicked = 0;

		/* P&P Medien GmbH - 11.05.2009
		var backStr = '<a class="back" href="#">&lt;</a> ';
		var forStr = '<a class="for" href="#">&gt;</a>';
		*/
		var backStr = '<a class="back" href="#"></a> ';
		var forStr = '<a class="for" href="#"></a>';
		var numStr = '';
		for (var i=0; i < pages;i++) {
			numStr += '<a class="number" href="#">'+ (i+1) +'</a> ';
		}
		var htmlStr = backStr + numStr + forStr;
		$("div.pnRight").html(htmlStr);

		$("div.page").eq(0).css("display","block");
		$("div.pnRight a").eq(1).css("color","#f4aa00");

		$("div.pagenav a.back").click(function() {	
			if (clicked > 0) {	changePages("prev");	}
		});

		$("div.pagenav a.number").click(function(e) {
			changePages("this",e);
		});

		$("div.pagenav a.for").click(function() {	
			if (clicked < (pages -1)) { changePages("next"); 	}
		});
	}
	else {
		$("div.page").eq(0).css("display","block");
	}

	function changePages(dir,e) {
		switch (dir) {		
			case 'next':
				clicked += 1;
				break;
			case 'this':
				clicked = pages - $(e.target).nextAll().length;
				break;
			case 'map':
				clicked = (pages - 1) - $(e.target).nextAll().length;
				break;
			case 'prev':
				clicked -= 1;
				break;
		}
		$("div.page").hide(); //.css("display","none");
		$("div.page").eq(clicked).fadeIn("slow"); //.css("display","block");
		$("div.pnRight a").css("color","#8c8d8e");
		$("div.pnRight").eq(clicked).find("a:eq("+ (clicked + 1) + ")").css("color","#f4aa00");
	}
	
	
	//Location Map
	if ("div.locations") {
		var locations = $("map.Map").length;
		for (var i = 1; i <= locations; i++) {
			$("map.Map area.pin" + i).click(function(e) {
				changePages("map",e);
			});			
		}
	}

	

});









/* Adjust Frame height */
function set_frame_height(height, scroll_top)
{
	if (document.getElementById("iframe-box") != null)
	{
		if (height > 0)
		{
			//document.getElementById("iframe-box").style.height = height + 'px';
			$("#iframe-box,#box-fade").animate({ 
				height: height + "px"
			}, 1000);
		}
		else
		{		
			$("#box-fade").animate({ 
				height: height + "px"
			}, 1000);
		}
		
		//document.getElementById("box-fade").style.height = height + 'px';
		
		if (height < document.documentElement.clientHeight)
		{
			height = document.documentElement.clientHeight;
		}
		else
		{
			height += 50;	
		}
		document.getElementById("overlay").style.height = height + 'px';
		window.scrollTo(0, scroll_top);
	}
}

/* Shadow Box */
var box_set_width = 798;
var box_set_height = 584;

function show_box(url)
{
	document.getElementById('iframe-box').src = url;
	setTimeout("fade_box()", 500);
}

function fade_box()
{	
	document.getElementById('overlay').style.display = 'block';
	$("#overlay").animate({ 
		opacity: 0.8
	}, 1000);
	
	document.getElementById('box-fade').style.marginLeft = document.documentElement.clientWidth/2-500/2 + 'px';
	document.getElementById('box-fade').style.height = '100px';
	document.getElementById('box-fade').style.width = '500px';
	
	margin_left = document.documentElement.clientWidth;	
	$("#box-fade").animate({ 
		marginLeft: margin_left/2-box_set_width/2 + 'px',
		width: box_set_width + "px"
	}, 800, '', animate_box);
}

function animate_box()
{
	$("#box-fade").animate({ 
		height: box_set_height + "px"
	}, 1000,'', show_content);
}

function show_content()
{
	var box_content = document.getElementById('box-content');
	box_content.style.display = 'block';
	parent.iframebox.location.reload();
}

function set_url(url)
{
	document.getElementById('iframe-box').src = url;
}