/*

#   DIVFlow 0.2
#
#   by Julian Sabielny
#   Mathematik for ImageSize is based on Michael L. Perrys Cover flow

*/
						 
function DIVFlow_Init(name, imgdata, einst)
{
	/* Img Data */
	this.imgs = imgdata;   
	this.name = name;
	
	/* Einst */
	this.divID = "over_screen_img";
	
	this.reflectionjs_akt = 0; // Noch nicht implementiert
	
	if( !this.reflectionjs_akt )
	{
		this.reflectionscript_akt = 1;
		this.reflectionscript_trans = 0;
		this.reflectionscript_url = "include/img.php?r=1&h=640&w=480&ns=1&bgc=080706&img=";
		this.reflectionscript_url = "include/img.php?r=0&h=640&w=480&ns=1&bgc=080706&img=";
	}
	
	this.size_reflectionp = 0;
	this.size_imgbig = 0.45;
	this.size_scrollbarp = 0.5;  
									
	this.einst_showimgs = 4;
	this.einst_scroll = 1;
	this.einst_showname = 1;
	this.einst_img = 1;
	this.einst_speed = 200;             
	this.einst_enable = 0;              
	this.einst_closeable = 1;  
									  
	this.msg_loading = '';      
	this.msg_close = '<span style="background-color:#aaa;font-size:12px;padding:3px;">Zur&uuml;ck zur Seite</span>';
	
	this.css_name = 'text-align: center; color:#fff;font-size:13px;';
								 
	this.close_pos = 10;   
										   
	this.slider_img = 'img/divflow/slider_'; 
	this.slider_ext = '.png';  
	this.slider_imgw = 7;   
	this.slider_imgh = 14;   
							   
	this.imgcur = 1; 
	this.imgposgoto = 0;             
	this.imgtotal = 0;   
	this.slider_updating = 0;     
	
	this.slider_imgm = 0;
	this.mouseleftpixels = -1;         
	this.currently_sliding = 0;
	this.imgposcur = this.imgcur*this.einst_speed; 
	
	/* Obj */
	this.obj_div = null;
	this.obj_OverDiv = null;
	this.obj_Slider = null;
	this.obj_Slider_bg = null;
	this.obj_Caption = null;
	this.obj_Close = null;

	/* Funktionen */
	this.Open = DIVFlow_Open;   
	this.Close = DIVFlow_Close;  
	
	this.Load = DIVFlow_Load;                   
	this.Show = DIVFlow_Show;         
	this.GoTo = DIVFlow_GoTo;
	this.GoToTimer = DIVFlow_GoToTimer;
	this.UpdateChanges = DIVFlow_UpdateChanges;  
	this.UpdateScrollbar = DIVFlow_UpdateScrollbar;
	this.ImgInit = DIVFlow_ImgInit;                 
									  
	this.Wheel = DIVFlow_Wheel;
	this.KeyDown = DIVFlow_KeyDown;
	this.MouseMove = DIVFlow_MouseMove;
				 
	this.status = 1;
}

function DIVFlow_Open(cur) {     
	/* Eigener Startcode */               
				   
	IDDisplay("over_screen_trans", "inline"); 
	IDDisplay("over_screen_img","inline"); 
	DimmId("over_screen_trans", 90, 10, -1);      
	   
	/* Eigener Startcode ENDE */   
	this.Load(cur);                                                    
}

function DIVFlow_Close() {  
	this.einst_enable = 0;            
	
	/* Eigener Schließcode */
	
	IDDisplay("over_screen_img","none");
	IDDisplay("over_screen_trans","none");  
	
	/* Eigener Schließcode ENDE */                            
}

