/* CYCLE */

$(function() {
    $('#banner').cycle({
        fx:     'fade',
        speed:  1000,
        timeout: 6000,
        pager:  '#banner-nav',
		slideExpr: 'div.banneritem'
    });
});

/* SALON-CYCLE */
	$(function() {
    $('#salon-cycle').cycle({
        fx:     'fade',
        speed:  1000,
        timeout: 6000,
		slideExpr: 'a'
    });
});

$(document).ready(function(){
	
	/* CART BUTTON */
	$(".cartbutton").click(function(){
		QuantityValue = $(this).parent().parent().find(".cartquantity").val();
			if (QuantityValue == 0) {$(this).parent().parent().find(".cartquantity").val('1');}
		$('#ato-m').submit();
	});
	
	/* CART ZONES */
	var zonename = $("#zonename").text();
	$("#zoneid option[name='"+zonename+"']").attr('selected', 'selected');
	$("#defaultzoneid strong").click(function(){
		$("#zoneid").slideToggle("fast");
		$(this).toggleClass("active"); return false;
	});

	$(" #nav ul:empty").css("display", "none");
	$(" #nav li a.current").parent().find("ul").css("display", "block");
	
	/* FORM JS */
	$(".addqty").click(function(){
		$(this).next().val( Number($(this).next().val()) + 1 );
		x = $(this).parent().attr('name');
        $(".changetheqty").change();
	});
	
	$(".subtractqty").click(function(){
		$(this).prev().val( Number($(this).prev().val()) - 1 );
		x = $(this).parent().attr('name');
        $(".changetheqty").change();
	});
	
	$(".changetheqty").change(function() {
		alert
	  t = eval("document." + x + ".quantity")
        failed = false
        if (isNaN(t.value))
        {
           alert("Please enter a valid number in quantity ");
           t.value = 1;
           t.focus();
           failed = true
     
        }
        else 
        {
          if (t.value <= 0 )
          {
                        alert("Quantity cannot be zero or less");
                        t.value = 1;
                        t.focus();
      
                        failed = true
          }
        }
  		eval("document." +x+ ".submit()")
        if (failed)
           document ['navigation'].quanttest.value = 'nogo'
	});
	
	
	/* hide duplicates */
	var seen = {};
	$('.namescan').each(function() {
		var txt = $(this).text();
		if (seen[txt])
			$(this).parent().parent().remove();
		else
			seen[txt] = true;
	});
	/* hide */


	/* STYLE FUNCTIONS */
	$("#header-nav li:not(:last)").addClass('bright');
	$("#footer div.block:not(:first)").addClass('bright');
	$("#brand-icons a:not(:last)").addClass('mright');
	$(".summary-row:last").addClass('bnone');
	$("#productlist .partnobox tr:first").addClass('bold');
	$('#cartmaininner1 tr:even').addClass('CartTrAlt');
	$(".partnobox tr:odd").addClass("beige");
	$("#globalsearch select option:first").text('Select a brand...');
	$("#globalsearch select option:first").val('');
	
	/* NEW WINDOW FUNCTION */
	$(function(){
		$('a.new-window').click(function(){
			window.open(this.href);
			return false;
		});
	});
	
	/* FANCYBOX */
	$("a#productimage").fancybox({
		'titleShow'     : false
	});
	
	/* IMAGE MANAGEMENT */
	$(".psum img").error(function(){
	  $(this).attr('src', 'images/product_images/none.gif');
	});	
});
