
/* Function to bind click on link for ajax */
function initLinks() {
	  	
	$(".global_popup").each(function () {
		if (!$(this).hasClass('close')) {
			$(this).bind("click",function(){ 
				unInitLinks();
				
				
				/* Check if click on link or tr tag */
				if ($(this)[0].tagName === "A"){
					linkTmp = $(this).attr('href');
				} else {
					linkTmp = $("td a",this).attr('href');
				}
				target = linkTmp.substring( linkTmp.indexOf("target") + 7 , linkTmp.lastIndexOf("&") );
				ajaxQuery = (linkTmp.charAt(linkTmp.length - 1) != "&")? "&ajax=True" : "ajax=True" ;
				
				if (!$(this).hasClass('aso_iframe')) {
					var popupContent = $.ajax({
							url: linkTmp + "&ajax=True",
							async: false,
							cache: false
						}).responseText;
					popupContent = popupContent.substring( popupContent.indexOf("<data>") + 6 , popupContent.indexOf("</data>") ) ;
				} else {
					var popupContent = getAsoIframeJs(linkTmp);
				}
				
				
				$("#global_popup").html(popupContent);
				$("#global_popup .menu").css("display","none");
				
				$("#BRHSC").animate({"marginLeft":300,"marginTop":300}, 700);						
				$("#TRHSC").animate({"marginLeft":300,"marginTop":-300}, 700);						
				$("#BLHSC").animate({"marginLeft":-300,"marginTop":300}, 700);	
				$("#content").fadeOut(500);   		
				$("#TLHSC").animate({"marginLeft":-300,"marginTop":-300}, 700, function(){
					activePrint();
					unInitLinks();
					fnResize();
																					
					$("#global_popup").fadeIn(500,function(){
						/* Special case for movie resource */
						if($("#left_frame .content object").length > 0){
							
							
							url = window.location.toString();
							url = url.substring( 0 , url.indexOf("?") );
							/* Get the acknowledgement content */
							var acknowledgement = $.ajax({
									url: url + "?ajax=True&target=acknowledgement",
									async: false,
									cache: false
								}).responseText;
							acknowledgement = acknowledgement.substring( acknowledgement.indexOf("<data>") + 6 , acknowledgement.indexOf("</data>") ) ;
							$("#left_frame .content").html('<a href="' + url + '?play_movie=true" id="movie_pre_slide"></a>' + acknowledgement);
							
						}
						$(this).show('fast', function() {
							$("#global_popup .menu").slideDown(600);
							
							$("#BRHSC").animate({"marginLeft":0,"marginTop":0}, 450);					
							$("#TRHSC").animate({"marginLeft":-10,"marginTop":5}, 450);						
							$("#BLHSC").animate({"marginLeft":4,"marginTop":-77}, 450);			
							$("#TLHSC").animate({"marginLeft":5,"marginTop":5}, 450, function(){
								initLinks();
							});			
						
						});		
					});  
																					  
				});
				
				return false;
			});		
		} else {
			$(this).bind("click",function(){ 
										  
				unInitLinks();
				
				$("#global_popup .menu").slideUp(550);
				
				$("#TLHSC").animate({"marginLeft":-300,"marginTop":-300}, 700);						
				$("#TRHSC").animate({"marginLeft":300,"marginTop":-300}, 700);						
				$("#BLHSC").animate({"marginLeft":-300,"marginTop":300}, 700);			
				$("#BRHSC").animate({"marginLeft":300,"marginTop":300}, 700, function(){
																					
					$("#global_popup").fadeOut(500,function(){
						$("#content").fadeIn(500);   
						$(this).hide('fast', function() {
													  	
							$("#global_popup").html("");
							
							$("#TLHSC").animate({"marginLeft":5,"marginTop":5}, 700);						
							$("#TRHSC").animate({"marginLeft":-10,"marginTop":5}, 700);						
							$("#BLHSC").animate({"marginLeft":4,"marginTop":-77}, 700);			
							$("#BRHSC").animate({"marginLeft":0,"marginTop":0}, 700);			
							initLinks();
						
						});		
					});  
																					  
				});
				
				return false;
			});			
		
		}
			
	});
	
	$(".popup").each(function () {
						  
		if (!$(this).hasClass('active') && !$(this).hasClass('close')) {
			
			$(this).bind("click",function(){ 
				unInitLinks();
				linkTmp = $(this).attr('href');
				target = linkTmp.substring( linkTmp.indexOf("target") + 7 , linkTmp.indexOf("&") );
				$("a.active").removeClass("active");
				$(this).addClass('active');
				
				ajaxQuery = (linkTmp.charAt(linkTmp.length - 1) != "&")? "&ajax=True" : "ajax=True" ;
				
				var popupContent = $.ajax({
						url: linkTmp + ajaxQuery,
						async: false,
						cache: false
					}).responseText;
				popupContent = popupContent.substring( popupContent.indexOf("<data>") + 6 , popupContent.indexOf("</data>") ) ;
				
				/* Check if a popup of the same kind is already displayed */
				switch(target)
				{
					case "values_spotlight":
						if ($("#popup_activity").css("display") == "block"){
							$("#popup_activity").fadeOut(500, function(){   	
								$(this).hide('fast', function() {
									$("#popup_activity").html("");
									$("#popup_" + target).html(popupContent);
									activePrint();
									unInitLinks();
									fnResize();
									$("#popup_" + target).fadeIn(700,function() {		
										$(this).show('fast', function() {				
											initLinks();
										});
									});  
								});
							});
						} else {
							$("#popup_" + target).html(popupContent);
							activePrint();
							unInitLinks();
							fnResize();
							$("#popup_" + target).fadeIn(700,function() {		
								$(this).show('fast', function() {				
									initLinks();
								});
							});  
						}
					  break;
					case "activity":
						if ($("#popup_" + target).css("display") == "block"){
							$("#popup_" + target).fadeOut(500, function(){   	
								$(this).hide('fast', function() {
									$("#popup_" + target).html(popupContent);
									activePrint();
									unInitLinks();
									fnResize();
									$("#popup_" + target).fadeIn(700,function() {		
										$(this).show('fast', function() {				
											initLinks();
										});
									});  
								});
							});
						} else if ($("#popup_values_spotlight").css("display") == "block"){
							$("#popup_values_spotlight").fadeOut(500, function(){   	
								$(this).hide('fast', function() {
									$("#popup_values_spotlight").html("");
									$("#popup_" + target).html(popupContent);
									activePrint();
									unInitLinks();
									fnResize();
									$("#popup_" + target).fadeIn(700,function() {		
										$(this).show('fast', function() {				
											initLinks();
										});
									});  
								});
							});
						} else {
							$("#popup_" + target).html(popupContent);
							activePrint();
							unInitLinks();
							fnResize();
							$("#popup_" + target).fadeIn(700,function() {		
								$(this).show('fast', function() {				
									initLinks();
								});
							});  
						}
					  break;
					default:
				}
				
				return false;
			});					
			
		} else if ($(this).hasClass('close')){
				
			$(this).bind("click",function(){ 
										  
				unInitLinks();
				target = $(this).attr('class').split(' ')[2];
				
				$("#popup_" + target).fadeOut(700,function() {		
					$(this).hide('fast', function() {				
						$("#popup_" + target).html("");
						$("a.active").removeClass("active");
						initLinks();
					});
				});
				return false;
			});			
		}
	});
	
	
	/* Bind click on learning pathway feature / SITEMAP */							
	$("ul#sitemap .lp").bind("click",function(){   
		unInitLinks();
		
		updateContent = checkCurrentResource($(this));		
		
	
		if ($(this).hasClass("resource")) {	
			animeLP_add($(this),true,true);
			$(this).siblings('ul').children('li').children('a').each(function () {
				animeLP_add($(this),false,false);										
			});
			
			/* If an activity popup is open, update the lp link */
			if (updateContent) {
				if ($("#content #popup_activity .top").find("a.lp").size() === 1) {
					animeLP_add($("#content #popup_activity .top a.lp"),false,false);										
				}
				$("#bottom #activities_list a.popup:not(.added_to_lp)").addClass("added_to_lp");
			}
			
		} else {
			
			/* If all activities of this resource has been added */
			if ($(this).parent("li").parent("ul").find("a.lp").size() === 1) {
				animeLP_add($(this),false,false);
				animeLP_add($(this).parent("li").parent("ul").siblings('a.lp_delete'),true,true);	
			} else {
				animeLP_add($(this),true,false);			
				animeLP_add($(this).parent("li").parent("ul").siblings('a.lp'),false,true);	
				
			}
			
			/* Position of activity */
			if (updateContent) {
				actPos = $(this).parent("li").parent("ul").find("a").index(this);
				$("#bottom #activities_list a.popup").eq(actPos).addClass("added_to_lp");
				
				/* If the activity popup of the selected activity is open, update the lp link */
				actId = $(this).attr("href").substring( $(this).attr("href").indexOf("lp=") + 3 , $(this).attr("href").indexOf("&act"));
				if ($("#content #popup_activity .top").find("a#" + actId ).size() === 1) {
					animeLP_add($("#content #popup_activity .top a#" + actId),false,false);										
				}
			}
			
		}			
		
		/* If add all on content is displayed */
		if (updateContent) {
			if ($("#bottom #activities_list a.resource").hasClass("lp")) {
				animeLP_add($("#bottom #activities_list a.resource"),false,true);											
			}
		}

		return false;
						   
	});
	
	$("ul#sitemap .lp_delete").bind("click",function(){   
		unInitLinks();
		
		updateContent = checkCurrentResource($(this));		
		
		if ($(this).hasClass("resource")) {	
			animeLP_delete($(this),true,true);
			$(this).siblings('ul').children('li').children('a').each(function () {
				animeLP_delete($(this),false,false);										
			});
			
			/* If an activity popup is open, update the lp link */
			if (updateContent) {
				if ($("#content #popup_activity .top").find("a.lp_delete").size() === 1) {
					animeLP_delete($("#content #popup_activity .top a.lp_delete"),false,false);										
				}
				$("#bottom #activities_list a.added_to_lp").removeClass("added_to_lp");
			
				/* If remove all on content is displayed */
				if ($("#bottom #activities_list a.resource").hasClass("lp_delete")) {
					animeLP_delete($("#bottom #activities_list a.resource"),false,true);											
				}
			}
		} else {
			/* If all activities of this resource has been removed */
			if ($(this).parent("li").parent("ul").find("a.lp_delete").size() <= 1) {
				animeLP_delete($(this),false,false);			
				animeLP_delete($(this).parent("li").parent("ul").siblings('a.lp_delete'),true,true);		
				
			} else {
				animeLP_delete($(this),true,false);			
			}			
			
			/* If the activity popup of the selected activity is open, update the lp link */
			if (updateContent) {
				actId = $(this).attr("href").substring( $(this).attr("href").indexOf("lp=") + 3 , $(this).attr("href").indexOf("&act"));
				if ($("#content #popup_activity .top").find("a#" + actId ).size() === 1) {
					animeLP_delete($("#content #popup_activity .top a#" + actId),false,false);										
				}
				
				/* If remove all on content is displayed and there is no activities added for this resource */
				if ($("#bottom #activities_list a.resource").hasClass("lp_delete") && $("#bottom #activities_list").find("a.added_to_lp").size() === 1) {
					animeLP_delete($("#bottom #activities_list a.resource"),false,true);											
				}			
				
				/* Position of activity */
				actPos = $(this).parent("li").parent("ul").find("a").index(this);
				$("#bottom #activities_list a.popup").eq(actPos).removeClass("added_to_lp");
			}
		}
		
		return false;
						   
	});
	$("ul#learning_pathway .lp_delete").bind("click",function(){   
		unInitLinks();
		
		updateContent = checkCurrentResource($(this));		
		
		if ($(this).hasClass("resource")) {	
			animeLP_delete($(this),true,true);
			$(this).parent("li").slideUp(150);
			
			obj = $(this).parent("li");
			
			/* If all activities of this subtheme have been removed */
			if ($(obj).parent("ul").children("li:visible").size() <= 1 ) {
				$(obj).parent("ul").parent("li").slideUp(150);
				
				obj = $(obj).parent("ul").parent("li");
				
				/* If all activities of this theme have been removed */
				if ($(obj).parent("ul").children("li:visible").size() <= 1 ) {
					$(obj).parent("ul").parent("li").slideUp(150);
					
					obj = $(obj).parent("ul").parent("li");
					
					/* If the learning pathway is now empty */
					if ($(obj).parent("ul").children("li:visible").size() <= 1 ) {
						$("ul#learning_pathway").slideUp(150);
						$("#global_popup .content br#brNode").after("<p style='display:none;'>There are no activities recorded in your learning pathway.</p>");
						$("ul#learning_pathway").slideUp(150,function(){
							$(this).hide('fast', function(){
								$("#global_popup .content p").fadeIn(150);
							});															
						});
					}
				}
			}			
			
			/* If an activity popup is open, update the lp link */
			if (updateContent) {
				if ($("#content #popup_activity .top").find("a.lp_delete").size() === 1) {
					animeLP_delete($("#content #popup_activity .top a.lp_delete"),false,false);										
				}
				$("#bottom #activities_list a.added_to_lp").removeClass("added_to_lp");
				
				/* If remove all on content is displayed */
				if ($("#bottom #activities_list a.resource").hasClass("lp_delete")) {
					animeLP_delete($("#bottom #activities_list a.resource"),false,true);											
				}
			}
		} else {
			/* If all activities of this resource have been removed */
			if ($(this).parent("li").parent("ul").children("li:visible").size() <= 1) {
				animeLP_delete($(this),false,false);			
				$(this).parent("li").slideUp(150);
				obj = $(this).parent("li");
				animeLP_delete($(obj).parent("ul").siblings('a.lp_delete'),true,true);		
				$(obj).parent("ul").parent('li').slideUp(150);
				obj = $(obj).parent("ul").parent('li');
				
				/* If all activities of this subtheme have been removed */
				if ($(obj).parent("ul").children("li:visible").size() <= 1 ) {
					$(obj).parent("ul").parent('li').slideUp(150);
					
					obj = $(obj).parent("ul").parent('li');
					
					/* If all activities of this theme have been removed */
					if ($(obj).parent("ul").children("li:visible").size() <= 1 ) {
						$(obj).parent("ul").parent("li").slideUp(150);
						
						obj = $(obj).parent("ul").parent("li");
						/* If the learning pathway is now empty */
						if ($(obj).parent("ul").children("li:visible").size() <= 1 ) {
							$("ul#learning_pathway").slideUp(150);
							$("#global_popup .content br#brNode").after("<p style='display:none;'>There are no activities recorded in your learning pathway.</p>");
							$("ul#learning_pathway").slideUp(150,function(){
								$(this).hide('fast', function(){
									$("#global_popup .content p").fadeIn(150);
								});															
							});
						}
					}
				}
				
			} else {
				animeLP_delete($(this),true,false);			
				$(this).parent("li").slideUp(150);
			}			
			
			if (updateContent) {
				/* If the activity popup of the selected activity is open, update the lp link */
				actId = $(this).attr("href").substring( $(this).attr("href").indexOf("lp=") + 3 , $(this).attr("href").indexOf("&act"));
				if ($("#content #popup_activity .top").find("a#" + actId ).size() === 1) {
					animeLP_delete($("#content #popup_activity .top a#" + actId),false,false);										
				}
				
				/* If remove all on content is displayed and there is no activities added for this resource */
				if ($("#bottom #activities_list a.resource").hasClass("lp_delete") && $("#bottom #activities_list").find("a.added_to_lp").size() === 1) {
					animeLP_delete($("#bottom #activities_list a.resource"),false,true);											
				}			
				
				/* Position of activity */
				actPos = $(this).parent("li").parent("ul").find("a").index(this);
				$("#bottom #activities_list a.popup").eq(actPos).removeClass("added_to_lp");
			}
		}
		
		return false;
						   
	});
	
	/* Bind click on learning pathway feature / RESOURCE PAGE */							
	$(".lp_content .lp").bind("click",function(){   
		unInitLinks();
		
		/* If click on add all */
		if ($(this).hasClass("resource")) {	
			animeLP_add($(this),true,true);
			
			/* If an activity popup is open, update the lp link */
			if ($("#content #popup_activity .top").find("a.lp").size() === 1) {
				animeLP_add($("#content #popup_activity .top a.lp"),false,false);										
			}
			
			$("#bottom #activities_list a.popup:not(.added_to_lp)").addClass("added_to_lp");
		} else {
			/* If all activities of this resource has been added */
			if ($("#bottom #activities_list").find("a.popup:not(.added_to_lp)").size() === 1) {
				animeLP_add($(this),false,false);
				animeLP_add($("#bottom #activities_list a.lp_delete"),true,true);	
			} else {
				animeLP_add($(this),true,false);			
				animeLP_add($("#bottom #activities_list a.lp"),false,true);	
			}
			
			/* Position of activity */
			actPos = $(this).attr("href").substring( $(this).attr("href").indexOf("numAct=") + 7 , $(this).attr("href").indexOf("&lp="));
			$("#bottom #activities_list a.popup").eq(actPos - 1).addClass("added_to_lp");
		}
		return false;
						   
	});
	
	$(".lp_content .lp_delete").bind("click",function(){   
		unInitLinks();
		
		/* If click on remove all */
		if ($(this).hasClass("resource")) {	
			animeLP_delete($(this),true,true);
			
			/* If an activity popup is open, update the lp link */
			if ($("#content #popup_activity .top").find("a.lp_delete").size() === 1) {
				animeLP_delete($("#content #popup_activity .top a.lp_delete"),false,false);										
			}
			
			$("#bottom #activities_list a.added_to_lp").removeClass("added_to_lp");
		} else {
			/* If all activities of this resource has been removed */
			if ($("#bottom #activities_list").find("a.added_to_lp").size() === 1) {
				animeLP_delete($(this),false,false);			
				animeLP_delete($("#bottom #activities_list a.lp_delete"),true,true);	
			} else {
				animeLP_delete($(this),true,false);			
			}
			
			/* Position of activity */
			actPos = $(this).attr("href").substring( $(this).attr("href").indexOf("&numAct=") + 8 , $(this).attr("href").indexOf("&lp="));
			$("#bottom #activities_list a.popup").eq(actPos - 1).removeClass("added_to_lp");
		}
		
		return false;
						   
	});
}
	
