// JavaScript document

var state=0;
var next=0;
/* 	state 	0	no movement
	state -1	streaming left, no end
	state	1	streaming right, no end
	state -2	streaming left once
	state  2	streaming right once
*/

var oldWidth=0;
var step=1;
var stepfac=1.3;
var origWidth=0, origHeight=0;
var img, img4, nextimg, linkimg;
var nextslide;
var slideA, slideB;
var menu, xtbl, msie;
var lastdir=2;
var col, maxcol;

function clipx() {
	var tbl = document.getElementById('tbl');
 	var left = parseInt( tbl.style.left );
 	var contHeight = 300;
	var	contWidth = 600;
	
	if (state) {
		if (state == -1)
		 	tbl.style.left = ((left == -contWidth) ? 0 : (left - 1)) + "px";
		else if (state == 1) 
			tbl.style.left = ((left == 0) ? (-contWidth) : (left + 1)) + "px";	
		else if (state == -2) {
			if (left<=-contWidth) {
				state=0;
				slideA.innerHTML = slideB.innerHTML;
				tbl.style.left=0;
			} else { 
				if (contWidth+left<14 && step>1)
					step/=2;
				tbl.style.left = (left - step) + "px";
				if (contWidth+left>14 && step<8)
					step*=2;
			}
		} else if (state == 2) {
			if (left>=0) {
				state=0;
				tbl.style.left=0;
			} else { 
				if (left>-14 && step>1)
					step/=2;
				tbl.style.left = (left + step) + "px";
				if ( left < -14 && step<8)
					step*=2;
			} 
		} else if (state == 12) {
			if (img.height==contHeight)
				state=22;
			else {
				if (!origWidth) {
					origWidth=img.width;
					origHeight=img.height;
					step=1;
				}
				if (contHeight-img.height<30 && step>1)
					step/=2;
				var w=slideA.clientWidth;
				img.width=origWidth*(img.height+=2*step)/origHeight;
				if (parseInt(img.id)>2)
					tbl.style.left=left-(slideA.clientWidth-w)+"px";
				if (contHeight-img.height>30 &&step<5)
					step*=2;

			} 
		} else if (state == 32) {
			if (img.height==origHeight)
				state=0;
			else {
				if (img.height-origHeight<30 && step>1)
					step/=2;
				var w=slideA.clientWidth;
				img.width=origWidth*(img.height-=2*step)/origHeight;
				if (parseInt(img.id)>2)
					tbl.style.left=left-(slideA.clientWidth-w)+"px";
				if (img.height-origHeight>30 && step<5)
					step*=2;

			} 
		} else if (state==22 && next) {
			state=32;
			step=1;
		}
	} else {
		if (next==3)
			next=lastdir*=-1;
		if (next==-2) {
			state=next;
			loadSlide( slideB, nextslide );
			next=0;
		} else if (next==0) 
			state=0;
		else if (next==2) {
			slideB.innerHTML = slideA.innerHTML;
			tbl.style.left = -contWidth +"px";
			loadSlide( slideA, nextslide);
			state=next;
			next=0;
		} else if (next==12) {
			img=nextimg;
			state=next;
			next=0;
		} else if (next>=100 && next<120 && next!=menu) {
			document.getElementById( "m"+next ).style.color="#ff0066";
			document.getElementById( "m"+menu ).style.color="black";
			document.getElementById( 'p115' ).innerHTML='';
			document.getElementById( 'p114' ).innerHTML='';
			document.getElementById( 'p113' ).innerHTML='';
			document.getElementById( 'p112' ).innerHTML='';
			document.getElementById( 'p111' ).innerHTML='';
      document.getElementById( 'p110' ).innerHTML='';
			menu=next;
			if (next==100) {
				nextslide=''; 
				next=-2;
			} else if (next==109) {
				nextslide='c'; 
				col=maxcol=1;
				next=-2;
			} else if (next==102) {
				nextslide='news'; 
				next=-2;
			} else if (next==103) {
				nextslide='about'; 
				next=-2;
			} else if (next==104) {
				nextslide='contact'; 
				next=-2;
			} else if (next==105) {
				nextslide='links'; 
				next=-2;
			} else if (next==110) {
				nextslide='hw2007';
				col=1;
				maxcol=7;
				next=-2;
			} else if (next==111) {
				nextslide='fs2008';
				col=1;
				maxcol=5;
				next=-2;
			} else if (next==112) {
				nextslide='hw2008';
				col=1;
				maxcol=5;
				next=-2;
			} else if (next==113) {
				nextslide='fs2009';
				col=1;
				maxcol=5;
				next=-2;
			} else if (next==114) {
				nextslide='hw2009';
				col=1;
				maxcol=8;
				next=-2;
			} else if (next==115) {
				nextslide='fs2010';
				col=1;
				maxcol=8;
				next=-2;
			} 			
		}
	}
	document.getElementById('slideCont').style.clip = 'rect(auto,'+ contWidth +'px,' + contHeight +'px,auto)';
	document.getElementById('collection').style.left=menu>108 ? document.getElementById('m109').offsetLeft + xtbl.offsetLeft+2 : -500;
	var dx=xtbl.offsetLeft % 121+(msie ? -43 : 21);
	var dy=(msie ? -44 : 27);
	document.body.style.backgroundPosition=dx + "px " + dy + "px";
}

