﻿
/*********************** Product Tabs ***************************/
$(function () {
    var tabContainers = $('div.content-switcher > div');
    
    $('div.tabs ul a').click(function () {
    	/*tabContainers.hide().filter(this.hash).fadeIn("slow");*/
        tabContainers.fadeOut("slow").animate({foo:1},600).filter(this.hash).fadeIn("slow");
        $('div.tabs ul li').removeClass('tab-active');
        $(this).parent().addClass('tab-active');
        
        return false;
    }).filter(':first').click();
});

/*********************** What's this button hover ***************************/
function showToottip(buttonId)
{
	$("#" + buttonId).parent("li").parent("ul").find('li input[value="Dec1"]').removeClass("down-disabled");
}

$("button").click(function () {
      $("div.whatsthis:hidden").show("fast");
    });

/*********************** Quantity Manipulator ***************************/
/* Sets down arrow to "active" if there is more than one item in basket */
$(document).ready(function(){
$('input.shorttextbox').each(function(index){
    var value = $(this).val()
    if(parseInt(value)>1)
		{
			
			$(this).parent("span").parent("div").find('li input[value="Dec1"]').removeClass("down-disabled");
			$(this).parent("span").parent("div").find('li input[value="Dec1"]').addClass("down");
		}
});
});

function incrementBoxCount(id, buttonId)
{
	var boxCount = $("#"+id).val();
	if(parseInt(boxCount)>=1)
	{
		decButtonOn(buttonId);
		boxCount++;
		$("#"+id).val(boxCount);
	}
	else
	{
		$("#"+id).val("1");
	}
}

function decrementBoxCount(id, buttonId)
{
	var boxCount = $("#"+id).val();
	if(parseInt(boxCount)>=2)
	{
		boxCount--;
		$("#"+id).val(boxCount);
		decButtonOn(buttonId);
		
		if(boxCount==1)
			{
				decButtonOff(buttonId);
			}
		}
	else
	{
		$("#"+id).val("1");
		decButtonOff(buttonId)
	}
}

function decButtonOn(buttonId)
{
		$("#" + buttonId).parent("li").parent("ul").find('li input[value="Dec1"]').removeClass("down-disabled");
		$("#" + buttonId).parent("li").parent("ul").find('li input[value="Dec1"]').addClass("down");
}

function decButtonOff(buttonId)
{
		$("#" + buttonId).parent("li").parent("ul").find('li input[value="Dec1"]').removeClass("down");
		$("#" + buttonId).parent("li").parent("ul").find('li input[value="Dec1"]').addClass("down-disabled");
}

/*********************** Move PopUp Holder IE6 ***************************/
$(function () {
    $('div.popup-holder').remove().insertAfter('div.page'); 
});

/*********************** Image Switcher ***************************/

$(function() 
{
	$(".switch-image").click(function() 
	{
		var image = $(this).attr("rel");
		$('#product-image').hide();
		$('#product-image').fadeIn('slow');
		$('#product-image').html('<img src="' + image + '"/>');
		return false;
	});
});

/*********************** Toggle What's this ***************************/
 $(document).ready(function() 
{
	$('.cv2-whats-this .description').hide();
	$(".cv2-whats-this a.link").click(function() {
    /*$('.cv2-whats-this .description:first').toggle();*/
    $(this).parents(".cv2-whats-this").find(".description").toggle("normal");
    return false;
}); 
});


/*********************** Password Strength Indicator ***************************/

$.fn.passwordStrength = function( options ){
	return this.each(function(){
		var that = this;
		that.opts = {};
		that.opts = $.extend({}, $.fn.passwordStrength.defaults, options);

		that.div = $(that.opts.targetDiv);
		that.defaultClass = that.div.attr('class');

		that.percents = (that.opts.classes.length) ? 100 / that.opts.classes.length : 100;

		v = $(this)
		.keyup(function(){
			if( typeof el == "undefined" )
			this.el = $(this);
			var s = getPasswordStrength (this.value);
			var p = this.percents;
			var t = Math.floor( s / p );

			if( 100 <= s )
			t = this.opts.classes.length - 1;

			this.div
			.removeAttr('class')
			.addClass( this.defaultClass )
			.addClass( this.opts.classes[ t ] );
		})
		/*Removed generate password button creation*/
	});

	function getPasswordStrength(H){
		var D=(H.length);
		
		/*Added below to make all passwords less than 4 characters show as weak*/
		if (D<4) { D=0 }
		
		if(D>5){
			D=5
		}
		var F=H.replace(/[0-9]/g,"");
		var G=(H.length-F.length);
		if(G>3){G=3}
		var A=H.replace(/\W/g,"");
		var C=(H.length-A.length);
		if(C>3){C=3}
		var B=H.replace(/[A-Z]/g,"");
		var I=(H.length-B.length);
		if(I>3){I=3}
		var E=((D*10)-20)+(G*10)+(C*15)+(I*10);
		if(E<0){E=0}
		if(E>100){E=100}
		return E
	}
	
	/* Removed generate password function*/
};

$(document).ready(function(){
	$('#password-input-box input[type="password"]').passwordStrength({targetDiv: '.pwd-indicator',classes : Array('weak','medium','strong')});

});

/*********************** Image Rotator ***************************/

function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

$(document).ready(function() {		
	//Load the slideshow
	theRotator();
});
