﻿
var debug=false;

 jQuery.preloadImages = function()
        {
          for(var i = 0; i<arguments.length; i++)
          {
            jQuery("<img>").attr("src", arguments[i]);
          }
 }
        
function setUI(){
       hideEmails(); 
       setInput();
       $(document).pngFix();
       // we love ie6 we do...
       setRollover(); 
	   doPromoRollover();
	   buildSiteMap();
       SEOLinkReplace();
       tableLinkRollovers();
       fixExternalURLs();
       
       setBottomToolBar();
       fixImageTitles();
      // protectImages();
     
       if(debug){
            $("#ERRReport").html( $("#ERRReport").html() + "<BR><br>");    
       }
       else
       {
        $("#ERRReport").hide();
       }
       faders();
       
       


       loadUrchin();
}

function buildSiteMap(){
    $("#SiteMapDiv").hide();
    $("#SiteMapDiv").html(genSiteMap());
    $("#SiteMapDiv").find("img").each(function()
    {
        $(this).css("display","none");
    });
    
}
function faders(){
        $('.adi').innerfade({
			speed: 'normal',
			timeout: 10000,
			type: 'random',
			containerheight: '20px'
	    });
	    
	    $('.headers').innerfade({
			speed: 'normal',
			timeout: 10000,
			type: 'random',
			containerheight: '215px'
	    });
	    $(".headers").show();
}



function openFileByRef(textRef){
    $('tr').find('[title*=' + textRef + ']').click();
}

function fixImageTitles(){

    $('img').each(function()
        {
            if($(this).attr("alt")){
                if(!$(this).attr("title")){
                    $(this).attr("title",$(this).attr("alt"));
                }
            }
            else
            {
            // if there is a title use title in alt.. else use the image src name.
                var theTitle = $(this).attr("src").split("/");
           //    alert(theTitle.length);
                var theRealTitle = theTitle[theTitle.length-1];
                theRealTitle = theRealTitle.substring(0,theRealTitle.indexOf("."));
                $(this).attr("title",theRealTitle);
                $(this).attr("alt",theRealTitle);
              //  $("#ERRReport").html("<BR>Missing alt/title: " + $(this).attr("src") + $("#ERRReport").html() + "");    
            }
        }
         
    );
    
}

function protectImages(){

    $('img').each(function()
        {
          if(!$(this).attr("hasRollover")){
          var theSRC =  $(this).attr("src");
          var theHeight = $(this).attr("height");
          var theWidth = $(this).attr("width");
              if(theHeight!=0 && theWidth!=0 ){
                  $(this).attr("src",getPaths() + "/images/spacer.gif");
                  $(this).css("background-image","url(" + theSRC + ")");
                  $(this).attr("height",theHeight);
                  $(this).attr("width",theWidth);
              }
              else
              {
                  if(debug){
                        $("#ERRReport").html("<BR>Missing width/height: " + theSRC + $("#ERRReport").html() + "");    
                  }
              }
            }
          }
         
    );
    
   
}
function fixExternalURLs(){
    $('[href*=http://]').each(function()
        {
             if(!$(this).attr("target")){
                $(this).attr("target","_blank");
             }
        }
    );
}

