
var IE6 = navigator.userAgent.toLowerCase().indexOf("msie");
    IE6 = ((IE6 != -1) && (parseInt(navigator.userAgent.substring(IE6 + 4)) == 6)) ? true : false;

var pageTracker = _gat._getTracker("UA-4197312-2");
    pageTracker._setLocalRemoteServerMode();
    pageTracker._initData();


function overlayDisplayBackground(opacity)
{
  if (opacity === undefined)
    opacity = 0.55;

  jQuery("#overlayBackground").css  ('opacity', opacity);
  jQuery("#overlayBackground").css  ('height',  jQuery().height());
  jQuery("#overlayBackground").show ();
}


function trackOverlay (overlayName)
{
  pageTracker._trackPageview(overlayName);
}


function trackPane (paneName)
{
  pageTracker._trackPageview(paneName);
}


function switchToShop()
{
  jQuery ("#buyOnline").fadeTo(600, 0.0,
    function()
    {
      jQuery (this).css("left", "816px");
      jQuery ("#shoppingCart").css("left", "0px").fadeTo(600, 1.0);
    }
  );
}

function switchToBuy()
{
  jQuery ("#shoppingCart").fadeTo(600, 0.0,
    function()
    {
      jQuery (this).css("left", "816px");
      jQuery ("#buyOnline").css("left", "0px").fadeTo(600, 1.0);
    }
  );
}


function setHash (paneName)
{
  if (carouselMgr.panes[0].bAutoSlide == false)
    document.location.hash = "#MAX_" + paneName;
}


function getHash ()
{
  var hash = document.location.hash;
  if (hash.indexOf("#") != -1)
  {
    hash = hash.substring (hash.indexOf("#") + 1);
    if (hash.indexOf("MAX_") != -1)
      hash = hash.substring (hash.indexOf("MAX_") + 4);
  }
  return (hash);
}


// shopping cart swap images
var swapImage = function(imageID,imagePath,state)
{
  var ai;
  if (state == 'over'){ai=imagePath+"_over.gif";}else{ai=imagePath+".gif";}
  jQuery('img#'+imageID).attr("src",ai);
}
  
  
function preloadImages ()
{
  var args = (typeof arguments[0] == 'object') ? arguments[0] : arguments;
  for (var ndx = args.length - 1; ndx >= 0; ndx--)
    jQuery("<img>").attr("src", '/images/' + args[ndx]);
}
  

