function scrollToTop(){
	$('html, body').stop().animate({scrollTop:0}, 500);
	return false;
}

$(document).ready(function(){
	//ajdust slideshow position						   
	$(window).bind('resize', function() {
		var w = $('body').width();
		var ofs  = $('#panel').offset();
		w = w - ofs.left;
		w = Math.max(901,Math.min(w,1150));				
		$('#slideshow').css('width',w);
	});
	
	$(window).resize();
	
	
	//display price tag
	
	var priceTageTimeout = null;
	$('a.catalogProduct').mouseover(function(){
		var ofs = $(this).offset();				
		clearTimeout(priceTageTimeout);
		$('#priceTag').html('rrp $'+$(this).attr('price')).fadeIn(200);						
	}).mousemove(function(e){
		$('#priceTag').css({left:e.pageX,top:e.pageY-30});
	}).mouseout(function(){
		priceTageTimeout = 	setTimeout(function(){
			$('#priceTag').fadeOut(100);		
		},100);
		
	});
	
	
	
});

function frameSlideshow(tag_param,speed_param,frame_list){
	if(frame_list && frame_list.length > 1){
		var frameIndex = 0;
		var imageIndex = 0;
		var expectLoad = 0;
		var $imageA = null;
		var $imageB = null;
		var tag = tag_param;
		var speed =  speed_param;
		
		$('#'+tag+'1').css('opacity',0);
		
		function scheduleNextFrame(){
			setTimeout(function(){
				frameIndex = (frameIndex + 1 ) % frame_list.length;
				imageIndex = 1 - imageIndex;
				$imageA = $('#'+ tag + imageIndex);
				$imageB = $('#'+ tag + (1-imageIndex));
				expectLoad = 1;
				$imageA[0].src = frame_list[frameIndex];
			},speed);
		}
		
		$('.'+tag).load(function(){
			if(expectLoad){	
				expectLoad = 0;
				//alert("loaded:" + frameIndex);	
				$imageA.animate({opacity:1},Math.round(speed/2));
				$imageB.animate({opacity:0},Math.round(speed/2));				
				scheduleNextFrame();
			}
		});		
		

		
		scheduleNextFrame();
	}
}