function loadUrchin(){
  
    $('#urchinDiv').html(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    setTimeout('runUrchin()',5000);
}

function runUrchin(){
    try {
    var pageTracker = _gat._getTracker(analyticsCode);
    pageTracker._trackPageview();
   
    } catch(err) { setTimeout('runUrchin()',5000);}

  
}

function doToolbar(){
      var win_width =$(window).width();
      var win_height =$(window).height();
      $("#BottomToolbar").css('top',(win_height-$("#BottomToolbar").height() - $(window).scrollTop()) + "px");
}

function setBottomToolBar(){
    var win_width =$(window).width();
    var win_height =$(window).height();
	    
    $("#BottomToolbar").css('top',(win_height-$("#BottomToolbar").height()) + "px");
    
    var resizeTimer = null;
   // $(window).bind('resize', function() { if (resizeTimer) clearTimeout(resizeTimer);     resizeTimer = setTimeout(doToolbar, 100);});
    
 
}

function SEOLinkReplace(){
    $('[href*=doAccordionSEOLink]').each(function()
        {
          if($(this).attr("href")){
            if($(this).attr("href").indexOf("javascript:") != -1){
             eval($(this).attr("href").split("javascript:").join(""));
            }
          }
        }
    );
}

function doPromoRollover(){
		 $(".promo").mouseover(function(){
   	       $(this).removeClass("promo");
	       $(this).addClass("promohover");
	       $(this).find('h1').addClass("h1Over");
	    });
	    $(".promo").mouseout(function(){
	        $(this).removeClass("promohover");
	        $(this).addClass("promo");
	        $(this).find('h1').removeClass("h1Over");
	    });    	
}

function tableLinkRollovers(){
		 $("tr [onclick]").find(".TableRow1").mouseover(function(){
   	      $(this).parent().children("td").removeClass("TableRow1");
	      $(this).parent().children("td").addClass("TableRowHighlight");
	    });
	    $("tr [onclick]").find(".TableRow1").mouseout(function(){
   	       $(this).parent().children("td").removeClass("TableRowHighlight");
	       $(this).parent().children("td").addClass("TableRow1");
	    });
	    
	    
	     $("tr [onclick]").find(".TableRow2").mouseover(function(){
   	       $(this).parent().children("td").removeClass("TableRow2");
	      $(this).parent().children("td").addClass("TableRowHighlight");
	    });
	    $("tr [onclick]").find(".TableRow2").mouseout(function(){
   	       $(this).parent().children("td").removeClass("TableRowHighlight");
	       $(this).parent().children("td").addClass("TableRow2");
	    });
}


function hideEmails(){
            $("a[href*=$$]").each(function(){
              $(this).attr("href",$(this).attr("href").split("$$").join("@"));
              $(this).html($(this).html().split("$$").join("@"));
	        });
}

function setInput(){

        $(".FormField").mouseover(function(){
	      //  $(this).addClass("FormFieldHover");
	      //  $(this).removeClass("FormField");
	        
	       
	        // ignore date pickers or any object containing a focus event.
	        if( $(this).attr("onFocus") == undefined )
	        {
	            $(this).focus();
	        }
	    });
	    
	    $(".FormField").mouseout(function(){
	        
	     //   $(this).addClass("FormField");
	     //   $(this).removeClass("FormFieldHover");
	    });
	    
        $(".LogoutButtons").mouseover(function(){
	        
	        $(this).addClass("LogoutButtonsHover");
	        $(this).removeClass("LogoutButtons");
	    });
	    
       $(".LogoutButtons").mouseout(function(){
	        
	        $(this).addClass("LogoutButtons");
	        $(this).removeClass("LogoutButtonsHover");
	    });
	    
	    $(".Button").mouseover(function(){
	        
	        $(this).addClass("ButtonHover");
	        $(this).removeClass("Button");
	    });
	    
	     $(".Button").mouseout(function(){
	        
	        $(this).addClass("Button");
	        $(this).removeClass("ButtonHover");
	    });
}

function setRollover(){

    $("[hasRollover]").each(function() {
        if ($(this).attr("src")) {
            if ($(this).attr("src").indexOf(".jpg") != -1) {
                $.preloadImages($(this).attr("src").split(".jpg").join("_on.jpg"));
            }
            if ($(this).attr("src").indexOf(".gif") != -1) {
                $.preloadImages($(this).attr("src").split(".gif").join("_on.gif"));
            }
            if ($(this).attr("src").indexOf(".png") != -1) {
                $.preloadImages($(this).attr("src").split(".png").join("_on.png"));
            }
        }
    });

    $("[hasRollover]").mouseover(function() {
        if ($(this).attr("src")) {
            if ($(this).attr("src").indexOf("_on.") == -1) {
                $(this).attr("src", $(this).attr("src").split(".png").join("_on.png"));
                $(this).attr("src", $(this).attr("src").split(".jpg").join("_on.jpg"));
                $(this).attr("src", $(this).attr("src").split(".gif").join("_on.gif"));
            }
        }
    });

	     $("[hasRollover]").mouseout(function(){
	        $(this).attr("src",$(this).attr("src").split("_on.png").join(".png"));
	        $(this).attr("src",$(this).attr("src").split("_on.jpg").join(".jpg"));
	        $(this).attr("src",$(this).attr("src").split("_on.gif").join(".gif"));
	    });  
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
    return xmlHttp;
}



function AjaxSiteMap(){
        if(GenSiteMap){
            var theLinks = "";
             $("#SiteMapDiv").find("a").each(function(){
	           theLinks += "!url!!loc!" + $(this).attr("href") + "!/loc!~";
	           theLinks += "!lastmod!" + theDate + "!/lastmod!~";
	           theLinks += "!priority!0.8!/priority!!/url!~\n";
	         });
             
            // alert(theLinks);
 
             var namevalue=encodeURIComponent(theLinks)
             var parameters="links="+namevalue;
             var data = "links=" + namevalue;
             try {
              //   alert(data);
                 $.post(document.location.href.toLowerCase().split("/pages/default.aspx").join("/scriptlibrary/gensitemap.aspx"), data, kill, "html");
               
            }
               catch(e)
               {
               
               }
        }


 
}

function kill(){

}
