// For toggling input boxes
jQuery.fn.toggleVal=function(focusClass){this.each(function(){$(this).focus(function()
{if($(this).val()==this.defaultValue){$(this).val("")}if(focusClass)
{$(this).addClass(focusClass)}}).blur(function(){if($(this).val()=="")
{$(this).val(this.defaultValue)}if(focusClass){$(this).removeClass(focusClass)}})})}

$(document).ready(function(){

	//For adding images to types of links
	$("a[href$=pdf]").addClass("pdf");
	$("a[href$=zip]").addClass("zip");

// For desaturating the images on page load	
$("ul.variation li.var img").each(function() {
	//initImage(this);
});

// Hover effect - expand boxes
$("ul.variation li.var").hover(function() {
	$(this).css({'z-index' : '90'});
	$('b',this).css({'display' : 'block'}).addClass('show');
	if ($.browser.msie) {
		$(this).find('img').addClass("hover").stop()
			.animate({
				marginTop: '-82px', 
				marginLeft: '-80px', 
				top: '50%', 
				left: '50%', 
				right: '50%', 
				padding: '5px',
				width: '155px', 
				height: '155px'
			}, 200);

	} else {
		$(this).find('img').addClass("hover").stop()
		.animate({
			marginTop: '-80px', 
			marginLeft: '-80px', 
			top: '50%', 
			left: '50%', 
			width: '150px', 
			height: '150px'
		}, 200);	
	}
		
	} , function() {
	$(this).css({'z-index' : '0'});
	$('b',this).css({'display' : 'none'}).removeClass('show');
	$(this).find('img').removeClass("hover").stop()
		.animate({
			marginTop: '0', 
			marginLeft: '0',
			top: '0', 
			left: '0', 
			width: '130px', 
			height: '130px', 
			padding: '5px'
		}, 200);
});

	// Desaturate effect
     $("ul.variation li.var").hover(
      function () {
        $(".color", this).fadeIn(600);
      }, 
      function () {
        $(".color", this).fadeOut(50);
      }
    );

	// Fix link problem in IE 7
	$("ul.variation li.var").click(function() {
		window.location.href = $('a',this).attr('href');
	});	
	
	$("a.colour").click(function() {
		return false;
	});
 
	// Initialise the input toggle function
	$(".toggle").toggleVal("active");


	// Stripe tables
	$("tbody>tr:odd").addClass('altrow');

    $("tbody>tr").hover(
      function () {
        $(this).addClass('hovered');
      }, 
      function () {
        $(this).removeClass('hovered');
      }
    );
	
	
	// For autoscrolling the table headers
    var $header   = $("ul.headers"),
        $window    = $(window),
        offset     = $header.offset(),
        topPadding = 10;

    $window.scroll(function() {
	
		left = ($(document).width()/2)-510;
        if ($window.scrollTop() > (offset.top)) {
			$header.addClass('fixed');
			
            $header.stop().animate({
				
                marginTop: //$window.scrollTop() - offset.top*2 + 
				topPadding
            }).css('margin-left',left);
        } else {
			$header.removeClass('fixed');
            $header.stop().animate({
                marginTop: 0
            }).css('margin-left','0');
        }
    });	
	
	// Tabs
	$('.pane-2').hide();
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {
		if ($(this).attr('class') != 'no_tab') {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
/*		if (activeTab == '#tab_specs') {
			$('.pane-1').hide();
			$('.pane-2').fadeIn(400);
		} else {
			$('.pane-2').hide();	
			$('.pane-1').fadeIn(400);
		
		}
*/		
		$(activeTab).fadeIn(function(){
			if ($.browser.msie) {
				this.style.removeAttribute("filter");
			}	
		}); //Fade in the active ID content
		return false;
		} else {
			return true;
		}
	});
	
	// For AJAX Option and Accessory popup boxes
    $('a.option-link').each(function () {
        $(this).attr('href', '/ajax-option/?link='+$(this).attr('id'));
    });
	
	// For Lightbox
	$(".gallery-item a, .fancybox").fancybox({'titleShow': true,'titlePosition':'inside','transitionIn'	: 'elastic','transitionOut'	: 'elastic'});	
	
	$("a.option-link").fancybox({'padding': 0,'titleShow': false});	

	
	
	// Homepage Crossfader
	var options = {
		'slideType':'slidehorizontal',
		'fadeInOut':true,
		'transitionTime':500,
		'showTime':6000,
		'slideDirection':'default'
	}; 
	$('.crossfade .item').dumbCrossFade(options);

	$('.next, .next_btn').click(function()  {
		$('.crossfade .item').dumbCrossFade('next') 
		return false;
	});	
	
	$('.prev').click(function() {
		$('.crossfade .item').dumbCrossFade('previous');
		return false;
	});	
	
	$('.slider_nav').click(function() {
		index = $(this).attr('id');
		$('.crossfade .item').dumbCrossFade('jump',index);
		$('.slider-nav a').removeClass('selected');
		$(this).addClass('selected');
	});		
	
		
});

/* for Desaturating the product images */
      var paircount = 0;

      function initImage(obj)
      {
        obj.onload = null;
        var $newthis = $(obj);
        if ($.browser.msie)
        {
          // You need this only if desaturate png with alpha channel
          $newthis = $newthis.desaturateImgFix();
        }
        // class for easy switch between color/gray version
        $newthis.addClass("pair_" + ++paircount);
        var $cloned = $newthis.clone();
        // reset onload event on cloned object
        $cloned.get(0).onload = null;
        // add cloned after original image, we will switch between
        // original and cloned later
        $cloned.insertAfter($newthis).addClass("color").hide();
        // desaturate original
        $newthis.desaturate();

      };
	  