function readyLoadImages()
{
 preloadImages(
  'features/pnl_background_2000CaloriePresale.jpg', // first 8 images are for the splash animation
  'splash/featuresPromo.jpg',
  'carousel/pnl_shop_products.jpg',
  'carousel/pnl_get_exclusive_offers.jpg',
  'splash/shopOnline.jpg',
  'splash/featuresPromo.jpg',
  'splash/gallery.jpg',
  'gallery/black.jpg',
  'common/logo_MAX_large.gif',
  'callouts/callouts_findAStore.gif',
  'callouts/callouts_inTheStudio.gif',
  'callouts/callouts_chatWithAPro.gif',
  'callouts/callouts_collections.gif',
  'callouts/callouts_specialOffers.gif',
  'callouts/callouts_findAStore_over.gif',
  'callouts/callouts_inTheStudio_over.gif',
  'callouts/callouts_chatWithAPro_over.gif',
  'callouts/callouts_collections_over.gif',
  'callouts/callouts_specialOffers_over.gif',
  'features/btn_buyNow_over.gif',
  'features/btn_buyNow.gif',
  'features/btn_checkItOut_over.gif',
  'features/btn_checkItOut.gif',
  'features/btn_start_shopping_over.png',
  'features/btn_start_shopping.png',
  'features/btn_view_the_gallery_over.png',
  'features/btn_view_the_gallery.png',
  'offers/btn_dont_miss_out.png',
  'offers/btn_dont_miss_out_over.png',
  'offers/btn_dont_miss_out_buy_gold.png',
  'offers/btn_dont_miss_out_buy_gold_over.png',
  'footer/btn-viewGallery.png',
  'footer/btn-viewGallery_over.png',
  'footer/btn_myMAXProfile.png',
  'footer/btn_myMAXProfile_over.png',
  'footer/btn_logout.png',
  'footer/btn_logout_over.png',
  'footer/btn_signInMyMAX.png',
  'footer/btn_signInMyMAX_over.png',
  'footer/btn_signUpNewsletter.png',
  'footer/btn_signUpNewsletter_over.png',
  'footer/btn-submit.png',
  'footer/btn-submit_over.png',
  'nav/nav-getExclusiveOffers-arrow.gif',
  'nav/nav-getExclusiveOffers_over.gif',
  'nav/nav-getExclusiveOffers.gif',
  'nav/btn_storelocator_over.gif',
  'nav/btn_storelocator.gif',
  'nav/nav-creative-arrow.gif',
  'nav/nav-products-arrow.gif',
  'nav/nav-offers-arrow.gif',
  'nav/nav-products_over.gif',
  'nav/nav-offers_over.gif',
  'nav/nav-creative_over.gif',
  'nav/nav-products.gif',
  'nav/nav-offers.gif',
  'nav/nav-MFlogo.gif',
  'nav/nav-creative.gif',
  'nav/nav_divider.gif');

  setTimeout ("onLoadImages()", 1000);
}

  
function onLoadImages()
{
  preloadImages(
  'shoppingCart/btn_checkoutNow_over.gif',
  'shoppingCart/btn_checkoutNow.gif',
  'shoppingCart/bkgd_shoppingCart.gif',
  'shoppingCart/btn_remove_over.gif',
  'shoppingCart/btn_remove.gif',
  'shoppingCart/bkgd_checkout.gif',
  'shoppingCart/btn_buy_available_items_over.png',
  'shoppingCart/btn_buy_available_items.png',
  'shoppingCart/btn_buy_this_item_over.png',
  'shoppingCart/btn_buy_this_item.png',
  'shoppingCart/btn_continue_shopping_over.png',
  'shoppingCart/btn_continue_shopping.png',
  'shoppingCart/btn_print_shopping_list_over.png',
  'shoppingCart/btn_print_shopping_list.png',
  'shoppingCart/btn_buy_online_over.png',
  'shoppingCart/btn_buy_online.png',
  'shoppingCart/overlay_addedToCart.png',
  'shoppingCart/overlay_updatedInCart.png',
  'shoppingCart/btn_scroll_right_over.gif',
  'shoppingCart/btn_scroll_left_over.gif',
  'shoppingCart/lbl_itemsInCart.gif',
  'shoppingCart/btn_scroll_right.gif',
  'shoppingCart/btn_scroll_left.gif',
  'user/arrow_right_sm.gif',
  'user/bkgd_forgotPassword.gif',
  'user/bkgd_maxProfile.gif',
  'user/bkgd_onItsWay.gif',
  'user/bkgd_signIn.gif',
  'user/bkgd_sorryAboutThat.gif',
  'user/bkgd_stayInTheLoop.gif',
  'user/bkgd_thanks.gif',
  'user/btn_cancel.gif',
  'user/btn_cancel_over.gif',
  'user/btn_close.gif',
  'user/btn_close_over.gif',
  'user/btn_continue.gif',
  'user/btn_continue_over.gif',
  'user/btn_continueExploring.gif',
  'user/btn_continueExploring_over.gif',
  'user/btn_finish.gif',
  'user/btn_finish_over.gif',
  'user/btn_send.gif',
  'user/btn_send_over.gif',
  'user/btn_signIn.gif',
  'user/btn_signIn_over.gif',
  'user/cancelBtn.jpg',
  'user/loginBckgrnd.jpg',
  'user/loginXBtn.jpg',
  'user/profile_bkgrnd.jpg',
  'user/register_bkgrnd.jpg',
  'user/saveChangesBtn.jpg',
  'user/signInBtn.jpg',
  //'gallery/gallery_colorGeniusBronzer_zoom.jpg',
  //'gallery/gallery_Lipfinity3D_zoom.jpg',
  //'gallery/gallery-vividImpactLip_zoom.jpg',
  'gallery/overlay_instructions.png',
  'footer/btn_closegallery.png',
  'footer/btn_closegallery_over.png');
  
  rotatingImages[1] = '/images/gallery/gallery_colorGeniusBronzer_zoom.jpg';
  rotatingImages[2] = '/images/gallery/gallery_colorGeniusBlush_zoom.jpg';
  rotatingImages[3] = '/images/gallery/gallery-vividImpactLip_zoom.jpg';
}

var currentNavName = "";
function inspirationNavOver(divName, ndxNavDiv)
{ 
  var completeNavDivName = "nav_" + divName + ndxNavDiv;
  if (currentNavName != completeNavDivName)
  {
    jQuery ("#" + "nav_" +divName + ndxNavDiv).css    ("color", "#FFFFFF");
    jQuery ("#" + "nav_" +divName + ndxNavDiv).css    ("cursor", "pointer");
  }
}

/*
 * this function compares the passed in shadeImageName to the currentShadeImage global
 * variable to control the mouse out behavior of the shades on the product detail screen
 */
function inspirationNavOut(divName, ndxNavDiv)
{
  var completeNavDivName = "nav_" + divName + ndxNavDiv;
  if (currentNavName != completeNavDivName)
  {
    jQuery ("#" + "nav_" +divName + ndxNavDiv).css    ("color", "#CCC");
    jQuery ("#" + "nav_" + divName + ndxNavDiv).css    ("cursor", "default");
  }
}

