//initialize variables
var flashPrompt = true;
var flashPlayerVer;
var menu_style;
var active_dir;
var this_page;
var swffile;
var advanced_hosting;
var advanced_hosting_mode;
var isTemplate;
var translated_url;
var jsmenu = true;
//initialize shadowbox before DOM is loaded//
Shadowbox.init({players:['img', 'html', 'flv', 'swf', 'qt', 'iframe']});

if (parent.$('iframe ').length) {
	advanced_hosting_mode = true;
}else{
	advanced_hosting_mode = false;
}
$(document).ready(function(){
		if(!flashCheck() && !flashPrompt) {
			//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();
			});
		}else if(jsmenu) {

			//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();
			});
		}
		if(!advanced_hosting_mode){
			//initImageReplacement();
		}
		if ($('#accordion_menu').length) {
			initAccordionMenu();
		}
		if(checkLang() == 'french'){
			$("body").addClass("french");
			$("#header").append("<a href='"+getTranslatedUrl()+"' id='translate'>English</a>");
			$("#ctl00_interior #header").append("<a href='/default-fr.aspx' id='homelink'>Home</a>");
			$("#userInfo .login").html("Acc&eacute;der");
			
			
			$('#loginpage h2').html("Membres seulement");
			$('label[for="ctl00_placeholderLoginForm_Login_UserName"]').html("Nom d'utilisateur");
			$('.labelUsername').html("Nom d'utilisateur");
			$('label[for="ctl00_placeholderLoginForm_Login_Password"]').html("Mot de pass&eacute;");
			$('.labelPassword').html("Mot de pass&eacute;");
			$('label[for="ctl00_placeholderLoginForm_Login_RememberMe"]').html("Se souvenir de moi");
			$('.labelRememberMe').html("Se souvenir de moi");
			$("#ctl00_placeholderLoginForm_Login_PasswordRecoveryLink").html("Vous avez oubli&eacute; votre mot de passe?");
			$(".labelForgotPassword").html("Vous avez oubli&eacute; votre mot de passe?");
			
			$("#home-search-instructions").html("Rechercher la base de donn&eacute;es des  membres de l'ACSCBMF.  Cliquer sur le bouton de recherche ci-dessous pour rechercher un chirurgien  par nom ou  par endroit.");
			$("#btnSearch").attr("href", "default-fr/find-a-surgeon.aspx");
			
			$('#ctl00_placeholderBody_ctl88_lblEnterEmail').html("Entrer votre courriel  pour recevoir votre mot de passe");
			//$('#ctl00_placeholderBody_ctl88_lblEmail').html("");
			$('#ctl00_placeholderBody_ctl88_btnSend').val("Envoyer le mot de passe");
			$('#ctl00_placeholderBody_ctl88_btnBackToPage').val("Retour a la page");
			$('#XXX').val("Votre mot de passe  a &eacute;t&eacute; envoy&eacute;");
			
			$('#portal1 h2').html("Trouver-un-sp&eacute;cialiste");
			$('#portal2 h2').html("Calendrier des &eacute;v&eacute;nements");
			$('#portal3 h2').html("Membres seulement");

		}else{
			$("body").addClass("english");
			$("#ctl00_placeholderLoginForm_Login_LoginButton").val("Log In");
			$("#ctl00_placeholderBody_ctl86_Login1_LoginButton").val("Log In");
			$("#ctl00_placeholderBody_ctl88_Login1_LoginButton").val("Log In");
			$("#header").append("<a href='"+getTranslatedUrl()+"' id='translate'>Fran&ccedil;ais</a>");
			$("#ctl00_interior #header").append("<a href='/default.aspx' id='homelink'>Home</a>");
		}
		

});

