// 2011-01-12: PORTED to main.dev.js --> MM.Item.hasSamples()
function HasSamples() {
	
	$('#hasSamples').addClass('enabled').click(function() {
		window.location = 'http://samples.rodandstaffbooks.com/' + $('#item-code').text() +'/';
	}).mouseover(function(){
		$(this).addClass('hover').attr('title','See samples...');
	}).mouseout(function(){
		$(this).removeClass('hover');
	});
	
}

// 2011-01-12: PORTED to main.dev.js --> MM.Item.sampleLinksToc()
function SampleLinksToc() {
    $('blockquote[class=toc]').each(function(index,el){
        if($(this).attr('sample-links') == 'parsed') { return; }
        
    	var item = $(this).attr('item') || $('#item-code').html();
    	var type = $(this).attr('type') || 'book';

    	if (type == 'book') {
    		$(this).find('li[sample]').addClass('book sample').wrapInner("<span></span>").prepend("<img src='/common/images/samples_"+ ($("#hasSamples").attr("samples") || 'samples') +"_toc.gif' />").children().attr('title','See samples...').click(function(){
    			window.location = 'http://samples.rodandstaffbooks.com/'+ item +'/#'+ $(this).parent().attr('sample');
    		});
    	} else if (type == 'audio') {
    		$(this).find('li[sample]').addClass('audio sample').wrapInner("<span></span>").prepend("<img src='/common/images/samples_"+ ($("#hasSamples").attr("samples") || 'audio') +"_toc.gif' />").children().attr('title','Listen to sample...').click(function(){
    			var href = 'http://www.rodandstaffbooks.com/audio/'+ item +'/#'+ $(this).parent().attr('sample');
    			wAudio = window.open(href, 'wAudio','location=1,status=1,menubar=0,scrollbar=0,width=350,height=200,resizable=1');
    			wAudio.focus(); return false;
    		});
    	}
    	// marks the element as parsed
    	$(this).attr('sample-links','parsed');
    });
}

// 2011-01-12: IN USE in product display template
// functionality not utilized so far
function initCoupon() {
	
	if ($('#coupon input').length && window.location && window.location.search) {
		if ((coupon = window.location.search.match(/coupon=([^\&]*)/))) {
			$('#coupon input').val(coupon[1]);
		}
		if ((your_price = window.location.search.match(/price=([^&]*)/))) {
			price_m = $('#price b').html().match(/\$(.*)/);
			price = +price_m[1];
			$('#price').html('Reg. Price: <del>$'+ price +'</del>' +
		        '<br /><span style="color:red;">Promotional Price: <b>$'+ your_price[1] +'</b>' +
		        ' <small>(save '+ Math.round((1 - your_price[1]/price)*100) +'%)</small></span>');
			document.write('<input type="hidden" name="price" value="'+ your_price[1] +'" />');
		}
		if ((error = $('#coupon .error').html())) {
			$('#coupon input').val('');
			document.write('<span style="color:red;">'+error+'</span><br /><br />');
		}
	}
	
}

