/*   paste in your code and press Beautify button   */
$(document).ready(function () {
//from quote.js begin

/*Global User Object. Checks the html data tag for usertype and builds an object that you can reference in your scripts for triggering different events for different users*/
var usertype = $("html").data("user-type");
if (usertype === "R") {
	usertype = "rep";	
} else {
	usertype = "user";
}

user = {
	type: usertype	
};

//Extend Array object to add a function to remove items
	Array.prototype.removeByValue = function (val) {
		for (var i = 0; i < this.length; i++) {
			if (this[i] == val) {
				this.splice(i, 1);
				break;
			}
	}
}

jQuery.validator.setDefaults({ 

ignore: ".ignore",
messages: {
		company: { 
		
			required: "Please enter your company name" 		
		},
		
		first_name: { 
		
			required: "Please enter a first name" 		
		},
		
		last_name: { 
		
			required: "Please enter a last name" 		
		},
		
		phone_number: { 
		
			required: "Please enter a phone number" 		
		},
		
		address1: { 
		
			required: "Please enter an address" 		
		},
		
		state: { 
		
			required: "Please select a state" 		
		},

		zipcode: { 
		
			required: "Please enter an zip code" 		
		},
		
		country: { 
		
			required: "Please select a country" 		
		},
		
		saved_shipping_addresses: {
			required: "Please choose a shipping address"
			
		}


	}
});


	//Prevent bubbling test 

	$("#expand_description").change(function()
	{
		var selectevalue=$($(this)).val();	
		var processv=$("#processfolder").val();
		$.get(processv, {'action':'11','q' : selectevalue},
			function(data)
			{
				$("#product_instruction").html(data);
				$("#submiterrormessage").html('');			
			});
	});	
//quickbuy.js start

	$("#product_customddl").change(function()
	{
		var selectevalue=$($(this)).val();	
		var processv=$("#processfolder").val();
		$.get(processv, {'action':'7','q' : selectevalue},
			function(data)
			{
				$("#product_instruction").html(data);
				$("#submiterrormessage").html('');			
			});
	});	

	$("#product_category").change(function()
	{
		var selectevalue=$($(this)).val();	
		var processv=$("#processfolder").val();
		$.get(processv, {'action':'2','q' : selectevalue},
			function(data)
			{
				$("#productresult").html(data);
			});
	});		

//quickbuy.js end

	//Apple Style MouseTooltip 

	function initiateMouseTip() {
		$('a[rel=mousetip]').mouseover(function (e) {

			var tip = $(this).attr('title');
			$(this).attr('title', '');
			var newMousetip = '<div class="mousetip"><p class="mousetipcopy">' + tip + ' </p></div>';
			$(this).append(newMousetip);
			$(".mousetip").css('top', e.pageY + 10);
			$(".mousetip").css('left', e.pageX + 20);

			$('.mousetip').fadeIn('500');
			$('.mousetip').fadeTo('10', 0.8);

		}).mousemove(function (e) {

			$(".mousetip").css('top', e.pageY + 10);
			$(".mousetip").css('left', e.pageX + 20);

		}).mouseout(function () {

			$(this).attr('title', $('.mousetipcopy').html());
			$(this).children('div.mousetip').remove();
		});
	}

	initiateMouseTip();

	/*!Product Detail Page Specifications Tab */

	$("span.tabs").tabs("#product-detail-specification-slider > section", {
		effect: 'fade',
		history: true,
		onClick: function () {
	
		}
	});

	$("form.disable-enter").bind("keypress", function (e) {
		if (e.keyCode == 13) return false;
	});

	/* Custom Styled Select Menus */


//Form Focus
$("form :input").focus(function() {
  $("label[for='" + this.id + "']").addClass("labelfocus");
}).blur(function() {
  $("label").removeClass("labelfocus");
});



	
//Breadcrumb Meganavigation
$(".open-dropdown").click(function () {
	$("#product-navigation").slideDown('fast');

});

	//Expand Collapse
	$(".collapse-trigger").click(function () {
		$(this).children(".expand-container").slideToggle('fast');
	});


/*!Rep Account Managment Tabs */

/*! Global Overlay Call */
	$("a.has-external-overlay[rel]").live('click', function(e) {
		 
		e.preventDefault();
		$(this).overlay({
		
		mask: '#333333',
		left: '50%',
		
		onBeforeLoad: function() {
		
		// grab wrapper element inside content
		var wrap = this.getOverlay().find(".contentWrap");
		
		// load the page specified in the trigger
		wrap.load(this.getTrigger().attr("href"));
		},
		
		load: true
		
		});
	});
	
	$("a.has-overlay[rel]").overlay({

		mask: '#333333',
		left: '50%'

	});
	
function ieLessThan8OptionDisable() {
    if ($.browser.msie && parseFloat($.browser.version) < 8) {
        $("select").find("[disabled]").addClass("disabled").removeAttr("disabled");
        $("select").change(function(){
            var selected = $(this).val();
            var disabled = $(this).find("[value="+selected+"]").hasClass("disabled");
            if (disabled) {
                /*alert("This option is disabled.\nSelect will be set to the first option.");*/
                $(this).find("option:first").attr("selected","selected");
            }
        });
    }
}

ieLessThan8OptionDisable();

function tagClasses() {
    var tagImage = $(".tags-image");
    
    $(tagImage).each(function(){
        var imageTest = $(this).children("a").children().length;
    if (imageTest != 0) {
        $(this).parent().children(".tags-header").addClass("ie7");
    }});
}

tagClasses();
	

});
