﻿var PreloadedImages = new Array();

jQuery.preloadImages = function()
        {
          for(var i = 0; i<arguments.length; i++)
          {
            jQuery("<img>").attr("src", arguments[i]);
          }
 }

function setUI(){
      
    
       hideEmails(); 
       setInput();
       $(document).pngFix();
       setRollover(); // EXPAND TO DYNAMIC PRELOADER...
       // we love ie6 we do...
	   doPromoRollover();
       SEOLinkReplace();
       // Urchin()
       
          $("[hasRollover]").each(function(){
            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"));
	        }
	    });
	    
}

function SEOLinkReplace(){
    $('[href*=doAccordionSEOLink]').each(function()
        {
          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 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");
	    });
	    
	     $(".imageCell").mouseover(function(){
	        
	        $(this).addClass("imageCellHover");
	        $(this).removeClass("imageCell");
	    });
	    
       $(".imageCell").mouseout(function(){
	        
	        $(this).addClass("imageCell");
	        $(this).removeClass("imageCellHover");
	    });
	    
	    $(".Button").mouseover(function(){
	        
	     //   $(this).addClass("ButtonHover");
	      //  $(this).removeClass("Button");
	    });
	    
	     $(".Button").mouseout(function(){
	        
	      //  $(this).addClass("Button");
	      //  $(this).removeClass("ButtonHover");
	    });
}

// - automatic image rollover code
function setRollover(){

       // alert($("[hasRollover]").length);
        
        $("[hasRollover]").each(function(){
	     //   alert($(this).attr("src"));
	        // preload image into array blah blah blah
	    });
        
	    $("[hasRollover]").mouseover(function(){
	        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 generateFlash(menuID,movieName,fileLocation,theWidth,theHeight){
	var theFlashOBJString = "";
	theFlashOBJString += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" id="' + movieName +'" width="' + theWidth +'" height="' + theHeight +'">';
	theFlashOBJString += '<param name="WMODE" value="transparent">';
	theFlashOBJString += '<param name="menu" value="false">';                    
	theFlashOBJString += '<param name=movie value="' + fileLocation + '?skipIntro=' + menuID +'">';
	theFlashOBJString += '<param name=quality value=high>';
	theFlashOBJString += '<param name="AllowScriptAccess" value="Always" />';
	theFlashOBJString += '<param name="allowFullScreen " value="true" />';
	theFlashOBJString += '<param name=play value=true>';
	theFlashOBJString += '<param name=exactfit value=true>';
	theFlashOBJString += '<embed play=true swliveconnect="true" name="' + movieName + '" src="' + fileLocation + '?skipIntro=' + menuID +'" quality=high  width="' + theWidth +'" height="' + theHeight +'" allowFullScreen ="true" WMODE="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed ></object >';
	document.write(theFlashOBJString);
}


	$(document).ready(function(){
        
             setUI();
             
             var theHTML = "";
                      
    $('#nav ul li ul').each(function(){
                theHTML +=  "<div style=\"padding:0px;width:165px\" class=\"finderDDL1\" ><div style=\"padding:2px;\"><a  href=\"" + $(this).parent().find('a').attr("href") + "\">" + $(this).parent().find('a').html() + "</a></div><div style=\"background-color:#FFFFFF;height:3px;font-size:3px;line-height:3px;\">&nbsp;</div><div class=\"finderDDl2\">" + $(this).html() + "<BR></div></div>";
              });
              
             $('#subCategory').html('<div style="padding:4px;">' + theHTML.split("&nbsp;&nbsp;").join("") + '</div>');
             
             theURLArr = document.location.href.split("/");
             
              $('#nav ul li [href*=' + theURLArr[theURLArr.length-1] + ']').each(function(){
                
                theHTML =  $(this).parent().find('ul').html() + "<BR>";
                //alert(theHTML);
              });
              
             $('#subCategories').html('<div style="padding:10px;">' + theHTML.split("&nbsp;&nbsp;").join("") + '</div>');
 
                 $('#nav').droppy({speed: 100});
          
		});

function showProductLink(theProductCategory)
{
    theURL = $('#nav').find('[href*=' + theProductCategory + ']').attr("href");
    
    document.location.href=theURL;
}

function showMediaLink()
{
    theURL = $('[href*=news.aspx]').attr("href");
    
    document.location.href=theURL;
}