 //
 // Cityguide Lineup Scroller
 // © eymedia.ch
 // sbe
 //


var ds_shown = 6; 				// Visible Datasets (Fix Valiue for this Project)
var ds_width = 149; 			// Width for the  Dataset  (Fix Valiue for this Project)
var arrow_l;					// Name for the Left Arrow
var arrow_r;					// Name for the Right Arrow
var ds_count; 					// Amount  of the Datasets(Should be posted from PHP)
var direction; 					// possible directions 'back' and 'forward'
var layer;  					// id of the Moving Div Layer
var xmove;						// X Valiue for the Movement
var img_name;					// Image Name for the Changing Image
var img_source;					// Image Path for the Changing Image
var sliderpos;
var slidesteps_big;
var slidestep_last;
var clicktimeout = false;		//this makes the arrows clickable
var activelayer;
var globalLayer = '';
var globalXMove = 0;
var t = '';
var loop = 0;
//Change arrow Image
function change_img(img_name,img_src) {
	$(img_name).src=img_src;
}
	
//function should detect wich arrow should be swichtched (but it dont get the variabels propper frome the muve_lineup() function
function arrow_finder(sliderpos, arrow_l, arrow_r, slidesteps_big, slidestep_last){
	if(sliderpos == 0)
	{
	change_img(arrow_l,'images/buttons/arrow_right_inactive.gif');		   
	}
	if(sliderpos < 0)
	{
	change_img(arrow_l,'images/buttons/arrow_right.gif');		   
	}
	if(sliderpos <= -(((slidesteps_big - 1) * (ds_width * ds_shown )) + (slidestep_last * ds_width)))
	{
	change_img(arrow_r,'images/buttons/arrow_right_inactive.gif');	 
	}
	if(sliderpos > -(((slidesteps_big - 1) * (ds_width * ds_shown )) + (slidestep_last * ds_width)))
	{
	change_img(arrow_r,'images/buttons/arrow_right.gif');	 
	}
}
 
 
//widerklicken
function makeclickable(){
	clicktimeout=false;
}
	
//Move Function
function move_lineup(direction, layer, ds_count, arrow_l, arrow_r){
	
	if(clicktimeout==true){
		return;
	} else {
	}
		
	activelayer = layer;
	clicktimeout=true;																								// Disable the onClick event
	setTimeout('makeclickable()', 2500);																				// Enable the onClick event after 1.5 sec gain
	var slidesteps = ds_count / ds_shown; 																				// Caalculates the Amount for the Big Steps
	slidesteps_big = Math.floor(slidesteps);																			// Amount for the Big Steps
	slidestep_last = ds_count - (ds_shown * slidesteps_big);														// Caalculates the last small Step
	sliderpos =  $(layer).offsetLeft;																					// Checks the actual Position of the Slide div Layer  
   
   
	
   
    //Move Back
		if(direction == 'back')
	  {
		if(sliderpos <= -(ds_shown * ds_width))																		// Calculate the Big 'xmove' xvaliue
		{
			xmove = ds_shown * ds_width;
			change_img(arrow_r,'images/buttons/arrow_right.gif');
			
			if(sliderpos==-894)
				change_img(arrow_l,'images/buttons/arrow_left_inactive.gif');
				
		}else if(sliderpos > -(ds_shown * ds_width) && sliderpos < 0){												// Calculate the small 'xmove' xvaliue for the last Moving
		xmove = slidestep_last * ds_width;
		change_img(arrow_l,'images/buttons/arrow_left_inactive.gif');																	// Disable the Left Arrow Image
		change_img(arrow_r,'images/buttons/arrow_right.gif');
		}else if(sliderpos == 0){																						// Calculate the the end of the slider and set the 'xmove' xvaliue to 0
		xmove = 0;
		}
		
	}
	
	//Move Forward
	if(direction == 'forward')
   {
   
 		if(sliderpos > -((slidesteps_big - 1) * (ds_width * ds_shown )))												// Calculate the Big 'xmove' xvaliue
		{
		xmove = -(ds_shown * ds_width);
		change_img(arrow_l,'images/buttons/arrow_left.gif');																	// Enable the Left Arrow Image
		}else if(sliderpos == -((slidesteps_big - 1) * (ds_width * ds_shown ))){										// Calculate the small 'xmove' xvaliue for the last Moving		
		xmove = -(slidestep_last * ds_width);
		change_img(arrow_r,'images/buttons/arrow_right_inactive.gif');
		change_img(arrow_l,'images/buttons/arrow_left.gif');																	// Disable the Right Arrow Image
		}
		else if(sliderpos <= -(((slidesteps_big - 1) * (ds_width * ds_shown )) + (slidestep_last * ds_width))){		// Calculate the the end of the slider and set the 'xmove' xvaliue to 0
		xmove =0;
		}		
	
	}
	
	loop = 0;
	globalLayer = layer;
	globalXMove = xmove;
	
	new Effect.Move(layer, { x: xmove, mode: 'relative', duration: 2.0 }); 														// Movemend Command with preseted valiues

	if($(layer).offsetLeft>0){
		change_img(arrow_l,'images/buttons/arrow_left_inactive.gif');
	}   
 
 	window.setTimeout('checkLeftPosition()', 2000);
 

    } 
    
    function checkLeftPosition(){
    	if($('lineup_slider_1').offsetLeft==0)
    		change_img('pfeil_l_1','images/buttons/arrow_left_inactive.gif');
    	if($('lineup_slider_2').offsetLeft==0)
    		change_img('pfeil_l_2','images/buttons/arrow_left_inactive.gif');
    }

      