/* CYCLE */

$(function() {
    $('#promo').cycle({
        fx:     'scrollVert',
        speed:  1000,
        timeout: 8000,
        pager:  '#promo-nav',
		slideExpr: 'a',
		pagerAnchorBuilder: function(idx, slide) {  
        return '<a href="#" title="' + jQuery(slide).attr("title") + '">' + jQuery(slide).attr("title") + '</a>';
    	} 
    });
});

$(function() {
    $('#left-cycle').cycle({
        fx:     'fade',
        speed:  'fast',
        timeout: 3000,
		slideExpr: 'img'
    });
});

$(function() {
    $('#deals-cycle').cycle({
        fx:     'scrollHorz',
        speed:  1000,
        timeout: 0,
        prev:   '#deals-cycle-prev', 
    	next:   '#deals-cycle-next',
		slideExpr: 'div.summary-row'
    });
});

$(function() {
    $('#deals2-cycle').cycle({
        fx:     'scrollHorz',
        speed:  1000,
        timeout: 0,
        prev:   '#deals2-cycle-prev', 
    	next:   '#deals2-cycle-next',
		slideExpr: 'div.summary-row'
    });
});

$(function() {
    $('#deals3-cycle').cycle({
        fx:     'scrollHorz',
        speed:  1000,
        timeout: 0,
        prev:   '#deals3-cycle-prev', 
    	next:   '#deals3-cycle-next',
		slideExpr: 'div.summary-row'
    });
});

$(document).ready(function(){	
	
	/* REMOVE EMPTY SPAN.WAS */
	$(".was del:empty").parent().remove();

	/* CART BUTTON */
	$(".cartbutton").click(function(){
		$(this).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;
	});

	$(" #leftnav ul:empty").css("display", "none");
	$(" #leftnav ul 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'
	});


	/* 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');
	$('#cartmaininner1 tr:even').addClass('CartTrAlt');
	$(".partnobox tr:first").addClass('bold');
	$(".partnobox tr:odd").addClass("beige");
	
	/* NEW WINDOW FUNCTION */
	$(function(){
		$('a.new-window').click(function(){
			window.open(this.href);
			return false;
		});
	});
	
	/* IMAGE MANAGEMENT */
	$(".psum img").error(function(){
	  $(this).attr('src', 'images/product_images/none.gif');
	});
	
	/* FANCYBOX */
	$("a#productimage").fancybox();
	
	$(".fbl").fancybox();
	
});
