/*--------------------------------------------------------------------------
 *  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,
	
	objMain:false,
	element_width:0,
	scroll_elements:0,
	
	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(){
		
			
		window.clearInterval(Scroller.animationId);		
		Scroller.isSliding=true;						
		Scroller.frameToPos = parseInt(Scroller.objMain.style['left']) + Scroller.width;
	
			Scroller.animationId=window.setInterval(function(){
															 
				var framePos = parseInt(Scroller.objMain.style['left'])||0;								
				var x = Scroller.calculateDecel(framePos, Scroller.frameToPos);				
				x =  parseInt(framePos - x);		
				//Scroller.objMain.scrollLeft = 	(x) + 'px';
				Scroller.objMain.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){
		//handel to point		
	
		
		if(Scroller.isSliding == true){
			return;
		}
		
		if(s == "r"){
			//nicht grˆfler als max			
				
			if(!(parseInt(Scroller.objMain.style['left']) <= (Scroller.element_widht+350))){				
				Scroller.width = -350;		
				Scroller.animateSlide();				
				 //alert('ice-element_' + (parseInt(objSlider.getAttribute('rel')) + 0));
			}
		}
		
		if(s == "l"){
			//nicht kleiner 1			
			if(!(parseInt(Scroller.objMain.style['left']) >= 0)){
				Scroller.width = +350;				
				Scroller.animateSlide();
				 //alert('ice-element_' + (parseInt(objSlider.getAttribute('rel')) - 1));
			}
		}		
	},
		
	// initializer that adds the renderer to the onload function of the window
	render: function(){
		
		if(!$("img_holder_set")){			
			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.objMain = $("img_holder_set");
		
		
		Scroller.element_widht = Scroller.objMain.offsetWidth;	
		Scroller.scroll_elements =  Scroller.element_widht / 350;
		Scroller.element_widht = Scroller.element_widht * -1;
		Scroller.objMain.style.left = '0px';
		
		$("btn_arrow_left").onclick = function () { 
				 					Scroller.clickArrow("l");							
								}	

		$("btn_arrow_right").onclick = function () { 
				 					Scroller.clickArrow("r");							
								}	
		
		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
/*-----------------------------------------------------------*/