function animeLP_add (obj,ajax,resource) {
	$(obj).fadeOut(150, function () {
		$(obj).hide('fast',function(){
			if (ajax) { /* If this this is the current link */
				linkTmp = $(obj).attr('href');
				
				if ($(obj).hasClass("lp_delete") && resource) {
					target = linkTmp.substring( linkTmp.indexOf("lp=") , linkTmp.indexOf("&act")  ) + "&act=add";
				} else {
					newUrl = linkTmp.substring( 0 , linkTmp.indexOf("&act")) + "&act=del";
					$(obj).removeClass("lp");
					$(obj).addClass("lp_delete");
					$(obj).attr("href",newUrl);
					if (linkTmp.indexOf("#") != -1){
						target = linkTmp.substring( linkTmp.indexOf("lp="),linkTmp.indexOf("#") );
					} else {
						target = linkTmp.substring( linkTmp.indexOf("lp=") );						
					}
				}
				
				$.ajax({
						url: "/learning_pathway.asp?" + target,
						async: false,
						cache: false
					});
				if (resource) {
					$(obj).attr("title","Remove all activities of this resource from learning pathway");		
					$(obj).html("Remove all");			
				} else {
					$(obj).attr("title","Remove this activity from learning pathway");								
				}
				
				$(obj).fadeIn(150,function(){
					$(obj).show('fast',function(){
						initLinks();										 
					});
				});
			} else { /* Otherwise, no ajax, no links init */ 
				linkTmp = $(obj).attr('href');
				target = linkTmp.substring( linkTmp.indexOf("&lp") + 1 );
				newUrl = linkTmp.substring( 0 , linkTmp.indexOf("&act")) + "&act=del";
				$(obj).removeClass("lp");
				$(obj).addClass("lp_delete");
				$(obj).attr("href",newUrl);
				
				if (resource) {
					$(obj).attr("title","Remove all activities of this resource from learning pathway");		
					$(obj).html("Remove all");			
				} else {
					$(obj).attr("title","Remove this activity from learning pathway");								
				}
				
				$(obj).fadeIn(150);
			} 
		});								  
	});
	
	
}
function animeLP_delete (obj,ajax,resource) {
			
	$(obj).fadeOut(150, function () {
		$(obj).hide('fast',function(){
			if (ajax) { /* If this this is the current link */
				linkTmp = $(obj).attr('href');
				target = linkTmp.substring( linkTmp.indexOf("lp=") );
				newUrl = linkTmp.substring( 0 , linkTmp.indexOf("&act")) + "&act=add";
				
				$.ajax({
						url: "/learning_pathway.asp?" + target,
						async: false,
						cache: false
					});
				$(obj).removeClass("lp_delete");
				$(obj).addClass("lp");
				$(obj).attr("href",newUrl);
				if (resource) {
					$(obj).attr("title","Add all activities of this resource to learning pathway");
					$(obj).html("Add all");
				} else {
					$(obj).attr("title","Add this activity to learning pathway");				
				}
				
				$(obj).fadeIn(150,function(){
					$(obj).show('fast',function(){
						initLinks();										 
					});
				});
			} else { /* Otherwise, no ajax, no links init */
				linkTmp = $(obj).attr('href');
				target = linkTmp.substring( linkTmp.indexOf("&lp") + 1 );
				newUrl = linkTmp.substring( 0 , linkTmp.indexOf("&act")) + "&act=add";

				$(obj).removeClass("lp_delete");
				$(obj).addClass("lp");
				$(obj).attr("href",newUrl);
				if (resource) {
					$(obj).attr("title","Add all activities of this resource to learning pathway");
					$(obj).html("Add all");
				} else {
					$(obj).attr("title","Add this activity to learning pathway");				
				}
				$(obj).fadeIn(150);
			} 
		});								  
	});
}

