
function hideFlash(element) {element.css("visibility", "hidden");}
function showFlash(element) {element.css("visibility", "visible");}

function showOverlay() {	
	$("#overlay").css({"left": 0});					
	// Set opacities to 0
	$("#background").animate({opacity:0}, 0);		
	$("#overlaypanel").animate({opacity:0}, 0);
	// Show the overlay.
	$("#overlay").show(); 		
	$("#background").show();	
	$("#overlaypanel").show();				
	// Fade in background
	$("#background").animate({opacity:0.8}, 1000);			
	// Face up the panel 	
	$("#overlaypanel").animate({opacity:1}, 1000, "linear", function() {
		if ($(this).hasClass("ie")) {			
			$("#overlaypanel").css("filter", "");			
		}
	});		
	// Hide flash
	hideFlash($('#risk-o-meter-flash'));
	hideFlash($('#mindreaderflash'));
	hideFlash($('#sextalkvideo'));
	hideFlash($('#quiz-flash'));
	hideFlash($('#party-flash'));
	$('#tongue-tied select').hide(); // And select
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7 && parseInt(jQuery.browser.version) > 4) {			
		$('body').supersleight();
	}
	if(!$("#overlay").hasClass("beer-goggles")) {
		$('#backdrop').remove();
		$(".goggle-intro").remove();
	}
}


function hideOverlay() {				
	$("#overlaypanel").animate({opacity:0}, 1000);		
	$("#background").animate({opacity:0}, 1000, "linear", function() { 				
		// Hide everything
		$("#overlay").hide(); 		
		$("#background").hide();	
		$("#overlaypanel").hide();	
		// Clear overlay panel content.
		$("#overlaypanelcontent").html('');			
		$("#overlaypanelcontent").attr('class', '');
		$("#overlaypanelflash").remove();	
		$("#overlay .inner2").append('<div id="overlaypanelflash"></div>');	
		// Remove background (when beer googles)
		if($("#overlay").hasClass("beer-goggles")) {$("#backdrop").remove();};
		// Reset the class attr 
		$("#overlay").attr('class', '');			
		// Show previously hidden elements
		showFlash($('#risk-o-meter-flash'));			
		showFlash($('#mindreaderflash'));
		showFlash($('#sextalkvideo'));
		showFlash($('#quiz-flash'));
		showFlash($('#party-flash'));
		$('#tongue-tied select').show();
		if ($('#tracking-frame')) $('#tracking-frame').remove();
	});	
}

$(document).ready(function() {
	// Transform panel to a "link"
	$(".panel").each(function(e) {		
		if(!$(this).hasClass("nohover")) {			
			$(this).mouseover(function() { $(this).addClass("active"); });			
			$(this).mouseout(function() { $(this).removeClass("active"); });										
			if($(this).attr("id") != "STI-quick-links" && $(this).attr("id") != "service-finder" && !$(this).hasClass("nolink")) {															
				$(this).click(function(){																										
					window.location = $(this).children(".wrapper").children("p").children("a").attr("href"); 
					return false; 			
				});		
			}
		}
	});
	
	// Input box focus and blur event handlers
	$("form#search fieldset label.text input").each(function(el){			
		$(this).focus(function() {
			if($(this).val() == 'Search for any topic') {
				$(this).val('');
			}					
		});
		$(this).blur(function() {
			if($(this).val() =='') {
				$(this).val('Search for any topic');
			}				
		});					
	});
	
	// Panel button rounded corners{	
	$("p.button").each(function(i) {		
		$(this).append('<span class="tl"></span>');
		$(this).append('<span class="bl"></span>');				
		$(this).append('<span class="tr"></span>');
		$(this).append('<span class="br"></span>');	
	});
			
	// When background is clicked.
	$("#background").click(function() { hideOverlay(); });	
		
	// When the symptom-o-tron is clicked.
	var player;
	$("#symptom-o-tron").click(function() {		
		function alertStatus(e) {			
			player = e.ref;		 			
			player.currentLevel = 0;						
			showOverlay();   			
			if(pageTracker) { pageTracker._trackEvent('symptomotron', 'clicklink'); }
		}	
		$("#overlay").attr("class", "symptom");
		$("#overlaypanelcontent").append('<a href="#" class="back" style="z-index:100;"><span>Back</span></a>');	
		$("#overlaypanelcontent").append('<img height="1" width="1" src="http://view.atdmt.com/action/mscshe_SymptomoTron_1"/>');	
		$("#overlaypanelcontent a.back").click(function() { hideOverlay(); });
		swfobject.embedSWF("/release/video/Symptomotron.swf", "overlaypanelflash", "540", "540", "9.0.0", "expressInstall.swf", null, {wmode:"transparent"}, null, alertStatus);							
		return false;
	});		
	
	// Flashing Light...	
	swfobject.embedSWF("/release/video/panic-button.swf", "panic-light", "50", "50", "9.0.0", "expressInstall.swf", null, {wmode:"transparent"}, null);							
			
	// PNG FIX
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7 && parseInt(jQuery.browser.version) > 4) {			
		$('body').supersleight();			
		$("#overlaypanel").addClass("ie");	
	}

	$("p.button a").each(function(el){
		if($(this).attr('href')=="http://www.healthscotland.com/uploads/documents/10077-LARC_Leaflet.pdf") {
		
			$(this).click(function(ev){
				$(this).parent().append('<img height="1" width="1" src="http://view.atdmt.com/action/mschlt_LLRCDownloadleaflet_1"/>');
				window.location("http://www.healthscotland.com/uploads/documents/10077-LARC_Leaflet.pdf");
				return false;
			});
		}
	});
});

// Symptom-o-tron Event tracking callbacks
function symptomotronGenderChoice(gender) {	if(pageTracker) { pageTracker._trackEvent('symptomotron', gender); }	}
function symptomotronSymptomChoice(gender, symptom) {	if(pageTracker) { pageTracker._trackEvent('symptomotron', gender, symptom); }}
function symptomotronLinkChoice(gender, symptom, link) {if(pageTracker) { pageTracker._trackEvent('symptomotron', gender, symptom, link); }	}


