/* ::---------------------------------------------------------------
:: +	slideit.js
	2009.07.08
	roberto cornice
	cornice@lemm.de

:: +	Slider für jQuery (immitiert mTheatre)

:: +	[c] 2009 by Lemm Werbeagentur GmbH

	------------------------------------------------------------::
	
	
:: +	Aufruf

		jQuery(document).ready(function() {
    		bs			= new slideIt("slideshowContainer");		//::> Id des Divs
    		bs.cWidth	= "520px";									//::> Breite
    		bs.cHeight	= "307px";									//::> Höhe
    		bs.speed	= 1000;										//::> Geschwindigkeit
			bs.start();												//::> Feuer
		});

*/

function slideIt(slideContainer) 		{
	
	this.cWidth		= "0";
	this.cHeight	= "0";
	
	this.slideContainer		= slideContainer;
	
	this.slideContent	= Array();
	
	this.frequenz		= 3500;
	this.slidespeed		= 500;
	this.fadeoutSecs	= 750;
	this.maxDisplay		= 2;
	this.startAlpha		= 100;
	this.directionAction= false;
	//::> do not change ::>		
	this.bilderIndex		= 1;
	this.slideShowDivIndex1	= 1;
	this.slideShowDivIndex2	= 2;
	this.slideShowDivIndex	= 0;
	this.timeout;
	this.hold			= false;
	this.tempContent	= Array();
	this.xDir			= -1;
	this.yDir			= 0;
	this.control;
	
	this.direction		= 1;
	
	this.da	= Array();
	this.da["circular"]	= Array();
	this.da["circular"][0]	= new Array( 1, 0 );
	this.da["circular"][1]	= new Array( 0, 1 );
	this.da["circular"][2]	= new Array( -1, 0 );
	this.da["circular"][3]	= new Array( 0, -1 );
	
	
	this.slideCounter	= 0;
	
	this.init	= function()	{
		
		if ( this.cWidth == "auto" )	{
			this.cWidth	= $("#"+this.slideContainer).width();
		}
		
		if ( this.cHeight == "auto" )	{
			this.cHeight	= $("#"+this.slideContainer).height();
		}
		//alert (this.cWidth+" - "+this.cHeight);
		var slide = this;
		$("#"+this.slideContainer).css(
			{
				"overflow":"hidden",
				"position":"relative"
			}
		);
		$("#"+this.slideContainer+" ul").css(
			{
				"margin": "0",
				"padding": "0"
			}
		);
		
		var moi	= this;
		$("#"+this.slideContainer+" ul li").each(function() {
				this.style.margin	= "0";
				this.style.padding	= "0";
				this.style.display	= "inline";
				moi.slideContent.push("<div style=\"float:left;\">"+this.innerHTML+"</div>");    					
		});
		
		
		$("#"+this.slideContainer).html(
			"<div id=\""+this.slideContainer+"_"+"slideShowDiv1\"></div>"+
			"<div id=\""+this.slideContainer+"_"+"slideShowDiv2\"></div>"
		);
		


		$("#"+this.slideContainer).css(
			{
				
	    		"width": this.cWidth,
	    		"height": this.cHeight,
	    		"overflow":	"hidden"
			}
		);
		
		
		$("#"+this.slideContainer+"_"+"slideShowDiv1").css(
			{
				"position":		"absolute",
				"width":		"100%",
	    		"overflow":		"hidden",
	    		"left":			"0"
			}
		);
		
		$("#"+this.slideContainer+"_"+"slideShowDiv2").css(
			{
				"position":		"absolute",
	    		"width":		"100%",
	    		"overflow":		"hidden",
	    		"left":			"0"
			}
		);
		
		if (this.xDir!=0)	{
			$("#"+this.slideContainer+"_"+"slideShowDiv1").css(
				{
		    		"margin-left":	this.cWidth
				}
			);
			
			$("#"+this.slideContainer+"_"+"slideShowDiv2").css(
				{					
		    		"margin-left":	0
				}
			);
		}
		
		if (this.yDir!=0)	{
			$("#"+this.slideContainer+"_"+"slideShowDiv1").css(
				{
		    		"margin-top":	this.height
				}
			);
			
			$("#"+this.slideContainer+"_"+"slideShowDiv2").css(
				{					
		    		"margin-top":	0
				}
			);
		}
		
		//alert(this.slideContent.length);
	//	alert(this.maxDisplay);
		//if (this.slideContent.length=<this.maxDisplay)	{
			//return;
		//}
		slideBilder	= this.getBilder();			
		for (b=0;b < slideBilder.length; b++)	{
			$("#"+this.slideContainer+"_"+"slideShowDiv2").append(
				slideBilder[b]
			);	
		}
		if (this.slideContent.length<=this.maxDisplay)	{
			return
		}
		
		this.timeout	= setTimeout(				
			function() { 
				
					slide.bilderShow()
										
			}, this.frequenz
		);   
		
	}
	
	this.slideMoar	= function( direction )	{
		if( this.direction == 1 && direction == -1  )	{
			this.bilderIndex = this.bilderIndex - this.maxDisplay + 1;	
			if( this.bilderIndex < 0 )	{
				this.bilderIndex	= this.bilderIndex + this.slideContent.length - 0;
			}
		} else if( this.direction == -1 && direction == 1  )	{
			this.bilderIndex = this.bilderIndex + this.maxDisplay - 1;
			if( this.bilderIndex > (this.slideContent.length -1 ) )	{
				this.bilderIndex	= this.bilderIndex - this.slideContent.length - 0;
			}
		}
		this.direction	= direction;
		this.xDir		= 1 * direction;
		this.bilderShow();
	}
	this.slideLess	= function()	{
		this.bilderShow();
	}
	
	this.bilderShow = function()	{
		
		// Pause-Modus	
		if (this.hold)	{
			return;
		}
				
		
		if( this.directionAction == "circular" )	{
			this.xDir	= this.da["circular"][this.slideCounter][0];
			this.yDir	= this.da["circular"][this.slideCounter][1];
		}
		//alert(this.cWidth);
		if (this.xDir!=0)	{
			$("#"+this.slideContainer+"_"+"slideShowDiv"+this.slideShowDivIndex1).css({
				'z-index' : '5',
				'display' : 'block',
				'margin-left' : String(this.xDir * parseInt(this.cWidth) )+"px",
				'opacity'	: 0
				}
			);
		}
		if (this.yDir!=0)	{
			$("#"+this.slideContainer+"_"+"slideShowDiv"+this.slideShowDivIndex1).css({
				'z-index' : '5',
				'display' : 'block',
				'margin-top' : String(this.yDir * parseInt(this.cHeight) )+"px",
				'opacity'	: 0
				}
			);
		}
		
		$("#"+this.slideContainer+"_"+"slideShowDiv"+this.slideShowDivIndex2).css({
			'z-index' : '4'
			}
		);
		
		
		$("#"+this.slideContainer+"_"+"slideShowDiv"+this.slideShowDivIndex1).html("");
		
		var slideBilder	= Array();
		
		slideBilder	= this.getBilder();			
		for (b=0;b < slideBilder.length; b++)	{
			$("#"+this.slideContainer+"_"+"slideShowDiv"+this.slideShowDivIndex1).append(
				slideBilder[b]
			);	
		}
		$("#"+this.slideContainer+"_"+"slideShowDiv"+this.slideShowDivIndex2).fadeOut(this.fadeoutSecs);
		if (this.xDir!=0)	{
			$("#"+this.slideContainer+"_"+"slideShowDiv"+this.slideShowDivIndex1).animate({ 
				marginLeft: "0",
				opacity: 1
	
				}, this.slidespeed, 
				"",
				function()	{
					if ($.browser.msie){this.style.removeAttribute('filter');}
				}
			);
		}
		this.slideCounter++;
		
		if( this.slideCounter > 3 )	{
			this.slideCounter = 0;
		}
		
		if (this.yDir!=0)	{
			$("#"+this.slideContainer+"_"+"slideShowDiv"+this.slideShowDivIndex1).animate({ 
				marginTop: "0",
				opacity: 1
	
				}, this.slidespeed
			);
		}

		
		this.slideShowDivIndex++;
		if (this.slideShowDivIndex==2)	{
			this.slideShowDivIndex=0;
			this.slideShowDivIndex1	= "1";
			this.slideShowDivIndex2	= "2";
		} else {
			this.slideShowDivIndex1	= "2";
			this.slideShowDivIndex2	= "1";
		}
		var slide = this;
		clearTimeout(this.timeout);
		this.timeout	= setTimeout(
			function() { 
				slide.bilderShow();
			}, this.frequenz
		);	
		
		
	}
	
	this.getBilder = function()	{	

		var returnArray	= Array();
		for (b=0; b<this.maxDisplay; b++)	{
			
			if( this.direction == 1 )	{
				this.bilderIndex++;
				if( this.bilderIndex >= this.slideContent.length )	{
					this.bilderIndex=0;
				}
			} else {
				this.bilderIndex--;
				if( this.bilderIndex < 0 )	{
					this.bilderIndex = this.slideContent.length-1;
				}
			}
			returnArray[b]	= this.slideContent[this.bilderIndex];
		}
		if( this.direction == -1 )	{
			returnArray.reverse();
		}
		return returnArray;
	}
	this.notbremse	= function()	{
		clearTimeout(this.timeout);
		$("#"+this.slideContainer+"_"+"slideShowDiv"+this.slideShowDivIndex2).stop();
		$("#"+this.slideContainer+"_"+"slideShowDiv"+this.slideShowDivIndex1).stop();
		this.hold	= true;
	}
}
