//initialize variables
var flashInstalled = jQuery.fn.flash.hasFlash(8);
var flashPrompt = false;
var menu_style;
var this_page;
var active_dir;
var template_media_vers;
//initialize shadowbox before DOM is loaded//
Shadowbox.init({players:['img', 'html', 'flv', 'swf', 'qt', 'iframe']});

$(document).ready(function(){
		if(!flashCheck()) {
			//add the 'noflash' ID to the <html> tag
			$("html").attr("id","noflash");
			//add the superfish class name to the client_header menu
			if(menu_style == "vertical"){
				$("#nav").attr("class","sf-menu sf-vertical");
			}else{
				$("#nav").attr("class","sf-menu");
			}
			//load the remote javascript for the non-flash menu system
			$.getScript("http://common.pbhs.com/Scripts/superfish.js", function(){
				// initialize the superfish menus
				$('ul.sf-menu').superfish();
			});
		}
	
});
function flashCheck(){
	if(!jQuery.fn.flash.hasFlash(8) || $("html").attr("id") == 'noflash') {
		return false;
	}else{
		return true;
	
	}
}
function loadTopbar(status){
	active_dir = getDir();
	if(flashCheck() && status != 'mockup') {
		if(template_media_vers == undefined){
			var client_header = $('#client_header').html();
			//$("body").after(client_header);
			//$('#client_header').clone(true).insertAfter('body');
			//alert(client_header);

		}
			$('#home #header').flash(
					{ 
					  src: '../_menu/topbar.swf',
					  width: '100%',
					  height: '100%',
					  flashvars: { load_page: getPage(), active_dir: getDir(), lang: lang, update: update, MMredirectURL: MMredirectURL, MMPlayerType: MMPlayerType, flashVer: versionStr, visited: visited, photo_selections: photo_selections, phrases: phrases, specialty: specialty, edit_mode: edit_mode, hide_name: 'false'}
					},
					{ version: 8, update: false }
					 );
			
			$('#interior #header').flash(
					{ 
					  src: '../_menu/topbar.swf',
					  width: '100%',
					  height: '100%',
					  flashvars: { load_page: getPage(), active_dir: getDir(), lang: lang, update: update, MMredirectURL: MMredirectURL, MMPlayerType: MMPlayerType, flashVer: versionStr, visited: visited, photo_selections: photo_selections, phrases: phrases, specialty: specialty, edit_mode: edit_mode, hide_name: 'false'}
					},
					{ version: 8, update: false }
					 );
			
	}
	if(flashCheck()) {
			initSwfReplacement();
	}
}
function loadBottombar(status){
	if(flashCheck()) {
			$('#footer').flash(
					{ 
					  src: '../_menu/bottombar.swf',
					  width: '100%',
					  height: '100%',
					  flashvars: { load_page: getPage(), active_dir: getDir()}
					},
					{ version: 8, update: false }
					 );
	}
}

////functions
function getPage(){
	if (this_page == undefined){
		this_page=unescape(location.href);
		var this_page_split = this_page.split("/");
		//alert(this_page_split.length);
		if(this_page.indexOf('?')!==-1)
			this_page=this_page.substring(0,this_page.indexOf('?'))
			this_page=this_page.substr(this_page.lastIndexOf('/')+1)
		
		if (this_page == ""){
			this_page = "index.asp";
		}
	}
	return this_page;
}

function getDir(){
	if($("body").attr("id") == "home"){
		var active_dir = "";
		
	}else{
	   var active_dir = "../"; 
	   
	}
	return active_dir;
}
jQuery.fn.decHTML = function() { 
  return this.each(function(){ 
    var me   = jQuery(this); 
    var html = me.html(); 
    me.html(html.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>')); 
  }); 
}; 
