/* MENU FUNCTION */

function mainmenu(){
$(" #nav ul ").css({display: "none"}); // Opera Fix
$(" #nav li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(200);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});
}

/* 2 DECIMAL PLACES FUNCTION */
Number.prototype.toDecimals=function(n){
    n=(isNaN(n))?
        2:
        n;
    var
        nT=Math.pow(10,n);
    function pad(s){
            s=s||'.';
            return (s.length>n)?
                s:
                pad(s+'0');
    }
    return (isNaN(this))?
        this:
        (new String(
            Math.round(this*nT)/nT
        )).replace(/(\.\d*)?$/,pad);
}

/* CYCLE */

$(function() {
    $('#promo').cycle({
        fx:     'fade',
        speed:  'fast',
        timeout: 3000,
        pager:  '#promo-nav',
		slideExpr: 'img'
    });
});

$(function() {
    $('#promo2').cycle({
        fx:     'fade',
        speed:  'fast',
        timeout: 3000,
        pager:  '#promo2-nav',
		slideExpr: 'img'
    });
});

$(function() {
    $('#specialised-bikes .cyclebatch').cycle({
        fx: 'scrollHorz', 
        timeout:  0, 
        speed:    500, 
        prev:    '#specialised-bikes .prev', 
        next:    '#specialised-bikes .next',
		pager:  '#specialised-bikes-nav',
		slideExpr: 'div.summary-row'
    });
});

$(function() {
    $('#front-bikes .cyclebatch').cycle({
        fx: 'scrollHorz', 
        timeout:  0, 
        speed:    500, 
        prev:    '#front-bikes .prev', 
        next:    '#front-bikes .next',
		pager:  '#front-bikes-nav',
		slideExpr: 'div.summary-row'
    });
});

$(function() {
    $('#cx-bikes .cyclebatch').cycle({
        fx: 'scrollHorz', 
        timeout:  0, 
        speed:    500, 
        prev:    '#cx-bikes .prev', 
        next:    '#cx-bikes .next',
		pager:  '#cx-bikes-nav',
		slideExpr: 'div.summary-row'
    });
});

$(function() {
    $('#cx2-bikes .cyclebatch').cycle({
        fx: 'scrollHorz', 
        timeout:  0, 
        speed:    500, 
        prev:    '#cx2-bikes .prev', 
        next:    '#cx2-bikes .next',
		pager:  '#cx2-bikes-nav',
		slideExpr: 'div.summary-row'
    });
});

$(function() {
    $('#cx3-bikes .cyclebatch').cycle({
        fx: 'scrollHorz', 
        timeout:  0, 
        speed:    500, 
        prev:    '#cx3-bikes .prev', 
        next:    '#cx3-bikes .next',
		pager:  '#cx3-bikes-nav',
		slideExpr: 'div.summary-row'
    });
});

$(function() {
    $('#bianchi .cyclebatch').cycle({
        fx: 'scrollHorz', 
        timeout:  0, 
        speed:    500, 
        prev:    '#bianchi .prev', 
        next:    '#bianchi .next',
		pager:  '#bianchi-nav',
		slideExpr: 'div.summary-row'
    });
});

$(function() {
    $('#new-arrivals .cyclebatch').cycle({
        fx: 'scrollHorz', 
        timeout:  0, 
        speed:    500, 
        prev:    '#new-arrivals .prev', 
        next:    '#new-arrivals .next',
		pager:  '#new-arrivals-nav',
		slideExpr: 'div.summary-row'
    });
});

$(function() {
    $('#summer-road .cyclebatch').cycle({
        fx: 'scrollHorz', 
        timeout:  0, 
        speed:    500, 
        prev:    '#summer-road .prev', 
        next:    '#summer-road .next',
		pager:  '#summer-road-nav',
		slideExpr: 'div.summary-row'
    });
});
$(function() {
    $('#food-offers .cyclebatch').cycle({
        fx: 'scrollHorz', 
        timeout:  0, 
        speed:    500, 
        prev:    '#food-offers .prev', 
        next:    '#food-offers .next',
		pager:  '#food-offers-nav',
		slideExpr: 'div.summary-row'
    });
});
$(function() {
    $('#topeak-offers .cyclebatch').cycle({
        fx: 'scrollHorz', 
        timeout:  0, 
        speed:    500, 
        prev:    '#topeak-offers .prev', 
        next:    '#topeak-offers .next',
		pager:  '#topeak-offers-nav',
		slideExpr: 'div.summary-row'
    });
});


$(document).ready(function(){	

	/* FINANCE TOOLS */
	TheFinanceDefaultTotal = $('#TheFinanceTotalPrice').text();
	TheFinanceDefaultTotal = TheFinanceDefaultTotal.replace(',' , '');
	TheFinanceDefaultTotal = TheFinanceDefaultTotal.replace('\u00A3' , '');
		TheFinanceDefaultTotal = parseFloat(TheFinanceDefaultTotal);
		var	TheFinanceDefaultTotal,
		TheFinanceDefaultTotal=TheFinanceDefaultTotal.toDecimals(2);
		
	$(".update_price").change(function() {
		TheDeposit = $("#intended-deposit").val();
		TheDeposit = TheDeposit.replace("," , "");
		TheDeposit = TheDeposit.replace("\u00A3" , "");
		TheDeposit = parseFloat(TheDeposit);
		var TheNewTotal = TheFinanceDefaultTotal - TheDeposit,
		TheNewTotal=TheNewTotal.toDecimals(2);
		$('#TheFinanceTotalPrice').text("\u00A3" + TheNewTotal);	
		$('#theFormTotal').val(TheNewTotal);
			/* TERM CALCULATION */
			term = $('#TheTerm').val();
			term = parseFloat(term);
			TermPayments = TheNewTotal / term;
			TermPayments=TermPayments.toDecimals(2);
			$('#TermPaymentsTotal').html(term + " monthly payments of <strong>\u00A3" + TermPayments + "</strong>");
	});

	/* LOGIN FORM CHANGE */
	var thezoneid = $("#urlvarzoneid").text();
	var theclassid = $("#urlvarclassid").text();
	$("#CustomerRegistration").attr("action", "custreg.asp?zoneid="+thezoneid+"&classid="+theclassid);
	$("#loginform").attr("action", "custreg.asp?action=validatelogin&zoneid="+thezoneid+"&classid="+theclassid);
	
	$("#showdisclaimer").click(function(){
		$("#disclaimer").slideToggle('fast');
		$(this).toggleClass('active');
	});

	/* 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;
	});
	
	/* DEAL BUTTONS */
	$('#deal-buttons a[name="Free Delivery"]').css('display', 'block');
	$('#deal-buttons a[name="0% Finance Available"]').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 */		
	$("#nav li a.toplevel:not(:first)").parent().addClass('bleft');
	$("#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');
	$(".partnobox tr:first").addClass('bold');
	$(".partnobox tr:odd").addClass("beige");
	$(".cp-small:last").addClass("mleft");
	$(".member-type").text($("#member-type").text());
	$(".breadcrumb font:first").remove();
	$(".breadcrumb a:first").addClass('first');
	$(".breadcrumb:last").parent().append('<div class="clear"></div>');
	
	/* SLIDE TOGGLES */
	$("#togglefooter").click(function(){
		$("#footer div.block").slideToggle("fast");
		$(this).toggleClass("active"); return false;
	});
	
	mainmenu();
	
	/* BRAND INFO RETRIEVAL */
	var brand = $(".brandicon a").attr("title");
	if (brand)
	{
		brand = brand.replace("Search for everything ", "")
		brand = brand.replace(" ", "-")
		brand = brand.replace(" ", "-")
		$("#getbrandinfo").click(function(){
			$("#brandinfo").load("brands/"+ brand +".html");
		});
		$("#searchbrandinfo").load("brands/"+ brand +".html");
	}
	
	/* PRINT FUNCTION */
	$("#print").click(function(){
		$(".cp").printElement({ overrideElementCSS: true });
	});
	
	/* HIDE WAS IF BLANK */
	$('span[name="\u00A30.00"}').css('display', 'block');
	
	/* SPECIAL OFFER ??? */
	if($('#sot-was span').is(":empty")){
		$('#special-offer-title').remove();
	}
	
	/* NEW WINDOW FUNCTION */
	$(function(){
		$('a.new-window').click(function(){
			window.open(this.href);
			return false;
		});
	});
	
	/* IMAGE FIX */
	$("img").error(function(){
	  $(this).css('display', 'none');
	});
	
	/* FANCYBOX */
	$("a#productimage").fancybox();
	$("a#pricereport").fancybox({
		'titleShow'     : false
	});
	$("a#deal-button-finanace").fancybox({
		'titleShow'     : false
	});
	$("#closepricereportform").click(function(){
		$.fancybox.close();
	});
	
	/* FORM FUNCTIONS */
	$("#pricereportform .partnobox tr:first").css('display', 'none');
	$("#pricereportform .partnoboxlt").css("display", "none");
	$("#pricereportform .partnoboxq .cartbutton").each(function(){
		var partno = $(this).parent().parent().find('.partnoboxp').text();
		$(this).replaceWith("<input type='radio' name='radiobutton' value='" + partno + "' class='radiobutton'>");
	});	

	/* CART BUTTON */
	$(".cartbutton").click(function(){
		$(this).parent().find(".cartquantity").val('1');
		$('#ato-m').submit();
	});
	
});

<!--

function MM_jumpMenu(targ,selObj,restore){ //v3.0

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

  if (restore) selObj.selectedIndex=0;

}

//-->
