﻿
//Fixes product Availability tables. 
$(document).ready(function()
{
    $('#producttable td').each(function()
    {
        var Content = $(this).html();
        if(Content == '-')
        {
            $(this).addClass('ProductNotAvailable');
            $(this).html('&nbsp;');
        }
        
        if(Content == 'localsupply')
        {
            $(this).addClass('ProductLocalSupply');
            $(this).html('<img src="/images/localsupply.png">');
        }
        
        if(Content == 'importedsupply')
        {
            $(this).addClass('ProductImportedSupply');
            $(this).html('<img src="/images/importedsupply.png">');
        }
        
        if(Content == 'offpeaklocal')
        {
            $(this).addClass('ProductOffPeak');
            $(this).html('<img src="/images/offpeaklocal.png">');
        }
    });
    
    $('#producttable td:not([class])').css('background-color','#E4EED2');

});

//Fonts.
Cufon.replace('.menufont',{hover: true});
Cufon.replace('h3');
Cufon.replace('h4');
Cufon.replace('.cufon-din');
Cufon.replace('.ServicesHeader a');

//Drop down menu. 
$(document).ready(function(){  
    $("ul.subnav").parent().addClass('dropdownmenu'); 
    //Menu Hover. 
    $("#TopNavigation li.dropdownmenu a.menufont").hover(function() {
        //Check if this menu is already in the midst of moving. 
        if($(this).hasClass('moving'))
        {
            return;
        };
        
        if($(this).parent().find("ul.subnav").hasClass('subhover'))
        {
            return;
        };
        
        $(this).parent().find("ul.subnav").addClass("moving");
        $(this).addClass("moving"); 
        
        //Slide up any existing menus.
        $('.subhover').each(function()
        {
                $(this).slideUp('slow');
                $(this).removeClass('subhover');
        });
        
        $(this).parent().find("ul.subnav").addClass("subhover"); 
        $(this).parent().find("ul.subnav").slideDown('slow',function(){
            $('.moving').removeClass('moving');
        }); 
    },
    //The "unhover"
    function()
    {
        
        
    });
    
    //This is hovering over the drop down menu. When they move outside the submenu. We stop the drop down menu. 
    $('ul.subnav').hover(function()
    {  
       
    },
    function()
    {
    
        if($(this).hasClass("moving"))
        {
            return;
        }
        
        $(this).slideUp('slow',function()
        {
            $(this).removeClass("subhover");
        });
    });
    
    $('ul.subnav').mouseout(function()
    {
       
    });
          
});  

        
        
//Homepage Slideshow
$(document).ready(function()
{
    $('#HomepageSlideshow').cycle('fade');
});

//Scroll bars for the content. 
//Use window.load, because document.ready fires too early. 
$(window).load(function()
{
    //$('#TwoColumnPageRight').jScrollPane(); 
});

//Initiate Fancy Box
$(document).ready(function()
{
    $('a.iframe').fancybox({
    padding : 20,
    width : 340,
	height : 400,
    titleShow:false,
    onComplete:function()
    {
        $.fancybox.resize();
    }
    
    });
});

//Services Slideshow Init
$(document).ready(function()
{
    $('#ServicesBackgroundImage').cycle({timeout: 0});
});


//Services Dropdowns
$(document).ready(function()
{
    
    $('#ServicesList li .ServicesContent').addClass('hidden');
    
    $('#ServicesList .ServicesHeader').click(function()
    {
        $('.SelectedHeader').removeClass('SelectedHeader');
        $(this).addClass('SelectedHeader');
        $('.ServicesContent').addClass('hidden');
        $('.open').slideUp('fast');
        $(this).siblings('.ServicesContent').addClass('open');
        $(this).siblings('.ServicesContent').slideDown('fast');
        
        $('h2 .SubTitle').text($(this).text());
        
        Cufon.refresh('.ServicesHeader a');
        Cufon.refresh('.cufon-din');
        
        //Change the header slide. 
        var Attribute = $(this).attr('cycle');
        var Attribute = parseInt(Attribute);
        $('#ServicesBackgroundImage').cycle(Attribute - 1);
    });
    
    //Check if there is any hash value in the URL. 
    //Thus we can link directly to the tabs. 
    var hash = false; 
    function checkHash(){ 
        if(window.location.hash != hash) { 
            hash = window.location.hash; 
            $(hash+' .ServicesHeader').trigger('click');
        } 
    }
    checkHash();
    
    //If we are already on the services page. We need to flip the page if they try the menu again. 
    $('.submenufont').click(function()
    {
        var SelectedTab = $(this).text();
        SelectedTab = SelectedTab.replace(" ","-");
        $('#'+SelectedTab+' .ServicesHeader').trigger('click');
    });
});