/* Function to check if the content should be updated when action on LP from sitemap/LP */
function checkCurrentResource (obj) {
	
	if($("#bottom #activities_list a.resource").length > 0){
		resourceIdDisplayed = $("#bottom #activities_list a.resource").attr("href").substring( $("#bottom #activities_list a.resource").attr("href").indexOf("lp=") + 3 , $("#bottom #activities_list a.resource").attr("href").indexOf("&act="));
	} else {
		resourceIdDisplayed = null;
	}
	
	/* Check if the current page display the selected resource */
	if ($(obj).hasClass("resource")) {	
		resourceId = $(obj).attr("id");
	} else {
		resourceId = $(obj).parent("li").parent("ul").siblings('a.resource').attr("id");			
	}
	
	if (resourceIdDisplayed === resourceId){
			return true;
	} else {
		return false;
	}
}

/* Function to unbind click on link for ajax */
function unInitLinks(){
	$(".popup").each(function () {
		$(this).unbind("click");
		$(this).click(function(){return false;});	
	});	
	$(".global_popup").each(function () {
		$(this).unbind("click");
		$(this).click(function(){return false;});	
	});	
	$(".lp").each(function () {
		$(this).unbind("click");
		$(this).click(function(){return false;});	
	});	
	$(".lp_delete").each(function () {
		$(this).unbind("click");
		$(this).click(function(){return false;});	
	});	
}

