// None of this is valid if we don't have any pricing ...
if ($('item_num').options.length > 0) {

	// Hide all the pricing boxes.
	$A($$('.item-pricing-container')).each(function(div) { div.hide(); });
	
	// Now, show the first pricing bit available.
	$('item-pricing-container_'+$F('item_num')).show();
	
	// Set things up so that if the select changes, we change the pricing shown.
	$('item_num').observe('change', function(e) {
		$A($$('.item-pricing-container')).each(function(div) { div.hide(); });
		$('item-pricing-container_'+$F('item_num')).show();
	});
	
} else {
	$('style_selector_block').hide();
	$('quantity_block').hide();
	$('button_block').hide();
}

$j(function() {

	$j('a.pmscolors-lightbox').lightBox();

	$j('#tabs').tabs();
	$j('a.lightbox').lightBox();
	$j('a.trigger-lightbox').click(function() {
		$j('a.lightbox:visible:first').trigger('click');
	});
	
	// start up the carousel
	$j('#carousel').cycle({
		fx: 'scrollLeft',
		pause: 1
	});
	// clicking on a thumb jumps to that image and stops the auto trans
	$j('#item-thumbs a.thumb').live('click', function() {
		$j('#carousel').cycle($j(this).attr('imgnum')*1);
		return false;
	});
	
	// these override the default links and take into account the style/color and quantity specified.
	$j('#link_buy').live('click', function() {
		location.href = $j('#link_buy').attr('href')+'&item_num='+$j('#item_num').val()+'&item_color='+$j('#item_num').val();
		return false;
	});
	$j('#link_info').live('click', function() {
		location.href = $j('#link_info').attr('href')+'&item_num='+$j('#item_num').val()+'&style_color='+$j('#item_num').val();
		return false;
	});
	
});

// item popup notice stuff
if (document.getElementById('popup_notice_text')) {

	document.popup_notice = new Control.Modal('popup_notice_trigger', {
		position: 'absolute',
		opacity: 0.5,
		imageCloseOnClick: true,
		containerClassName: 'popup_notice_window',
		afterOpen: function() {
			$('popup_notice_close_link').observe('click', function() {
				document.popup_notice.close();
			});
		}
	});
	
}
