$(document).ready(function()
{  

  // Drop down menus for IE6
  $("#nav li").hover(
    function () 
    {
      $(this).addClass("hover");
    },
    function()
    {
      $(this).removeClass("hover");
    }
  );
  
  
  $("p>img.showcaptionleft").unwrap();
  $("img.showcaptionleft").each(function() 
  {
    $(this).wrap("<div class=\"imagebox-left\" style=\"width: " + $(this).attr("width") + "px;\"></div>");
    $(this).css("margin","0");
    $(this).parent().append("<div class=\"caption\">"+$(this).attr("alt")+"</div>");
  });
  
  $("p>img.showcaptionright").unwrap();
  $("img.showcaptionright").each(function() 
  {
    $(this).wrap("<div class=\"imagebox-right\" style=\"width: " + $(this).attr("width") + "px;\"></div>");
    $(this).css("margin","0");
    $(this).parent().append("<div class=\"caption\">"+$(this).attr("alt")+"</div>");
  });
  
  $("p>img.showcaption").unwrap();
  $("img.showcaption").each(function() 
  {
    $(this).wrap("<div class=\"imagebox\" style=\"width: " + $(this).attr("width") + "px;\"></div>");
    $(this).css("margin","0");
    $(this).parent().append("<div class=\"caption\">"+$(this).attr("alt")+"</div>");
  });
  
  
  // Home page slideshow
  if ($('#slideshow').length)
    slideShow(5000); 
  
  // Tidy captions
  $(".caption").wrapInner("<div class=\"caption-inner\"></div>");
  
  // Links with rel="external" open in a new window
  $("a[rel='external']").attr("target","_blank");
  
  // Zebra striped table rows
  $("table.data tr:even").addClass("alt");
  
  // Print link functionality
  $("a.print").click(
    function () 
    {
      if (window.print)
        window.print();
      else
        alert("Sorry, your browser doesn't support the print feature. Use the File menu on your browser to select Print.");
      return false;  
    }
  );
  
  // Tooltips
  /* Tooltip code from: http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/ */
  $('a.hastooltip').tooltip(
  {
    track: true,
    delay: 0,
    showURL: false,
    fade: 100
  });
  
  // Fix PNG for IE6
  $(document).pngFix();
 
  $("dl dt:eq(0)").addClass("first");
  $("dl dd:eq(0)").addClass("first");
  
  $("#breadcrumbs li:last-child").addClass("last");
  $("#footer li:last-child").addClass("last");
  
  $("#tools li:eq(1)").addClass("texttool");
  $("#tools li:eq(2)").addClass("texttool");
  
  $("table tr td:first-child").addClass("first");
  $("table tr td:last-child").addClass("last");
  $("table tr th:first-child").addClass("first");
  $("table tr th:last-child").addClass("last");
  $("table tr:last-child").addClass("last");
  addTableSpacerRows($('table'));
  $("table thead tr").prepend("<th class=\"spacer\"></th>");
  $("table thead tr").append("<th class=\"spacer\"></th>");
  $("table tbody tr").prepend("<td class=\"spacer\"></td>");
  $("table tbody tr").append("<td class=\"spacer\"></td>");
  
  $(".homepage #contentheader").wrap("<div id=\"contentheader-wrap\"></div>");
  
  $("p img.left").closest("p").css("padding-bottom","0");
  $("p img.right").closest("p").css("padding-bottom","0");
  
  $("ul.index li>a img").parent().css("border-top","1px solid #fff");
  $("ul.index li>a img").parent().css("border-right","1px solid #fff");
  $("ul.index li>a img").parent().css("float","left");
  $("ul.index li").hover
  (
      function(){ $(this).find("a img").parent().css("border-right-color", "#eee");},
      function(){ $(this).find("a img").parent().css("border-right-color", "#fff");}
  )

  $("h3.highlight").wrapInner("<span></span>");
  
  // Remove bullets on lists of file downloads
  $("li > a.ai").closest("ul").addClass("nobullet");
  $("li > a.aiff").closest("ul").addClass("nobullet");
  $("li > a.bz2").closest("ul").addClass("nobullet");
  $("li > a.c").closest("ul").addClass("nobullet");
  $("li > a.chm").closest("ul").addClass("nobullet");
  $("li > a.conf").closest("ul").addClass("nobullet");
  $("li > a.cpp").closest("ul").addClass("nobullet");
  $("li > a.css").closest("ul").addClass("nobullet");
  $("li > a.deb").closest("ul").addClass("nobullet");
  $("li > a.divx").closest("ul").addClass("nobullet");
  $("li > a.doc").closest("ul").addClass("nobullet");
  $("li > a.file").closest("ul").addClass("nobullet");
  $("li > a.gif").closest("ul").addClass("nobullet");
  $("li > a.gz").closest("ul").addClass("nobullet");
  $("li > a.hlp").closest("ul").addClass("nobullet");
  $("li > a.htm").closest("ul").addClass("nobullet");
  $("li > a.html").closest("ul").addClass("nobullet");
  $("li > a.iso").closest("ul").addClass("nobullet");
  $("li > a.jpeg").closest("ul").addClass("nobullet");
  $("li > a.jpg").closest("ul").addClass("nobullet");
  $("li > a.js").closest("ul").addClass("nobullet");
  $("li > a.mov").closest("ul").addClass("nobullet");
  $("li > a.mp3").closest("ul").addClass("nobullet");
  $("li > a.mpg").closest("ul").addClass("nobullet");
  $("li > a.odc").closest("ul").addClass("nobullet");
  $("li > a.odf").closest("ul").addClass("nobullet");
  $("li > a.odg").closest("ul").addClass("nobullet");
  $("li > a.odi").closest("ul").addClass("nobullet");
  $("li > a.odp").closest("ul").addClass("nobullet");
  $("li > a.ods").closest("ul").addClass("nobullet");
  $("li > a.odt").closest("ul").addClass("nobullet");
  $("li > a.ogg").closest("ul").addClass("nobullet");
  $("li > a.pdf").closest("ul").addClass("nobullet");
  $("li > a.php").closest("ul").addClass("nobullet");
  $("li > a.pl").closest("ul").addClass("nobullet");
  $("li > a.gif").closest("ul").addClass("nobullet");
  $("li > a.ppt").closest("ul").addClass("nobullet");
  $("li > a.ps").closest("ul").addClass("nobullet");
  $("li > a.py").closest("ul").addClass("nobullet");
  $("li > a.ram").closest("ul").addClass("nobullet");
  $("li > a.rar").closest("ul").addClass("nobullet");
  $("li > a.rb").closest("ul").addClass("nobullet");
  $("li > a.rm").closest("ul").addClass("nobullet");
  $("li > a.rpm").closest("ul").addClass("nobullet");
  $("li > a.rtf").closest("ul").addClass("nobullet");
  $("li > a.swf").closest("ul").addClass("nobullet");
  $("li > a.swx").closest("ul").addClass("nobullet");
  $("li > a.sxc").closest("ul").addClass("nobullet");
  $("li > a.sxd").closest("ul").addClass("nobullet");
  $("li > a.sxi").closest("ul").addClass("nobullet");
  $("li > a.sxw").closest("ul").addClass("nobullet");
  $("li > a.tar").closest("ul").addClass("nobullet");
  $("li > a.tex").closest("ul").addClass("nobullet");
  $("li > a.tgz").closest("ul").addClass("nobullet");
  $("li > a.txt").closest("ul").addClass("nobullet");
  $("li > a.vcf").closest("ul").addClass("nobullet");
  $("li > a.wav").closest("ul").addClass("nobullet");
  $("li > a.wma").closest("ul").addClass("nobullet");
  $("li > a.wmv").closest("ul").addClass("nobullet");
  $("li > a.xls").closest("ul").addClass("nobullet");
  $("li > a.xml").closest("ul").addClass("nobullet");
  $("li > a.xpi").closest("ul").addClass("nobullet");
  $("li > a.xvid").closest("ul").addClass("nobullet");
  $("li > a.zip").closest("ul").addClass("nobullet");

  
  
  $("#content").append("<div class=\"clear\"></div>");
});