function DIVFlow_Load(cur) {
	if( this.status == 1 )
	{                                    
		var version_ar = navigator.appVersion.split("MSIE")
		if( version_ar )
			this.ieversion = parseFloat(version_ar[1])
		
		this.obj_div = document.getElementById(this.divID);      
									
		if( this.einst_scroll )
		{
			this.obj_OverDiv = document.createElement('div');    
			this.obj_OverDiv.id = this.divID+'_OverDiv';    
			this.obj_OverDiv.style.cssText = 'position:absolute;z-index:10004;cursor:pointer;height:100%;width:100%'; 
			this.obj_OverDiv.style.display = "none"; 
			this.obj_div.appendChild(this.obj_OverDiv);   
														  
			this.obj_Slider = document.createElement('div');    
			this.obj_Slider.id = this.divID+'_Slider';
			this.obj_Slider.style.display = "none"; 
			this.obj_Slider.style.cssText = 'position:absolute;z-index:10005;cursor:pointer;height:'+this.slider_imgh+'px;margin-top:-'+(this.slider_imgh/2)+'px;';                                                                
			this.obj_Slider.innerHTML = '<div style="float:left; background-image:url('+this.slider_img+'left'+this.slider_ext+'); width:'+this.slider_imgw+'px; height:'+this.slider_imgh+'px;"></div><div style="float:left; background-image:url('+this.slider_img+'main'+this.slider_ext+'); width:'+this.slider_imgm+'px; height:'+this.slider_imgh+'px" id="'+this.divID+'_SliderMain"></div><div style="float:left; background-image:url('+this.slider_img+'right'+this.slider_ext+'); width:'+this.slider_imgw+'px; height:'+this.slider_imgh+'px;"></div>'; 
			
			eval('this.obj_Slider.onmousedown = function () { '+this.name+'.currently_sliding = 1; '+this.name+'.imgposgoto = '+this.name+'.imgposcur; }');
																	
			eval('document.onmouseup = function (ev) { if( '+this.name+'.currently_sliding ) { '+this.name+'.currently_sliding = 0; '+this.name+'.obj_OverDiv.style.display = "none"; '+this.name+'.mouseleftpixels = -1; '+this.name+'.imgcur = Math.round('+this.name+'.imgposcur/'+this.name+'.einst_speed); '+this.name+'.GoTo('+this.name+'.imgcur); } }');                        
			   
			this.obj_div.appendChild(this.obj_Slider);                                                         
			
			this.obj_SliderBG = document.createElement('div');
			this.obj_SliderBG.id = this.divID+'_SliderBG';
			this.obj_SliderBG.style.display = "none"; 
			this.obj_SliderBG.style.cssText = 'position:absolute;z-index:10002;height:'+this.slider_imgh+'px;margin-top:-'+(this.slider_imgh/2)+'px;border:none;';       
			this.obj_SliderBG.innerHTML = '<div style="width:100%;margin-top:'+(this.slider_imgh/2)+'px;border-top:1px solid #fff;"></div>';                                                                   
			this.obj_div.appendChild(this.obj_SliderBG);    
		}   
			  
		if( this.einst_closeable )
		{
			this.obj_Close = document.createElement('div');
			this.obj_Close.id = this.divID+'_Caption';
			this.obj_Close.style.display = "none"; 
			this.obj_Close.style.cssText = 'position:absolute;z-index:10010;border:none;cursor:pointer;';       
			this.obj_Close.innerHTML = this.msg_close; 
			eval('this.obj_Close.onclick = function () { '+this.name+'.Close();  }');  
			this.obj_div.appendChild(this.obj_Close);     
		}
		   
		if( this.einst_showname )
		{
			this.obj_Caption = document.createElement('div');
			this.obj_Caption.id = this.divID+'_Close';
			this.obj_Caption.style.display = "none"; 
			this.obj_Caption.style.cssText = 'position:absolute;z-index:10002;border:none;'+this.css_name;  
			this.obj_Caption.align = 'center';  
			this.obj_div.appendChild(this.obj_Caption);       
		}
		
		if( cur > this.imgs.length )
			cur = this.imgs.length;
		
		if( !cur || cur < 1 )
			cur = 1;
		
		var curdown = cur;
		var curup = cur+1;                   
		
		while(this.imgtotal<this.imgs.length-1) 
		{
			if( this.imgs[curdown] )
			{
				this.imgtotal++;
				this.imgs[curdown]["obj"] = document.createElement('div');
				this.imgs[curdown]["obj"].id = this.divID+'_Div'+curdown;
				this.imgs[curdown]["obj"].style.cssText = 'position:absolute;border:none;';  
				this.imgs[curdown]["obj"].style.visibility = "hidden";   
				this.imgs[curdown]["obj"].style.display = "none";                                                                 
				
				if( this.reflectionscript_akt ) 
					this.imgs[curdown]["obj"].innerHTML = '<img src="'+this.reflectionscript_url+this.imgs[curdown]["src"]+'" id="'+this.divID+'_Img'+curdown+'" onload="setTimeout(\''+this.name+'.ImgInit('+curdown+');\', 100);" border=0 />';
				else   
					this.imgs[curdown]["obj"].innerHTML = '<img src="'+this.imgs[curdown]["src"]+'" id="'+this.divID+'_Img'+curdown+'" onload="setTimeout(\''+this.name+'.ImgInit('+curdown+');\', 50);" border=0 />';                         
				this.obj_div.appendChild(this.imgs[curdown]["obj"]);   
				curdown--;
			}
			
			if( this.imgs[curup] )
			{
				this.imgtotal++;
				this.imgs[curup]["obj"] = document.createElement('div');
				this.imgs[curup]["obj"].id = this.divID+'_Div'+curup;
				this.imgs[curup]["obj"].style.cssText = 'position:absolute;border:none;';  
				this.imgs[curup]["obj"].style.visibility = "hidden";   
				this.imgs[curup]["obj"].style.display = "none";                                                                 
				
				if( this.reflectionscript_akt )   
					this.imgs[curup]["obj"].innerHTML = '<img src="'+this.reflectionscript_url+this.imgs[curup]["src"]+'" id="'+this.divID+'_Img'+curup+'" onload="setTimeout(\''+this.name+'.ImgInit('+curup+');\', 100);" border=0 />';
				else   
					this.imgs[curup]["obj"].innerHTML = '<img src="'+this.imgs[curup]["src"]+'" id="'+this.divID+'_Img'+curup+'" onload="setTimeout(\''+this.name+'.ImgInit('+curup+');\', 50);" border=0 />';                         
				this.obj_div.appendChild(this.imgs[curup]["obj"]);   
				curup++;
			}  
							  
		}               
		this.einst_showimgs++;                
		
		/* Init Events */
		var tmp = window.onresize;
		eval('window.onresize = function () { if(tmp) tmp(); '+this.name+'.UpdateChanges(); }');
		
		var tmp = document.onkeydown;
		eval('document.onkeydown = function (ev) { if(tmp) tmp(ev); '+this.name+'.KeyDown(ev); }');
		
		var tmp = document.onmousemove;   
		eval('document.onmousemove = function (ev) { if(tmp) tmp(ev); '+this.name+'.MouseMove(ev); }');
		
		if (window.addEventListener)          
			eval('this.obj_div.addEventListener("DOMMouseScroll", function (ev) { '+this.name+'.Wheel(ev); }, false);');        
		eval('this.obj_div.onmousewheel = function (ev) { '+this.name+'.Wheel(ev); }');     
			
		
		this.status = 2;                                     
	}
	
	if( this.status >= 2 )
	{
		this.einst_enable = 1;
		if( cur )
		{
			this.imgcur = cur;
			this.imgposcur = this.imgcur*this.einst_speed;     
		}
		
		this.UpdateChanges();  
	}
}

