$(document).ready(function () {
    // PRODUCTS DROP DOWN
    $('#mainNav a, #social').hover(function () {
        var className = $(this).attr('id');
        if (className == 'ctl00_Navigation_a3') {
            $('#productsNav').show();
            $('#diamondNav').hide();
            $('#helpadviceNav').hide();
            $('#aboutusNav').hide();
        } else if (className == 'a6') {
            //$('#diamondNav').show();
            $('#productsNav').hide();
            $('#helpadviceNav').hide();
            $('#aboutusNav').hide();
        } else if (className == 'ctl00_Navigation_a2') {
            $('#helpadviceNav').show();
            $('#productsNav').hide();
            $('#diamondNav').hide();
            $('#aboutusNav').hide();
        } else if (className == 'ctl00_Navigation_a5') {
            $('#aboutusNav').show();
            $('#productsNav').hide();
            $('#diamondNav').hide();
            $('#helpadviceNav').hide();
        } else {
            $('#productsNav').hide();
            $('#diamondNav').hide();
            $('#helpadviceNav').hide();
            $('#aboutusNav').hide();
        }
    }
    );


    $('#helpadviceNav').hide();
    $('#aboutusNav').hide();

    /*$('#mainNav a').each(function (itemcount) {
        var thisHref = $(this).attr('href');
        switch (thisHref) {
		    case '/help-and-advice/':
		        $(this).bind({mouseenter:function(e){$('#helpadviceNav').show();}});
                break;
            case '/about-us/':
                $(this).bind({mouseenter:function(e){$('#aboutusNav').show();}});
                break;
		}
    });

    $('#helpadviceNav').mouseleave(function(){
        var thisHref = $(this).attr('href');
        if (thisHref != '/help-and-advice/'){$('#helpadviceNav').hide(); }
    });

    $('#aboutusNav').mouseleave(function(){
        var thisHref = $(this).attr('href');
        if (thisHref != '/about-us/'){$('#aboutusNav').hide(); }
    });*/

    $(".sub-navigation").each(function(itemcount){
        $(this).bind({
            mouseenter:function(e){
                $(this).addClass('nav-show');
            },
            mouseleave:function(e){
                $(this).hide();
                $(this).removeClass('nav-show');
            } 
        });
    });

    /*$('').mouseleave(function () {

        var className = $(this).attr('id');
        if (className != 'ctl00_Navigation_a3') {
            $('#productsNav').hide();
        } else if (className != 'a6') {
            $('#productsNav').show();
        }
    });*/



    // hide pop menu if hovered out
    $('#productsNav').mouseleave(function () {

        var className = $(this).attr('id');
        if (className != 'ctl00_Navigation_a3') {
            $('#productsNav').hide();
        } else if (className != 'a6') {
            $('#productsNav').show();
        }
    });
    // SEARCH BOX VALUE
    $('#search input:text').focus(function () {
        var newValue = $(this).val();
        if ($(this).val() == 'Search our site...') {
            $(this).attr('value', '');
        } else {
            $(this).val(newValue);
        }
    });
    $('#search input:text').blur(function () {
        var newValue = $(this).val();
        if ($(this).val() == '') {
            $(this).attr('value', 'Search our site...');
        } else {
            $(this).val(newValue);
        }
    });
	
	if(document.getElementById("stockistsBox")){
    	// STOCKISTS BOX VALUE
    		$('#stockistsBox input:text').focus(function () {
        	var newValue = $(this).val();
        	if ($(this).val() == 'Enter town or postcode') {
        	    $(this).attr('value', '');
        	} else {
        	    $(this).val(newValue);
        	}
    	});
    	$('#stockistsBox input:text').blur(function () {
    	    var newValue = $(this).val();
    	    if ($(this).val() == '') {
    	        $(this).attr('value', 'Enter town or postcode');
        	} else {
        	    $(this).val(newValue);
        	}
    	});
	}
	
	if(document.getElementById("homePageBanner")){
    	// HOME PAGE BANNER   
    	$('#homePageBanner .panels').cycle({
    	    fx: 'fade',
    	    speed: 600,
    	    //timeout: 0,
    	    //autostop: true,
    	    next: '#homePageBannerNext',
    	    prev: '#homePageBannerPrev',
    	    pager: 'ul#bannerNavBullets',
    	    cleartypeNoBg: true,
    	    pagerAnchorBuilder: function (idx, slide) {
    	        return 'ul#bannerNavBullets li:eq(' + idx + ')';
    	    }
    	});
	}
	
	if(document.getElementById("onTheRoadScroller")){
    	// ON THE ROAD
    	$('#onTheRoadScroller .panels').cycle({
    	    fx: 'fade',
    	    speed: 600,
    	    timeout: 0,
    	    cleartypeNoBg: true,
    	    next: '.onTheRoadScrollerNext',
    	    prev: '.onTheRoadScrollerPrev'
    	});
	}
	
	if(document.getElementById("hotProducts")){
    	// HOT PRODUCTS
    	$('#hotProducts .panels').cycle({
        	fx: 'fade',
        	speed: 600,
        	timeout: 0,
        	next: '.hotProductsNext',
        	prev: '.hotProductsPrev'
    	});
	}
	
	if(document.getElementById("careTeam")){
    	// CARE TEAM
    	$('#careTeam .panels').cycle({
    	    fx: 'fade',
        	speed: 600,
        	timeout: 0,
        	next: '.careTeamNext',
        	prev: '.careTeamPrev'
    	});
	}
	
	if(document.getElementById("helpAndAdvice")){
    	// HELP AND ADVICE PANELS
    	$('#helpAndAdvice .panels').cycle({
    	    fx: 'fade',
    	    speed: 300,
    	    pause: 0,
    	    timeout: 0,
    	    pager: '#helpAndAdviceNav',
    	    pagerAnchorBuilder: function (idx, slide) {
    	        return 'ul#helpAndAdviceNav li:eq(' + idx + ')';
    	    }
    	});
	}
	
    $('#helpAndAdviceNav').addClass('js');
	
    $.fn.cycle.updateActivePagerLink = function (pager, currSlideIndex) {
        $(pager).find('li').removeClass('active')
        .filter('li:eq(' + currSlideIndex + ')').addClass('active');
    };
    // EXPANDER
    $('.expander .slide1, .expander .slide2').hide();
    $('.expander h2, .expander h3').addClass('cursor');
    $('.expander h2').click(function () {
        $(this).toggleClass("active");
        $(this).parent().find("div.slide1").slideToggle('medium');
    });
    $('.expander h3').click(function () {
        $(this).toggleClass("active");
        $(this).parent().find("div.slide2").slideToggle('medium');
    });

	if(document.getElementById("productDetails")){
    	$('#productDetails .panel').hide();
    	$('#productDetails .panel:first').show();
    	$('#productDetails ul li:first').addClass('active');
    	$('#productDetails ul li a').click(function () {
    	    $('#productDetails ul li').removeClass('active');
    	    $(this).parent().addClass('active');
    	    var currentTab = $(this).attr('href');
    	    $('#productDetails .panel').hide();
        	$(currentTab).show();
        	return false;
    	});
	}


	if(document.getElementById("diamond-club-banner-full")){
    	$('#diamond-club-banner-full').bind({
    	    mouseenter: function (e) { $(this).css('cursor', 'pointer'); },
    	    click: function (e) { window.location = '/diamond-club-member/'; }
    	});
	}



});
