/****/

var depth0;
var depth1;
var depth2;
var depth3;
var depth4;
var depth5;

var mindreaderindex;
readerVid = ["Mindreader0.swf", "Mindreader1.swf", "Mindreader2.swf", "Mindreader3.swf"];	

/****/

function addPeople(where) {			
	// Clear the backdrop
	$("#backdrop").html('');	
	$("#backdrop").attr("class", where);
	
	switch(where) {
		case "pub":			
			$("#backdrop").append(	'<div class="depth0 person" id="shoots-and-leaves"><span></span></div>' + 
									'<div class="depth0 person" id="underage"><span></span></div>' +
									'<div class="depth1 person" id="one-night-stand"><span></span></div>' +
									'<div class="depth2 person" id="violent"><span></span></div>' +
									'<div class="depth2 person" id="married"><span></span></div>' +
									'<div class="depth3 person" id="herpes"><span></span></div>' +
									'<div class="depth4 person" id="mr-right"><span></span></div>' +
									'<div class="depth0 person" id="stag"><span></span></div>' +
									'<div class="depth5 person" id="miss-right"><span></span></div>'); // These need to be depth sorted.
										
			$("#backdrop").append(	'<div class="notice depth0" id="notice-shoots-and-leaves">' +
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' + 
											'<h3>Shoots and Leaves</h3>' +										
											'<p>He&rsquo;s a wee monkey after one thing but you <a href="/relationships/choices/">want a relationship</a> ...</p>' +
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth0" id="notice-stag">' +
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' + 
											'<h3>Stag</h3>' +										
											'<p>Oh dear, really not the right partner for you. Try again.</p>' +
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth0" id="notice-underage">' +
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +
											'<h3>Under Age</h3>' +
											'<p>Booze impairs your ability to make <a href="/relationships/choices/">good choices</a>.</p>' +																				
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth1" id="notice-one-night-stand">' +
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +
											'<h3>One Night Stand</h3>' +
											'<p>Watch out for the horny devil. Is naff, drunken sex <a href="/talk-sex/why-talk-about-sex/what-you-want/">what you really want</a>?</p>' +										
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth2" id="notice-violent">' + 
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +
											'<h3>Violent</h3>' +										
											'<p>Booze makes you worry less about personal safety.</p>' +
										'</div>' +
									'</div>' + 
									
									'<div class="notice depth2" id="notice-married">' +
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +
											'<h3>Married</h3>' +
											'<p>No ring so who knew? Trouble ahead.</p>' +										
										'</div>' +
									'</div>' + 
									
									'<div class="notice depth3" id="notice-herpes">' +
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +
											'<h3>Herpes</h3>' +
											'<p>Many people are infected without knowing it – <a href="/the-clinic/do-i-need-a-test/">do you need a test</a>?</p>' +										
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth4" id="notice-mr-right">' +
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +
											'<h3>Mr Right</h3>' +
											'<p>Despite the dodgy do, he&rsquo;s the only one for you. So when should <a href="/talk-sex/talking-about/testing/">you talk about testing</a>?</p>' +										
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth5" id="notice-miss-right">' +								
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +
											'<h3>Miss Right</h3>' +
											'<p>She could be &lsquo;the one&rsquo;. But how do you <a href="/talk-sex/talking-about/using-protection/">talk about protection</a>?</p>' +										
										'</div>' + 
									'</div>'							
								);			
									
			break;
			
		case "bbq":
			$("#backdrop").append(	'<div class="depth0 person" id="person4"><span></span></div>' + 
									'<div class="depth0 person" id="person5"><span></span></div>' + 									
									'<div class="depth1 person" id="person3"><span></span></div>' + 									
									'<div class="depth1 person" id="person7"><span></span></div>' + 
									'<div class="depth2 person" id="person2"><span></span></div>' + 
									'<div class="depth3 person" id="person1"><span></span></div>' + 
									'<div class="depth4 person" id="person6"><span></span></div>' + 
									'<div class="depth5 person" id="person8"><span></span></div>'
								);
									
			$("#backdrop").append(	'<div class="notice depth3" id="notice-person1">' + 
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +
											'<h3>Life Partner?</h3>' +										
											'<p>Alcohol increases desire but are you two <a href="/relationships/ready-for-sex/">really ready for sex?</a></p>' +
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth2" id="notice-person2">' +
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +
											'<h3>Lives with Mum</h3>' +										
											'<p>Can&rsquo;t cook, can&rsquo;t clean, never used a washing machine.</p>' +
										'</div>' +
									'</div>' + 
									
									'<div class="notice depth1" id="notice-person3">' +
										'<div class="inner-1"></div>' +									
										'<div class="inner-2">' +									
											'<h3>HIV Positive</h3>' +
											'<p>Many people are infected without knowing it &ndash; <a href="/the-clinic/do-i-need-a-test/">do you need a test?</a></p>' +
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth0" id="notice-person4">' +
										'<div class="inner-1"></div>' +									
										'<div class="inner-2">' +									
											'<h3>Gnome</h3>' +
											'<p>A little short for you don&rsquo;t you think?</p>' +										
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth0" id="notice-person5">' + 
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +									
											'<h3>Chlamydia</h3>'+
											'<p>Not everyone has noticable symptoms &ndash; <a href="/the-clinic/do-i-need-a-test/">do you need a test?</a> ...</p>' +
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth4" id="notice-person6">' + 
										'<div class="inner-1"></div>' +								
										'<div class="inner-2">' +									
											'<h3>Condom Hater</h3>' + 
											'<p>There&lsquo;s more to safer sex than condoms - <a href="/better-sex/safer-sex-alternatives/">find safer sex alternatives</a></p>' +						
										'</div>' +
									'</div>' + 
									
									'<div class="notice depth1" id="notice-person7">' + 
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +									
											'<h3>Miss Right</h3>' +										
											'<p>She&rsquo;s the only one for you. So when should you <a href="/talk-sex/talking-about/testing/">talk about testing?</a></p>' +
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth5" id="notice-person8">' + 
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +									
											'<h3>One Night Stand</h3>' +										
											'<p>Is naff, drunken sex <a href="/talk-sex/why-talk-about-sex/what-you-want/">what you really want?</a></p>' +
										'</div>' +
									'</div>'									
								);
								
			break;
			
		case "houseparty":
			$("#backdrop").append(	'<div class="depth0 person" id="person1-hp"><span></span></div>' + 																		
									'<div class="depth2 person" id="person4-hp"><span></span></div>' + 
									'<div class="depth3 person" id="person5-hp"><span></span></div>' +					
									'<div class="depth4 person" id="person3-hp"><span></span></div>' + 									
									'<div class="depth5 person" id="person2-hp"><span></span></div>' + 
									'<div class="depth5 person" id="person6-hp"><span></span></div>'
								);
								
			$("#backdrop").append(	'<div class="notice depth0" id="notice-person1-hp">' + 
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +									
											'<h3>Chlamydia</h3>' +										
											'<p>Many people are infected without knowing it &ndash; <a href="/the-clinic/do-i-need-a-test/">do you need a test?</a> ...</p>' +
										'</div>' +
									'</div>' + 
									
									'<div class="notice depth5" id="notice-person2-hp">' + 
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +									
											'<h3>Shoots and Leaves</h3>' +										
											'<p>After one thing but you <a href="/relationships/choices/">want a relationship</a> ...</p>' +
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth4" id="notice-person3-hp">' + 
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +									
											'<h3>HIV Positive</h3>' +										
											'<p>If you get drunk, will you still be able to <a href="/better-sex/alcohol-and-drugs/">use a condom?</a> ...</p>' +
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth2" id="notice-person4-hp">' + 
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +									
											'<h3>Life Partner?</h3>' +										
											'<p>Alcohol increases desire but are you two really <a href="/relationships/ready-for-sex/">ready for sex?</a> ...</p>' +
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth3" id="notice-person5-hp">' +
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +									
											'<h3>Trainspotter</h3>' +										
											'<p>One-topic talker &ndash; yawn.</p>' +
										'</div>' + 
									'</div>' + 
									
									'<div class="notice depth5" id="notice-person6-hp">' +
										'<div class="inner-1"></div>' +
										'<div class="inner-2">' +									
											'<h3>Herpes</h3>' +										
											'<p>Not everyone has noticable symptoms &ndash; <a href="/the-clinic/do-i-need-a-test/">do you need a test?</a> ...</p>' +
										'</div>' + 
									'</div>'																		
								);					
			break;
	}	
	
	$("div.notice").hide();
	
	// Get collections of elements depths
	depth0 = $(".depth0");
	depth1 = $(".depth1");
	depth2 = $(".depth2");
	depth3 = $(".depth3");
	depth4 = $(".depth4");
	depth5 = $(".depth5");
			
	// Person hover event handler
	$(".person").hover(
		function() {
			$(this).addClass("hover");
			showNotice($(this).attr("id"));
		},
		function() {
			$(this).removeClass("hover");
		}
	);
		
	// Event tracking.
	$("div.notice a").click(function() { if(pageTracker) { pageTracker._trackPageview("/gadgets/beergoggles/" + where + $(this).attr("href")); }});
		
	// Apply pngfix on new elements
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7 && parseInt(jQuery.browser.version) > 4) {	$('body').supersleight();}
}