function flashCheck(){
	flashPlayerVer = jQuery.fn.flash.hasFlash.playerVersion();
	if(!jQuery.fn.flash.hasFlash(8) || $("html").attr("id") == 'noflash' || $("html").attr("id") == 'platinum') {
		return false;
	}else{
		return true;
	}
}
function loadTopbar(status){
	active_dir = getDir();

	if(flashCheck() && status != 'mockup') {
		
		
		if(checkLang() == 'french'){
			if($("body").attr("id") == "ctl00_home" && isTemplate != true){
				swffile = '/templates/caoms/index_fr.swf';
			}else if($("body").attr("id") == "ctl00_interior"){
				swffile = '/templates/caoms/_menu/topbar_fr.swf';
			}else if(isTemplate){
				swffile = '/templates/caoms/_menu/topbar_fr.swf';
			}
		}else{
			if($("body").attr("id") == "ctl00_home" && isTemplate != true){
		    swffile = '/templates/caoms/index.swf';
			}else if($("body").attr("id") == "ctl00_interior"){
				swffile = '/templates/caoms/_menu/topbar.swf';
			}else if(isTemplate){
				swffile = '/templates/caoms/_menu/topbar.swf';
			}	
			 swffile = '/templates/caoms/index.swf';
				
		}

	
		if(advanced_hosting == true){
			this_page = getDir() + "Templates/template.dwt";
		}
		if(this_page == undefined){
			if(checkLang() == 'french'){
				this_page = 'default-fr/'+getPage();
			}else{
				this_page = getPage();
			}
		}

		$('body#ctl00_home #header').flash(
			{
				src: swffile,
				id: 'flash_header',
				flashvars: { load_page: this_page, active_dir: getDir(), flashVer: flashPlayerVer, translated_url :  getTranslatedUrl(), current_language : checkLang()}
			},
			{ version: 8, update: false },
			  function(htmlOptions) {
				  if (parent.$('iframe ').length || $('#Content1_edtrDynamicContent').length) {
					  htmlOptions.wmode = 'transparent';
				  }
				  htmlOptions.height = '100%';
				  htmlOptions.width = '100%';
				  $(this).append($.fn.flash.transform(htmlOptions));
			  }
			 );
		
		
		
	}else if(flashPrompt && status != 'mockup'){
		   $("#header").append('<p class="text_center"><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>');
	}
	if(flashCheck() || $("html").attr("id") == 'platinum') {
			
	}
}
function loadBottombar(){
	if(flashCheck() && isTemplate != true) {
		if(this_page == undefined){
			this_page = getPage();
		}
				$('#footer').flash(
			{
				src: '',
				id: 'flash_footer',
				flashvars: { load_page: this_page, active_dir: getDir() }
			},
			{ version: 8, update: false },
			  function(htmlOptions) {
				  if (parent.$('iframe ').length || $('#Content1_edtrDynamicContent').length) {
					  htmlOptions.wmode = 'transparent';
				  }
				  htmlOptions.height = '100%';
				  htmlOptions.width = '100%';
				  $(this).append($.fn.flash.transform(htmlOptions));
			  }
			 );
	}
}

////functions
function getPage(){

		var 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(20,this_page.indexOf('?'))
			this_page=this_page.substr(this_page.lastIndexOf('/')+1)
		
		if (this_page == ""){
			this_page = "default.aspx";
		}
		return this_page;
	
}

function checkLang(){

		var this_page=unescape(location.href);
		var this_page_split = this_page.split("/");
		var lang;
			var regFrench = /-fr/g; 
			var regFrenchDash = /_120/g; 
			if(this_page_split[3].match(regFrench) || this_page_split[2].match(regFrench)  || this_page_split[3].match(regFrenchDash) || this_page_split[2].match(regFrenchDash)){
			lang = 'french';
			//alert(lang);
			}
		
		return lang;
	
}

function getDir(){
	if($("body").attr("id") == "ctl00_home"){
		var active_dir = "/";
		
	}else{
	   var active_dir = "/templates/caoms/"; 
	   
	}
	return active_dir;
}
function getTranslatedUrl(){
	
	var this_page=unescape(location.href);
	var this_page_split = this_page.split("/");
	//alert('asd'+this_page_split[3]);
	if(this_page_split[3] == "default.aspx" || this_page_split[3] == ""){
		translated_page = "default-fr.aspx";
	}else if(this_page_split[3] == "default-fr.aspx"){
		translated_page = "default.aspx";
	}else{
		
		//alert(this_page_split.length);
		if(this_page_split[3] != "default-fr"){
			this_page_split.splice(3,0,"default-fr");
		}else{
			this_page_split.splice(3,1);
		}
		var translated_page = "";
		for(var i=0; i<(this_page_split.length-1); i++) {
			translated_page += this_page_split[i]+"/";
		}
	
		translated_page += this_page_split[(this_page_split.length-1)];
	}
		return translated_page;
}
