scrolltimeout=false;

function activate_product(product) {
	if (scrolltimeout)
		window.clearTimeout(scrolltimeout);

	if ((product+1) > $('div.productscroll img').length) {
		$('div.productcontainer').scrollLeft(0);
		product=1;
	}

	$('div.productcontainer').animate({scrollLeft: product*212}, {queue:false, duration: 500});

	if ( $.browser.msie ) {
		$('div.productname h2').slideUp(250, function() { $('div.productname h2').text($('div.productscroll img').eq(product).attr('title')).slideDown(250) });
		$('div.productdescription p').slideUp(250, function() { $('div.productdescription').removeClass('cat').removeClass('dog').removeClass('rodent').addClass($('div.productscroll img').eq(product).parent().attr('class')); $('div.productdescription p').html($('div.productscroll img').eq(product).attr('alt')+' '+$('<a>').attr('href', $('div.productscroll a').eq(product).attr('href')).addClass('more').text('['+$('div.productdescription p').attr('title')+']').outerHTML()).slideDown(250) });
	} else {
		$('div.productname h2').fadeOut(250, function() { $('div.productname h2').text($('div.productscroll img').eq(product).attr('title')).fadeIn(250) });
		$('div.productdescription p').fadeOut(250, function() { $('div.productdescription').removeClass('cat').removeClass('dog').removeClass('rodent').addClass($('div.productscroll img').eq(product).parent().attr('class')); $('div.productdescription p').html($('div.productscroll img').eq(product).attr('alt')+' '+$('<a>').attr('href', $('div.productscroll a').eq(product).attr('href')).addClass('more').text('['+$('div.productdescription p').attr('title')+']').outerHTML()).fadeIn(250) });
	}

	currproduct=product;

	scrolltimeout = window.setTimeout('activate_product('+(product+1)+')', 8000);
}

function pos_product() {
	posi = $('div.start.right').offset();
  $('div.productleftscroll').css('left', posi.left+11).css('top', posi.top+19).show();
  $('div.productcontainer').css('left', posi.left+40).css('top', posi.top+45).show();
  $('div.productrightscroll').css('left', posi.left+189).css('top', posi.top+19).show();
  $('div.productname').css('left', posi.left+65).css('top', posi.top-8).show();
  $('div.productdescription').css('left', posi.left+65).css('top', posi.top+150).show();
}

$(document).ready(function(){
	currproduct=0;
//	$('div.productscroll table').html($('tr').html($('div.productscroll table tr').html()).html()+$('td').html($('div.productscroll table td').eq(0).html()).outerHTML());
	$('div.productscroll table').html('<TR>'+$('div.productscroll table tr').html($('div.productscroll table tr').html()).html()+'<TD>'+$('div.productscroll table td').eq(0).html()+'</TD></TR>');

	$('img:visible').each(function() {
		$(this).load(function() {
			pos_product();
		});
	});

	$('div.productcontainer').fadeTo(0);

	pos_product();
	activate_product(0);

	$('div.productcontainer').delay(250).fadeTo(500, 1);

  $('div.productleftscroll img').click( function() {
  	if (currproduct>0) {
	  	currproduct--;
			activate_product(currproduct);
		}
		else {
			currproduct = $('div.productscroll img').length-1;
			$('div.productcontainer').scrollLeft(currproduct*212);
			activate_product(currproduct-1);
		}
  });

  $('div.productrightscroll img').click( function() {
  	currproduct++;
		activate_product(currproduct);
  });

  $(window).wresize(function(){
  	pos_product();
  });
});
