$(document).ready(function(){
// find product price

if ( $('#product div.right-block div.panel ul').length<1 ) 
	return false;

matches = $('#product div.right-block div.panel ul').html().match(/Add to cart \(\$([0-9\.]+)\)/);
// if price found
if (matches && matches[1])
{
	price	= matches[1];

	// hide original price
	$("#product div.right-block ul li:contains('Add to cart')").addClass('old-price');

	// add discount box
	discount_draw( price );

	// update timer every 60 seconds
	window.setTimeout('discount_timer()',1000*60);
}

});

function discount_draw( price )
{
	old_href= $("#product div.right-block ul li:contains('Add to cart') a").attr('href');

	new_price=Math.floor( (price - (price*10/100)) *100 ) / 100;
	html	= "<div id='discount'><a href=''>Add to cart (<s></s>) <strong></strong></a><br/>Discount expires in <span id='discount-expire'>60</span> minutes</div>";
	html	= html.replace("<a href=''>","<a href='"+old_href+"?coupon=INSTANTDISCOUNT'>");
	html	= html.replace("<s></s>","<s>$"+price+"</s>");
	html	= html.replace("<strong></strong>","<strong>$"+new_price+"</strong>");
	$('#product div.right-block').prepend(html);

	// add new price in 'quick links'
	html	= "<li class='new-price'>"+ $("#product div.right-block ul li.old-price").html() +"</li>";
	html	= html.replace(price,new_price);
	html	= html.replace(old_href,old_href+"?coupon=INSTANTDISCOUNT");
	$("#product div.right-block ul li.old-price").after( html );
}


function discount_timer()
{
	time = $('#discount-expire').html();
	if ( time > 1 )
	{
		time--;
		$('#discount-expire').html( time );
		window.setTimeout('discount_timer()',1000*60);
	}
	else
	{
		$('#discount').hide();
		$('li.new-price').hide();
		$('li.old-price').show();
	}
}