/*
 * this function controls the mouse click behavior of the shades on the product detail screen
 */
function inspirationNavClick(mainNavName, divName, ndxNavDiv)
{
   var completeNavDivName = "nav_" + divName + ndxNavDiv;
   var x = 0;
      
   for (y = 0; y < 3; y++)
   {
      x++;
      
      if(x != ndxNavDiv)
      {
         //jQuery ("#" + "nav_" + divName + x).css    ("text-decoration", "none");
         jQuery ("#" + "nav_" + divName + x).css    ("color", "#CCC");
         jQuery ("#" + divName + x).hide();
      }
      else
      {
         //jQuery ("#" + "nav_" + divName + x).css    ("text-decoration", "none");
         jQuery ("#" + "nav_" + divName + x).css    ("color", "#E4A772");
         jQuery("#" + mainNavName).attr("class", "stepActive" + ndxNavDiv);
           
         jQuery ("#" + divName + x).show();
      }
   }
   
   currentNavName = completeNavDivName;
}


/**
   Below functions are for Inspiring Looks Section product popups
 **/
function productOver(productLineNameInternal, ndxShadeImage, shadeImageName)
{
  if (currentProductInfo[productLineNameInternal].currentShadeName != shadeImageName)
  { 
    jQuery ("#" + productLineNameInternal + ndxShadeImage).css("border", "1px solid black");   
    jQuery ("#" + productLineNameInternal + ndxShadeImage).css("cursor", "pointer");
  }
}

function productOut(productLineNameInternal, ndxShadeImage, shadeImageName)
{
  if (currentProductInfo[productLineNameInternal].currentShadeName != shadeImageName)
  {
     jQuery ("#" + productLineNameInternal + ndxShadeImage).css    ("border", "1px solid white");   
     jQuery ("#" + productLineNameInternal + ndxShadeImage).css    ("cursor", "default");
  }
}

function productClick(productLineNameInternal, ndxShadeImage, shadeImageName, productLineName, productName, productImageName, numberOfProducts, shoppingCartImageName, upc)
{
  for (x = 0; x < numberOfProducts; x++)
  {
     jQuery ("#" + productLineNameInternal + x).css    ("border", "1px solid white");  
  }
  
  jQuery ("#" + productLineNameInternal + ndxShadeImage).css    ("border", "1px solid black");   
  
  currentProductInfo[productLineNameInternal].currentShadeName      = shadeImageName;
  currentProductInfo[productLineNameInternal].productLineName       = productLineName;
  currentProductInfo[productLineNameInternal].productName           = productName;
  currentProductInfo[productLineNameInternal].shoppingCartImageName = shoppingCartImageName;
  currentProductInfo[productLineNameInternal].shadeImageName        = shadeImageName;
  currentProductInfo[productLineNameInternal].upc                   = upc;
}
var swapImagePNG = function(imageID,imagePath,state){
  var ai2;
  if (state == 'over'){ai2=imagePath+"_over.png";}else{ai2=imagePath+".png";}
  jQuery('img#'+imageID).attr("src",ai2);
}
    
function inspirationOverlayDisplayBackground(opacity, divName)
{
   var contentPanesLeft = null;
   var contentPanesTop = null;
   var left = null;
   var top = null;
   
   contentPanesLeft = parseInt($("contentPanes").style.left);
   contentPanesTop = parseInt($("contentPanes").style.top);
  
  if (opacity === undefined)
    opacity = 0.55;
    
  /*alert("body height= " + jQuery(window).height());
  alert("body width= " + jQuery(window).width());
  alert("width= " + fixedwidth);
  alert("height= " + fixedheight);
  alert("left= " + fixedleft);
  alert("top= " + fixedtop);*/
  
  jQuery("#" + divName + "OverlayBackground").css  ('opacity', opacity);
  jQuery("#" + divName + "OverlayBackground").css  ('height',  jQuery(window).height());
  jQuery("#" + divName + "OverlayBackground").css  ('width',  jQuery(window).width());
  jQuery("#" + divName + "OverlayBackground").css  ('left',  -contentPanesLeft);
  jQuery("#" + divName + "OverlayBackground").css  ('top',  -121);
  jQuery("#" + divName + "OverlayBackground").show ();
}

/**
   end functions for Inspiring Looks Section product popups
 **/


function isValidEmail(value)
{
  var bOK    = false;
  var ndxAt  = value.indexOf     ("@");
  var ndxDot = value.lastIndexOf (".");
  if ((ndxAt != -1) && (ndxAt < ndxDot) && (ndxDot == value.length - 4))
    bOK = true;
  return (bOK);
}


