/*
 * Adbox Script 
 * Sebastian Mach @ ECONA
 * requires JQuery
 *  * 
 * */
var page_set;
var adposition = 0;

function getWindowWidth(win) {   
   if (win == undefined) win = window;   
	     if (win.innerWidth) {   
	         return win.innerWidth;   
	     }   
	     else {   
	         if (win.document.documentElement &&   
	             win.document.documentElement.clientWidth) {   
	             return win.document.documentElement.clientWidth;   
	         }   
	         return win.document.body.offsetWidth;   
	     }   
}   
function resizeadd(w,h)
{
	
	
	var	ct	=	75;// / 2 - h/2;
	var	cl	=	screen.width / 2 - w/2;			
	  jQuery('div.bigad').animate({
		    width: w,		    
		    height: h,
		    top:ct,
		    left:cl
		  }, 500, function() {
		  });
	  jQuery('iframe.adframe').animate({
		    width: w,		    
		    height: h,
		    top:ct,
		    left:cl
		  }, 500, function() {
		  });
		  	  
	  
}
function centeradd()
{
	var cnt = 1;
	var	centeredtop		=	window.innerHeight / 2 - 300;
	var	centeredleft	=	getWindowWidth() / 2 - 400;	
	if (document.getElementById("bigad"))
	{		
		document.getElementById("bigad").style.Top	=	centeredtop+"px";
		document.getElementById("bigad").style.Left	=	centeredleft+"px";
	}	
}

function setwidth()
{
	document.getElementById("darklayer").style.Width	=	"5000px";
}

function startAdbox()
{		
	/* Wenn Seiten gesetzt sind */
	if (page_set && page_set.length > 0)
	{
		/* Werbung zentrierem */
		
		updateCounter();
		jQuery('div.darklayer').hide();			
		var newWidth	=	getWindowWidth() -17;
		var newHeight	=	document.body.offsetHeight;
	
	
	
		
		if (adposition == 0)
		{	
			jQuery('div.prevAd').hide('fast');
		}
		if (document.getElementById("darklayer"))
		{		
			document.getElementById("darklayer").style.width	=	(newWidth)+"px";
			document.getElementById("darklayer").style.Height	=	(newHeight)+"px";
		}
		if (document.getElementById("adnavi"))
		{		
			document.getElementById("adnavi").style.width		=	(newWidth)+"px";
		}						
		jQuery('div.darklayer').animate({
		    opacity: 0.75,		    
		    height: newHeight
		  }, 500, function() {
			  
			/* Ads und navi einblenden */
			  jQuery('div.adnavi').animate({
				    opacity: 0.99,		    
				    height: 40
				  }, 500, function() {
					  
					  jQuery('div.bigad').show("slow");									 					  
					  showAds();						 
				  }) 
			  
		  });
	}else{
		//alert('keine Probefahrten');
	}
}
function closeAdbox()
{
	jQuery('div.bigadshaddow').hide('slow');
	jQuery('div.adnavi').hide('slow');
	jQuery('div.darklayer').hide('slow');
	jQuery('div.bigad').hide('slow');
	
}
function nextAd()
{	
	var	showpos	=	adposition +1;
	var	all		=	page_set.length;
	
	/* ggncheck */
	if (page_set.length > adposition+1)
	{
		adposition++;
		showAds();
	}
	if (adposition == 1)
	{
		jQuery('div.prevAd').show('small');
	}
	if (showpos	==	all-1)
	{
		jQuery('div.nextAd').hide('slow');
	}
}
function prevAd()
{
	var	showpos	=	adposition +1;
	var	all		=	page_set.length;	
	if (adposition > 0)
	{
		/* ggncheck */
		adposition--;
		showAds();
	}

	
	if (all - showpos == 0 )
	{
		jQuery('div.nextAd').show('slow');
	}
	if (adposition	==	0)
	{
		jQuery('div.prevAd').hide('slow');
	}	
}
function showAds()
{
	
	updateCounter();	
	
	if (page_set[adposition]['w'] &&	page_set[adposition]['h'])
	{
		resizeadd(page_set[adposition]['w'],page_set[adposition]['h']);
	}		
	window.open(page_set[adposition]['url'],'bigframe');
}
function updateCounter()
{
	var	showpos	=	adposition +1;
	var	all		=	page_set.length;
	jQuery('div.counter').html('Probefahrt '+showpos+' / '+all);
	jQuery('div.adhead').html(page_set[adposition]['caption']);
}