//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;

PreLoad(); //Pre-load button images into cache

function PreLoad()   //in a function to limit scope of unneeded variables
{
	var buttonSources = new Array("index","theprogram","classschedules","tuition","supplies","application","instructors","testimonials","contact","vendors");
	var totalButtons = buttonSources.length;
	var buttonFolder = "images/buttons/";
	for(i=0; i<totalButtons; i++)
	{
		var b, name = buttonSources[i];
		b = new Image(); b.src = buttonFolder+"normal/"+name+".png";
		b = new Image(); b.src = buttonFolder+"hover/"+name+".png";
	}
}

$(document).ready(function()
{
   if($.flash && $('#flashrotator').length!=0)  //make sure jquery.swfobject.js is loaded AND the div tag exists
   {
      var start = window.location.href.lastIndexOf('/')+1; //name of html file is same as name of image subdir
      var end = window.location.href.indexOf('.', start);
      var dir = window.location.href.substring(start,end);
      if (dir=="index" || end==-1) dir="default";  //hack. ok. not exactly the same.
      $('#flashrotator').flash({
         swf: 'ImageRotator.swf',
         width: 280,
         height: 311,
         quality: 'high',
         wmode: 'transparent',  //allows background to show thru while swf is loading
         swfversion: '7.0.70.0',
         scale: 'noborder',
         base: 'images/'+dir+'/',
         expressinstall: 'expressInstall.swf'  //redundant. for excplicitly showing dependency
      });
   }

   $("ul.menu li a img").hover(
      function() { $(this).attr("src", $(this).attr("src").replace("normal","hover")); },
      function() { $(this).attr("src", $(this).attr("src").replace("hover","normal")); }
   );
      
   $("ul.menu li a").each(
      function() {
        var hr=$(this).attr("href");
        if (hr==null || hr=="" || hr=="#") { $(this).attr("href","javascript:void(0);"); }
      }
   );

   $("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+' Academy of Cosmetic Arts &bull; All Rights Reserved | <a href="Contact.htm" >Contact Us</a></span></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-2"); pageTracker._trackPageview(); } catch(err) {}
   $.geekGaTrackPage('UA-11851965-1');    //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()
{ 
   var ul = this;
   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 maxheight = $(ul).outerHeight();
   var maxwidth = $(ul).outerWidth();
   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;
   $(this).parent().eq(0).hoverIntent({ sensitivity:7, interval:200, over:navHoverOver, timeout:500, out:navHoverOut }); 
}
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); }


