
$(document).ready(function(){
   
   $(".left").click(function(e){
   	showPreImage();
   });
   
   $(".right").click(function(e){
   	showNextImage();
   });
   
   /*$(".footer_").click(function(e){
   	$(".footer_open").show();
   });*/
   
   $(".footer_").toggle(
                   function()
                   {
                      $(".footer_open").show();
    
                   },
                   function()
                   {
                       $(".footer_open").hide();
                   });
   $("#close").click(function(e){
   	$(".footer_open").hide();
   });
   $(".left").mouseover(function(e){
   	$(".footer_open").hide();
   });
   $(".middle").mouseover(function(e){
   	$(".footer_open").hide();
   });
   $(".right").mouseover(function(e){
   	$(".footer_open").hide();
   });
   
   getWindowSize();
   
   if(goto != "")
   {
   		for(i=0;i<artikel.length;i++) {
   			if(artikel[i] == goto) {
   				count = i-1;
   				showImage();
   				break;
   			}
   		}
   }
   else {
   showImage();
   }
 });
 

 // var pics = new Array('img1.jpg', 'img2.jpg', 'img3.jpg', 'img4.jpg', 'img5.jpg', 'img6.jpg');
 var count = -1;
 var autoplay = true;
 function showImage() {
 	if(autoplay == true) {
 	var pic = new Image();
 	count++;
 	if(count >= pics.length){count = 0;}
 	
 	pic.src = pics[count]+"?nocache="+Math.random();
 	pic.onload = function () { 
 		var preWidth = this.width;
 		var newWidth = myWidth*0.6;
 		var ratWidth = newWidth / preWidth;
 		
 		var preHeight = this.height * ratWidth;
 		size = "width='" + newWidth + "' height='" + preHeight + "'";
 		
 		if(myHeight*0.7 < preHeight) {
 			var newHeight = myHeight*0.7;
 			var ratHeight = newHeight / preHeight;
 			
 			var newWidth = newWidth * ratHeight;
 			size = "width='" + newWidth + "' height='" + newHeight + "'";
 		}
 		
 		if(fullsize == true) {
 			size = "width='" + this.width + "' height='" + this.height + "'";
 		}
 		
 		if(count%2 == 0 ){
 			var id1 = "input1";
 			var id2 = "input2";
 		}
 		else {
 			var id1 = "input2";
 			var id2 = "input1";
 		}
 		document.getElementById(id1).innerHTML = "<img border='0' src='" + pic.src + "' " + size + " />";
 		
 		$('#' + id1).parent().parent().parent().fadeIn(1000);
 		$('#' + id2).parent().parent().parent().fadeOut(1000);
 		$('.footer_').html(unescape(bus[count]));
 		
 		if(shop[count] == "") {
 			document.getElementById('order_link').href = "front_content.php?idart=13&order=" + bus[count] + "&pic=" + escape(pics[count]);
 			$('#normal').show();
 			$('#shop').hide();
 		}
 		else {
 			$('#shop').html(unescape(shop[count]));
 			$('#normal').hide();
 			$('#shop').show();
 		}
 		$('#pigment').hide();
 		$('#lambda').hide();
 		if(farben[count] != "") $('#' + farben[count]).show();
 		
 	};
 	//setTimeout(showImage, 4000);
 	}
 }
 
var clickStop = false;
 function showNextImage() {
 	if(clickStop == false) {
 	clickStop = true;
 	var pic = new Image();
 	count++;
 	if(count >= pics.length){count = 0;}
 	pic.src = pics[count]+"?nocache="+Math.random();
 	pic.onload = function () { 
 		var preWidth = this.width;
 		var newWidth = myWidth*0.6;
 		var ratWidth = newWidth / preWidth;
 		
 		var preHeight = this.height * ratWidth;
 		size = "width='" + newWidth + "' height='" + preHeight + "'";
 		
 		if(myHeight*0.7 < preHeight) {
 			var newHeight = myHeight*0.7;
 			var ratHeight = newHeight / preHeight;
 			
 			var newWidth = newWidth * ratHeight;
 			size = "width='" + newWidth + "' height='" + newHeight + "'";
 		}
 		
 		if(fullsize == true) {
 			size = "width='" + this.width + "' height='" + this.height + "'";
 		}
 		
 		if(count%2 == 0 ){
 			var id1 = "input1";
 			var id2 = "input2";
 		}
 		else {
 			var id1 = "input2";
 			var id2 = "input1";
 		}
 		document.getElementById(id1).innerHTML = "<img border='0' src='" + pic.src + "' " + size + " />";
 		
 		$('#' + id1).parent().parent().parent().fadeIn(1000);
 		$('#' + id2).parent().parent().parent().fadeOut(1000);
 		$('.footer_').html(unescape(bus[count]));
 		
 		if(shop[count] == "") {
 			document.getElementById('order_link').href = "front_content.php?idart=13&order=" + bus[count] + "&pic=" + escape(pics[count]);
 			$('#normal').show();
 			$('#shop').hide();
 		}
 		else {
 			$('#shop').html(unescape(shop[count]));
 			$('#normal').hide();
 			$('#shop').show();
 		}
 		$('#pigment').hide();
 		$('#lambda').hide();
 		if(farben[count] != "") $('#' + farben[count]).show();
 		
		setTimeout(function () {clickStop = false;},1000);
 	}
 	}
 }
 
 function showPreImage() {
 	if(clickStop == false) {
 	clickStop = true;
 	var pic = new Image();
 	count--;
 	if(count < 0){count = pics.length - 1;}
 	pic.src =  pics[count]+"?nocache="+Math.random();
 	pic.onload = function () { 
 		var preWidth = this.width;
 		var newWidth = myWidth*0.6;
 		var ratWidth = newWidth / preWidth;
 		
 		var preHeight = this.height * ratWidth;
 		size = "width='" + newWidth + "' height='" + preHeight + "'";
 		
 		if(myHeight*0.7 < preHeight) {
 			var newHeight = myHeight*0.7;
 			var ratHeight = newHeight / preHeight;
 			
 			var newWidth = newWidth * ratHeight;
 			size = "width='" + newWidth + "' height='" + newHeight + "'";
 		}
 		
 		if(fullsize == true) {
 			size = "width='" + this.width + "' height='" + this.height + "'";
 		}
 		
 		if(count%2 == 0 ){
 			var id1 = "input1";
 			var id2 = "input2";
 		}
 		else {
 			var id1 = "input2";
 			var id2 = "input1";
 		}
 		document.getElementById(id1).innerHTML = "<img border='0' src='" + pic.src + "' " + size + " />";
 		
 		$('#' + id1).parent().parent().parent().fadeIn(1000);
 		$('#' + id2).parent().parent().parent().fadeOut(1000);
 		$('.footer_').html(unescape(bus[count]));
 		
 		if(shop[count] == "") {
 			document.getElementById('order_link').href = "front_content.php?idart=13&order=" + bus[count] + "&pic=" + escape(pics[count]);
 			$('#normal').show();
 			$('#shop').hide();
 		}
 		else {
 			$('#shop').html(unescape(shop[count]));
 			$('#normal').hide();
 			$('#shop').show();
 		}
 		$('#pigment').hide();
 		$('#lambda').hide();
 		if(farben[count] != "") $('#' + farben[count]).show();
 		
		setTimeout(function () {clickStop = false;},1000);
 	}
 	}
 }
 
 
 var myWidth = 0, myHeight = 0;

 function getWindowSize() {
 
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
}

