

// view_product.js
// mark guinn, 6.6.07

/*
$(document).ready(function(){
	Shadowbox.init({ skipSetup:true });

	// shadowbox for images
    Shadowbox.setup($('a.thumbnail'), $.extend({}, 
		TOC.Defaults.shadowbox, 
		{gallery:'SecondaryImages'}
    ));	
});
*/

$(document).ready(function(){
	// image gallery
	$('<div id="img_popup" class="jqmWindow" style="display:none"><img id="popup_image" /><br/><small id="popup_caption"></small><a href="javascript:;" class="jqmClose">Close</a></div>')
		.appendTo(document.body)
		.jqm();

	$('.thumbnail').bind('click', function(){
		$('#img_popup').jqmShow().css('opacity',0.01);
		$('#popup_caption').html(this.title);
		$('#popup_image')
			.bind('load', show_image)
			.attr('src', this.href);
		return false;
	});		

		
	// add to cart
	$('<div id="cart_popup" class="jqmWindow popupForm" style="display:none"><div id="cart_loading"><img src="/images/indicator.gif" border="0"/> Adding to cart...</div><div id="cart_content"></div></div>')
		.appendTo(document.body)
		.jqm();
		
	$('input.inline-add-to-cart-btn').bind('click', function(){
		this.form.xhr.value = '1';
		
		$('#cart_content').hide();
		$('#cart_loading').show();
		$('#cart_popup').jqmShow();		
		$(this.form).ajaxSubmit({ success: show_cart_form });
		
		return false;
	});
	
	
	// row hovering
	$('.part-row').hover(
		function(){ $(this).addClass('row-hover'); },
		function(){ $(this).removeClass('row-hover'); }
	).click(
		function(){ $(this).toggleClass('row-highlight'); }
	);

		
});

function show_image()
{
	var s = {};
	var $ip = $('#img_popup').css('height','auto');

	s['width'] = parseInt($(this).outerWidth());
	s['margin-left'] = -s['width'] / 2;
	var h = parseInt($ip.outerHeight());
	var dh = parseInt($(window).innerHeight());
	var t = Math.round(50 - ((h / dh) * 50));
	if (t < 0)
	{
		s['height'] = h = dh - 50;
		var t = 50 - ((h / dh) * 50);
		s['overflow'] = 'auto';
	}

	if ($.browser.msie)
	{
		s['position'] = 'absolute';
		s['top'] = ($(window).height() - $(this).outerHeight()) / 2 + $(window).scrollTop();
	}
	else
	{
		s['top'] = t + '%';
	}
	$ip.css(s).fadeTo('fast', 1);
}

function show_cart_form(html)
{
	$('#cart_loading').hide();
	$('#cart_content').html(html).slideDown('normal');
	
	// set up the handlers for the new page
	$('#back-btn').bind('click', function(){ 
		$('#cart_popup').jqmHide();
		return false; 
	});
	
	$('#add-to-cart').bind('click', function(){
		$('#cart_loading').show();
		$('#cart_content').slideUp('normal');		
		$(this.form).ajaxSubmit({ success:show_cart_form });
		return false;
	});
	
	// see if we need to update the quick cart
	$('#new-quickcart-items').each(function(){ $('#quickcart-items').html(this.innerHTML); });
	$('#new-quickcart-price').each(function(){ $('#quickcart-price').html(this.innerHTML); });
}

