/* SLIDESHOW */

function slideSwitch() {
    var $active = jQuery('#fader li.active');

    if ( $active.length == 0 ) $active = jQuery('#fader li:last');

    var $next =  $active.next().length ? $active.next()
        : jQuery('#fader li:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
jQuery(function() {
    setInterval( "slideSwitch()", 5500 );
});

/* PRODUCT OPTION DROPDOWN */

jQuery(function(){
	jQuery('#products-options li').hover(function(){
		jQuery(this).find('ul').addClass('show');
	},
	function(){
		jQuery(this).find('ul').removeClass('show');
	});

});


/* CLEAR SEARCH BOX */

jQuery(function(){
	jQuery('form.search-form input').focus(function(){
		if(jQuery(this).attr('value') == 'enter a search term or product code') {
			jQuery(this).attr('value', '');
		}
	});
});


/** IE6 Hover **/

jQuery(function(){
	jQuery('#product-options ul li').hover(function() {
		jQuery(this).find('ul').show();
	},function() {
		jQuery(this).find('ul').hide();
	});
});

/** PRODUCT OPTIONS NICE DROP DOWN **/

	// By default they will just see radio buttons
	// if js enabled they will see a better "progressively enhanced" drop down
	jQuery(function(){
		// add js class to div#product-options so that our CSS can make it all look nice.
		jQuery('#product-options').addClass('js');
		
		
		// add onclick events for all labels in here...
		
		// on the click of a label, add the class padding-right to the option-cont div,
		// add the HTML contents of the chosen product option to the choose-product-option div
		// and then remove the duplicated form input.
		
		jQuery('#product-options label').click(function() {
			
			// COLLAPSE on click
			jQuery('#option-cont').addClass('no-hover');
			
			jQuery('#choose-product-option').html(jQuery(this).html());
			jQuery('#choose-product-option input').remove();
			
			this_obj=jQuery(this);
			jQuery('#'+this_obj.attr('for')).attr('checked', true);
		});
		
		
		// when the mouse leaves the element remove the no-hover class
		jQuery('#product-options label').mouseleave(function() {
			// make expandable again
			jQuery('#option-cont').removeClass('no-hover');
		});
		
		// If only one option, simulate a click!
		var options = jQuery('#product-options label');
		if(options.length == 1) {
			options.click();
			// check the radio button.
			jQuery('#'+options.attr('for')).attr('checked', true);
		}
	});
	
/** END PRODUCT OPTIONS NICE DROP DOWN **/


// new window
jQuery(function() {
	jQuery('a.new-window').click(function() {
		jQuery(this).attr('target', '_blank');
		return true;
	});
});
