// Global function to refer to the pages that have tabs...
var shelleysPages = ['home', 'about-shlley-s', 'how-to-buy-a-diamond', 'engagement-rings', 
 'design-studio', 'estate-jewelry', 'selling-your-jewelry', 'jewelry-education', 'service-repair'];

// Hash of the main pages to their sub-pages.
var shelleysSubPages = new Object();
shelleysSubPages['home'] = [];
shelleysSubPages['about-shlley-s'] = ['our-staff', 'locations', 'warranty-retruns', 'contact-owner'];
shelleysSubPages['how-to-buy-a-diamond'] = ['hearts-on-fire-1', 'tips-1', 'contact-diamond-expert'];
shelleysSubPages['engagement-rings'] = ['hearts-on-fire-2', 'create-your-own-1', 'antique-rings', 'contact-ring-advisor'];
shelleysSubPages['design-studio'] = ['create-your-own-2', 'contact-designer'];
shelleysSubPages['estate-jewelry'] = ['tips-2', 'contact-estate-specialist'];
shelleysSubPages['selling-your-jewelry'] = ['tips-3', 'shelley-s-auction', 'contact-advisor'];
shelleysSubPages['jewelry-education'] = ['jewelry-care', 'diamond-care', 'appraisals', 'contact-jewelry-expert'];
shelleysSubPages['service-repair'] = ['goldsmiths', 'contact-repair-advisor'];

// Page names... 
var shelleyNameMappings = new Object();
shelleyNameMappings['home'] = "Home";
shelleyNameMappings['about-shlley-s'] = "About Shelley's";
shelleyNameMappings['our-staff'] = "Our Staff";
shelleyNameMappings['locations'] = "Locations";
shelleyNameMappings['warranty-retruns'] = "Warranty/Returns";
shelleyNameMappings['contact-owner'] = "Contact Owner";
shelleyNameMappings['how-to-buy-a-diamond'] = "How to Buy a Diamond";
shelleyNameMappings['hearts-on-fire-1'] = "Hearts on Fire";
shelleyNameMappings['tips-1'] = "Tips";
shelleyNameMappings['contact-diamond-expert'] = "Contact Diamond Expert";
shelleyNameMappings['engagement-rings'] = "Engagement Rings";
shelleyNameMappings['hearts-on-fire-2'] = "Hearts on Fire";
shelleyNameMappings['create-your-own-1'] = "Create Your Own";
shelleyNameMappings['antique-rings'] = "Antique Rings";
shelleyNameMappings['contact-ring-advisor'] = "Contact Ring Advisor";
shelleyNameMappings['design-studio'] = "Design Studio";
shelleyNameMappings['create-your-own-2'] = "Create Your Own";
shelleyNameMappings['contact-designer'] = "Contact Designer";
shelleyNameMappings['estate-jewelry'] = "Unique and Collectible";
shelleyNameMappings['tips-2'] = "Tips";
shelleyNameMappings['contact-estate-specialist'] = "Contact Estate Specialist";
shelleyNameMappings['selling-your-jewelry'] = "Selling Your Jewelry";
shelleyNameMappings['tips-3'] = "Tips";
shelleyNameMappings['shelley-s-auction'] = "Shelley's Auction Gallery";
shelleyNameMappings['contact-advisor'] = "Contact Advisor";
shelleyNameMappings['jewelry-education'] = "Jewelry Education";
shelleyNameMappings['jewelry-care'] = "Jewelry Care";
shelleyNameMappings['diamond-care'] = "Diamond Care";
shelleyNameMappings['appraisals'] = "Appraisals";
shelleyNameMappings['contact-jewelry-expert'] = "Contact Jewelry Expert";
shelleyNameMappings['service-repair'] = "Service & Repair";
shelleyNameMappings['goldsmiths'] = "Goldsmiths";
shelleyNameMappings['contact-repair-advisor'] = "Contact Repair Advisor";