/* Function to active print link when ajax load */ 
function activePrint(){
	/* Display print icon */
	$(".print").css("display","block");
	/* Bind print icon */
	$(".print").click(function(){
		var idPopup = $(this).attr("name");
		
		if (idPopup == "global_popup" ) {
			var title = $("#" + idPopup + " .menu h1").html();	   
			var contentHTML = $("#" + idPopup + " .content").html();
			
			
		} else if (idPopup == "popup_activity") {
			var title = $("#" + idPopup + " .title h3").html();	
			var contentHTML = $("#" + idPopup + " .content").html();
			
		}
		var toPrint = "<h1>" + title + "</h1>" + contentHTML;
		$("#print_div").html(toPrint);
		
		//$("#print_div p").css("fontSize","1em");
		$("#print_div *").removeAttr("style");
		/*$("#print_div p").removeAttr("style");
		$("#print_div ul").css("fontSize","1em");
		$("#print_div h2").css("fontSize","1.3em");
		$("#print_div h3").css("fontSize","1.15em");
		$("#print_div h4").css("fontSize","1em");
		$("#print_div table").css("fontSize","1em");*/
		//$("#print_div table").css("lineHeight","1em");
		//$("#print_div ul").css("lineHeight","1.2em");
		//$("#print_div p").css("lineHeight","1.2em");
		window.print(); 
		return false;
	});
}

