var totalScrollItems = 5;
var currentSI = 1;
var currentCircle = "hc1";
var targetSI = 1;
var difference = 0;
var pId=0;

window.addEvent('domready', function(){
	$('navImg1').addEvents({		
		'mouseenter': function(){
			if (pId != 1) {
				this.src="images/nav/aboutusb.jpg";
			}
		},
		'mouseleave': function(){
			if (pId != 1) {
				this.src="images/nav/aboutusa.jpg";
			}
		},
		'mousedown': function(){
			if (pId != 1) {
				this.src="images/nav/aboutusc.jpg";
			}
		}
	});

	$('navImg2').addEvents({		
		'mouseenter': function(){
			if (pId != 2) {
				this.src="images/nav/newmotorb.jpg";
			}
		},
		'mouseleave': function(){
			if (pId != 2) {
				this.src="images/nav/newmotora.jpg";
			}
		},
		'mousedown': function(){
			if (pId != 1) {
				this.src="images/nav/newmotorc.jpg";
			}
		}
	});

	$('navImg3').addEvents({		
		'mouseenter': function(){
			if (pId != 3) {
				this.src="images/nav/usedmotorb.jpg";
			}
		},
		'mouseleave': function(){
			if (pId != 3) {
				this.src="images/nav/usedmotora.jpg";
			}
		},
		'mousedown': function(){
			if (pId != 1) {
				this.src="images/nav/usedmotorc.jpg";
			}
		}
	});

	$('navImg4').addEvents({		
		'mouseenter': function(){
			if (pId != 4) {
				this.src="images/nav/workshopb.jpg";
			}
		},
		'mouseleave': function(){
			if (pId != 4) {
				this.src="images/nav/workshopa.jpg";
			}
		},
		'mousedown': function(){
			if (pId != 1) {
				this.src="images/nav/workshopc.jpg";
			}
		}
	});

	$('navImg5').addEvents({		
		'mouseenter': function(){
			if (pId != 5) {
				this.src="images/nav/accessoriesb.jpg";
			}
		},
		'mouseleave': function(){
			if (pId != 5) {
				this.src="images/nav/accessoriesa.jpg";
			}
		},
		'mousedown': function(){
			if (pId != 1) {
				this.src="images/nav/accessoriesc.jpg";
			}
		}
	});

	$('navImg6').addEvents({		
		'mouseenter': function(){
			if (pId != 6) {
				this.src="images/nav/faqb.jpg";
			}
		},
		'mouseleave': function(){
			if (pId != 6) {
				this.src="images/nav/faqa.jpg";
			}
		},
		'mousedown': function(){
			if (pId != 1) {
				this.src="images/nav/faqc.jpg";
			}
		}
	});

	$('navImg7').addEvents({		
		'mouseenter': function(){
			if (pId != 7) {
				this.src="images/nav/howtofindb.jpg";
			}
		},
		'mouseleave': function(){
			if (pId != 7) {
				this.src="images/nav/howtofinda.jpg";
			}
		},
		'mousedown': function(){
			if (pId != 1) {
				this.src="images/nav/howtofindc.jpg";
			}
		}
	});

	$('hc1').addEvents({		
		'mousedown': function(){
			$(currentCircle).src = "images/home/homecircleblack.jpg";
			this.src = "images/home/homecircleorange.jpg";
			targetSI = 1;
			var newPos = (targetSI-1) * 620;
			newPos = -newPos + "px";
			$('picScroller').set('tween', {
				duration: 2000,
				transition: Fx.Transitions.Quad.easeIn // This could have been also 'bounce:out'
			}).tween('margin-left', newPos);
			currentSI = targetSI;
			currentCircle = this.id;
		}
	});

	$('hc2').addEvents({		
		'mousedown': function(){
			$(currentCircle).src = "images/home/homecircleblack.jpg";
			this.src = "images/home/homecircleorange.jpg";
			targetSI = 2;
			var newPos = (targetSI-1) * 620;
			newPos = -newPos + "px";
			$('picScroller').set('tween', {
				duration: 2000,
				transition: Fx.Transitions.Quad.easeIn // This could have been also 'bounce:out'
			}).tween('margin-left', newPos);
			currentSI = targetSI;
			currentCircle = this.id;
		}
	});

	$('hc3').addEvents({		
		'mousedown': function(){
			$(currentCircle).src = "images/home/homecircleblack.jpg";
			this.src = "images/home/homecircleorange.jpg";
			targetSI = 3;
			var newPos = (targetSI-1) * 620;
			newPos = -newPos + "px";
			$('picScroller').set('tween', {
				duration: 2000,
				transition: Fx.Transitions.Quad.easeIn // This could have been also 'bounce:out'
			}).tween('margin-left', newPos);
			currentSI = targetSI;
			currentCircle = this.id;
		}
	});

	$('hc4').addEvents({		
		'mousedown': function(){
			$(currentCircle).src = "images/home/homecircleblack.jpg";
			this.src = "images/home/homecircleorange.jpg";
			targetSI = 4;
			var newPos = (targetSI-1) * 620;
			newPos = -newPos + "px";
			$('picScroller').set('tween', {
				duration: 2000,
				transition: Fx.Transitions.Quad.easeIn // This could have been also 'bounce:out'
			}).tween('margin-left', newPos);
			currentSI = targetSI;
			currentCircle = this.id;
		}
	});

	$('hc5').addEvents({		
		'mousedown': function(){
			$(currentCircle).src = "images/home/homecircleblack.jpg";
			this.src = "images/home/homecircleorange.jpg";
			targetSI = 5;
			var newPos = (targetSI-1) * 620;
			if (remainder != 0) {
				var newTarget = 152 * remainder;
				newTarget = newTarget - 1;
				newPos = (newPos - 610) + newTarget; 
			}			
			newPos = -newPos + "px";			
			$('picScroller').set('tween', {
				duration: 2000,
				transition: Fx.Transitions.Quad.easeIn // This could have been also 'bounce:out'
			}).tween('margin-left', newPos);
			currentSI = targetSI;
			currentCircle = this.id;
		}
	});

	$('lScrollImg').addEvents({		
		'click': function(){
			if (currentSI > 1) {
				$(currentCircle).src = "images/home/homecircleblack.jpg";				
				currentSI = currentSI - 1;
				currentCircle = "hc" + currentSI;
				$(currentCircle).src = "images/home/homecircleorange.jpg";
				var newPos = (currentSI - 1) * 620;
				newPos = -newPos + "px";
				$('picScroller').set('tween', {
					duration: 2000,
					transition: Fx.Transitions.Quad.easeIn // This could have been also 'bounce:out'
				}).tween('margin-left', newPos);
			}
		},
		'mouseover': function(){
			if (currentSI > 1) {
				this.src = "images/home/homescrollLeft2.jpg";
			}
		},
		'mouseout': function(){
				this.src = "images/home/homescrollLeft.jpg";
		}		
	});

	$('rScrollImg').addEvents({		
		'click': function(){
			if (currentSI < 5) {
				$(currentCircle).src = "images/home/homecircleblack.jpg";
				currentSI = currentSI + 1;
				currentCircle = "hc" + currentSI;
				$(currentCircle).src = "images/home/homecircleorange.jpg";
				var newPos = (currentSI-1) * 620;
				if (currentSI == totalScrollItems && remainder != 0) {
					var newTarget = 152 * remainder;
					newTarget = newTarget - 1;
					newPos = (newPos - 610) + newTarget; 					
				}
				newPos = -newPos + "px";
				$('picScroller').set('tween', {
					duration: 2000,
					transition: Fx.Transitions.Quad.easeIn // This could have been also 'bounce:out'
				}).tween('margin-left', newPos);
			}
		},
		'mouseover': function(){
			if (currentSI < 5) {
				this.src = "images/home/homescrollRight2.jpg";
			}
		},
		'mouseout': function(){
				this.src = "images/home/homescrollRight.jpg";
		}		
	});
	
	$('general_enquiry').addEvents({
		'mouseover': function(){
			this.src = "images/home/general_enquiries_over.jpg";
		},
		'mouseout': function(){
			this.src = "images/home/general_enquiries.jpg";
		}		
	});	

	$('hb1').addEvents({		
		'click': function(){
			window.location = "http://www.geoffcox.co.uk/customercomments.htm";
		}
	});

	$('hb2').addEvents({		
		'click': function(){
			window.location = "http://www.geoffcox.co.uk/finance.htm";
		}
	});

	
	$('hb3').addEvents({		
		'click': function(){
			window.location = "http://www.geoffcox.co.uk/workshop.htm";
		}
	});

	$('hb4').addEvents({		
		'click': function(){
			window.location = "http://www.geoffcox.co.uk/accessories.htm";
		}
	});

	$('lside1').addEvents({
		'click': function(){
			window.location = "http://www.geoffcox.co.uk/comingsoonvolkswagon.htm";
		}
	});

	$('lside2').addEvents({
		'click': function(){
			window.location = "http://www.geoffcox.co.uk/motorhomesforcash.htm";
		}
	});

	$('lside4').addEvents({
		'click': function(){
			window.location = "http://www.geoffcox.co.uk/pricepromise.htm";
		}
	});	
});	