//If this window is within a frame the following line will force it to break out into a full window.
if (window != top) top.location.href = location.href;

$(document).ready(function()
{
   $("ul.menu li").children("a").each(
      function()
      {
        var hr=$(this).attr("href");
        if (hr==null || hr=="" || hr=="#") { $(this).attr("href","javascript:void(0);"); }
       //if (!($.browser.msie && $.browser.version=="7.0")) $(this).html('<span>'+$(this).html()+'</span>');
       //Drop-shadow looks like shit on Italics text under IE
      }
   );

   //IE7 dropdown menu items do not display properly when dropshadows are used!!
   //if ($.browser.msie && $.browser.version=="7.0") $("ul.menu > li").children("a").each(function() { $(this).html('<span>'+$(this).html()+'</span>'); });
   //Drop-shadow looks like shit on Italics text under IE

   //append down-arrow for dropdown menus
   $("ul.menu ul").parent().children("a").append("<span style='font-size:90%; font-style:normal;'>&#x25bc;</span>");
   
   AdjustNavBar();   //evenly distribute navbar elements & set width of dropdown to widest element.

   $("ul.menu li ul").each(navDropdown);  //initialize all navbar dropdown menus
   
   //Append Footer
   var d=new Date().getFullYear();
   $("body").append('<div id="footer"><span>&copy;'+d+' Eye Candy People &bull; All Rights Reserved | <a href="contact.htm" >Contact Us</a></span></div>');
   
   if ($.browser.msie)
   {
      $("body").append(
      '<div id="browsers" style="margin-top:6px;color:white; font:10px Arial, Geneva, sans-serif;">'+
      '<img src="images/browsers.png" width="110" height="18" alt="Browsers" usemap="#browsers" border="0" />'+
      ' Best when viewed with any browser except IE.'+
      '<map name="browsers">'+
      '<area shape="rect" coords="00,00,18,18" href="http://www.webdevout.net/ie-is-dangerous" target="_blank" alt="No IE" />'+
      '<area shape="rect" coords="23,00,41,18" href="http://www.mozilla.com/en-US/" target="_blank" alt="Mozilla FireFox" title="Mozilla FireFox" />'+
      '<area shape="rect" coords="46,00,64,18" href="http://www.google.com/chrome/" target="_blank" alt="Google Chrome" title="Google Chrome" />'+
      '<area shape="rect" coords="69,00,86,18" href="http://www.apple.com/safari/" target="_blank" alt="Apple Safari" title="Apple Safari" />'+
      '<area shape="rect" coords="93,00,119,18" href="http://www.opera.com/" target="_blank" alt="Opera" title="Opera" />'+
      '</map>'+
      '</div>');
   }
   
   // Google Analytics - std code ONLY works at end of <body>
   //var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); 
   //document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
   //try { var pageTracker = _gat._getTracker("UA-11851965-3"); pageTracker._trackPageview(); } catch(err) {}
   //$.geekGaTrackPage('UA-11851965-3');    //SEE: jquery.geekga.js - jQuery plugin for Google Analytics v1.1 (http://www.geekology.co.za/blog/2009/08/speeding-up-google-analytics-load-times-with-jquery-plugin/)
});

function navDropdown() 
{
   $(this).parent().eq(0).hoverIntent({ sensitivity:7, interval:200, over:navHoverOver, timeout:500, out:navHoverOut });   //initialize all navbar dropdown menus
   
   // House-cleaning: make sure dropdowns are back rolled back up before changing to the next page.
   //If this is not done when the 'back' button is pushed and the page is restored, the dropdown is still dropped down!

   //roll-up dropdown from parent click
   //if ($(this).attr("href")!="javascript:void(0);")  //This causes hoverIntent flake out and not allow dropdown to drop down reliably upon backup
   //{
   //   $(this).parents('li:eq(0)').children('a:eq(0)').click(function(){
   //      $(this).parents('li:eq(0)').children('ul:eq(0)').stop(true).animate({height: "hide", opacity: 'hide'}, 0);
   //      });
   //}
   
   //roll-up dropdown from a child item click
   $("li a",this).click(function(){
      $(this).parents('ul:eq(0)').stop(true).animate({height: "hide", opacity: 'hide'}, 0);
      });
}

function navHoverOver()
{
   var current = $('ul:eq(0)', this);
   var h = current[0].absHeight;    //ul.absHeight defined and set in subMenuInit()
   var dur = (3000*h)/120;          //dynamically adjust drop speed relative to height so all dropdowns take the same time to complete.
   current.height(h);               //moving too fast between dropdowns causes property to not be reset to default value.
   current[0].style.opacity = 1.0;  //moving too fast between dropdowns causes property to not be reset to default value.
   current.stop(true).animate({ height: 'show' }, {queue:false, duration:dur, easing: 'easeOutBounce'});
}
function navHoverOut() { $('ul:eq(0)',this).stop(true).animate({height: "hide", opacity: 'hide'}, 600); }

//=============================================================================

function AdjustNavBar()
{
   var navbar = document.getElementById("menu");
   var parentWidth = navbar.clientWidth;
   var width=0;
   for(i=0; i<navbar.children.length; i++) { width += navbar.children[i].clientWidth; }
   var incr = (parentWidth-width) / (navbar.children.length*2);
   for(i=0; i<navbar.children.length; i++)
   {
      var navbarchild= navbar.children[i];
      navbarchild.style.marginLeft = incr+'px';
      navbarchild.style.marginRight = (i<(navbar.children.length-1) ? incr+'px' : '0px');

      var j;
      var ul = navbarchild.getElementsByTagName('UL');
      if (ul.length==0) continue;  //menu does not have any sub-menu items.
      ul = ul[0];
      var li = navbarchild.getElementsByTagName('LI');
      if (li.length==0) continue; //UL submenu does not have any LI items. this should never occur.

      //determine maximum width of all the sub-menu items to determine the optimum submenu box width
      var p = ul.style.position;        //submenu LI items do not have dimensions because of property display:none 
      var v = ul.style.visibility;      //so we temporarily apply display:block to force items to have dimension.
      var d = ul.style.display          //we also temporily set visibility:hidden to avoid flicker.
      ul.style.position='absolute';
      ul.style.visibility='hidden';
      ul.style.display='block';
      var maxwidth=0;
      var maxheight=0;
      for(j=0; j<li.length; j++)
      {
         var w = li[j].clientWidth;
         if (w>maxwidth) maxwidth=w;
         maxheight += li[j].clientHeight;
      }
      //ul.style.height = maxheight;  //not settable
      ul.height = maxheight;
      ul.absHeight = maxheight;    //moving too fast between dropdowns causes property to not be reset to default value. Therfore we must keep a private copy so we can manually reset it.
      ul.style.width = maxwidth+"px";
      ul.style.position=p;
      ul.style.visibility=v;
      ul.style.display=d;
      //force width to be the same as the dropdown box so to ensure LI items always wrap to the next line
      for(j=0; j<li.length; j++) { li[j].style.width = (maxwidth-20)+"px"; } //-20 to adjust for CSS "ul.menu ul li" padding
   }
}
//=============================================================================

