var liHeight = 124;
//var ulHeight = 372;
var ulHeight = 422;

var btMargin = 0; //contains the current margin value of the slider!
var btMove = 1; //contains the amount of which to change the margin by!
var fxSlide = null;

function btSlider() {
	var btUl = $$('div#sliderListWrapper ul')[0];
		
	if (btMargin<=-liHeight && btMove > 0) { //If the slider is travelling bottom
		var li = $$('div#sliderListWrapper li:first-child'); //Gets the 1st li in the list
		li.inject(btUl, 'bottom'); // places 1st li to the end of the ul, making it the last
		btUl.setStyle('margin-top','0px'); // resets margin to 0
		btMargin = 0;
	} 
	
	if (btMargin>=0 && btMove < 0) { //If the slider is travelling right
		var li = $$('div#sliderListWrapper li:last-child');
		li.inject(btUl, 'top');
		btUl.setStyle('margin-top','-' + liHeight + 'px');
		btMargin = -liHeight;
	}
	
	var fxSlide = new Fx.Morph(btUl, {duration:1, link:'ignore'});
	fxSlide.start({ 'margin-top': [(btMargin-btMove) + 'px'] });
	fxSlide.addEvent('complete', function() {
		btMargin = btMargin-btMove;
		btSlider();
	});
};


window.addEvent('domready', function() {
	
	var btFx = new Fx.Morph('rightContent', {duration: 750, transition: Fx.Transitions.Sine.easeOut, link: 'cancel'});
	
	var btW = $('sliderWrapper');
		 
	btW.addEvent('mousemove', function(event) { MouseMove(event); });
			
	var btUl = $$('div#sliderListWrapper ul')[0]; //Retrieves the UL of shows
	var btLi = $$('div#sliderListWrapper li')
	var btMl = (((btLi.length*liHeight) - ((btLi.length*liHeight)*2))/2) + (ulHeight/2);
	btUl.setStyles({ 'height': (btLi.length*liHeight)	}); //Sets the width of the UL 
	
	for (x=0; x<btLi.length; x++) {
		var a = btLi[x].getChildren('a')[0];
		a.addEvent('click', function(event) {
			//event.stop();
		});
		
		a.addEvent('mouseenter', function() { //On mouse over of an A tag we want to stop the scrolling and display a nice border around the A tag
			btW.removeEvents('mousemove');
			var li = this.getParent();
			
			if (btMove > 0) { //If we are moving left then we need to place the tool tip on the right
				//btMove = 0.25;
			} else { //If we are moving right then we need to place the tool tip on the left
				//btMove = -0.25;
			}
			
		});
		
		a.addEvent('mouseleave', function() {
			btW.addEvent('mousemove', function(event) { MouseMove(event); });				
			this.getParent().set('class', '');
			if ($('bookTicketsToolTip')!=null) { $('bookTicketsToolTip').destroy(); }
			//tooltip = false;
		});
	} //loops through each li and assigns a click event to the a tag!
	
	(function() { btSlider() }).delay(100); // Starts the sliding!
	
	function MouseMove(event) {		
		var btPos = btW.getPosition(); //contains the position of div#sliderWrapper
		var mouseX = event.client.y - btPos.y; //contains the x-coord of the mouse position relative to the position of div#sliderWrapper
		var btCentre = btW.getSize();
		btCentre = (btCentre.y)/2; //contains the position of the center of div#sliderWrapper, so we can calc how fast and in which direction we need to move the ul
		var mouseXC = btCentre - mouseX; //contains the mouse pos relative to the centre point
		btMove = Math.round((mouseXC/(ulHeight/2))*10); // calcs thenumber of sections thats change the speed variation
		
		if (btMove>=5) {
			btMove = btMove-4;
		} else if (btMove<=4 && btMove>2) {
			btMove = 0.75;
		} else if (btMove<=2 && btMove>0) {
			btMove = 0.25;
		} else if (btMove>=-2 ) {
			btMove = -0.25;
		} else if (btMove>=-4) {
			btMove = -0.75;
		} else if (btMove<=-5) {
			btMove = btMove+4;
		}
		//helper.innerHTML =  btMove;
	};
		
});