/* Dumb Crossfade plugin */
/* 2010 Hubsoft.com && SebringCreative.com (written by Jason Sebring, mail@jasonsebring.com) - Dual licensed under the MIT and GPL licenses. */
(function($){$.fn.dumbCrossFade=function(settings){var publicAccessorLabel='dumbCrossFade.publicAccessor';var configLabel='dumbCrossFade.config';if(typeof(this.data(publicAccessorLabel))!=='undefined'&&this.data(publicAccessorLabel)!==null){var pa=this.data(publicAccessorLabel);var cg=this.data(configLabel);var args=Array.prototype.slice.apply(arguments);if(args.length>0){if(typeof(args[0])==='object'){if(settings)$.extend(cg,settings);var args=Array.prototype.slice.apply(arguments);if(args.length>1){args=args.slice(1,args.length);}else{pa.start();return this;}}if(arguments.length===1){pa[arguments[0]]();}else if(arguments.length>1){var args=Array.prototype.slice.apply(arguments);args=args.slice(1,args.length);pa[arguments[0]].apply(this,args);}}return this;}var config={'slideType':'slidehorizontal','index':0,'showTime':5000,'transitionTime':1000,'doHoverPause':true,'maxZIndex':10,'slideChange':null,'direction':'forward','fadeInOut':false},timeOut=null,itemArray=[],blockAnimation=false,lastIndexRequest=-1,$self=this
$window=$(window),$body=$('body');if(settings)$.extend(config,settings);function cancelSlideShow(){if(timeOut!==null){window.clearTimeout(timeOut);timeOut=null;}}function doSlideShowNow(){if(blockAnimation){if(arguments.length>0){lastIndexRequest=arguments[0];}return;}var currentIndex=config.index;var nextIndex=(arguments.length>0)?arguments[0]:(config.index>=itemArray.length-1)?0:config.index+1;if(config.direction==='backward'){if(currentIndex===0){nextIndex=itemArray.length-1;}else{nextIndex=currentIndex-1;}}if(currentIndex==nextIndex){return;}var $f=itemArray[currentIndex].show(),$n=itemArray[nextIndex];blockAnimation=true;doneF=function(){$f.hide();if(config.fadeInOut){$f.css({'opacity':'1.0'});$n.css({'opacity':'1.0'});}blockAnimation=false;if(lastIndexRequest!=-1){doSlideShowNow(lastIndexRequest);lastIndexRequest=-1;}};$f.css('z-index',(config.maxZIndex-1)+'');$n.css('z-index',config.maxZIndex+'');switch(config.slideType){case'slidehorizontal':var pos=$f.position(),width=$f.width(),adjustX='-='+width;if(config.direction==='forward'){$n.css({'left':(parseInt(pos.left)+width)+'px'});}else{$n.css({'left':(parseInt(pos.left)-width)+'px'});adjustX='+='+width;}if(config.fadeInOut){$n.css({'opacity':'0','display':'block'});$f.animate({'left':adjustX,'opacity':'0'},config.transitionTime,'swing');$n.animate({'left':adjustX,'opacity':'1.0'},config.transitionTime,'swing',doneF);}else{$n.show();$f.animate({'left':adjustX},config.transitionTime,'swing');$n.animate({'left':adjustX},config.transitionTime,'swing',doneF);}break;case'slidevertical':var pos=$f.position(),height=$f.height(),adjustY='-='+height;if(config.direction==='forward'){$n.css({'top':(parseInt(pos.top)+height)+'px','display':'block'});}else{$n.css({'top':(parseInt(pos.top)-height)+'px','display':'block'});adjustY='+='+height;}if(config.fadeInOut){$n.css({'opacity':'0','display':'block'});$f.animate({'top':adjustY,'opacity':'0'},config.transitionTime,'swing');$n.animate({'top':adjustY,'opacity':'1.0'},config.transitionTime,'swing',doneF);}else{$n.show();$f.animate({'top':adjustY},config.transitionTime);$n.animate({'top':adjustY},config.transitionTime,doneF);}break;case'fade':$n.fadeIn(config.transitionTime,doneF);break;}if(config.slideChange!==null){config.slideChange(nextIndex);}config.index=nextIndex;}function doSlideShow(){cancelSlideShow();timeOut=window.setTimeout(function(){doSlideShowNow();doSlideShow();},config.showTime);}$self.each(function(){(itemArray.length===config.index)?$(this).show():$(this).hide();if(itemArray.length===0){if(config.doHoverPause){$(this).parent().hover(function(){cancelSlideShow();},function(){cancelSlideShow();doSlideShow();});}}itemArray[itemArray.length]=$(this);});var publicAccessor={'jump':function(index){cancelSlideShow();doSlideShowNow(index);return publicAccessor;},'start':function(){$self.children().hide();itemArray[config.index].show();config.direction='forward';doSlideShow();},'stop':function(){cancelSlideShow();},'next':function(){config.direction='forward';cancelSlideShow();doSlideShowNow();},'previous':function(){config.direction='backward';cancelSlideShow();doSlideShowNow();}};this.data(publicAccessorLabel,publicAccessor);this.data(configLabel,config);doSlideShow();return this;};})(jQuery);