function addTableSpacerRows(jQtable)
{
    jQtable.each(function()
    {
        var $table = $(this);
        // Number of td's in the last table row
        //var n = $('tr:last td', this).length;
        var n = 1;
        $('tr:last td:last', this).prevAll().each(function() 
        {  
      n += $(this).attr('colspan') ? parseInt($(this).attr('colspan')) : 1;  
    });
    
    var tr = '<tr class="spacer">';
        for(var i = 0; i < n; i++)
        {
            tr += '<td> </td>';
        }
        tr += '</tr>';
        
        if($('tbody', this).length > 0)
        {
          $('tbody', this).prepend(tr);
            $('tbody', this).append(tr);
        }
        else 
        {
            $(this).prepend(tr);
            $(this).append(tr);
        }
    });
}





$(document).ready(function()
{
  // Reset Font Size
  var originalFontSize = $('html').css('font-size');
  var $cookie_name = "hcc-font-size";
  
  if($.cookie($cookie_name)) 
  {
    var $getSize = $.cookie($cookie_name);
    $("html").css({fontSize : $getSize + ($getSize.indexOf("px")!=-1 ? "" : "px")}); // IE fix for double "pxpx" error
  } 
  else 
  {
    $.cookie($cookie_name, originalFontSize);
  }
  
  $(".textreset").click(function()
  {
    $('html').css('font-size', originalFontSize);
    $.cookie($cookie_name, originalFontSize);
    return false;
  });
  // Increase Font Size
  $(".textup").click(function()
  {
    var currentFontSize = $('html').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.1 + "px";
    $('html').css('font-size', newFontSize);
    $.cookie($cookie_name, newFontSize);
    return false;
  });
  // Decrease Font Size
  $(".textdown").click(function()
  {
    var currentFontSize = $('html').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum/1.1 + "px";
    $('html').css('font-size', newFontSize);
    $.cookie($cookie_name, newFontSize);
    return false;
  });
});