/* Function listenning the window resize */
function fnResize (){
	
	/* Get the default site size */
	var minWidth = $("#jquerySiteSizes").css("width").substr(0,$("#jquerySiteSizes").css("width").indexOf("px"));
	var minHeight = $("#jquerySiteSizes").css("height").substr(0,$("#jquerySiteSizes").css("height").indexOf("px"));
	
	clientWidth = document.body.clientWidth;
	clientHeight = document.body.clientHeight;
	
	var purcentWidth = Math.round( clientWidth / minWidth * 100 ) / 100;
	var purcentHeight = Math.round( clientHeight / minHeight * 100 ) / 100;
	purcentHeight = (purcentHeight >= 1.40)? 1.40 : purcentHeight ;
	purcentWidth = (purcentWidth >= 1.40)? 1.40 : purcentWidth ;
	
	$(".content").each(function(){
		
		if ( !$("div",this).hasClass("noFontResize") ) {
			$("p",this).each(function(){
				
				if (purcentWidth >= purcentHeight && clientHeight > minHeight ){
					$(this).css("fontSize",purcentHeight + "em");
					//$(this).css("lineHeight",(purcentHeight + 0.2) + "em");
				} else if (purcentHeight > purcentWidth && clientWidth > minWidth) {
					$(this).css("fontSize",purcentWidth + "em");
					//$(this).css("lineHeight",(purcentWidth + 0.2) + "em");
					
				} else {
					$(this).css("fontSize","1em");
					//$(this).css("lineHeight","1.2em");
				}
			});
			$("ul",this).each(function(){		
				if (purcentWidth >= purcentHeight && clientHeight > minHeight ){
					$(this).css("fontSize",purcentHeight + "em");
					//$(this).css("lineHeight",purcentHeight + "em");
					$("li",this).css("backgroundPosition","left " + (purcentHeight / 3) + "em");
				} else if (purcentHeight > purcentWidth && clientWidth > minWidth) {
					$(this).css("fontSize",purcentWidth + "em");
					//$(this).css("lineHeight",purcentWidth + "em");
					$("li",this).css("backgroundPosition","left " +  (purcentWidth / 3) + "em");
					
				} else {
					$(this).css("fontSize","1em");
					//$(this).css("lineHeight","1em");
					$("li",this).css("backgroundPosition","left 5px");
				}
			});
			$("table",this).each(function(){		
				if (purcentWidth >= purcentHeight && clientHeight > minHeight ){
					$(this).css("fontSize",purcentHeight + "em");
					//$(this).css("lineHeight",(purcentHeight * 0.9) + "em");
				} else if (purcentHeight > purcentWidth && clientWidth > minWidth) {
					$(this).css("fontSize",purcentWidth + "em");
					//$(this).css("lineHeight",(purcentWidth * 0.9) + "em");
					
				} else {
					$(this).css("fontSize","1em");
					//$(this).css("lineHeight","1em");
				}
			});
			$("h2",this).each(function(){		
				if (purcentWidth >= purcentHeight && clientHeight > minHeight ){
					$(this).css("fontSize",(purcentHeight + 0.3) + "em");
				} else if (purcentHeight > purcentWidth && clientWidth > minWidth) {
					$(this).css("fontSize",(purcentWidth + 0.3) + "em");
					
				} else {
					$(this).css("fontSize","1.3em");
				}
			});
			$("h4",this).each(function(){		
				if (purcentWidth >= purcentHeight && clientHeight > minHeight ){
					$(this).css("fontSize",purcentHeight + "em");
				} else if (purcentHeight > purcentWidth && clientWidth > minWidth) {
					$(this).css("fontSize",purcentWidth + "em");
					
				} else {
					$(this).css("fontSize","1em");
				}
			});
			
		}
								
								
	});
	
	
	/*if (jQuery.browser.msie && jQuery.browser.version.substr(0,3)=="6.0") {
		if (document.body.clientWidth < minWidth) {
			$(".minSiteWidth").css("width",minWidth);
		} else {
			$(".minSiteWidth").css("width","100%");
		}
		/*if (document.body.clientHeight < minHeight) {
			$(".minSiteHeight").css("height",minHeight);
		} else {
			$(".minSiteHeight").css("height","100%");
		}
		
	}*/
	
	/*$("#content p").each(function(){
		var purcentWidth = Math.round( clientWidth / minWidth * 100 ) / 100;
		var purcentHeight = Math.round( clientHeight / minHeight * 100 ) / 100;
		if (clientWidth >= clientHeight && clientHeight >= minHeight ){
			$(this).css("fontSize",purcentHeight + "em");
			$(this).css("lineHeight",purcentHeight + "em");
		} else if (clientHeight > clientWidth && clientWidth >= minWidth) {
			$(this).css("fontSize",purcentWidth + "em");
			$(this).css("lineHeight",purcentWidth + "em");
			
		} else {
			$(this).css("fontSize","1em");
			$(this).css("lineHeight","1em");
		}
	});*/
	
}