// This is the function that is called after HTML has been loaded, or after resizing
function fixheight()
{
  
  // Set minimum height
  var dynamicHeight = document.documentElement.clientHeight;
  var px = (dynamicHeight - 80) + "px";
  document.getElementById("container").style.minHeight = px;

  // Reset the position of the image  
  var dynamicWidth = document.documentElement.clientWidth;
  px = (dynamicWidth / 2 - 150) + "px";
  document.getElementById("logo").style.left = px;
  
  // Stretch out the border of the tab
  var tabDiv = document.getElementById("tabberlive");
  dimensions = getPosition(tabDiv);
  var tabMargin = (50 - dimensions[0]);
  if (tabMargin < 0)
  {
    tabDiv.style.marginLeft = tabMargin + "px";
    tabDiv.style.paddingLeft = (-1 * tabMargin) + "px";
  }

  // Impose a padding-top on the left nav  
  document.getElementById("left").style.paddingTop = (dimensions[1]) + "px";  
  document.getElementById("left").style.marginTop = "0px";  
  dimensions = getPosition(document.getElementById("content"));  
  
  // Impose a minimum height on the left nav
  var dimensions2 = getPosition(document.getElementById("left"));
  dynamicHeight = document.getElementById("container").offsetHeight;
  document.getElementById("left").style.minHeight = (dynamicHeight - dimensions2[1] - dimensions[1]) + "px";
  
  // Remove left div by request 
  document.getElementById("container").style.dispay = 'none';
  
  // Set the active tab
  document.getElementById(getActiveTab()).className = "tabberactive";
}

// This will get the currently active tab
function getActiveTab()
{
  // The default ID.
  var defaultID = 'home';
  
  // The URL to match.
  var url = document.URL;
  
  // Match the URL against any of those documents
  for (var i = 0; i < shelleysPages.length; i++)
  {
    var page = shelleysPages[i];
    if (url.indexOf(page) >= 0)
    {
      return page;
    }
    
    // Next cycle through all the other subpages
    for (var j = 0; j < shelleysSubPages[page].length; j++)
    {
      var subpage = shelleysSubPages[page][j];
      if (url.indexOf(subpage) >= 0)
      {
        return page;
      }
    }
  }
  return defaultID;
}

// This will get the currently active subpage  (not tab)
function getActivePage()
{
  // The default ID.
  var defaultID = 'home';
  
  // The URL to match.
  var url = document.URL;
  
  // Match the URL against any of those documents
  for (var i = 0; i < shelleysPages.length; i++)
  {
    var page = shelleysPages[i];
    if (url.indexOf(page) >= 0)
    {
      return page;
    }
    
    // Next cycle through all the other subpages
    for (var j = 0; j < shelleysSubPages[page].length; j++)
    {
      var subpage = shelleysSubPages[page][j];
      if (url.indexOf(subpage) >= 0)
      {
        return subpage;
      }
    }
  }
  return defaultID;
}

// This returns all elements of a certain class name.
function getElementsByStyleClass (className) 
{
  var all = document.all ? document.all :
    document.getElementsByTagName('*');
  var elements = new Array();
  for (var e = 0; e < all.length; e++)
    if (all[e].className == className)
      elements[elements.length] = all[e];
  return elements;
}

function animateLogo(element)
{
  document.getElementById("logo").src = 'http://www.shelleysjewelry.com/uploads/images/core_images/animated-logo.gif';
  
  if (element != undefined)
  {
    element.style.zIndex = 999;
  }
}

function stopLogo(element)
{
  document.getElementById("logo").src = 'http://www.shelleysjewelry.com/uploads/images/core_images/static-logo.gif';
  if (element != undefined)
  {
    element.style.zIndex = 0;
  }
}


// Fades in an element
function fadein(id, opac) 
{
  var step = 5;
  if(opac < 100)
  {
    opac+=step;
    document.getElementById(id).opacity = opac;
    document.getElementById(id).style.filter = 'alpha(opacity=' + (opac) + ')';
    setTimeout('fadein(\'' + id + '\', '  + opac + ')', 50);
  }
}