$('html').addClass('hideJSContent');

/* *******************************************************************
Run the hide functions first to try avoid seeing the hide on page load
******************************************************************* */


/* *******************************************************************
Page font resizer, The key classes are .resetfont, .increasefont, and .decreasefont
******************************************************************* */
$(document).ready(function(){
  // Reset Font Size
  var originalFontSize = $('html').css('font-size');
    $(".resetFont").click(function(){
    $('html').css('font-size', originalFontSize);
  });
  // Increase Font Size
  $(".increaseFont").click(function(){
    var currentFontSize = $('html').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.2;
    $('html').css('font-size', newFontSize);
    return false;
  });
  // Decrease Font Size
  $(".decreaseFont").click(function(){
    var currentFontSize = $('html').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*0.8;
    $('html').css('font-size', newFontSize);
    return false;
  });
});


/* *******************************************************************
Adc Dynamic form, see http://maindeva/bonus
******************************************************************* */

$(document).ready(function(){
$('.quantity input').keypress(function(event) {
if (event.charCode && (event.charCode < 48 || event.charCode > 57))
{
event.preventDefault();
}
});

$('#o1, #o2').hide()
var totalQuantity;
$('*').mouseout(function () {
                        totalQuantity = 0;
                        $('.quantity input').each(function() {
                                    var quantity = parseInt(this.value);
                                    quantity = isNaN(quantity) ? 0 : quantity;
                                    totalQuantity += quantity;
                        });
                                    if(totalQuantity == 0 ){
                        $('#o1, #o2').hide('slow')
            }
            if(totalQuantity == 1 ){
                        $('#o1').show('slow')
                        $('#o2').hide('slow')
            }
            if(totalQuantity >= 2 ){
                        $('#o1').hide('slow')
                        $('#o2').show('slow')
            }
            });

//Duplication of the above function this time triggered by the .change event for those who are not using a mouse.
$('*').change(function () {
                        totalQuantity = 0;
                        $('.quantity input').each(function() {
                                    var quantity = parseInt(this.value);
                                    quantity = isNaN(quantity) ? 0 : quantity;
                                    totalQuantity += quantity;
                        });
                                    if(totalQuantity == 0 ){
                        $('#o1, #o2').hide('slow')
            }
            if(totalQuantity == 1 ){
                        $('#o1').show('slow')
                        $('#o2').hide('slow')
            }
            if(totalQuantity >= 2 ){
                        $('#o1').hide('slow')
                        $('#o2').show('slow')
            }
            });
});
 

$(document).ready(function() {
	$('.sitebrowse-item ul:not(:first)').hide();
});


/* ***************************
Choose delivery slider options
*************************** */
$(document).ready(function() {
	
	// Slide up any input that is not selected
	$('ol.information input').parent().find('div.formreveal:visible').slideUp();
	// Slide down the selected radio button
	$('ol.information input:checked').parent().find('div.formreveal').slideDown();
	
	// Slider options when the user click the radio/label
	$('ol.information input[name^="del_method"]').click(function() {
		$(this).parents('ol.information').find('div.formreveal:visible').slideUp();
		$(this).parent().find('div.formreveal').slideDown();
	});
});

/* ****************
Accordian functions
**************** */
$(document).ready(function() {
	$('.sitebrowse-item ul:first').show();
	$('.sitebrowse-item h2:first').addClass('open');	
	$('.sitebrowse-handle').click(function () {
		$('.sitebrowse-item ul:visible').slideUp().prev().removeClass('open');
		$(this).addClass('open').next().slideDown();
	});
	$('.browseOptionsLink').click(function () {
		$(this).next('.browseOptions').slideToggle();
	});
});

/* ***********************************************
Make LIs hoverable in IE6 for site drop-down menus
*********************************************** */
$(document).ready(function() {
	$('li.sitenavTab').hover(function() {
		$(this).find('.sitenavDropDown').show();
		$(this).find('a.sitenavLink').css('backgroundColor', '#c1d34b');
	}, function() {
		$(this).find('.sitenavDropDown').hide();
		$(this).find('a.sitenavLink').css('backgroundColor', '#791539');
	});
});

$(document).ready(function() {
   $('#homepage-ui-tabs > ul').tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 7000);
});

