function bindContactSubmit() {
	jQuery('.contactPopup button').click( function () {
		var submitContent = jQuery('#popupEnquiryIntro').html() + '\n\n' + jQuery('#lightwindow textarea#comment').val();
		jQuery('#lightwindow textarea#comment').val(submitContent);
	});	
}

function checkWindowSize() {
    var width = jQuery(window).width(),
    new_class = width > 1600 ? 'wLarge' :
                width > 1440 ? 'w1680' :
                width > 1280 ? 'w1440' :
                width > 1100 ? 'w1280' : 
                width < 1100 ? 'wMin' :	'';

    jQuery(document.body).removeClass('wLarge w1680 w1440 w1280 wMin').addClass(new_class);
}

var ctrlPressed = false;

jQuery(document).ready( function() {

	jQuery('a[rel=external]').attr('target','_blank');

	jQuery('.block-layered-nav li a,.products-grid li a').live('click',
		function(){
			if (ctrlPressed == false) {
				jQuery('.products-grid').animate({
					opacity : 0
					},1000
				);			
			}
		}
	);
	
	jQuery(document).keydown(	
		function(e) {
			if (e.ctrlKey) {
				ctrlPressed = true;
			}
		}
	);	

	jQuery(document).keyup(	
		function() {
			ctrlPressed = false;
		}
	);		
	
	jQuery( 'select#search-manufacturer' ).selectmenu({
		style: 'dropdown',
		width: '180px'
	});

	var productSku = jQuery('.data.sku').html();

	jQuery( '#popupEnquiryIntro' ).html( 'Enquiry for product ' + productSku );	
	
	jQuery(".block-layered-nav").ajaxSuccess(function(){
		ajaxRebind();	
	});	
	
	ajaxRebind();	
	
	jQuery('.col-main').change(function(){
		jQuery('.lightwindow-once').removeClass('lightwindow');
	});
		

	jQuery('#search-manufacturer').change(function(){
		if (jQuery('#search-manufacturer').val()){
			if (!jQuery('#q').val()) {
				window.location = "/#manufacturer=" + jQuery('#search-manufacturer').val();
				return false;
			}
			jQuery('#search_mini_form').submit();
		}
	});

	jQuery('#search_mini_form').submit(function(){
	
		var manufacturer =  jQuery('#search_mini_form option:selected').val();		
		
		if (manufacturer != "")
		{
			window.location = "/catalogsearch/result/?q=" + jQuery('#q').val() + "#manufacturer=" + manufacturer + "&q=" + jQuery('#q').val();
		}
		else
		{
			return true;
		}
		return false;
	});
	
	//init the window size classes
	checkWindowSize();
	//on window resize
	window.onresize = function() { checkWindowSize(); }	
	
	
	jQuery(".products-grid li.item ").live('mouseenter mouseleave', function(){
		jQuery(this).toggleClass('over');
	})
	
	if (!jQuery.browser.msie) {     
		jQuery('.slider').nivoSlider({pauseTime: 8000,animSpeed: 1000,slices: 8, boxRows: 2}); 		
	} else {     
		jQuery('.slider').nivoSlider({pauseTime: 8000,animSpeed: 1000,slices: 8, boxRows: 2, effect: 'fade'}); 		
	}   
	
	/* Product description tabs */
	
	jQuery(".product-specification-tab-title").click( function(){
		jQuery('.product-specification-pane').removeClass('active').addClass('inactive');
		jQuery('.product-specification-tab').removeClass('active').addClass('inactive');
		jQuery('#' + jQuery(this).attr('rel')).addClass('active').removeClass('inactive');
		jQuery(this).parent('.product-specification-tab').removeClass('inactive').addClass('active');
		return false;
	});	
	
	/* Some nice logic for select lists */
		
	jQuery("#product-options-wrapper dd select").live('change',function(){ showHideConfigOptions() });
	showHideConfigOptions();
});


function showHideConfigOptions(){

	//Hide all options beyond the currently selectable one
	jQuery("#product-options-wrapper dd select").show().parent('dd').prev('dt').show().next().children('select').filter('[disabled]').hide().parent('dd').prev('dt').hide();

}


/* CUFON */
var cufonSelectors = '#layer-refinements .currently li .inner,' +
					 '#nav li.level0 a.level-top,' + 
					 'h1,h2,h3,h4,h5,h6,' + 
					 '.block-title,' + 
					 'th,' + 
					 '.pager .amount, .pager .limiter, .pager .pages, .toolbar .sort-by,' + 
					 '.breadcrumbs,' + 
					 '.footer-links a,' + 
					 '#sitemap_top_links,' + 
					 'dt, ' + 
					 '.copyright,' + 
					 '.cufon' +
					 '.product-specification-tab-title';
Cufon.replace(cufonSelectors, { fontFamily: 'Myriad Pro Bold', hover: true } );

//Rebind after catalog ajax refresh
function ajaxRebind(){
	Cufon.refresh();
}

//Hook into prorotype ajax every time product images change for simple configurable products
Ajax.Responders.register({
  onComplete: function(sender) {
	if (sender.container.success == 'SCPcustomOptionsDiv') {
		lightwindowInit();
	}
  }
});