function DIVFlow_UpdateChanges() { 
	 if( this.einst_enable )
	 {
		 this.w = this.obj_div.offsetWidth;       
		 this.m = this.w*0.46;
		 
		 if( this.einst_scroll )
		 {
			this.slider_imgm = (this.w * this.size_scrollbarp)/this.imgtotal - this.slider_imgw*2;
				   
			this.scrollbarw = this.w * this.size_scrollbarp;
			this.obj_SliderBG.style.width = this.scrollbarw +"px";
			this.obj_SliderBG.style.left = ( this.w - ( this.w * this.size_scrollbarp ) ) / 2 +"px";
			this.obj_SliderBG.style.top = this.m+40 +"px";
			this.obj_SliderBG.style.display = "block";     
		 
			this.obj_Slider.style.width = this.slider_imgw*2+this.slider_imgm+'px';       
			this.obj_Slider.style.top = this.m+40 +'px'; 
			document.getElementById(this.divID+'_SliderMain').style.width = this.slider_imgm+"px"; 
			
			this.obj_Slider.style.display = "block";                                                      
			this.UpdateScrollbar();
		 }            
		 
		 if( this.einst_closeable )
		 {
			this.obj_Close.style.left = this.w - this.obj_Close.offsetWidth - this.close_pos +"px";
			this.obj_Close.style.top = this.close_pos +"px";
			this.obj_Close.style.display = "block";    
		 }  
		 
		 if( this.einst_showname )
		 {                                            
			this.obj_Caption.style.top = this.m +"px";
			this.obj_Caption.style.width = this.w +"px";
			this.obj_Caption.style.display = "block";      
		 }          
		  
		  
		 this.obj_OverDiv.style.display = "none"; 
		 this.Show();           
	 } 
}

