ignore = function(){
	return false;
};

$(window).load(function(){
	$('.product-image').jqzoom();
	$('.upsales').parent().append("<div class=\"scrollbar\"><div class=\"scroll\"><img src=\"/default/images/scroll.png\" alt=\"Scrollbar\" /></div></div>");
	
	sw = '680';
	pw = $('.upsales table').width();
	scrollwidth = Math.floor(sw-((sw/pw)*(pw-sw)));

	if(pw <= 700){
		$(".scrollbar").css("display", "none");
	}
	$(".scroll").css({ 'width':scrollwidth+'px' });
	
	$(".scroll").draggable({ containment: 'parent', 'axis':'x' });
	
	$('.scroll').bind('drag', function(event, ui) {
		percentage = Math.round(parseFloat($(this).css("left"))/$(this).parent().width()*100);
		out = Math.round(($(".upsales table").width()/100)*percentage);
		$(".upsales").animate({ scrollLeft: out+'px' }, 0);
	});
	
});

$(".products").ready(function(){
								  
	$("#scroll").css("display", "block");
	$("#product-links").css("display", "block");
	$("#product-links-basic").remove();

	
	$("#product-links > dl > dd > div").css({ 'width':((($("#product-links").find("img").length)*200)+($("#product-links").find("img").length-1)*4)+'px' });
	
	sw = $("#scroll").width();
	pw = $("#product-links > dl > dd > div").width();
			 
	scrollwidth = Math.floor(sw-((sw/pw)*(pw-sw)));

	$("#scrollbar").css({ 'width':scrollwidth+'px' });
	
	$("#scrollbar").draggable({ containment: 'parent' });
	
	$('#scrollbar').bind('drag', function(event, ui) {
		percentage = Math.round(parseFloat($(this).css("left"))/$(this).parent().width()*100);
		out = Math.round(($("#product-links > dl > dd > div").width()/100)*percentage);
		$("#product-links > dl > dd").animate({ scrollLeft: out+'px' }, 0);
	});
	
	$("#product-links > dl > dt").find("a").click(function(){
		var current = $("#product-links > dl > dd").scrollLeft();
		switch($(this).attr("rel")){
			case 'Left':
				$("#product-links > dl > dd").animate({ scrollLeft: (current-660)+'px' }, 660, "swing");
				
				if((current-660)>0){
					me = "#product-links > dl > dd > div";
					var percentage = Math.round((current-660)/$(me).width()*100);
					var out = Math.round(($("#scroll").width()/100)*percentage);
					$("#scrollbar").animate({ 'left':out+'px' }, 660);
				}else{
					$("#scrollbar").animate({ 'left':'0px' }, 660);
				}
			
			break;
			case 'Right':
				$("#product-links > dl > dd").animate({ scrollLeft: (current+660)+'px' }, 660, "swing");
				
				me = "#product-links > dl > dd > div";
				var percentage = Math.round((current+660)/$(me).width()*100);
				var out = Math.round(($("#scroll").width()/100)*percentage);
				if(out > ($('#scroll').width()-$('#scrollbar').width())){
					$("#scrollbar").animate({ 'left':($('#scroll').width()-$('#scrollbar').width())+'px' }, 660);
				}else{
					$("#scrollbar").animate({ 'left':out+'px' }, 660);
				}
			break;
		}
		return false;
	});
	
	if($("#product-links").find("img").length < 7){
		$("#scrollbar").css({ 'width':$('#scroll').width()+'px', 'opacity':'0' });
		$("#scroll").css({ 'opacity':'0' });
		$("#product-links > dl > dt").css({ 'opacity':'0' });
	}
});

$(window).bind("load", function(){
	width = 0;
	
	for(i=0;i<$('.homescroll img').length;i++){
		width += $('.homescroll img').eq(i).width();
	}
	width -= 4;
	$('.homescroll div').css({ 'width':width }).attr("direction", "right");
	$('.homescroll div').slideshow()
	setInterval("$('.homescroll div').slideshow()", 13000);
});

jQuery.fn.slideshow = function(){
	if($(this).attr("direction") == "left"){
		$(this).attr("direction", "right");
		$(this).animate({ 'left':0 },  10000, "linear");
	}else{
		$(this).attr("direction", "left");
		$(this).animate({ 'left':(parseFloat($(this).width())-900).reverse() }, 10000, "linear");
	}
}