function initGoggles(tracking){
		// Set the class
		$("#overlay").attr("class", "beer-goggles");

		// Add overlay panel content
		$("#overlaypanelcontent").html(	'<div class="inner-1"></div>' + 
										'<div class="inner-2">' + 
											
											'<div class="inner goggle-intro">' +
												'<img src="/release/images/assets/beer-goggles.png"/>' +
												'<h2>Super Beer Goggles</h2>' +		
												'<p>Many of us enjoy drinking with our partners or even first meet them at parties or nights out.</p>' +
												'<p>But alcohol clouds judgement and traditional \'beer goggles\' make things appear better than they really are.</p>' +
												'<p>Try our new Super Beer Goggles and find out the things you can\'t tell at a glance.' +		
												'<p><a href="#" class="to-the-pub">To the pub-club</a></p>' +																								
												'<p><a href="#" class="to-the-bbq">To the BBQ</a></p>' +
												'<p><a href="#" class="to-the-houseparty">To the house party</a></p>' +
												'<p><a href="#" class="back"><span>Back to home</span></a></p>' +
											'</div>' +
										'</div>'
									);
		
		$("#overlaypanelcontent a.back").click(function() { window.onscroll = null; hideOverlay(); });
					
		// To the house party				
		$(".to-the-houseparty").click(function(){
			$("#overlay").attr("class", "beer-goggles houseparty");
			addPeople("houseparty");				
			if(pageTracker) { pageTracker._trackPageview('/gadgets/beergoggles/houseparty');}
			return false;
		});
		
		// To the barbeque
		$(".to-the-bbq").click(function(){
			$("#overlay").attr("class", "beer-goggles bbq");
			addPeople("bbq");			
			if(pageTracker) { pageTracker._trackPageview('/gadgets/beergoggles/bbq');}
			return false;
		});
		
		// To the pub
		$(".to-the-pub").click(function(){
			$("#overlay").attr("class", "beer-goggles pub");	
			addPeople("pub");			
			if(pageTracker) { pageTracker._trackPageview('/gadgets/beergoggles/pub');}
			return false;
		});

		// Add the backdrop div	
		$("#overlay .inner2").prepend('<div id="backdrop"></div>');				
		var backdrop = $("#overlaypanel #backdrop");								
		
		// Add the people
		addPeople("pub");
		
		// Current X position.
		var xPos = 0;					
								
		// Mouse move event handler
		if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7 && parseInt(jQuery.browser.version) > 4) {		
			var i = 0;
			$("#overlaypanel").mousemove(function(e){
				var xMousePos = e.clientX - this.offsetLeft;													
				if(xMousePos > 227) {
					xPos =  -(xMousePos - 227) * (1520 / 775);
					backdrop.css("left", xPos + "px"); i++;					
					if(i > 5) {
						i=0;																							
						var depthFactor = -((xMousePos + 30) / 514 - 0.5);							
						depth1.css("margin-left", Math.round(depthFactor * 50) + "px");						
						depth2.css("margin-left", Math.round(depthFactor * 100) + "px");						
						depth3.css("margin-left", Math.round(depthFactor * 200) + "px");						
						depth4.css("margin-left", Math.round(depthFactor * 250) + "px");						
						depth5.css("margin-left", Math.round(depthFactor * 300) + "px");																														
					}
				}						
			});					
		} else {
			$("#overlaypanel").mousemove(function(e){
				var xMousePos = e.clientX - this.offsetLeft;
				if(xMousePos > 227) {
					xPos =  -(xMousePos - 227) * (1520 / 775);
					backdrop.css("left", xPos + "px");						
					var depthFactor = -((xMousePos + 30) / 514 - 0.5);							
					depth1.css("margin-left", Math.round(depthFactor * 50) + "px");						
					depth2.css("margin-left", Math.round(depthFactor * 100) + "px");						
					depth3.css("margin-left", Math.round(depthFactor * 200) + "px");						
					depth4.css("margin-left", Math.round(depthFactor * 250) + "px");						
					depth5.css("margin-left", Math.round(depthFactor * 300) + "px");																														
				}						
			});			
		}		

		// Event tracking.
		if(pageTracker && tracking) { pageTracker._trackPageview('/gadgets/beergoggles'); }
				
		// Frame resize handler			
		window.onscroll = function() { 
			if($("#overlay").hasClass("beer-goggles")) {
				$("#overlaypanel").css('top', (100 + getScrollXY()[1]) + "px");
			}
		}
		$("#overlaypanel").css('top', (100 + getScrollXY()[1]) + "px");
}		

