﻿$(document).ready(function(){
  initBehaviour();
});

function initBehaviour()
{
  initExternalLink();
  initStopFlicker();  
  initActAsLinkHover();
  initButtonHover();
  initSmoothScroll();
  initFormEnhancements();
  initCmsEnhancements();
  initHeaderSearch();
  initDropNav();
  //initGoogleAnalytics();
} // initBehaviour()

function initExternalLink()
{
  $("a.externalLink").live("click", function(){ window.open(this.href); return false; });
} // initExternalLink()

function initStopFlicker()
{
  try { document.execCommand("BackgroundImageCache", false, true); } 
  catch(err) {}
} // initStopFlicker()

function initActAsLinkHover()
{
  $(".actAsLink").hover(
    function(){ $(this).addClass("actAsLinkHover"); }, // over
    function(){ $(this).removeClass("actAsLinkHover"); } // out
  );
  if($.browser.opera) { $("label.actAsLink").one("click", function(){ $(this).find("input").trigger("click"); }); }
} // initActAsLinkHover()

function initButtonHover()
{
  $(".btnHover").hover(
    function(){ $(this).addClass("btnHoverHover"); }, // over
    function(){ $(this).removeClass("btnHoverHover"); } // out
  );
} // initButtonHover()

function initSmoothScroll()
{
	$("a[href*=#]").click(function(){
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) 
		{
			var target = $(this.hash);
			target = target.length && target || $("[name=" + this.hash.slice(1) +"]");
			if (target.length) 
			{
        var targetOffset = target.offset().top;
        $("html,body") .animate({scrollTop: targetOffset}, "slow");
        return false;
			}
		}
	});
} // initSmoothScroll()

function initFormEnhancements()
{
  // ie enhancements
  if($.browser.msie)
  {
    $("input.txt").focus(function(){$(this).addClass("txtFocus");}).blur(function(){$(this).removeClass("txtFocus");});
    $("textarea.txt").focus(function(){$(this).addClass("txtFocus");}).blur(function(){$(this).removeClass("txtFocus");});
    $("select.ddl").focus(function(){$(this).addClass("ddlFocus");}).blur(function(){$(this).removeClass("ddlFocus");});
  }
  // js enhancements
  $("div.pagingWrapper div.filterWrapper input.btn").hide();
} // initFormEnhancements()

function initCmsEnhancements()
{
  $("ul, ol, dl").not(".clearfix").addClass("clearfix");
} // initCmsEnhancements()

function initHeaderSearch()
{
  var old = "Search...";
  $("div.headerWrapper div.search input.txtHeaderSearch")
    .focus(function(){ if($(this).val() == old) { $(this).val(""); } })
    .blur(function(){ if($(this).val() == "") { $(this).val(old); } });
} // initHeaderSearch()

function initDropNav()
{
  $("div.header ul.nav li").hover(
    function(){
      $(this).find("a").addClass("primaryHover");
      $(this).find("div.dropNavWrapper").css("visibility", "visible");
    },
    function(){
      $(this).find("a").removeClass("primaryHover");
      $(this).find("div.dropNavWrapper").css("visibility", "hidden");
    }
  );
} // initDropNav()

function initGoogleAnalytics()
{
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-473454-50']);
  _gaq.push(['_trackPageview', 'PAGE: pagename']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
} // initGoogleAnalytics()