/* ****************
Show/Hide functions
**************** */
$(document).ready(function() {
    // Add a click function to all a tags with class of showhide-toggle, then toggle the next element.
    	$('p a.review-toggle').click(function() {	
    		$(this).parent().next().slideToggle(400);	
    		return false;	
    	});
    // Show/Hide script including the code for a close button/link
    	$('a.showhide-toggle').click(function() {
    		$(this).next().slideToggle(300);
    		return false;	
    	});
    	$('a.close').click(function() {
    		$(this).parents().filter('div.info').slideUp(300);
    		return false;
    	});
});

$(document).ready(function() {
    // Apply this with JS so when non-JS user renders the carousel they'll see overflow default i.e. scroll bars	
    $('#homepage-carousel').css({'overflow':"hidden"});
    //Creates next and previous buttons on carousel
    $("#homepage-carousel").prepend('<div class="prev"></div><div class="next"></div>');
	    
    var getFullWidth = 0;
    $("#carouselContainer div.carouselItem").each(function() {
    	  getFullWidth = getFullWidth + $(this).width() + 10;
    });
    
    $('#carouselContainer').css({'width':getFullWidth + "px"})
    
    var containerWidth = $("#homepage-carousel").width() + 31;    
    var maxScroll = getFullWidth - containerWidth;
    
    $(".next").hover(function () {
    	$('#carouselContainer').stop().animate({left:"-" + maxScroll + "px"}, 2000);
    }, function () {
    	$('#carouselContainer').stop();
    });
    
    $(".prev").hover(function () {
    	$('#carouselContainer').stop().animate({left:'21px'}, 2000);
    }, function () {
    	$('#carouselContainer').stop();
    });
});



$(document).ready(function() {
    if ($.browser.msie && $.browser.version <= 6 ) {
        $('.sitenavTab').hover(function () {
            $('.browseDropdown').css({visibility:'hidden'});
        }, function(){
            $('.browseDropdown').css({visibility:'visible'});
        });
    }
});

/*CVC for new card*/
$(document).ready(function() {	
	$("td.otheroption").hide();
	$(".paymentOptions").change(function () {
		if ($('.otheroptions').is(':selected')) {
			$(this).parent().parent().find('td.otheroption').fadeIn();
		} else {
			$(this).parent().parent().find('td.otheroption').fadeOut();
		}   
	});
});

/*CVC for Stored*/
$(document).ready(function() {
    
    CheckStoredCVCRequired();
    CheckCVCRequired();
	checkmaestro();
    
    $("input:radio").click(function() {
        CheckStoredCVCRequired();
    });
	$("#cc_type").change(function() {
	    CheckCVCRequired();
        checkmaestro();        
    });
});

function checkmaestro()
{
	
	var maestroValue = $('#cc_type :selected').val();
	
    if (maestroValue == 'SW::Maestro (Switch)'){
        $('#maestro_additions').show();    
    }
    else {
        $('#maestro_additions').hide();  
    }   
}
function CheckCVCRequired(){
    // $('#cvcreq').addClass('PGDHide');
    if ($("select#cc_type option[selected]").attr('data') == 'cvc_req') {
        $('#cvcreq').removeClass('PGDHide');
        $('#cvcLabel').addClass('mandatory');
    }
    else {
        $('#cvcreq').addClass('PGDHide');
        $('#cvcLabel').removeClass('mandatory');
    }
}

function CheckStoredCVCRequired()
{
    if ($("input:radio:checked").attr("data") == 'cvc_req') {
            $('#cvcscreq').removeClass('PGDHide');
            $('#cvcSCLabel').addClass('mandatory');
            //alert('one');
        }
        else {
            $('#cvcscreq').addClass('PGDHide');
            $('#cvcSCLabel').removeClass('mandatory');
            //alert('two')
        }   
}
	
// Slider options when the user click the radio/label
	//$('ol.information input:radio').click(function () {
		//$(this).parents('ol.information').find('div.formreveal:visible').slideUp();
		//$(this).parent().find('div.formreveal').slideDown();
	//});


//Click to collect functions
$(document).ready(
            function() {
                $(":input[name='addrno']").change(
                function() {
                    deliveryPostcode = $(":input[name='addrno']:checked + span").text();
                    $(":input[name='shop']:radio").each(function() {
                        var shoppostcode = $(this).val();
                        var mapQuery = deliveryPostcode + '&to=' + shoppostcode;
                        //mapQuery = escape(mapQuery);
                        mapQuery = 'directions.aspx?from=' + mapQuery;
                        var shoppostcode2 = $(this).next('a').attr('href', mapQuery);
                    })
                }
            )

            }
         );