function DIVFlow_Show() {    
	if( this.status > 1 && this.einst_enable )
	{               
		var zindex = this.imgcur;
		var pos = -this.imgposcur+this.einst_speed; 
		var imgsize = this.w*this.size_imgbig*2;
		var z, xs;        
	
		for(var x=1; x<=this.imgtotal; x++) 
		{    
			if( this.imgcur+this.einst_showimgs <= x || this.imgcur-this.einst_showimgs >= x )
			{ 
				this.imgs[x]["obj"].style.display = "none";                                  
			}
			else
			{       
				if( this.imgs[x]["loaded"] )
				{                 
					var z = Math.sqrt(10000 + pos * pos) + 100;
					var xs = (pos / z) * this.w * 0.5 + this.w * 0.5;           

					this.imgs[x]["obj"].style.width = this.imgs[x]["pw"] / z * imgsize +"px";  
					this.imgs[x]["obj"].style.left = xs - (this.imgs[x]["pw"]/2) / z * imgsize +"px";   
					this.imgs[x]["obj"].style.height = ( this.imgs[x]["ph"] / z * imgsize ) * (this.size_reflectionp+1) +"px";    
					this.imgs[x]["obj"].style.top = this.m - ( (this.imgs[x]["ph"] / z * imgsize)) - 30 +"px";                                        
									  
					this.imgs[x]["obj"].style.zIndex = 10000-zindex; 
					this.imgs[x]["obj"].style.display = "block"; 
					
					if( this.imgcur > x )
						zindex--;
					else
						zindex++;
						
					if( x == this.imgcur )          
						this.obj_Caption.innerHTML = this.imgs[x]["name"];    
				}       
			} 
			pos += this.einst_speed;
		}   
		this.slider_updating=0;
	}       
}       
			   
function DIVFlow_GoTo(x) {          
	this.imgposgoto = x*this.einst_speed;                                     
		
	setTimeout(this.name+".GoToTimer()", 50);
}


function DIVFlow_GoToTimer() {
	if( this.status <= 1 && !this.einst_enable )
		return;
   
	if( this.imgposgoto > this.imgtotal*this.einst_speed && this.imgposgoto > this.imgposcur-this.einst_speed/4 && this.imgposgoto < this.imgposcur+this.einst_speed/4 )
	{
		this.imgposgoto = this.imgtotal*this.einst_speed;     
	}
	else if( this.imgposgoto < this.einst_speed && this.imgposgoto > this.imgposcur-this.einst_speed/4 && this.imgposgoto < this.imgposcur+this.einst_speed/4 )
	{
		this.imgposgoto = this.einst_speed;         
	}
										  

	if (this.imgposgoto < this.imgposcur-1 || this.imgposgoto > this.imgposcur+1)
	{
		this.imgposcur = (this.imgposcur + (this.imgposgoto-this.imgposcur)/4); 
		this.imgcur = Math.round(this.imgposcur/this.einst_speed); 
		
		this.Show();
								
		this.UpdateScrollbar();
		setTimeout(this.name+".GoToTimer()", 50);
	}  
	else
	{
		this.imgposcur = this.imgposgoto; 
		this.imgcur = Math.round(this.imgposcur/this.einst_speed); 
		
		this.Show();           
		this.UpdateScrollbar();     
	} 
}

function DIVFlow_ImgInit( x ) {  
			 
	if( !this.imgs[x]["loaded"] )
	{        
		var img = document.getElementById(this.divID+'_Img'+x);  
		
		imgs[x]["obj"].style.display = "block"; 
		
		if( img && img.width )
		{                                                           
			/* Init Size */
			this.imgloaded++;              
			
			if( this.imgloaded == this.imgtotal )
			{
				this.status = 3;                                       
			}                                           
				
			this.imgs[x]["ow"] = this.imgs[x]["w"] = img.width;
			this.imgs[x]["oh"] = this.imgs[x]["h"] = img.height; 
			this.imgs[x]["p"] = this.einst_speed*x;   
			this.imgs[x]["loaded"] = 1;
												 
			/* Reflection */                   
			this.imgs[x]["oh"] = img.height/(this.size_reflectionp+1);   
			
			
			if( this.imgs[x]["oh"] > this.imgs[x]["ow"] )
			{                            
				this.imgs[x]["ph"] = 85; 
				this.imgs[x]["pw"] = this.imgs[x]["ph"]/this.imgs[x]["oh"]*this.imgs[x]["ow"];     
			}
			else
			{
				this.imgs[x]["pw"] = 100;
				this.imgs[x]["ph"] = this.imgs[x]["pw"]/this.imgs[x]["ow"]*this.imgs[x]["oh"];                     
			}
			
			
			if( this.reflectionscript_trans && this.ieversion && this.ieversion >= 5.5 && document.body.filters )
			{                  
				img.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+img.src+'\', sizingMethod=\'scale\')';
				img.onload = '';
				img.src = 'http://std-tpl.ovanio.com/img/space.gif';  
			}                                                       
																			 
			img.style.width = "100%";
			img.style.height = "100%";                                       
			eval('img.onclick = function() {'+this.name+'.GoTo('+x+');}');           
			
			this.Show();                                                
														   
			imgs[x]["obj"].style.cursor = "pointer"; 
			imgs[x]["obj"].style.visibility = "visible";  
		}                                          
	}
}

