// Kleenheat Global JavaScript Document
var gashouse = 0;
Cufon.replace(".side_box h1", { fontFamily: 'frutiger_reg' });
Cufon.replace("#copy h2, #store_details h2", { fontFamily: 'frutiger_reg' });
Cufon.replace("#copy h3", { fontFamily: 'frutiger_light' });
Cufon.replace("#store_details h1, .cufonReplace", { fontFamily: 'frutiger_reg' });
Cufon.replace("#store_listing h1", { fontFamily: 'frutiger_reg' });
Cufon.replace("#postcode h1", { fontFamily: 'frutiger_reg' });
Cufon.replace(".preprod_stateselector h1", { fontFamily: 'frutiger_reg' });

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function changeState(state) {
    
    if (state != "") {
        var curUrl;
        if (state == "WA" || state == "NT") {
            setCookie('is_east','no',99,'/gashouse/');
            setCookie('is_state',state,99,'/gashouse/');	
            curUrl = document.location.href.replace("home-east.aspx","home.aspx");
        } else {
            setCookie('is_east','yes',99,'/gashouse/');	
            setCookie('is_state',state,99,'/gashouse/');		        
            curUrl = document.location.href.replace("home.aspx","home-east.aspx");
        }
        curUrl=curUrl.replace("#","");

        document.location.href = curUrl;
    }
}
		    
function changeStateFromFooter(state) {
    if (state != "") {
        var curUrl;
        if (state == "WA" || state == "NT") {
            setCookie('is_east','no',99,'/gashouse/','','');
            setCookie('is_state',state,99,'/gashouse/','','');	
            curUrl = "/gashouse/home.aspx";
        } else {
            setCookie('is_east','yes',99,'/gashouse/','','');	
            setCookie('is_state',state,99,'/gashouse/','','');		        
            curUrl = "/gashouse/home-east.aspx";
        }
        
        document.location.href = curUrl;
    }
}

function changeStateAndRedirect(state, url) {

    if (state != "") {
        if (state == "WA" || state == "NT") {
            setCookie('is_east','no',99,'/gashouse/','','');
            setCookie('is_state',state,99,'/gashouse/','','');	
            url = url + "?state=" + state;
        } else {
            setCookie('is_east','yes',99,'/gashouse/','','');	
            setCookie('is_state',state,99,'/gashouse/','','');		        
            url = url + "?state=" + state;
        }
        
        document.location.href = url;
    }
}

function setCookie( name, value, expires, path, domain, secure )
{
    var today = new Date();
    today.setTime( today.getTime() );

    if ( expires )
    {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" + escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
        ( ( path ) ? ";path=" + path : "" ) +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
}

$(document).ready(function() {
    
    try 
    {
        var cState = getCookie('is_state');
        $("#f_stateSelector").val(cState);
    } catch(ex) {

    }
    
    // Fix PNGs in IE6
    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
        DD_belatedPNG.fix('.png_bg');
    }

    $("ul.sf-menu").superfish({
        delay: 100,
        speed: 300,
        animation: { opacity: 'show', height: 'show' }
    });

    $("ul.sf-menu ul").hover(
		function() {
		    if (!$(this).prev("a").hasClass("active")) {
		        $(this).prev("a").addClass("current active");
		    }
		},
		function() {
		    if ($(this).prev("a").hasClass("current")) {
		        $(this).prev("a").removeClass("current active");

		    }
		}
	);


	$(".side_box ul ul li:first-child").css("padding-top","8px");
	$(".side_box ul ul li:last-child").css("padding-bottom","8px");

      var currentPath = window.location.pathname;
	        currentPath = currentPath.replace(".aspx","");
	        var currentArray = new Array();
	        currentArray = currentPath.split("/");
	        var currentSet = "/" + currentArray[1] + "/" + currentArray[2];

	        if (currentSet == "/gas/about-us") {
	            $(".about_us a").addClass("active");
	        } else if (currentSet == "/gas/products") {
	            $(".products a").addClass("active");
	        } else if (currentSet == "/gas/contact-us") {
	            $(".contact_us a").addClass("active");
	        } else if (currentSet == "//undefined") {
	            $(".home a").addClass("active");
	        }

	        if (currentSet == "/autogas/home") {
	            $(".home a").addClass("active");
	        } else if (currentSet == "/autogas/what-is-auto-gas") {
	            $(".what_is_autogas a").addClass("active");
	        } else if (currentSet == "/autogas/outlet-locator") {
	            $(".outlet_locator a").addClass("active");
	        } else if (currentSet == "/autogas/installers") {
	            $(".installers a").addClass("active");
	        } else if (currentSet == "/autogas/faq") {
	            $(".faq a").addClass("active");
	        } else if (currentSet == "/autogas/calculators") {
	            $(".calculators a").addClass("active");
	        }
   
	        if (currentSet == "/kwikgas/home") {
	            $(".home a").addClass("active");
	        } else if (currentSet == "/kwikgas/what-is-kwik-gas") {
	            $(".what_is_kwik-gas a").addClass("active");
	        } else if (currentSet == "/kwikgas/commercial-use") {
	            $(".commercial_use a").addClass("active");
	        } else if (currentSet == "/kwikgas/where-to-exchange") {
	            $(".where_to_exchange a").addClass("active");
	        } else if (currentSet == "/kwikgas/safety-tips") {
	            $(".safety_tips a").addClass("active");
	        } else if (currentSet == "/kwikgas/fundraising") {
	            $(".fundraising a").addClass("active");
	        }

				
    postcodeSearch = $('#slPostcode').val();
    $('#slPostcode').focus(function() {
        if ($(this).val() == postcodeSearch) {
            $(this).val("");
        }
    }).blur(function() {
        if ($(this).val() == "") {
            $(this).val(postcodeSearch);
        }
    });

    radiusSearch = $('#slRadius').val();
    $('#slRadius').focus(function() {
        if ($(this).val() == radiusSearch) {
            $(this).val("");
        }
    }).blur(function() {
        if ($(this).val() == "") {
            $(this).val(radiusSearch);
        }
    });

    globalHeaderDrop();

    try {
        var setItem = $(".banner").html();

        setItem = setItem.trim();

        if (setItem == "") {
            $(".banner").hide();
        }

        if (numBanner == 2) {
            $("#tab_3").hide();
        } else if (numBanner == 1) {
            $("#tab_3").hide();
            $("#tab_2").hide();
        }
    } catch (ex) { }



});