/* Google map functions */
$(window).resize(function()
{
  if(typeof loadMap==='function')
    loadMap();
});

$(window).unload(function()
{
  if(typeof GUnload==='function')
    GUnload();
});

$(document).ready(function()
{
  if(typeof loadMap==='function')
    loadMap();
});




















function slideShow(speed) 
{  
    //Set the opacity of all images to 0  
    $('ul#slideshow li').css({opacity: 0.0});  
      
    //Get the first image and display it (set it to full opacity)  
    $('ul#slideshow li:first').css({opacity: 1.0});   
      
    //Call the gallery function to run the slideshow      
    var timer = setInterval('gallery()',speed);  
      
    //pause the slideshow on mouse over  
    $('ul#slideshow').hover(  
        function () {  
            clearInterval(timer);     
        },    
        function () {  
            timer = setInterval('gallery()',speed);           
        }  
    );
}  
  
function gallery() 
{  
  
  
    //if no IMGs have the show class, grab the first image  
    var current = ($('ul#slideshow li.show')?  $('ul#slideshow li.show') : $('#ul#slideshow li:first'));  
  
    //Get next image, if it reached the end of the slideshow, rotate it back to the first image  
    var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul#slideshow li:first') :current.next()) : $('ul#slideshow li:first'));  
          
    //Set the fade in effect for the next image, show class has higher z-index  
    next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);  
      
    //Hide the current image  
    current.animate({opacity: 0.0}, 1000).removeClass('show');   
}  
/*
 * Functions added by Alex Clifford
 * Last updated: 11:30 AM 15/02/2010
 *
 */

/*Show and Hide descriptions on Bushcare Web Map*/
function fnBushWebMapShowHide(number)
{
  var descriptions = document.getElementById('BushWebMapDescriptions');
  var hideAll = descriptions.getElementsByTagName('div');
  
  for (var i = 0; i < hideAll.length; i++)
  {
    hideAll[i].className = 'BushWebMapHide';
  }

  var showHide = document.getElementById('description' + number);
  
  showHide.className = 'BushWebMapShow';
}

 /* Lightbox popup - http://leandrovieira.com/projects/jquery/lightbox/ */
     $(function() {
        $('a.popup').lightBox();
    });

/* Add H2's to a-z index and site map*/
$(document).ready(function()
{
  $("ul.Level0>li>a").wrap("<h2>");
  $("ul.Level0>li>a").append("</h2>");
  //$("ul.Level1 li a").unwrap("<h2>");
  //$("ul.Level0 li a").append("</h2>");
});

