﻿$(window).load(function() {
    // Hero Section
    loadXML();
    
    $(window).oneTime(8000, function() {
        setSlideShow();
    });
   
    $('#slidetabs > a').hover(function() {
        if(!$(this).hasClass('current'))
            $(this).stop(true, true).css('margin-top', '-72px');
            
    }, function() {
        if(!$(this).hasClass('current'))
            $(this).stop(true, true).removeAttr('style');
    });
    
    $('#slidetabs > a').click(function(){
        $(this).stop(true, true).removeAttr('style');
    });
    
    // Side-bar Accordian
    if(! $("#projects-banner-container").length > 0)
    {
      $("#side-container").tabs(".accordian-container div.content", {tabs: '.button', effect: 'slide', initialIndex: 0});
    }
   else
   {
   
   }
  
    
    $('.accordian-container > .button').hover(function() {
        if(!$(this).hasClass('current'))
            $(this).stop(true, true).css('background-position', '0 -46px');
            
    }, function() {
        if(!$(this).hasClass('current'))
            $(this).stop(true, true).removeAttr('style');
    });
    
    $('.accordian-container > .button').click(function(){
        $(this).stop(true, true).removeAttr('style');
         if( $("#projects-banner-container").length > 0)
         {
          $("#side-container").tabs(".accordian-container div.content", {tabs: '.button', effect: 'slide', initialIndex: 0});

         }

    });
    
    $('#form-container > .headline > select > option').each(function (index){
        if(!$(this).attr('selected'))
            $(this).css('font-style', 'normal');
    });
    
    // sets the map path of the xml location
    setFlexiblePromoArea('');
});

function setSlideShow()
{
    $(window).stopTime();
    $('#init-panel-au').fadeOut();
    
    if($('#slidetabs > a').attr('onclick'))
        $('#slidetabs > a').removeAttr('onclick');
        
    $("#slidetabs").tabs("#hero > .rotating-panels", {
        effect: 'fade',
        fadeOutSpeed: "slow",
        rotate: true
    }).slideshow({ interval: 8000,clickable: false });
    
   if( $("#slidetabs").data("slideshow") != null)
    {
    $("#slidetabs").data("slideshow").play();
    }
}

function loadXML()
{
    var now         = new Date();
    var cacheDate   = now.setDate(now.getDate()+30);
    var xmlURL      = "/Style Library/DREMEL/en-au-xml/homepage-hero.xml?cache=" +cacheDate;
    var innerHTML   = null;
    
    $.ajax({
        type: "GET",
        url: xmlURL,
        dataType: "xml",
        success: function(xml) {
                $(xml).find('inital').each(function(){
                var id          = $(this).attr('id');
                var cssClass    = $(this).attr('class');
                var content     = $(this).attr('content');
                innerHTML = '<div id="' + id + '" class="' + cssClass + '">' + content + '</div>';
            });
            $(xml).find('section').each(function(){
                var id          = $(this).attr('id');
                var cssClass    = $(this).attr('class');
                var content     = $(this).attr('content');
                
                innerHTML += '<div id="' + id + '" class="' + cssClass + '">' + content + '</div>';
            }); //close each(
         
            $('#hero').html(innerHTML);
        }
    }); //close $.ajax(
   
}