function globalHeaderDrop() {
	
	$("#global_header ul a.droplink").mouseover(
		function() {
			var hoverItem = $(this).attr("id").substring(3);
			$(".drop").removeClass("active");
			$(".drop#drop_" + hoverItem).addClass("active");
		}
	);
	
	$("#global_header .drop").hover(
		function(){
			$(this).addClass("active");
    	},function(){
			$(".drop").removeClass("active");
    	}
	);

}

function switchTab(tabId) {

    setSlide = 0;
    $("#tab_1").removeClass("active");
    $("#tab_2").removeClass("active");
    $("#tab_3").removeClass("active");

    $("#tab_" + tabId).addClass("active");
    
    $("#ctl00_fadebanner_usercontrols_kleenheat_switchbanner_ascx1_Img1").hide();
    $("#ctl00_fadebanner_usercontrols_kleenheat_switchbanner_ascx1_Img2").hide();
    $("#ctl00_fadebanner_usercontrols_kleenheat_switchbanner_ascx1_Img3").hide();
    $("#ctl00_fadebanner_usercontrols_kleenheat_switchbanner_ascx1_Img" + tabId).show();
    
    $("#banner_container_1").hide();
    $("#banner_container_2").hide();
    $("#banner_container_3").hide();
    $("#banner_container_" + tabId).show();
	        
}


var currentImg = 1;
var setSlide = 1;

function slideSwitch() {
    try {
        if (setSlide == 1) {
        nextImg = currentImg + 1
        totalImg = numBanner + 1;
        if (nextImg == totalImg) {
            nextImg = 1;
        }

        var currentSet = "#ctl00_fadebanner_usercontrols_kleenheat_switchbanner_ascx1_Img" + currentImg;
        var nextSet = "#ctl00_fadebanner_usercontrols_kleenheat_switchbanner_ascx1_Img" + nextImg;

        $(currentSet).hide();
        $(nextSet).fadeIn();
    
        $("#tab_1").removeClass("active");
        $("#tab_2").removeClass("active");
        $("#tab_3").removeClass("active");
        

    
        $("#tab_" + nextImg).addClass("active");
        
        $("#banner_container_1").hide();
        $("#banner_container_2").hide();
        $("#banner_container_3").hide();
        
            $("#banner_container_" + nextImg).show();
        
        currentImg = nextImg;
    }
    } catch(ex) {
    
    }
}

function runSlide() {
    setInterval( "slideSwitch()", 5000 );
}

function slideSwitchKwik() {

    try {
        if (setSlide == 1) {
        nextImg = currentImg + 1
        totalImg = numBanner + 1;
            if (nextImg == totalImg) {
            nextImg = 1;
            }

        var currentSet = "#ctl00_fadebanner_ctl00_Img" + currentImg;
        var nextSet = "#ctl00_fadebanner_ctl00_Img" + nextImg;

        $(currentSet).hide();
        $(nextSet).fadeIn();
    
        $("#tab_1").removeClass("active");
        $("#tab_2").removeClass("active");
        $("#tab_3").removeClass("active");
        

    
        $("#tab_" + nextImg).addClass("active");
        
        $("#banner_container_1").hide();
        $("#banner_container_2").hide();
        $("#banner_container_3").hide();
        
            $("#banner_container_" + nextImg).show();
        
        currentImg = nextImg;
    }
    } catch(ex) {
    
    }
}

function runSlideKwik() {
    setInterval( "slideSwitchKwik()", 5000 );
}

function displayErrorsAlert(aErrors) {

    if (aErrors.length) {
        if (aErrors.length > 1) {
            var prefix = 'Some errors occurred:\n\n';
            var suffix = '\nPlease correct these errors and try again.';
        }
        else {
            var prefix = 'An error has occurred:\n\n';
            var suffix = '\nPlease correct this error and try again.';
        }

        var errorMessage = prefix;

        for (var i = 0; i < aErrors.length; i++) {
            errorMessage += aErrors[i] + "\n";
        }

        errorMessage += suffix;

        alert(errorMessage);
    }

}