
jQuery(document).ready(function(){
	
	jQuery(window).load(function () {
		jQuery(".fade_overlay").fadeTo(200, 1).fadeOut("slow"); //fadeTo() used as a makeshift delay timer
		
		jQuery(".fade_overlay_cle").fadeTo(200, 1).fadeOut("slow"); //fadeTo() used as a makeshift delay timer
		
		jQuery("#ShowAllClients").click(function(){
			activate_clientlist();
		});
		
		jQuery("#TakeMeBack").click(function(){
			deactivate_clientlist();
		});
		
		/* FOR THE NEW MAIN NAV */
		//Fix for flickering text in FF2
		jQuery.each(jQuery.browser, function(i, val) {
		  if(i=="mozilla" && jQuery.browser.version.substr(0,3)=="1.8")
			jQuery("#main_nav").css("opacity", ".9999")
		});

		//Remove last nav item margin
		jQuery("#main_nav li:last-child").css("padding-right", "0px");

		//center subnav
		jQuery("#main_nav li ul[class!='right_side']").each(function(){
			_width = -(jQuery(this).innerWidth() - jQuery(this).parent().innerWidth())/2 +"px";
			jQuery(this).css("left", _width);
		});

		//For subnavs	
		jQuery("#main_nav li:has(ul)[class!='on']").hover(
			function(){			
				jQuery("#main_nav li ul").fadeOut("fast");
				jQuery(this).find("ul").fadeIn("fast");
			},
			function(){
				jQuery("#main_nav li[class='on'] ul").fadeIn("fast");
				jQuery(this).find("ul").fadeOut("fast");
			}
		);
    });

	//For FAQs
	jQuery(".QuickLinksLink").click(function(event){
		if(!jQuery(this).hasClass("norm")){
			event.preventDefault();
			var visible_area = jQuery('#PracticesiFrame').contents().find('.mcontentwrapper'); // the area in flexscroll that scrolls
			var content = visible_area.find('.contentwrapper');
			var title = jQuery(this).text();
			var answer = visible_area.find("span:contains("+title+")");

			//Trying to fix the custom scroller, still a bug where if you use the scrollbar the quicklinks don't work then
			//console.info(visible_area.height());
			//console.info(visible_area.find('.contentwrapper').position());
			//console.info(answer.position());
			//console.log(answer.position()['top']/visible_area.height());
			var answer_pos = (content.height()-answer.position()['top'] < 448) ? content.height() : answer.position()['top'];
			var scroll_pos = 448*(answer_pos/content.height())+"px";
			//console.log(scroll_pos);
			jQuery('#PracticesiFrame').contents().find(".vscrollerbar").animate({top:scroll_pos},800);
		
			visible_area.scrollTo(answer,800); //scroll to the answer with the same title as the quicklink
			visible_area.find("span").removeClass("orange");
			answer.addClass("orange");
		}
		jQuery(".QuickLinksLink.orange").removeClass("orange"); //kill the orange on the last clicked link
		jQuery(this).addClass("orange"); //add orange to the new link
	});
   
});

/* To interface with the Flash main_nav */
function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function activate_clientlist() {
	top.getFlashMovie("main_nav").activate_clientlist();
}

function deactivate_clientlist() {
	top.getFlashMovie("main_nav").deactivate_clientlist();
}

//these two functions must be used together. The change_office must be in the parent scope for flash but change_office_lcoal is used so that the jquery script can be called locally for the frame.
function change_office(office){
	self.frames['MasteriFrame'].change_office_local(office);
}

function change_office_local(office){
	jQuery(".fade_overlay").fadeIn("normal", function(){ window.location.href = "/offices/"+office+".asp"; });
}
