// 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);
		}
	}

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

// 0. Bildfolge Gastgeber 
imagelist_nr = imagelist.length;imagelist[imagelist_nr] = Array();flag[imagelist_nr] = Array();img[imagelist_nr] = Array();
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/welcome/ufer.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/welcome/hof.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/welcome/aufenthaltsraum.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;

// 1. Bildfolge Hof/Gastgeber
imagelist_nr = imagelist.length;imagelist[imagelist_nr] = Array();flag[imagelist_nr] = Array();img[imagelist_nr] = Array();
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/hof.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/scheunentor.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/tuer.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;

// 2. bildfolge Sommer
imagelist_nr = imagelist.length;imagelist[imagelist_nr] = Array();flag[imagelist_nr] = Array();img[imagelist_nr] = Array();
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/sommer/hof.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/sommer/garten.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/sommer/kutschfahrt.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/sommer/lustige_huehner.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;

// 3. Bildfolge Winter
imagelist_nr = imagelist.length;imagelist[imagelist_nr] = Array();flag[imagelist_nr] = Array();img[imagelist_nr] = Array();
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/winter/winter_hof.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/winter/bergpanorama.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/winter/feuerholz.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/sommer/aufenthaltsraum.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;

// 4. Bildfolge Auszeichnungen, gleich wie Hof/Gastgeber
imagelist_nr = imagelist.length;imagelist[imagelist_nr] = Array();flag[imagelist_nr] = Array();img[imagelist_nr] = Array();
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/hof.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/scheunentor.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/hof/tuer.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;

// 5. wohnen
imagelist_nr = imagelist.length;imagelist[imagelist_nr] = Array();flag[imagelist_nr] = Array();img[imagelist_nr] = Array();
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/wohnen/27.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/wohnen/35.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/wohnen/38.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;

// 6. kinder
imagelist_nr = imagelist.length;imagelist[imagelist_nr] = Array();flag[imagelist_nr] = Array();img[imagelist_nr] = Array();
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/kinder/convoi.jpg"; [imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/kinder/pfluftl.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/kinder/trampolin.jpg"; [imagelist_nr][imagelist[imagelist_nr].length] = false;

// 7. ausfluege
imagelist_nr = imagelist.length;imagelist[imagelist_nr] = Array();flag[imagelist_nr] = Array();img[imagelist_nr] = Array();
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/ausfluege/baden.jpg"; [imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/ausfluege/radln.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/ausfluege/skiwandern.jpg"; [imagelist_nr][imagelist[imagelist_nr].length] = false;

// 8. gästebuch
imagelist_nr = imagelist.length;imagelist[imagelist_nr] = Array();flag[imagelist_nr] = Array();img[imagelist_nr] = Array();
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/gaestebuch/garten.jpg"; [imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/gaestebuch/lagerfeuer.jpg"; flag[imagelist_nr][imagelist[imagelist_nr].length] = false;
imagelist[imagelist_nr][imagelist[imagelist_nr].length] = "/pixs/teaser/gaestebuch/ponys.jpg"; [imagelist_nr][imagelist[imagelist_nr].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: 'esterer_song',  url: '/sounds/esterer_song.mp3',  autoLoad: true,autoPlay: false, onfinish: function() {soundManager.play('esterer_song');},
		esterer_song = soundManager.createSound({  id: 'esterer_song',  url: '/sounds/esterer_song.mp3',  autoLoad: true,autoPlay: false, 
		onload: function() {
				//alert('The sound '+this.sID+' loaded!');
				},
			volume: 100
			});
		}
	}

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

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()", standzeit);
				});
			}
		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()", standzeit);
				});
			}
		}
	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);
	}