/* Function for images preload */
function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

/* Get the flash version */
function getFlashVersion(){ 
  // ie 
  try { 
    try { 
      // avoid fp6 minor version lookup issues 
      // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ 
      var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
      try { axo.AllowScriptAccess = 'always'; } 
      catch(e) { return '6,0,0'; } 
    } catch(e) {} 
    return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
  // other browsers 
  } catch(e) { 
    try { 
      if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
        return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
      } 
    } catch(e) {} 
  } 
  return '0,0,0'; 
} 

function checkFlashVersion(resourceType){
	
	var fullVersion =getFlashVersion();
	var version = getFlashVersion().split(',').shift(); 
	
	if(version == 0){ // No flash
	
		if (resourceType == 0){
			errorText = "<div class='content noFontResize'><div id='noFlashFrame'><p>The <b>Adobe Flash player</b> v10 or higher is required to view this content.</p><p>You can download the latest version here:</p><center> <a href='http://www.adobe.com/go/getflashplayer' target='_blank' title='Get Adobe Flash player'><img src='/interface/images/buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a></center></div></div>";
		} else {
			errorText = "<div class='content noFontResize'><div id='noFlashFrame'><p>The <b>Adobe Flash player</b> is required to view this content.</p><p>You can download the latest version here:</p><center> <a href='http://www.adobe.com/go/getflashplayer' target='_blank' title='Get Adobe Flash player'><img src='/interface/images/buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a></center></div></div>";
		}
		
		$("#left_frame").html(errorText);
		$("#BLHSC a.view_full_size").css("visibility","hidden");
	} else if (version < 10 && resourceType == 0){ //Version too old
	
		errorText = "<div class='content noFontResize'><div id='noFlashFrame'><p>Your current version of <b>Adobe Flash player</b> is " + fullVersion + "</p><p>The <b>Adobe Flash player</b> v10 or higher is required to view this content.</p><p>You can download the latest version here:</p><center> <a href='http://www.adobe.com/go/getflashplayer' target='_blank' title='Get Adobe Flash player'><img src='/interface/images/buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a></center></div></div>";
	
		$("#left_frame").html(errorText);
		$("#BLHSC a.view_full_size").css("visibility","hidden");
		
	}
	
}

