/*--------------------------------------------------------------------------
 *  Smooth Scroller Script, version 1.0.1
 *  (c) 2007 Dezinerfolio Inc. <midart@gmail.com>
 *
 *  For details, please check the website : http://dezinerfolio.com/
 *
/*--------------------------------------------------------------------------*/

Scroller = {
	// control the speed of the scroller.
	// dont change it here directly, please use Scroller.speed=50;		
	tx:0,
	speed:8,
	width:0,
	animationId:false,
	isSliding:false,
	
	objMainLilly:false,
	objMainMax:false,
	element_widthLilly:0,
	element_widthMax:0,
	scroll_elementsLilly:0,
	scroll_elementsMax:0,
	
	element_width:360,
	
	frameToPos:0,	
	scroll_width:470,
	scroll_border:12,
	scroll_element_width:20,
	
	start_element:10,
	first_start_silderh:0,
	ie:false,
	scroll_elements_counts:0,
	silderh_width:34,
	scrollerOBJ:"team_scroll_holder",
				
							
	// attach an event for an element
	// (element, type, function)
	add: function(event, body, d) {
	    if (event.addEventListener) return event.addEventListener(body, d,false)
	    if (event.attachEvent) return event.attachEvent('on'+body, d)
	},

	// kill an event of an element
	end: function(e){
		if (window.event) {
			window.event.cancelBubble = true
			window.event.returnValue = false
      		return;
    	}
	    if (e.preventDefault && e.stopPropagation) {
	      e.preventDefault()
	      e.stopPropagation()
	    }
	},
	
	echo: function(s){ 
    	var elDebug = document.getElementById("debug");
    	elDebug.innerHTML = "<p> " + s + "</p>" + elDebug.innerHTML;	
	},
	
	
	// returns the X position of the div
	/*showArrows: function () {
		
		//nur einen
		if(parseInt(Scroller.objMain.style['left']) == 0){
			$("btn_arrow_left").style.display = 'none';
			$("btn_arrow_right").style.display = 'block';
			$("btn_arrow_right").style.top = '400px';
			if(!Scroller.ie)
				Scroller.objMain.style.top =  '-40px';	
			return;
		}
		
		if(parseInt(Scroller.objMain.style['left'])  <= (Scroller.element_widht+350)){
			$("btn_arrow_left").style.display = 'block';
			$("btn_arrow_right").style.display = 'none';
				if(!Scroller.ie)
					Scroller.objMain.style.top =  '-40px';	
			return;
		}		
		$("btn_arrow_left").style.display = 'block';
		$("btn_arrow_right").style.display = 'block';
		if(!Scroller.ie)
			$("btn_arrow_right").style.top = '360px';
		if(!Scroller.ie)
			Scroller.objMain.style.top =  '-80px';	
		
		return;
	},*/
	
	animateSlide:function(fewo){
		
			
		window.clearInterval(Scroller.animationId);		
		Scroller.isSliding=true;	
		
		if(fewo == "lilly"){
			Scroller.frameToPos = parseInt(Scroller.objMainLilly.style['left']) + Scroller.width;								
		}
		if(fewo == "max"){
			Scroller.frameToPos = parseInt(Scroller.objMainMax.style['left']) + Scroller.width;							
		}
				
		
	
			Scroller.animationId=window.setInterval(function(){				
				if(fewo == "lilly"){
					var framePos = parseInt(Scroller.objMainLilly.style['left'])||0;								
				}
				if(fewo == "max"){
					var framePos = parseInt(Scroller.objMainMax.style['left'])||0;								
				}
				var x = Scroller.calculateDecel(framePos, Scroller.frameToPos);				
				x =  parseInt(framePos - x);		
				//Scroller.objMain.scrollLeft = 	(x) + 'px';
				if(fewo == "lilly"){
					Scroller.objMainLilly.style.left =  x + 'px';									
				}
				if(fewo == "max"){
					Scroller.objMainMax.style.left =  x + 'px';									
				}
				
				if(x == Scroller.frameToPos){
					window.clearInterval(Scroller.animationId);
					Scroller.isSliding=false;
					//Scroller.showArrows();
				}
			}, 30);

	},
	
	calculateDecel:function(from,to){
		/*var n=from-Math.floor((from-to)*.4);
		if(Math.abs(from-to)<4)return to;
		else return n;*/
		ix = from - to;	
		
		ax =  Math.ceil( ix / Scroller.speed )
	//	ax = ix*.4
		if(ax == 0 && Math.abs(ix) > 0)
			ax =  ix / Scroller.speed;

		return ax;
	},
		
	clickArrow: function(s, fewo){
		//handel to point		
			
		if(Scroller.isSliding == true){
			return;
		}
			
		if(s == "r"){
			//nicht grˆfler als max			
			
			if(fewo == "lilly"){
				if(!(parseInt(Scroller.objMainLilly.style['left']) <= (Scroller.element_widhtLilly + Scroller.element_width))){				
					Scroller.width = Scroller.element_width * -1;	
					Scroller.animateSlide(fewo);								
				}
			}
			if(fewo == "max"){
				if(!(parseInt(Scroller.objMainMax.style['left']) <= (Scroller.element_widhtMax + Scroller.element_width))){				
					Scroller.width = Scroller.element_width * -1;		
					Scroller.animateSlide(fewo);									 
				}
			}
		}
		
		if(s == "l"){
			//nicht kleiner 1	
				
			if(fewo == "lilly"){			
				if(!(parseInt(Scroller.objMainLilly.style['left']) >= 0)){				
					Scroller.width = Scroller.element_width;	
					Scroller.animateSlide(fewo);								
				}
			}
			if(fewo == "max"){
				if(!(parseInt(Scroller.objMainMax.style['left']) >= 0)){				
					Scroller.width = Scroller.element_width;		
					Scroller.animateSlide(fewo);									 
				}
			}						
		}		
	},
		
	// initializer that adds the renderer to the onload function of the window
	render: function(){
		
		if(!$("fewo_lilly_pixx_in_holder")  && !$("fewo_max_pixx_in_holder")){			
			return false;	
		}

		//if ie?	
		
		         var browser=navigator.appName;
				 var b_version=navigator.appVersion;
				 var version=parseFloat(b_version); 
		 if((browser == "Microsoft Internet Explorer")){
			
			if (typeof document.body.style.maxHeight != "undefined") {
				//ie7 = true;
			} else {
				Scroller.ie = true;
			}
			
		}	
		
		//Scroller.ie = (document.all && !window.opera) ? true : false;			
		//rack!		
		Scroller.objMainLilly = $("fewo_lilly_pixx_in_holder");
		Scroller.objMainMax = $("fewo_max_pixx_in_holder");
		
		
		Scroller.element_widhtLilly = Scroller.objMainLilly.offsetWidth;	
		Scroller.element_widhtMax = Scroller.objMainMax.offsetWidth;
		
		Scroller.scroll_elementsLilly =  Scroller.element_widhtLilly / Scroller.element_width;
		Scroller.scroll_elementsMax =  Scroller.element_widhtMax / Scroller.element_widht;
		
		Scroller.element_widhtLilly = Scroller.element_widhtLilly * -1;
		Scroller.element_widhtMax = Scroller.element_widhtMax * -1;
		
		Scroller.objMainLilly.style.left = '0px';
		Scroller.objMainMax.style.left = '0px';
		
		$("btn_lilly_back").onclick = function () { 
				 					Scroller.clickArrow("l", "lilly");							
								}																

		$("btn_lilly_next").onclick = function () { 
				 					Scroller.clickArrow("r", "lilly");							
								}	
		
		$("btn_max_back").onclick = function () { 
				 					Scroller.clickArrow("l", "max");							
								}																

		$("btn_max_next").onclick = function () { 
				 					Scroller.clickArrow("r", "max");	
					
								}
		//Scroller.showArrows();
		
	},
	
	
	// initializer that adds the renderer to the onload function of the window
	init: function(){		
		
		Scroller.add(window,'load', Scroller.render);		
		//Scroller.add(window,'load', Scroller.render)
	}
	
}
// invoke the initializer of the scroller
Scroller.init();

/*------------------------------------------------------------
 *						END OF CODE
/*-----------------------------------------------------------*/