function clip() {
	clipx();
	setTimeout(clip,15);	 	
}

function large( nr ) {
	if (state==22) 
		next=32; 
	else {
		nextimg=document.getElementById( nr ); 
		next=12;
	}
}

function preview( s ) {

	var td=document.getElementById( "preview");
	td.innerHTML = '<img src="'+s+'" />';
}

function shift( step ) {
	
	if (step==-1) {
		if (col==1)
			col=maxcol;
		else
			col--;
	} else if (col==maxcol)
		col=1;
	else
		col++;
	next=-2*step;
}

function loadSlide( slide, prefix ) {

	var line="";
	var html="<center><table border='0' width='550' height='400'><tr height='350' >"; //align='center'>";
	if (prefix == "news" || prefix=="contact" || prefix=="about" || prefix=="links" ) {
		var sl = document.getElementById( prefix );
		html += "<td style='text-align:left'>" +(sl ? sl.innerHTML : "" ) + "</td>";
	} else {
		var nr=0;
		while (++nr < 5)
			html+="<td><a href='javascript:large(" + nr + ")'><img id='" + nr + "' src='images/" + prefix + (menu>=109 ? col :"") + nr + ".jpg' " +
				" width='142' height='142'></a></td>"
		if (menu>=110) {
		  document.getElementById( 'p'+menu ).innerHTML='('+col+' von '+maxcol+')';
		  if (menu==110) {
  			line="<a class='textline' href='mailto:annikadautz@gmx.at'>fotos: annika dautz</a>, " +
  			"<a class='textline' href='mailto:pezimnetz@yahoo.de'>model: petra zach</a>";
		  } else if (menu==111 || menu==112 || menu==113 || menu==114 ) {
  			line="<a class='textline' href='mailto:annikadautz@gmx.at'>fotos: annika dautz</a>, " +
  			"models: anna & dajana tschirko";
		  } else if (menu==115) {
  			line="<a class='textline' target='_new' href='http://www.marcelkoehler.com'>fotos: marcel köhler</a>, " +
  			"models: mira & julia";
      } else
		  	line=" ";
		}
	}
	slide.innerHTML = html + "</tr></table>";
	document.getElementById( "textline" ).innerHTML=line;		
	document.getElementById( "left" ).style.display=(line=="" || maxcol==1 ? "none" : "inline");
	document.getElementById( "right" ).style.display=(line=="" || maxcol==1 ? "none" : "inline");	
}

// Multiple onload function created by: Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  msie = (navigator.appName!="Netscape")
  slideA = document.getElementById("slideA");
  slideB = document.getElementById("slideB");
  document.getElementById("slides").style.display="none";
  xtbl=document.getElementById( 'xtbl' );
  var site=window.location.search.substr( 1 );
  if ( !document.getElementById( site ))
    site="";
  loadSlide( slideA, site );
  menu=100;
  document.getElementById( "m100" ).style.color="#ff0066";
  try {
    FB.init("51581d2a05717aa7590030e9dd47c54a");
  } 
  catch(e) {
  }
  var a = document.getElementsByTagName('a')[22];
  clip();
});