// JavaScript Document
debugtext = "";

function setimg()
	{
	bx = 1280;
	by = 486;
	wx = $(window).width();
	wy = $("#stage1").css("height");
	wy = wy.replace("px","");
	//jetzt = vormals.replace(/Hinz/g, "Kunz, geb. Hinz");
	
	fx = wx/bx;
	fy = wy/by;
	
	if (fy < fx) // immmer der größte Faktor ist ausschlaggebend
		{
		y = by *fx // neue Bildhöhe
		mg_korrektur = Math.round ((y-wy)/2)*-1;
		$("#testimg1").css('margin-top',mg_korrektur);
		$("#testimg1").css('margin-left',"0px");
		$("#testimg1").css('width',wx); //100%
		$("#testimg1").css('height',y);
		
		$("#testimg2").css('margin-top',mg_korrektur);
		$("#testimg2").css('margin-left',"0px");
		$("#testimg2").css('width',wx);
		$("#testimg2").css('height',y);
		}
	else
		{
		x = bx *fy // neue Bildbreite
		mg_korrektur = Math.round ((x-wx)/2)*-1;
		$("#testimg1").css('margin-top',"0px");
		$("#testimg1").css('margin-left',mg_korrektur);
		$("#testimg1").css('width',x);
		$("#testimg1").css('height',wy);
		
		$("#testimg2").css('margin-top',"0px");
		$("#testimg2").css('margin-left',mg_korrektur);
		$("#testimg2").css('width',x);
		$("#testimg2").css('height',wy);
		}
	$("#ornamentimg").css('width',wx);
	$("#ornamentimg").css('height',215); // fixer wert -> verzerrt
	$("#textbalken_bottom").css('height',($(document).height()-500));
	}

img = Array(); flag = Array();
imagelist = Array();

//***** Main
serie = 0;
imagelist[serie] = Array(); flag[serie] = Array(); img[serie] = Array();
imagelist[serie][imagelist[serie].length] = "/pixs/teaser/luftbild.jpg"; flag[serie][imagelist[serie].length] = false;
imagelist[serie][imagelist[serie].length] = "/pixs/teaser/rezeption.jpg"; flag[serie][imagelist[serie].length] = false;
imagelist[serie][imagelist[serie].length] = "/pixs/teaser/steinwand.jpg"; flag[serie][imagelist[serie].length] = false;
imagelist[serie][imagelist[serie].length] = "/pixs/teaser/fruehstueck.jpg"; flag[serie][imagelist[serie].length] = false;
imagelist[serie][imagelist[serie].length] = "/pixs/teaser/hochzeit.jpg"; flag[serie][imagelist[serie].length] = false;




function preload(group,nr)
	{
	//alert(group+ " "+nr);
	img[group][nr] = new Image();
	img[group][nr].src = imagelist[group][nr];
	next = nr + 1;
	if (next < imagelist[group].length)
		{
		img[group][nr].onload = function() {flag[group][nr] = true; preload(group,next);}
		}
	else
		{
		img[group][nr].onload = function() {flag[group][nr] = true; }

		nextgroup = group+1;
		if (nextgroup < imagelist.length)
			{preload(nextgroup,0);}
		}
	
	if ((nr == 0) & (group == 0)) // Das erste Bild ist geladen 
		{
		//soundManager.createSound({  id: 'plaetschern',  url: '/sounds/Boat-MaRc-8003_hifi.mp3',  autoLoad: true,autoPlay: true, onfinish: function() {soundManager.play('plaetschern');},volume:70});
		//soundManager.createSound({  id: 'birds',  url: '/sounds/birds.mp3',  autoLoad: true,autoPlay: true, onfinish: function() {soundManager.play('birds');},volume:100});
		//soundManager.createSound({  id: 'song',  url: '/sounds/iStock_000008574218_downsmp.mp3',  autoLoad: true,autoPlay: true, onfinish: function() {soundManager.play('song');},volume:80});
		
		
		}
	}

actual_img = -1;
actual_group = 0;
actual_layer = 1;

function changer()
	{
	setimg();
	
	new_img = actual_img +1;
	if (new_img >= img[actual_group].length) {new_img = 0;}
	if (flag[actual_group][new_img] == true)
		{
		if (actual_layer == 1)
			{
			$("#testimg2").attr("src",img[actual_group][new_img].src);
			debugtext = "2 bekommt Src. 1 fadet jetzt aus";
			$("#stage1").animate({opacity: 0},2000,"linear",function()
				{
				actual_layer = 2;
				actual_img = new_img;
				debugtext = "2 bekommt Src. 1 fadet jetzt aus - FERTIG";
				window.setTimeout("changer()", 3000);
				});
			}
		else
			{
			$("#testimg1").attr("src",img[actual_group][new_img].src);
			debugtext = "1 bekommt Src. 1 fadet jetzt ein";
			$("#stage1").animate({opacity: 1},2000,"linear",function()
				{
				actual_layer = 1;
				actual_img = new_img;
				debugtext = "1 bekommt Src. 1 fadet jetzt ein - FERTIG";
				window.setTimeout("changer()", 3000);
				});
			}
		}
	else
		{
		window.setTimeout("changer()", 500);
		}
	}
	
function deb_out()
	{
	$("#debugger").html(""+flag[1][0]+" "+flag[1][1]+" "+flag[1][2]+" "+flag[1][3]+" - Act: "+actual_group+" - "+actual_img+" - Ly: "+actual_layer+"| Z-Index: "+$("#stage1").css("z-index")+" - "+$("#stage2").css("z-index")+" | Window: "+wx+" - "+wy+"<br>"+debugtext );
	//$("#debugger").html("WTC: "+wtc.join(",")+"<br>INSTR: "+m_instr.join(",")+"<br>"+debugtext );
	window.setTimeout("deb_out()", 100);
	}