function clickclear(thisfield, defaulttext)
{
    if (thisfield.value == defaulttext) {
        thisfield.value = "";
    }
}

function clickrecall(thisfield, defaulttext)
{
    if (thisfield.value == "") {
        thisfield.value = defaulttext;
    }
}

jQuery(document).ready(function(){
		
		var productNavTimeout;

		/**
		* Add a "selected" class to the "find out about" menu item when we're on the home page
		*/
		jQuery("body#body-home li#main-nav-find-out-about").addClass('selected');

		/**
		* Set the product type nav timeout
		*/
		function setHideProductTypeNavTimeout ()
		{
			productNavTimeout = setTimeout(function(){
				jQuery("#sub-nav-container").slideUp('slow');
				jQuery("#main-navigation ul li#main-nav-find-out-about").removeClass('selected');
			},2000);
		}

		/**
		* Clear the product type nav timeout
		*/
		function clearHideProductTypeNavTimeout ()
		{
			clearTimeout(productNavTimeout);
		}

		/**
		* Open the product type nav on tab mouseover
		*/
		jQuery("body:not(#body-home,#body-find-out-about) #main-navigation ul li#main-nav-find-out-about").hover(function(){
			jQuery("#sub-nav-container").slideDown('slow');
			jQuery("#main-navigation ul li#main-nav-find-out-about").addClass('selected');
		});
		
		// Sub menu show/hide addition...
		
		// If we're at the top level then hide the sub menu
		if("" == jQuery.trim(jQuery('#breadcrumbs').html())){
		    jQuery('#main-navigation #sub-nav-container #sub-navigation ul ul.sub-menu').hide();
		    jQuery('#breadcrumbs').attr('style', 'font-size:0;line-height:0;');
		}
		
		// If the user clicks on a sub menu header then show the child sub menu.
		jQuery('#product-type-nav-sound-vision.menu-item,#product-type-nav-home-electrical.menu-item,#product-type-nav-pc-photo-gaming.menu-item').click(function(){
            jQuery('ul.sub-menu').slideDown('slow');
		});
	
		// End of sub menu show/hide addition.
		
		/**
		* Set up a timeout on mouseout
		*/
		jQuery("body:not(#body-home,#body-find-out-about) #main-navigation").mouseout(function(){
			setHideProductTypeNavTimeout();
		});

		/**
		* Cancel the timeout onmouseover
		*/
		jQuery("#main-navigation").mouseover(function(){
			clearHideProductTypeNavTimeout();
		});

		/* Site search */
		jQuery('#search-container').slidinglabels({
			/* these are all optional */
			className    : 'form-slider', // the class you're wrapping the label and input with -> default = slider
			topPosition  : '5px',  // how far down you want each label to start
			leftPosition : '5px',  // how far left you want each label to start
			axis         : 'y',    // can take 'x' or 'y' for slide direction
			speed        : 'fast'  // can take 'fast', 'slow', or a numeric value

		});

		/* Home page carousel */
		lastBlock = jQuery("#content #content-carousel-container #left");
		maxWidth = 300;
		minWidth = 140;

		jQuery("#content #content-carousel-container ul li a").hover(
			function(){
				$(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:100});
				$(this).animate({width: maxWidth+"px"}, { queue:false, duration:100});
				lastBlock = this;
			}
		);

		/**
		 * Sexy Combo boxes
		 */
		jQuery('.block select').jqTransSelect();

		jQuery('.block select[disabled]').parents('.jqTransformSelectWrapper').fadeTo(0, 0.5);

		jQuery('body').delegate('a.scroll-up', 'click', function(e) {
			e.preventDefault();
			$this = jQuery(this);
			if($this.next('ul').position().top <= 0) {
				$this.next('ul').stop(true,true).animate({top: $this.next('ul').position().top + 30});
			}				
		});

		jQuery('body').delegate('a.scroll-down', 'click', function(e) {
			e.preventDefault();
			$this = jQuery(this);
			if($this.prev('ul').position().top > (0 - $this.prev('ul').height() + 180)) {
			//alert($this.prev('ul').height());
				$this.prev('ul').stop(true,true).animate({top: $this.prev('ul').position().top - 30});
			}
		});
		
		jQuery(document).click(function(e) {
			if(e.originalTarget) {
                if(e.originalTarget.tagName !== 'A') {
                    jQuery('.dropdown').hide();
                }
			}
		});

		$scroll_up = jQuery('<a class="scroll-up" href="#">Scroll Up</a>');
		$scroll_down = jQuery('<a class="scroll-down" href="#">Scroll Down</a>');
		jQuery('.jqTransformSelectWrapper:not(:has(.scroll-up)) ul').before($scroll_up).after($scroll_down);
		
		if(jQuery.browser.msie && jQuery.browser.version < 8) {
			jQuery('form > div').mousedown(
				function(e) {
					jQuery(this)
						.closest('div')
						.css('z-index', 999)
						.siblings('div')
						.css('z-index', 10);
				}
			);
		}
		
		/**
		 * Clear default search text
		 */
		search_term = 'e.g. Technika LCD TV 32';
		jQuery('#query')
			.focus(function(e) {
				$this = jQuery(this);
				if($this.val() === search_term) {
					$this.val('');
				};
			})
			.blur(function(e) {
				$this = jQuery(this);
				if($this.val() === search_term || $this.val().length === 0) {
					$this.val(search_term);
				};
			});

		/**
		 * Browse our library by department
		 */
		jQuery('#manual-product-types li ul').each(function(index, item) {
			$this = jQuery(this);

			$this.css('left', $this.prev('a').position().left);

			$this.hide();
		});

		jQuery('#manual-product-types ul.departments > li').hover(
			function(e) {
				jQuery(this).addClass('hover').find('ul').stop(true, true).fadeIn(250);
			},
			function(e) {
				jQuery(this).removeClass('hover').find('ul').stop(true, true).fadeOut(250);
			}
		)
		.css('cursor', 'pointer')
		.click(function(e) {
			window.location = jQuery(this).children('a').attr('href');
		});

		jQuery('#find-out-about-products > li').hover(
			function(e) {
				jQuery(this).find('div').stop(true, true).fadeIn(250);
			},
			function(e) {
				jQuery(this).find('div').stop(true, true).fadeOut(250);
			}
		)
		.css('cursor', 'pointer')
		.click(function(e) {
			window.location = jQuery(this).children('a').attr('href');
		});
		/**
		 * Extend the jqTransform plugin to include a method to reset select boxes
		 */
		(function($){
			$.fn.jqResetSelect = function(){
				return this.each(function(index){
					var $select = $(this);

					if($select.hasClass('jqTransformHidden')) {
						$select.prev('.dropdown').remove();
						$select.prev('div').remove();
						$select
							.removeClass('jqTransformHidden')
							.unwrap()
							.show();
					}
				});
			};
		})(jQuery);
		
		
		// Old browser support.
		jQuery(".feature-post-list > div:nth-child(1)").addClass('top');
		jQuery(".feature-post-list > div:nth-child(2)").addClass('top');
		jQuery(".feature-post-list > div:nth-child(3)").addClass('top');
		jQuery(".feature-post-list > div:nth-child(3n+3)").addClass('right-most');

});