function isNumeric (elemValue)
{
  var numericExpression = /^[0-9]+$/;
  return (elemValue.match(numericExpression));
}


function setCookie (valueName, value, expiredays)
{
  var expiredate = new Date();
  expiredate.setDate (expiredate.getDate() + expiredays);
  document.cookie = valueName + "=" + value + ";expires=" + expiredate.toGMTString ();
}


function getCookieValue (valueName)
{
  var value = "";
  var ndxStart;
  var ndxEnd;

  try
  {
    if (document.cookie.length > 0)
    {
      ndxStart = document.cookie.indexOf (valueName + "=");
      if (ndxStart != -1)
      {
        ndxStart += valueName.length + 1;
        ndxEnd    = document.cookie.indexOf (";", ndxStart);
        if (ndxEnd == -1)
          ndxEnd = document.cookie.length;
        value = document.cookie.substring (ndxStart, ndxEnd);
      }
    }
  }
  catch (err)
  {
  }
  return (value);
}


/*
 * this function is used to control the mouse over behavior 
 */
function mouseOver( imageId, newImgSrc)
{
   jQuery("#" + imageId).attr({src:   newImgSrc}); 
}

/*
 * this function is used to control the mouse out behavior 
 */
function mouseOut( imageId, oldImgSrc)
{
   jQuery("#" + imageId).attr({src:   oldImgSrc}); 
}

/* 
  This function hides all of the overlays that
  may be currently displayed
*/
function hideOverlay() 
{
   clearForm('consumerSurveyForm'); 
   clearForm('loginForm');  
   clearForm('forgotPasswordForm');
   
   jQuery("#overlayBackground").hide ();
   jQuery("#loginMainContainer").hide ();
   jQuery("#ageTooYoungContainer").hide ();
   jQuery("#registerMainContainer").hide ();
   jQuery("#registerConfirmationContainer").hide ();
   jQuery("#myProfileMainContainer").hide ();
   jQuery("#myProfileConfirmationContainer").hide ();
   jQuery("#forgotPasswordMainContainer").hide ();
   jQuery("#forgotPasswordConfirmationContainer").hide ();
   
   jQuery("#lipfinityMainContainer").hide ();
   jQuery("#jakeBMainContainer").hide ();
   jQuery("#patMMainContainer").hide ();
}

/* 
 * This function is used to clear any form data.
 */
function clearForm(formName)
{
   var currentForm = document.forms[formName];
   var ndx = 0;
   
   for (ndx = 0; ndx < currentForm.elements.length; ndx++)
   {
      fieldName = currentForm.elements[ndx].name;
      
      if(fieldName == "gender" || fieldName == "profileGender" || fieldName == "userGender")
      {
        //alert("GENDER");
      }
      else
      {
        setValue(fieldName, "");
      }
      
   }
}

/* 
 * This function is used display the passed in iFrame as well as set
 * the src for the iFrame using the passed in src.
 */
function displayFrame(frameName, frameSrc)
{   
   var scroll = 0;
   
   trackOverlay (frameName);      // tell web analytics that we're displaying this overlay
   
   var contentPanesLeft = null;
   //check to see if carouselMgr is null.  If it is null then we came from gallery.jsp
   if(carouselMgr != null)
   {
      carouselMgr.autoStop();      // if we're autoscrolling the feature pane, kill the autoscroller
      // get the left position of the contentPanes
      contentPanesLeft = parseInt($("contentPanes").style.left);
   }
   else
   {
      contentPanesLeft = 240;
   }
   
   overlayDisplayBackground (); // make background semi-opaque and only the overlay clickable

   // get the top position of the footer
   var footerTop = parseInt($("footer").style.top);
   
   // set the left position 172 left of the contentPanes
   var left = contentPanesLeft + 172;
   
   // set the top position 565 above the footer (545 for the div height + 20 spacing)
   var top = footerTop - 565;
   
   // now position the iFrame using the left and top variables
   jQuery("#"+frameName).css('left',left);
   jQuery("#"+frameName).css('top',top);

   jQuery("#"+frameName).attr({src: frameSrc});
   jQuery("#"+frameName).fadeIn("fast");
}

/* 
 * This function is used hide the passed in iFrame. If a
 * value is passed in for the newUrl then the goToPane 
 * function will be called.
 */
function hideFrame(frameName, newUrl) 
{  
   var goToURL = newUrl;
   
   jQuery("#" + frameName).fadeOut("fast");
   jQuery("#overlayBackground").hide ();
   
   jQuery("#"+frameName).attr({src: ""});
   
   // If the goToURL is undefined then that means it wasn't passed
   // in because the user is just closing the iFrame so don't
   // call the goToPane function
   if(goToURL)
   {
     carouselMgr.goToPane(goToURL);
   }
}

