// ------- SEARCH FOCUS/BLUR
function myFocus(element) {
   if (element.value == element.defaultValue) {
   element.value = '';
   }
}
function myBlur(element) {
   if (element.value == '') {
   element.value = element.defaultValue;
  }
}
//Checkout Submit Qty On Blur
function submitQty(element){
	document['shopping_cart'].submit();
	return false;
}
$(document).ready(function() {
	$(".orderResultsDiv").hide();
	$('a#hideOrderResultsDiv').click(function() { 
		 $.cookie("isHidden","true");
    }); 
	
    var hidden = $.cookie('isHidden');

    if (hidden == null) {
        $('.orderResultsDiv').show();
    }
	
    $('#hideOrderResultsDiv').click(function(){
    	$('.orderResultsDiv').animate({opacity: 0}, 400 );
	    $(".orderResultsDiv").slideUp();
	});
	
	// Little Drop Sequence
	$('.hidden').hide();
	$('.hidden').next().toggle(
    	function () {
        	$(this).html('- Collapse');
        	$(this).prev().slideDown();
      	},
      	function () {
       			$(this).html('+ Read More...');
       			$(this).prev().slideUp();
      	}
    );

 	// ------- PAUSE FUNCTION
 	$.fn.pause = function(duration) {
    	$(this).animate({ dummy: 1 }, duration);
    	return this;
	};
	 // ------- REVERSE CHECKBOXES
	 $('#select_all').change(function() {
    var checkboxes = $(this).parent().children('input');
    if($(this).is(':checked')) {
        checkboxes.attr('checked', 'checked');
    } else {
        checkboxes.removeAttr('checked');
    }
});
	
	 // ------- WELCOME INTRO SLIDE
 	$('#welcomeIntroShort').pause(200).animate({width: 100}, 500);
    	$("#welcomeIntroButton").toggle(
   		function(){
     	$('#welcomeIntroShort').animate({
      	width: 0
     	}, 500)
     	$('#welcomeIntroLong').pause(600).animate({
      	width: 520
     	}, 500)
     	$('#welcomeIntroButton').addClass('welcomeIntroClose');
   		},
   		function()
   		{
   		$('#welcomeIntroLong').animate({
      	width: 0
     	}, 500)
      	$('#welcomeIntroShort').pause(600).animate({
     	width: 100
      	}, 500)
    	$('#welcomeIntroButton').removeClass('welcomeIntroClose');
   	});
   	// ------- NEWS TICKER
   	$("#news").newsTicker();
 	// ------- WELCOME BOX ANIMATION
    $('.welcomeBoxes').hoverIntent(function() {
    	$(this).children('a').stop().animate({ "height": '278' }, 300);
        $('#welcomeBoxesCont').stop().animate({ "height": '288' }, 300);
    }, function() {
    	$(this).children('a').stop().animate({ "height": '235' }, 300);
    });
    $('#welcomeBoxesCont').mouseleave(function(){
    	$(this).stop().animate({ "height": '246' }, 300);
    });
	// -------- PRODUCT INFO BUTTONS
    $('.shopQuarter').hoverIntent(function() {
    	$(this).children('.infoButton').children('img').stop().animate({ "opacity": '1' }, 300);
    }, function() {
    	$(this).children('.infoButton').children('img').stop().animate({ "opacity": '0' }, 300);
    });

   	// ------- FORM VALIDATION
   	$('#content form').validate();
   	// ------- PORTFOLIO
   	$('ul#portfolio').innerfade({speed: 1500,timeout: 5000,type: 'sequence',containerheight: '360px'});
   	
	// ------- SMOOTH SCROLL TO THE TOP
	$("a.anchorLink").anchorAnimate('200');
	// ------- HOME PAGE READ MORE
	$('#homePageReadMore').click(function(){
	    $('#welcomeIntroShort').pause(700).animate({width: 0}, 500);
     	$('#welcomeIntroLong').pause(1300).animate({width: 520}, 500);
     	$('#welcomeIntroButton').pause(700).addClass('welcomeIntroClose');
	});
	
	// ------ PRODUCT INTEGRATION PAGE
	
	$('#integrationImages') 
	.cycle({ 
    fx:     'fade', 
    speed:  '1000', 
    timeout: 0, 
    pager:  '#integrationSelector',
    pagerEvent: 'mouseover',
   	before: onBefore,
    pagerAnchorBuilder: function(idx, slide) { 
          return '<li>' + $(slide).attr('title') +  '</li>';
    } 
    });
	
	function onBefore() { 
    $('#integrationTextOutput').html('<h2>'+ this.title +'</h2><p>' + this.alt +'</p>');
    }
	
	////////////////////////////////////
	
	//RPM ONLY BELOW
	
	////////////////////////////////////

	// ------- NON SHOP PRODUCT DESCRIPTION PAGES
	$('#couplingSelectorDrop').hide();
	$('#couplingSelectorButton').click(function(){
    	$('#couplingSelectorDrop').slideToggle('slow');
    	$(this).text($(this).text() == 'Hide Advanced Requirements' ? 'Show Advanced Requirements' : 'Hide Advanced Requirements');
    });
	
	$('.spacerColExtra').animate({opacity: 0}, 0 );
    $('.spacerColExtra').hide();
    $('.colExtraButton').click(function(){
    	$('.colExtraButton').slideUp('slow');
    	$('.spacerColExtra').slideDown('slow');
    	$('.spacerColExtra').animate({opacity: 1}, 600 );
    });
    $('#sideSelect li a').hover(function() {
	$(this).children(".sideArrow").stop().animate({ "margin-right": 0 }, 100);}, 
	function() {
		$(this).children(".sideArrow").stop().animate({ "margin-right": 3 }, 100);
    });
    // --------- RPM NON SHOP FEATURES SLIDER
    $('.sideBody').hide();
    $('#sideSelectBody #sideArrow1').show();
	$('#sideSelect li a').click(function(){
    	$('#sideSelect li a div').removeClass('active');
    	$(this).children().addClass('active');
	var currentId = $(this).attr('id');
	var currentContainer = '#sideSelectBody #' + currentId;
    	$('.sideBody').slideUp();
    	$(currentContainer).slideDown();
    });
    

	$(".expandImage").toggle(function(){
	    $('#productImages').animate({width: 425}, 600);
		$('.prodPageDesc').animate({width: 250}, 400);
		$('#prodImageContainer, #prodPagePic').animate({width: 423, height: 423}, 600);
		$('#productImages #expandImage').text('( - ) Reduce Image');
	},
	function(){
		$('#productImages').animate({width: 300}, 500);
		$('.prodPageDesc').animate({width: 375}, 500);
		$('#prodImageContainer, #prodPagePic').animate({width: 298, height: 298}, 500);
		$('#productImages #expandImage').text('( + ) Enlarge Image');
	});
	
	$("#accountBarButton").mouseenter(function(){
		$("#accountBarDrop").show();
		$("#accountBarDrop").next('a').addClass('active');
	});
	$("#accountBarButton").mouseleave(function(){
		$("#accountBarDrop").hide();
		$("#accountBarDrop").next('a').removeClass('active');
	});
	
	$("#basketBarButton").mouseenter(function(){
		$("#basketBarDrop").show();
		$("#basketBarDrop").next('a').addClass('active');
	});
	$("#basketBarButton").mouseleave(function(){
		$("#basketBarDrop").hide();
		$("#basketBarDrop").next('a').removeClass('active');
	});
	
	$("#closeDescDrop").click(function(){
		$("#innerDescDrop").slideToggle("slow");
		$(this).text($(this).text() == 'Hide' ? 'Show' : 'Hide');
	});
	$("#innerDescDrop2").hide();
	$("#closeDescDrop2").click(function(){
		$("#innerDescDrop2").slideToggle("slow");
		$(this).text($(this).text() == 'Hide' ? 'Show' : 'Hide');
	});
	$("#showDiscount").click(function(){
        $("#qtyDiscounts").toggle();
        return false;
    //  $(this).slideUp("slow");
	});
	
	//Product Thumb - Alt On Hover
	$('.toolTip').hover(
	    function() {
	    this.tip = $(this).children('img').attr('title');
	    $(this).append(
	     '<div class="toolTipWrapper">'
	        +'<div class="toolTipTop"></div>'
	        +'<div class="toolTipMid">'
	          +this.tip
	        +'</div>'
	      +'</div>'
	    );
	    this.title = "";
	    this.width = $(this).width();
	    $(this).find('.toolTipWrapper').css({left:this.width-22})
	    $('.toolTipWrapper').fadeIn(300);
	  },
	    function() {
	      $('.toolTipWrapper').fadeOut(100);
	      $(this).children('.toolTipWrapper').remove();
	        this.title = this.tip;
	      }
	  );
	Cufon.replace('#content h1')('#content h2')('#content h3')('#content h4')('#prodContent h1')('#prodContent h2')('#prodContent h3')('#prodContent h4')('#content h5')('.welcomeBoxes h2')('.welcomeInfoDrop p')('#welcomeIntroLong h1')('#welcomeNews')('#catalogueBanner h4')('#welcomeFooterContainer a')('#welcomeFooterContainer p')('#footerContainer a')('#footerContainer p')('.checkoutHead td');
});
function displayimage(filename, thumb){
    $('#prodPagePic').attr('src','images/products/large/' + filename );
    $(".prodPageSmallImg").removeClass("prodPageSmallImgActive");
    $(thumb).addClass("prodPageSmallImgActive");
    return false;
}
