jQuery.fn.imageScroller = function(options) {			
	var scroll = this;
	var $this = $(this);
	
	var $scrollingBox = $this.find(".scrolling_box");
	var $scroller = $this.find(".scroller a");
	var $scrollerLine = $this.find(".scroller");
		
	var scrollerEnabled = false;
	var scrollerStartX;
	var scrollerMinX = 0;
	var scrollerMaxX = $scrollerLine.width() - $scroller.width();
	var scrollerNewX;	

	var scrollingBoxWidth = 0;
	var scrollWidth = $(this).width();
	
	$.each($scrollingBox.children(), function(){
		/*scrollingBoxWidth += parseInt($(this).css("width").slice(0,-2)) + 
							 parseInt($(this).css("margin-left").slice(0,-2)) + 
							 parseInt($(this).css("margin-right").slice(0,-2)); 
		alert($(this).css("width") + " " + $(this).css("margin-left") + " " + $(this).css("margin-right"));*/
		scrollingBoxWidth += $(this).outerWidth();
	});
		
	$this.css("overflow", "hidden");
	$scroller.css("left", "0px");
	$scrollingBox.css("width", scrollingBoxWidth + "px");

	$scroller.mousedown(function(e){
		scrollerEnabled = true;
		scrollerStartX = e.pageX - parseInt($scroller.css("left").slice(0,-2));
		return false;
	});
	$("body").mouseup(function(e){
		if (scrollerEnabled) scrollerEnabled = false;
	});		
	$("body").mousemove(function(e){
		if (!scrollerEnabled) return false;
		scrollerNewX = e.pageX - scrollerStartX;
		if ((scrollerNewX > scrollerMinX) && (scrollerNewX < scrollerMaxX)) {
			$scroller.css("left", scrollerNewX + "px");
		} else if (scrollerNewX < scrollerMinX) {
			scrollerNewX = scrollerMinX;		
		} else if (scrollerNewX > scrollerMaxX) {
			scrollerNewX = scrollerMaxX;		
		}
		$scroller.css("left", scrollerNewX + "px");
		
		if(scrollingBoxWidth - scrollWidth > 0) {
			$scrollingBox.css("left", -scrollerNewX*(scrollingBoxWidth - scrollWidth)/scrollerMaxX + "px");
		}

		return false;
	});
	$scroller.click(function(){
		return false;
	});
};

jQuery.fn.rollUpText = function(options) {
	var rollUpText = this;
	var $this = $(this);
	
	var $rollup_text = $this.find(".rollup_text");
	var rollUpTextHeight = $rollup_text.outerHeight();
	
	$this.css("overflow", "hidden");
	$rollup_text.css("bottom", -rollUpTextHeight);
	
	$this.mouseenter(function(){
		$rollup_text.stop();
		$rollup_text.animate({
			"bottom": "0px"
		}, 300);		
	}).mouseleave(function(){
		$rollup_text.stop();
		$rollup_text.animate({
			"bottom": -rollUpTextHeight
		}, 300);		
	});
};

$(function() {
	$("#home_scroll_box").imageScroller();
	$("#testimonials_scroll_box").imageScroller();
	$("#catalogue_scroll_box").imageScroller();
	$("#testimonials_race_for_life").rollUpText();
	$("#about_press_media_img").rollUpText();
	
	if($.browser.msie && ($.browser.version.indexOf("6") > -1)){
		$("#home_banner_woman").css("zoom", "0.998");
		$("#home_banner_text").css("zoom", "0.998");
		$("#about_banner_image").css("bottom", "-1px");
		$("#services_sports_img").css("bottom", "-1px");
		$("#services_workwear_img").css("bottom", "9px");
	}
});