/****/

function showNotice(id) {
	var notice = $("#notice-" + id);		
	$(".notice").hide();									
	notice.show();			
}

/****/

function readMoreMinds() {			
	$("#mindreaderflash").after('<div id="temp-mindreaderflash"></div>');
	$("#mindreaderflash").remove();	
	$("#temp-mindreaderflash").attr('id', 'mindreaderflash');
	do { random = Math.floor(Math.random() * 4);
	} while(random == mindreaderindex)
	swfobject.embedSWF("/release/video/" +	readerVid[random], "mindreaderflash", "310", "226", "9.0.0", "expressInstall.swf", {}, {wmode:"transparent"});							
}

/****/

var player;

function getScrollXY() {
  var scrOfX = 0;
  var scrOfY = 0;
  if(typeof(window.pageYOffset) == 'number') {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [scrOfX, scrOfY];
}
/****/

flash_install = '/release/includes/flash/expressInstall.swf';

$(document).ready(function() {
	
	//embed the quiz
	swfobject.embedSWF("/release/includes/flash/quiz.swf", "quiz-flash", "300", "190", "9.0.0",flash_install);

	
	// Embed the homepage video player.
	var params = {
		'allowscriptaccess':'always',
		'allowfullscreen':'true'
	}
	var flashvars = {
		'file':'/release/video/contraceptive-advice.flv',
		'frontcolor':'EFEFEF',
		'lightcolor':'353236',
		'skin':'/release/video/overlay.swf',
		'autohide':'true',
		'icons':'true',
		'image':'/release/images/assets/homepage-flash-placeholder.jpg',
		'controlbar':'over',
		'autostart':'false',
		'mute':'false',
		'shuffle' : 'true',
		'plugins':'gapro-1',
		'gapro.accountid' : 'UA-9037691-1',
		'gapro.trackstarts':'true',
		'gapro.trackpercentage' : 'true',
		'gapro.tracktime':'true'
	}
	
	swfobject.embedSWF("/release/video/player.swf", "sextalkvideo", 290, 163, "9.0.0", flash_install, flashvars, params);

	// Embed the homepage video player. (SANDBOX)
	var params = {
		'allowscriptaccess':'always',
		'allowfullscreen':'true'
	}
	var flashvars = {
		'file':'/release/includes/flash/playlist.xml',
		'frontcolor':'EFEFEF',
		'lightcolor':'353236',
		'skin':'/release/includes/flash/overlay.swf',
		'autohide':'true',
		'icons':'true',
		'image':'/release/images/assets/homepage-flash-placeholder.jpg',
		'controlbar':'over',
		'autostart':'false',
		'plugins':'gapro-1',
		'gapro.accountid' : 'UA-9037691-1',
		'gapro.trackstarts':'true',
		'gapro.trackpercentage' : 'true',
		'gapro.tracktime':'true'
	}
	swfobject.embedSWF("/release/includes/flash/player.swf", "sextalkvideo-sandbox", 290, 163, "9.0.0", flash_install, flashvars, params);
	
	// Embed the risk-o-meter
	swfobject.embedSWF("/release/video/Risk-O-Meter-home.swf", "risk-o-meter-flash", "135", "100", "9.0.0", "expressInstall.swf", {}, {wmode:"transparent"});					
	
	// Home page mind reader (at random?)	
	random = Math.floor(Math.random() * 4);
	mindreaderindex = random;
	swfobject.embedSWF("/release/video/" +	readerVid[random], "mindreaderflash", "310", "226", "9.0.0", "expressInstall.swf", {}, {wmode:"transparent"});							
	
	// When risk-o-meter link is clicked.
	$("#risk-o-meter a").click(function() {
		function alertStatus(e) {			
			player = e.ref;		 			
			player.currentLevel = 0;
			player.setCurrentLevel = function(level) {								
				if(level != this.currentLevel) {
					this.currentLevel = level;
					this.setLevel(level); 			
				}
			}
			if(pageTracker) { pageTracker._trackPageview('/gadgets/riskometer'); }
			showOverlay();	 			
			return false;
		}
		
		$("#overlay").attr("class", "risks");
								
		$("#overlaypanelcontent").append('<a href="#" class="back"><span>Back to home</span></a>');		
		$("#overlaypanelcontent a.back").click(function() { hideOverlay(); });
		
		$("#overlaypanelcontent").append('<form><select id="riskselect"></select></form>')				
		$("#riskselect").append('<option class="riskometer">How risky is:</option>');
		$("#riskselect").append('<option class="analsex">Anal sex</option>');
		$("#riskselect").append('<option class="cybersex">Cyber sex</option>');
		$("#riskselect").append('<option class="burstcondom">Burst Condom</option>');
		$("#riskselect").append('<option class="groupsex">Group sex</option>');
		$("#riskselect").append('<option class="masturbation">Masturbation</option>');
		$("#riskselect").append('<option class="oralsex">Oral sex</option>');
		$("#riskselect").append('<option class="phonesex">Phone sex</option>');
		$("#riskselect").append('<option class="sextoys">Sex toys</option>');
		$("#riskselect").append('<option class="vaginalsex">Vaginal sex</option>');
		
		$("select").change(function() {
			if(pageTracker) {pageTracker._trackPageview('/gadgets/riskometer/'+$(this).find(':selected').attr("class"));}
			
			switch($(this).find(':selected').attr("class")) {
				case "riskometer":
					$("#overlay div.copy").html(initialcopy);			
					player.setCurrentLevel(0); 		
					break;
				
				case "cybersex":
					$("#overlay div.copy").html(cybersexcopy);
					player.setCurrentLevel(1); 			
					break;
				
				case "analsex":
					$("#overlay div.copy").html(analsexcopy);
					player.setCurrentLevel(3); 			
					break;	
					
				case "burstcondom":
					$("#overlay div.copy").html(burstcondomcopy);
					player.setCurrentLevel(3); 			
					break;	
					
				case "groupsex":
					$("#overlay div.copy").html(groupsexcopy);
					player.setCurrentLevel(3);		
					break;
					
				case "masturbation":
					$("#overlay div.copy").html(masturbationcopy);
					player.setCurrentLevel(2);	
					break;	
										
				case "oralsex":
					$("#overlay div.copy").html(oralsexcopy);
					player.setCurrentLevel(2);	
					break;
		
				case "phonesex":
					$("#overlay div.copy").html(phonesexcopy);
					player.setCurrentLevel(2);	
					break;
		
				case "sextoys":
					$("#overlay div.copy").html(sextoyscopy);
					player.setCurrentLevel(2);	
					break;
					
				case "vaginalsex":
					$("#overlay div.copy").html(vaginalsexcopy);
					player.setCurrentLevel(3);	
					break;	
			}			
					
		});
								
		var initialcopy =	'<h2>Risk-O-Meter</h2>' + 
							'<p>Learn the risks of sexual behaviours and mishaps, and how to reduce them.</p>';
		
		var cybersexcopy = 	'<h2>Cyber sex is <span class="low">low risk</span></h2>' +
							'<p>As there is no physical contact during cyber sex (also called \'virtual sex\' or \'online sex\') there is no risk of sexually transmitted infections to either partner.</p>' +
							'<p class="small">However, there are other risks:</p>' +
							'<ul>' +
							'<li>someone may make your sexually explicit posts, pictures, chat or video public</li>' +
							'<li>your real life relationships could be put in jeopardy if you\'re \'cybering\' with someone other than your regular partner</li>' +
							'<li>sexual predators could use online information to find you in the real world</li>' +
							'</ul>' +
							'<p class="small">Find out more about <a href="/better-sex/a-z-of-sex/cyber-sex/">safer cyber sex</a>.</p>';							
							
		var burstcondomcopy =	'<h2>A burst condom is <span class="high">high risk</span></h2>' +
								'<p>A burst condom puts both partners at risk of sexually transmitted infections. Women having sex with men also risk pregnancy if a condom bursts.</p>' +
								'<p class="small">Reducing the risk of a condom burst:</p>'+				
								'<ul>' +
								'<li>make sure it\'s properly unrolled</li>' +
								'<li>squeeze the air out of the \'teat\' before putting it on</li>' +
								'<li>keep your fingernails short and smooth</li>' +
								'<li>use extra lube suitable for use with condoms</li>' +
								'<li>never use oils, oil-based lubricants, or oily foodstuffs during sex.</li>' +
								'</ul>' +			 
								'<p class="small">Find out more about <a href="/better-sex/protection/">safer condom usage</a>.</p>';
								
		var analsexcopy =	'<h2>Anal sex is <span class="high">high risk</span></h2>' +
							'<p>Having unprotected anal sex, whether you\'re a man or a woman, is a HIGH RISK activity for almost every sexually transmitted infection.</p>' +
							'<p class="small">You can reduce the risks of anal sex if you:</p>'+				
							'<ul>' +
							'<li>always use a condom</li>' +
							'<li>use extra lubrication</li>' +
							'<li>never share anal toys without a fresh condom</li>' +
							'<li>don\'t touch your face, genitals or any cuts or wounds before washing your hands.</li>' +
							'</ul>' +			 
							'<p class="small">Find out more about <a href="/better-sex/a-z-of-sex/anal-sex/">safer anal sex</a>.</p>' +
							'<p class="small">If you\'ve had unprotected anal sex, you should <a href="/the-clinic/do-i-need-a-test/">consider getting tested</a>.</p>';
				
		var groupsexcopy =	'<h2>Group sex is <span class="high">high risk</span></h2>' +
							'<p>Having sex with lots of partners increases the risk of catching a sexually transmitted infection.</p>' +
							'<p>Group sex will always be risky.</p>' +
							'<p class="small">You can reduce the risks if everyone:</p>'+
							'<ul>' +
							'<li>always uses a condom</li>' +
							'<li>gets tested regularly</li>' +
							'<li>never shares toys without a fresh condom.</li>' +
							'</ul>' +			 
							'<p class="small">Find out more about <a href="/better-sex/a-z-of-sex/group-sex/">safer group sex</a>.</p>';
							
		var masturbationcopy =	'<h2>Masturbation is <span class="medium">medium risk</span></h2>' +
								'<p> When practised between partners, masturbation is a medium risk activity, but is a <strong>no-risk</strong> activity if you do it alone.</p>' +
								'<p>Reducing the risks from masturbation</p>' +
								'<p class="small">If you masturbate by touching or being touched by a partner:</p>'+
								'<ul>' +
								'<li>wash your hands before and after with soap</li>' +
								'<li>be careful not to spill any semen or vaginal fluids</li>' +
								'<li>use plenty of condom-friendly lubrication</li>' +
								'<li>avoid touching the eyes, mouth, nose or any broken skin.</li>' +
								'</ul>' +		
								'<p class="small">Find out more about <a href="/better-sex/a-z-of-sex/masturbation/">safer masturbation</a>.</p>';
	
		var oralsexcopy =	'<h2>Oral sex is <span class="medium">medium risk</span></h2>' +
							'<p>Most sexually transmitted infections can be passed on through unprotected oral sex. It can be <strong>medium risk</strong> if you practise safer oral sex.</p>' +
							'<p>Reducing the risks from oral sex</p>' +
							'<p class="small">The risks from oral sex can be reduced if you:</p>'+
							'<ul>' +
							'<li>always use a fresh condom or dental dam</li>' +
							'<li>change the dam or condom if in use for a long time</li>' +
							'<li>refrain from oral sex if there are any signs of infection or</li>' +
							'<li>refrain from oral sex if the person giving it has any cuts or sores in their mouth.</li>' +
							'</ul>' +		
							'<p class="small">Find out more about <a href="/better-sex/a-z-of-sex/oral-sex/">safer oral sex</a>.</p>';
	
		var phonesexcopy =	'<h2>Phone sex is <span class="medium">medium risk</span></h2>' +
							'<p>As there is no physical contact during phone sex (also called \'virtual sex\' or \'online sex\') there is no risk of sexually transmitted infections to either partner.</p>' +
							'<p class="small">However, there are other risks:</p>'+
							'<ul>' +
							'<li>someone may make your sexually explicit chat, pictures or video public</li>' +
							'<li>your real life relationships could be put in jeopardy if you have phone sex with someone other than your regular partner</li>' +
							'<li>sexual predators could use information from your sex chat to find you in the real world.</li>' +
							'</ul>' +		
							'<p class="small">Find out more about <a href="/better-sex/a-z-of-sex/phone-sex/">safer phone sex</a>.</p>';
	
		var sextoyscopy =	'<h2>Using sex toys is <span class="medium">medium risk</span></h2>' +
							'<p>Using sex toys is a <strong>medium-risk</strong> activity for most sexually transmitted infections if you share them with a partner. There\'s <strong>no risk</strong> if you use them alone.</p>' +
							'<p>Reducing the risks from using sex toys</p>'+
							'<p class="small">The health risks from using sex toys can be reduced if you:</p>'+
							'<ul>' +
							'<li>always cover the toy with a fresh condom before use</li>' +
							'<li>change condoms before swapping toys with a partner</li>' +
							'<li>use plenty of condom-friendly lubrication</li>' +
							'<li>only use well-made toys displaying the European safety CE mark</li>' +
							'</ul>' +		
							'<p class="small">Find out more about <a href="/better-sex/a-z-of-sex/toys/">sex toys</a>.</p>';
	
		var vaginalsexcopy =	'<h2>Vaginal sex is <span class="high">high risk</span></h2>' +
								'<p>Having unprotected vaginal sex carries a HIGH-RISK for both partners for most sexually transmitted infections.</p>' +
								'<p>Reducing the risks from vaginal sex</p>'+
								'<ul>' +
								'<li>always use a condom</li>' +
								'<li>use lots of condom-safe lubrication</li>' +
								'<li>change condoms before switching to oral or anal sex	</li>' +
								'</ul>' +		
								'<p class="small">Find out more about <a href="/better-sex/a-z-of-sex/vaginal-sex/">safer vaginal sex</a>.</p>';

		$("#overlaypanelcontent").append('<div class="copy"></div>');						
		$("#overlaypanelcontent div.copy").html(initialcopy);
						
		swfobject.embedSWF("/release/video/Risk-O-Meter.swf", "overlaypanelflash", "300", "300", "9.0.0", "expressInstall.swf", null, {wmode:"transparent"}, null, alertStatus);					
										
		return false;
	});
	
	// When your-body is clicked.
	$("#your-body").click(function() {
	  if(pageTracker) { pageTracker._trackPageview('/gadgets/yourbody');}
		$("#overlay").attr("class", "yourbody");
				
		$("#overlaypanelcontent").append('<a href="#" class="back"><span>Back to home</span></a>');		
		$("#overlaypanelcontent").append('<img height="1" width="1" src="http://view.atdmt.com/action/mscshe_Yourbody_1"/>');		
		$("#overlaypanelcontent a.back").click(function() { hideOverlay(); });
				
		$("#overlaypanelcontent").append('<h2>Your body</h2>');		
		$("#overlaypanelcontent").append('<p class="choose">Choose your body</a>');		
		$("#overlaypanelcontent").append('<a href="#" class="choice female"></a>');		
		$("#overlaypanelcontent").append('<a href="#" class="choice male"></a>');		
		
		$("#overlaypanelcontent").append('<a href="#" class="hotspot" id="brain"></a>');	
		$("#overlaypanelcontent").append('<a href="#" class="hotspot" id="eyes"></a>');	
		$("#overlaypanelcontent").append('<a href="#" class="hotspot" id="ears"></a>');	
		$("#overlaypanelcontent").append('<a href="#" class="hotspot" id="mouth"></a>');	
		$("#overlaypanelcontent").append('<a href="#" class="hotspot" id="heart"></a>');	
		$("#overlaypanelcontent").append('<a href="#" class="hotspot" id="hands"></a>');	
		$("#overlaypanelcontent").append('<a href="#" class="hotspot" id="reporgans"></a>');
							
		var brain_copy = '<h3>Brain</h3><p>One key to great sex and even better relationships is to know <a href="/talk-sex/why-talk-about-sex/what-you-want/">what you want</a></p>';
		var ears_copy = '<h3>Ears</h3><p>Make yourself popular - listen to <a href="/talk-sex/why-talk-about-sex/what-they-want/">what they want</a></p>';
		var eyes_copy = '<h3>Eyes</h3><p>Eyes are the windows to the soul, but they\'re rubbish at spotting <a href="/the-clinic/">sexually transmitted infections</a></p>';
		var mouth_copy = '<h3>Mouth</h3><p>Sex is better if you <a href="/talk-sex/talking-about/">talk about it first</a></p>';
		var heart_copy = '<h3>Heart</h3><p>What about <a href="/talk-sex/why-talk-about-sex/good-communication/">your feelings?</a></p>';		
		var hands_copy = '<h3>Hands</h3><p>There\'s more than just penetration to <a href="/better-sex/enjoying-sex/">enjoying sex</a></p>';
		var reporgans_copy = '<h3>Reproductive Organs</h3><p>Sex can be fun, but some people still do it to <a href="/making-babies/">make babies!</a></p>';

		$("#overlaypanelcontent").append('<div class="notice brain left"><div class="inner-1"></div><div class="inner-2">' + brain_copy + '</div></div>');		
		$("#overlaypanelcontent").append('<div class="notice eyes right"><div class="inner-1"></div><div class="inner-2">' + eyes_copy + '</div></div>');
		$("#overlaypanelcontent").append('<div class="notice ears left"><div class="inner-1"></div><div class="inner-2">' + ears_copy + '</div></div>');
		$("#overlaypanelcontent").append('<div class="notice mouth right"><div class="inner-1"></div><div class="inner-2">' + mouth_copy + '</div></div>');
		$("#overlaypanelcontent").append('<div class="notice heart left"><div class="inner-1"></div><div class="inner-2">' + heart_copy + '</div></div>');
		$("#overlaypanelcontent").append('<div class="notice hands right"><div class="inner-1"></div><div class="inner-2">' + hands_copy + '</div></div>');
		$("#overlaypanelcontent").append('<div class="notice reporgans left"><div class="inner-1"></div><div class="inner-2">' + reporgans_copy + '</div></div>');
			
		// Event tracking on links.
		$('#overlaypanelcontent div.notice a').click(function() {
			if(pageTracker) { pageTracker._trackPageview("/gadgets/yourbody/" + $("#overlaypanelcontent").attr("class") + $(this).attr("href")); }						
		});
		
		$("#overlaypanelcontent a.choice")
			.click(function() {																												
				$("#overlaypanelcontent a.choice")
					.unbind('mouseover')
					.unbind('mouseout')
					.removeClass("hover");

				$("p.choose").remove();
				
				if($(this).hasClass('female')) {
					// Track (first) choice of gender.
					if(pageTracker) { pageTracker._trackPageview('/gadgets/yourbody/female'); }
					$("#overlaypanelcontent").addClass("female");								
				} else {
					// Track (first) choice of gender.
					if(pageTracker) { pageTracker._trackPageview('/gadgets/yourbody/male'); }
					$("#overlaypanelcontent").addClass("male");								
				}
				
				$("#overlaypanelcontent").append('<a href="#" class="bodythumb"></a>');
				
				$("a.bodythumb").click(function() {				
					if($("#overlaypanelcontent").hasClass('female')) {
						$("#overlaypanelcontent")
							.addClass("male")
							.removeClass("female");								
					} else {					
						$("#overlaypanelcontent")
							.addClass("female")
							.removeClass("male");															
					}
					
					return false;
				});
															
				$('a.hotspot').each(function() {								
					$(this).hover(
						function() {
							var notice = $('div.notice.' + $(this).attr('id'));
							
							if(!notice.hasClass('visible')) {
								$('div.notice.visible').animate({opacity:0}, 500, "linear", function() { $(this).hide(); $(this).removeClass('visible')});
								
								notice																						
									.addClass('visible')
									.animate({opacity:0}, 0)						
									.show()						
									.animate({opacity:1}, 500);
									
								notice.children("div.inner-2").animate({opacity:1}, 500);
							}											
						},
						function() {
						}					
					);
				});							
			})
		.hover(
			function(){
				$(this).addClass("hover");
			},
			function() {							
				$(this).removeClass("hover");				
			});
							
		showOverlay(); 
		
		return false;
	});
	
	/* Load the first scene into the hidden overlay for now */
	//initGoggles(false);
	// Beer Googles is clicked
	$("#beer-goggles").click(function() {
		if(!$("#overlay").hasClass("beer-goggles")) { initGoggles(true); }	
		$("#overlaypanelcontent").append('<img height="1" width="1" src="http://view.atdmt.com/action/mscshe_SuperBeerGoggles_1"/>');	
		function random() {return Math.round(Math.random()*1000)}
		$('body').append('<iframe id="tracking-frame" src="http://fls.uk.doubleclick.net/activityi;src=2572019;type=sexua151;cat=beerg990;ord='+random()+'?" width="1" height="1" frameborder="0"></iframe>');
		showOverlay();
		return false;
	});		
	
	// Auld Wives Tales 	
	var nextExclaim;
	var nextAnswer;
	
	$("#auld-wives-tales p.button a").click(function() {
		if($(this).children('span.text').text() == 'Learn the truth...') {			
			if(pageTracker) { pageTracker._trackEvent('auldwivestales', 'clicklink', 'learnthetruth'); }
			$("#auld-wives-tales div.question").hide();
			$("#auld-wives-tales div.answer").show();
			random = Math.floor(Math.random() * numberOfTales);
			$("#auld-wives-tales div.question p.number").html(wivesTales[random]["number"]);
			$("#auld-wives-tales div.question p.text").html(wivesTales[random]["question"]);
			nextExclaim = wivesTales[random]["exclaim"];
			nextAnswer = wivesTales[random]["answer"];
			$(this).children('span.text').text('More yarns...');			
		} else {			
			if(pageTracker) { pageTracker._trackEvent('auldwivestales', 'clicklink', 'moreyarns'); }
			$("#auld-wives-tales div.question").show();
			$("#auld-wives-tales div.answer").hide();
			$("#auld-wives-tales div.answer p.exclaim").html(nextExclaim);
			$("#auld-wives-tales div.answer p.text").html(nextAnswer);		
			$(this).children('span.text').text('Learn the truth...');			
		}	
					
		return false;	
	});
	
	// Tonguetied Event tracking
	$('a#safer-link').click(function() {if(pageTracker) { pageTracker._trackEvent('freecondoms', 'clicklink');}});
	$('a#do-i-need').click(function() {if(pageTracker) { pageTracker._trackEvent('stihelpbutton', 'clicklink');}});
	$('input#servicebutton').click(function() {if(pageTracker) { pageTracker._trackEvent('servicefinder', 'clicklink');}});
	$('input#tonguebutton').click(function() {if(pageTracker) { pageTracker._trackEvent('tonguetied', 'clicklink', $('select#tongueselect').value);}});		
	
		// anchorlink-to-overlay magic
	var url = location.href;
	var index = url.indexOf('#');
	if ( index > 0 && url.substr(index+1) ) {
		link = url.substr(index+1);
		if (link == 'beer-goggles') {	setTimeout("$('#'+link+' a').trigger('click')",1) } 
		else {$('#'+link+' a').trigger('click');}
	}
});
	