
var disableSWF=false;                   //Will NOT display Flash elements if set to true.

//-------------------------------------------------------------------------------------------
// PEPS Rollover class
//------------------------------------------------------------------------------------------ 
PEPS = {};
  PEPS.rollover = {
   init: function(){
      this.preload();
      $(".ro").children("img").hover(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); }, 
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
   },
   preload: function(){
      $(window).bind('load', function() {
         $('.ro').children("img").each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   { 
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '1' + src.match(/(\.[a-z]+)$/)[0]; 
   },

   oldimage: function( src )
   { 
      return src.replace(/1\./, '.'); 
   }

};

$(function(){  

  //-------------------------------------------------------------------------------------------
  // IE6 SUPPORT, fix PNG images
  //------------------------------------------------------------------------------------------ 
  if(scripts_isIE6)
  {
      $(window).load( function() { 

		$(document).pngFix();

      });
  }

  //-------------------------------------------------------------------------------------------
  // Initialize PEPS rollover class
  //------------------------------------------------------------------------------------------ 
  PEPS.rollover.init();
  
  $("li.menuHdr").bind("mouseover", function(){
  	$(this).css("cursor", "pointer");
  });
  
  $("li.menuHdr").bind("mouseout", function(){
  	$(this).css("cursor", "default");
  });

  $("li.menuHdr").click(function(){
		var trackingLabel = $(this).attr("id");
		var trackpg = '/'+trackingLabel.replace(/\_/,'\/');
		//alert(trackpg);
	
	if($(this).next("li").hasClass("open")){
		$(this).next("li").slideUp("normal", function(){
	  		$(this).removeClass("open");
	  	});
	}else{
		$(this).next("li").slideDown("normal", function(){
			$(this).addClass("open");
		});
	}
  	$(this).parent("ul").children("li").each(function(){
  		if($(this).hasClass("open")){
  			$(this).slideUp();
  			$(this).removeClass("open");
  		}
  	});
  });
  
  $("a.creamQuiz").click(function(){
  	$("div#cream-quiz").show();
  });
  
  $("a#closeQuiz").click(function(){
  	$("div#cream-quiz").hide();
  });
});
  //-------------------------------------------------------------------------------------------
  // CLICK TRACKING FOR EXTERNAL LINKS
  //-------------------------------------------------------------------------------------------


   

  
//-------------------------------------------------------------------------------------------
// POSITION DIV IN THE CENTER OF WINDOW
//------------------------------------------------------------------------------------------
function centerLyr(divID)
{
    $('#'+divID).css("position","absolute");
 
    var newTop = ( $(window).height() - $('#'+divID).height() ) / 2+$(window).scrollTop();
    if(newTop<0) newTop = 0;

    var newLeft = ( $(window).width() - $('#'+divID).width() ) / 2+$(window).scrollLeft();
    if(newLeft<0) newLeft = 0;

    $('#'+divID).css("top", newTop + "px");
    $('#'+divID).css("left", newLeft + "px");
}

//-------------------------------------------------------------------------------------------
// RE-POSITION DIV IN THE CENTER OF WINDOW ON WINDOW RESIZE
//------------------------------------------------------------------------------------------
function rePositionLyr(status,divID) 
{
    switch(status) {
	case true:
		$(window).bind('resize', function() {
			centerLyr(divID);
		});
	    break;
	case false:
		$(window).unbind('resize');
	    break;
    }
}

//-------------------------------------------------------------------------------------------
// POSITION OVERLAY IN THE CENTER OF WINDOW
//------------------------------------------------------------------------------------------
function showPopupDivCenter(divID) 
{
    if (scripts_isIE6) $('#'+divID).bgiframe();
    var toShow = $("#"+divID); 
    toShow.css({"z-index":"9000","visibility":"visible"});
    centerLyr(divID);
    rePositionLyr(true,divID);
}

//-------------------------------------------------------------------------------------------
// OPEN DIV OVERLAY AND POSITION CENTER
//------------------------------------------------------------------------------------------
function openDivCenter(divID,closeBtnID,removeFlashID)
{
    var toShow="";
    // Build the background overlay div
    toShow += "<div class='site_overlay'></div>";
    $('body').append(toShow);

    $('div.site_overlay').css('height',$(document).height()).bind('click',function(){
	closeDiv(divID);
    });

    $('div.site_overlay').css('opacity',0).fadeTo('slow',0.65, function(){
	showPopupDivCenter(divID);
	$('div.site_overlay').css("z-index","9000");
	$('#'+divID).css("z-index","9500");
    });

	
    if(closeBtnID!=""){
        $("#"+closeBtnID).bind('click',function(){
	        closeDiv(divID);
		if(removeFlashID!=""){
			var html = $('#'+removeFlashID).html();
			if(html.indexOf("noflashcontent")==-1)
			  $('#'+removeFlashID).html("");
		}
        });
    }
}

//-------------------------------------------------------------------------------------------
// CLOSE OPENED DIV OVERLAY
//------------------------------------------------------------------------------------------
function closeDiv(divID)
{
    $('div.site_overlay').remove();
    rePositionLyr(false,divID);
    var toHide = $("#"+divID); 
    toHide.css({"z-index":"0","visibility":"hidden"});
    if(divID=="all-products"){
	toHide.css("width", "1px");
	toHide.css("height", "1px");
    }
}

//-------------------------------------------------------------------------------------------
// LOAD FLASH OBJECT
//------------------------------------------------------------------------------------------
function playVid(swfPath, flv,img,divid,w,h)
{
	var so = new SWFObject(swfPath, "demo3", w, h, "9.0.0", "#ffffff");

	if(flv!="")
	{
	  so.addParam("wmode", "window");
	  so.addParam("allowScriptAccess", "sameDomain");
	  so.addParam("allowfullscreen", "true");
	  so.addParam("play", "true");
	  so.addParam("loop", "true");
	  so.addParam("scale", "showall");
	  so.addVariable("file", flv);
	  so.addVariable("autostart", "true");
	  so.addVariable("image", img);
	} else {
	  so.addParam("wmode", "transparent");
	}
	so.write(divid);
}

/**
 * Read the JavaScript cookies tutorial at:
 *   http://www.netspade.com/articles/javascript/cookies.xml
 */

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


$(function(){
 $("#digger").css("visibility","hidden");
 $("#digger2").css("visibility","hidden");
 if (diggerAnim != "") {
  playVid("/static/swf/interior0" + diggerAnim + ".swf", "","","diggerAnim",284,284);
 }
 var html = $("#diggerAnim").html();
 if(html=="") {
  $("#digger").css("visibility","visible");
  $("#digger2").css("visibility","visible");
 }
 if ((section != "") && (section != "home")) {
  $("#nav-" + section).attr("src","/static/images/nav-" + section + "1.gif");
 }
 if (section == "home") {
  $("body").css("background","#233f90 url('/static/images/bg.jpg') repeat-x 0px 0px");
 }
 if ((subpage != "") && (section == "athletesfoot")) {
  $("#nav-" + subpage).css("color","#C52116");
 }
 if ((subpage != "") && (section != "athletesfoot")) {
  $("#nav-product-" + subpage).attr("src","/static/images/nav-product-" + subpage + "1.gif");
  $("#nav-df" + subpage).show();
 }
 $("#nav ul li a img").mouseover(function () {
  $(this).attr("src", "/static/images/" + $(this).attr("id") + "1.gif");
 });
 $("#nav ul li a img").mouseout(function () {
  if ($(this).attr("id") != "nav-" + section) {
   $(this).attr("src", "/static/images/" + $(this).attr("id") + ".gif");
  }
 });
 $("#products-nav a img").mouseover(function () {
  $(this).attr("src", "/static/images/" + $(this).attr("id") + "1.gif");
 });
 $("#products-nav a img").mouseout(function () {
  if ($(this).attr("id") != "nav-product-" + subpage) {
   $(this).attr("src", "/static/images/" + $(this).attr("id") + ".gif");
  }
 });
});