/* VERSION B */
function getAsoIframeJs (iframeAsoUrl) {
	
	titleResource = $("#TLHSC h1").text();
	
	
	if (jQuery.browser.msie && jQuery.browser.version == "6.0" ) {
				popupContent = '<table id="global_popup_BG"><tr><td><!--KEEP FULL--></td></tr></table><div class="menu"><table cellpadding="0" cellspacing="0"><tr><td class="print_cell" align="center" /><td class="title"><h1>' + titleResource + '</h1></td><td class="close_cell" align="center"><a href="/peacemakers/tuning_in/babe_make_them_feel_inferior.html" class="global_popup close" title="Close"><!--KEEP FULL--></a></td></tr></table></div><table width="100%" height="100%" style="position: absolute; z-index:1650;"><tr><td><div id="aso_alert">Click on image to play movie. Double click for full screen. The other links in frame are not used in World of Values activities.</div><div class="content" id="aso_content"><div class="inner  container_resources"><iframe src="' + iframeAsoUrl + '#download-butt"/></div></div></td></tr></table>';
		} 	
	else if (jQuery.browser.msie && jQuery.browser.version == "7.0" ) {
				popupContent = '<table id="global_popup_BG"><tr><td><!--KEEP FULL--></td></tr></table><div class="menu"><table cellpadding="0" cellspacing="0"><tr><td class="print_cell" align="center" /><td class="title"><h1>' + titleResource + '</h1></td><td class="close_cell" align="center"><a href="/peacemakers/tuning_in/babe_make_them_feel_inferior.html" class="global_popup close" title="Close"><!--KEEP FULL--></a></td></tr></table></div><table width="100%" height="100%" style="position: absolute; z-index:1650;"><tr><td><div id="aso_alert">Click on image to play movie. Double click for full screen. The other links in frame are not used in World of Values activities.</div><div class="content" id="aso_content"><div class="inner  container_resources"><iframe frameborder="0" border="0" src="' + iframeAsoUrl + '#player"/></div></div></td></tr></table>';
		} else {
				popupContent = '<table id="global_popup_BG"><tr><td><!--KEEP FULL--></td></tr></table><div class="menu"><table cellpadding="0" cellspacing="0"><tr><td class="print_cell" align="center" /><td class="title"><h1>' + titleResource + '</h1></td><td class="close_cell" align="center"><a href="/peacemakers/tuning_in/babe_make_them_feel_inferior.html" class="global_popup close" title="Close"><!--KEEP FULL--></a></td></tr></table></div><table width="100%" height="100%" style="position: absolute; z-index:1650;"><tr><td><div id="aso_alert">Click on image to play movie. Double click for full screen. The other links in frame are not used in World of Values activities.</div><div class="content" id="aso_content"><div class="inner  container_resources"><iframe src="' + iframeAsoUrl + '#content"/></div></div></td></tr></table>';
		
		}
		
		return popupContent;	
	
	}
 
