var embedFlash=null;
var embedContainer=null;
function loadSamples()
{
	embedContainer=$('fw_anim');
	if(embedContainer==null)
		embedContainer=$('fw_intro');
		
	var arrayPageSize = this.getPageSize();
	var h=arrayPageSize[1]+'px';
	var url='formwind_beispiele.html';
	new Ajax.Request(url,
	{
		method: 'get',
		onSuccess: function(transport) 
		{
		    var el=$('samples');
	        el.update(transport.responseText).setStyle({ zIndex:100, height:h });
			fade(el,0,100,500);
			removeBGAnimation();
		}
  	});
}
function setOpacity(el,level)
{
	var l2=level/100;
	el.style.opacity=l2;
	el.style.MozOpacity=l2;
	el.style.KhtmlOpacity=l2;
	el.style.filter="alpha(opacity="+level+")";
}

function fade(el,cur,dest,dur)
{
	if(cur!=dest)
	{
		var speed=5;
		var dif=Math.abs(cur-dest);
		if(dif<speed)
		{
			setOpacity(el,dest);
		}else{
			cur=(cur<dest)?cur+speed:cur-speed;
			setOpacity(el,cur);
			var delay=dur/(dif/speed);
			setTimeout(function(){fade(el,cur,dest,dur-delay)},delay);
		}
	}
}
function restore()
{
	var el=$('samples');
	fade(el,100,0,500);
	setTimeout(function(){el.setStyle({zIndex:0});restoreBGAnimation();},500);
}

function removeBGAnimation()
{
	if(embedContainer!=null)
	{
		embedFlash=embedContainer.innerHTML;
		embedContainer.innerHTML=null;
	}
}
function restoreBGAnimation()
{
	if(embedFlash!=null)
		embedContainer.innerHTML=embedFlash;
}
function changeImage(id,newImg)
{
   document.getElementById(id).src  = newImg;
}
var iCurSample=0;
var arrSamples=new Array('gfx/formwind_leistungen/00_ihre-website.jpg','gfx/formwind_leistungen/01_personellnet.jpg','gfx/formwind_leistungen/02_tagesmutter.jpg','gfx/formwind_leistungen/03_floringo.jpg','gfx/formwind_leistungen/04_mique-bone.jpg','gfx/formwind_leistungen/05_aclemenz.jpg','gfx/formwind_leistungen/06_b2b.jpg','gfx/formwind_leistungen/07_strategische-massnahmen.jpg','gfx/formwind_leistungen/08_kickoff.jpg','gfx/formwind_leistungen/09_imagefilm.jpg','gfx/formwind_leistungen/10_imagebroschuere.jpg','gfx/formwind_leistungen/11_imagebroschuere2.jpg','gfx/formwind_leistungen/12_imagebroschuere3.jpg','gfx/formwind_leistungen/13_multimedia.jpg','gfx/formwind_leistungen/14_messeauftritt.jpg','gfx/formwind_leistungen/15_messekonzept.jpg','gfx/formwind_leistungen/16_messekonzept2.jpg','gfx/formwind_leistungen/17_corporate-identity.jpg','gfx/formwind_leistungen/18_janet.jpg','gfx/formwind_leistungen/19_astro.jpg','gfx/formwind_leistungen/20_fels.jpg');
function nextSample()
{
	if(iCurSample+1<arrSamples.length){ iCurSample++; }else{ iCurSample=0; }
	changeImage('sample_img',arrSamples[iCurSample]);
}
function prevSample()
{
	if(iCurSample-1<0){ iCurSample=arrSamples.length-1; }else{ iCurSample--; }
	changeImage('sample_img',arrSamples[iCurSample]);
}

function getPageSize()
{
	 var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