function DIVFlow_UpdateScrollbar() { 
   if( this.einst_scroll && this.einst_enable )          
   {    
		var new_left = ( this.w - ( this.w * this.size_scrollbarp ) ) / 2 + (this.imgposcur-this.einst_speed)/(this.imgtotal*this.einst_speed)*this.scrollbarw;
		
		if( new_left + parseInt(this.obj_Slider.style.width) > this.w )
			new_left = this.w - parseInt(this.obj_Slider.style.width);
		else if( new_left < 0 )
			new_left = 0;
				   
		this.obj_Slider.style.left = new_left +"px";
   }
}   

function DIVFlow_Wheel(ev) {     
   if( this.einst_scroll && this.einst_enable )          
   { 
		var delta = 0;

		ev = ev || window.event; 

		if (ev.wheelDelta)
		{
			delta = ev.wheelDelta/120;
			if (window.opera)   
				delta = -delta;   
		}    
		else if (ev.detail)       
			delta = -ev.detail/3; 

		if (delta)
		{
			if (delta < 0)                                             
				setTimeout(this.name+".GoTo("+(this.imgcur+1)+")", 50); 
			else                                               
				setTimeout(this.name+".GoTo("+(this.imgcur-1)+")", 50);  
		} 
	}
}    

function DIVFlow_KeyDown(ev) {     
   if( this.einst_enable )          
   {         
		ev = ev || window.event;           
		
		if (ev.keyCode == 37)                      
			setTimeout(this.name+".GoTo("+(this.imgcur-1)+")", 50);     
		else if (ev.keyCode == 39)        
			setTimeout(this.name+".GoTo("+(this.imgcur+1)+")", 50);    
   }
   
   return true
}      

function DIVFlow_MouseMove(ev) {     
   if( this.einst_enable && !this.slider_updating && this.currently_sliding == 1 )          
   {     
		ev = ev || window.event;                     
											   
		if(ev.pageX || ev.pageY) 
			var mousex = ev.pageX;      
		else 
			var mousex = ev.clientX;                                       

		if( this.mouseleftpixels == -1 )
		{     
			this.mouseleftpixels = mousex-this.obj_Slider.offsetLeft+( this.w - ( this.w * this.size_scrollbarp ) ) / 2;    
			this.obj_OverDiv.style.display = "block";    
		}                   
		var onepixel = ( this.imgtotal * this.einst_speed ) / this.scrollbarw;   
		
		var imggoto = (mousex-this.mouseleftpixels)*onepixel+this.einst_speed;
																	  
		this.imgposcur = imggoto; 
		this.imgposgoto = this.imgposcur; 
		this.imgcur = Math.round(this.imgposcur/this.einst_speed); 
		
		this.UpdateScrollbar();   

		setTimeout(this.name+".Show();", 50); 
		this.slider_updating = 1;
   }                                                    
	   
	return true;
}                               





/* Eigener Code */  
function IDDisplay(id, str) {
	document.getElementById(id).style.display = str;   
}      

function DimmId( id, stop, step, start )
{                          
	var Obj = document.getElementById(id);
   
	if( Obj.getAttribute('AlphaLocked') )    
		setTimeout("DimmId('"+id+"', "+stop+", "+step+", 0)", 500 );  
	else
		DimmGoto( id, stop, step, start );
	  
}    

function DimmGoto( id, stop, step, start )
{                          
	var Obj = document.getElementById(id);
	
	if( parseInt(Obj.getAttribute('AlphaCur')) )
		var val = parseInt(Obj.getAttribute('AlphaCur'));
	else
		var val = start;

	if( !val || start == -1 )
		val = 0;       
			
	if( stop >= val )
	{
		val = val + step;
		var action = 1;
	}
	else 
	{
		val = val - step;  
		var action = 0;
	}  
	
	if( val > 100 )
		val = 100;
	else if( val < 0 )
		val = 0;
		
	var setval = val/100;   
	
	Obj.style.filter="alpha(opacity:"+val+")";
	Obj.style.KHTMLOpacity=+setval;
	Obj.style.MozOpacity=setval;
	Obj.style.opacity=setval;  
	Obj.setAttribute('AlphaCur', val);     
	
	if( (action == 1 && stop > val) || (action == 0 && stop < val) )
	{   
		setTimeout("DimmGoto('"+id+"', "+stop+", "+step+", 0)", 50 );
		Obj.setAttribute('AlphaLocked', "yes");        
	}
	else
		Obj.setAttribute('AlphaLocked', '');     
}