function bookmark() {
	var ver = navigator.appName; 
	var num = parseInt(navigator.appVersion); 
	var txt = "bookmark this site"; 
	var url = document.location // get location of the site
	var who = document.title // get title of the site
	
	// only work in IE
	if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) 
	{ 
		window.external.AddFavorite(url,who);
	}
	else
	{ 
	// if its netscape then pop up a alert message for the time being
		txt += "using (Ctrl+D)"; 
		window.alert(txt);
	} 
}

function showTools() {
  if (document.getElementById("pageTools"))
  {
  	var pagetools = document.getElementById("pageTools");
	  pagetools.className = "pagetoolsShow";
  }
}

// Alienor Davies added the below for Firefox : 28.11.06
function bookmarkPage() {
	var url = document.location // get location of the site
	var title = document.title // get title of the site
	var txt = "bookmark this site"; 
  if (window.sidebar) { 
    // Mozilla Firefox Bookmark		
    window.sidebar.addPanel(title, url,"");	
  } 
  else if( window.external ) { 
    // IE Favorite		
    window.external.AddFavorite( url, title); 
  }	
  else if(window.opera && window.print) { 
    // Opera Hotlist		
		txt += "using (Ctrl+T)"; 
		window.alert(txt);
  } 
	else
	{ 
	// if its netscape then pop up a alert message for the time being
		txt += "using (Ctrl+D)"; 
		window.alert(txt);
	} 
}

// Pop up window generator
function newWindow() {
var x = document.getElementsByTagName('A');
for (var i=0;i< x.length;i++)
	{
	if (x[i].className == 'newWindow')
		{
		x[i].onclick = function () {
			return popup1(this.href)
			}
		x[i].title += '';
		}
	}
}

function popupcode() {
var x = document.getElementsByTagName('A');
for (var i=0;i< x.length;i++)
	{
	if (x[i].className == 'newWindowA4')
		{
		x[i].onclick = function () {
			return popup3(this.href)
			}
		x[i].title += ' (Opens in a new window)';
		}
	}
}

function viewImage() {
var x = document.getElementsByTagName('A');
for (var i=0;i< x.length;i++)
	{
	if (x[i].className == 'viewImage')
		{
		x[i].onclick = function () {
			return popup2(this.href)
			}
		x[i].title += '';
		}
	}
}


function popup1(url) {
newwindow=window.open(url,'name','height=450, width=550, resizable=yes, scrollbars=yes, status=yes');
if (window.focus) {newwindow.focus()}
return false;
}

function popup2(url) {
newwindow=window.open(url,'name','height=250, width=450, resizable=yes, scrollbars=yes, status=yes');
if (window.focus) {newwindow.focus()}
return false;
}
function popup3(url) {
newwindow=window.open(url,'name','height=650, width=525, resizable=yes, scrollbars=yes, status=yes');
if (window.focus) {newwindow.focus()}
return false;
}

var flashShow;
flashShow = false;

// Pop up window generator
function tagQuestionnaireLinks(URL) {
// if cookie is set, user has already taken part....then don't do the below
	var x = document.getElementsByTagName('A');
	for (var i=0;i< x.length;i++)
	{
		x[i].onclick = function () {
			return popUpSurvey(URL);
		}
	}
	
}

function popUpSurvey(URL) {
	var page = window.open(URL, 'popup', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=504,height=551,left = 490,top = 312');
	page.focus();
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?"));
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}

function updateSendToFriendForm(videoId, subVideo){
	var form = document.forms["sendToFriendForm"];
	form.elements["videoid"].value = videoId;
	form.elements["subvideo"].value = subVideo;
}

window.onload=function(){
	 if (flashShow)fo.write("flowplayerholder");
	 newWindow;
	 popupcode;
	 viewImage;
	 showTools;
}

function getWindowDimensions(){
	var dims = new Object();
	dims.frameWidth = 0;
	dims.frameHeight = 0;
	if (self.innerWidth){
		dims.frameWidth = self.innerWidth;
		dims.frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth){
		dims.frameWidth = document.documentElement.clientWidth;
		dims.frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body){
		dims.frameWidth = document.body.clientWidth;
		dims.frameHeight = document.body.clientHeight;
	}
	return dims;
}
function getFlashMovieObject(movieName){
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName]){
			return document.embeds[movieName];
		}
	}else if (window.document[movieName]){
 		return window.document[movieName];
 	}else{
 		return document.getElementById(movieName);
 	}
}
function playFlashMovie(movieName, subVideo) {
    var flashMovie = getFlashMovieObject(movieName);
    flashMovie.SetVariable('playvideonum', subVideo);
	flashMovie.Play();
}

/*
 * Checks whether the current user agent is Safari 2 or less.
 */
function isSafari2() {
	browserInfoComponents = navigator.appVersion.split(' ');
	browserInfo = browserInfoComponents[browserInfoComponents.length - 1].split('/');
	return ((browserInfo[0] == 'Safari') && (parseInt(browserInfo[1]) < 500));
}

function validate_name(fld,alerttxt)
{
	var error="";
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
     	error='Please enter your name\n';
		if(alerttxt=='Surname')
			error='Please enter your surname\n';
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validate_story(fld,alerttxt)
{
	var error="";
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
    	error='Please enter your story\n';
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
  var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "Please enter your email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function isFlashEnabled() {
	try {
		try {
			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];
	} 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 "true";
};

//Danny added calendar functionality


$(document).ready( function(){
	
	$('.noJavascriptWeeks').hide();
	$('.dropDown').show();
	$('.jsAlt').show();
	
	
/* For changing the page with the select box */

	$('.numberOfWeeks').change( function(){
		
		var trimester = $(this).val();
		
		window.location = trimester;

	})
	
/* ----------------------------------------- */

//Clicking on calendar tabs used to change content in the main content area

$('.firstTrimester a').click( function(){
	
	var theLink = $(this).attr('class');
	
		$(".stageContent").load("/smoking-and-pregnancy/calendar/ajax/" + theLink + ".html");
		 $('.periods li').removeClass("on");
		 $(this).parent().addClass(" on");
		 
	return false;
})

$('.secondTrimester a').click( function(){
	
	var theLink = $(this).attr('class');
	
		$(".stageContent").load("/smoking-and-pregnancy/calendar/ajax/" + theLink + ".html");
		 $('.periods li').removeClass("on");
		 $(this).parent().addClass(" on");
		 
	return false;
})

$('.thirdTrimester a').click( function(){
	
	var theLink = $(this).attr('class');
	
		$(".stageContent").load("/smoking-and-pregnancy/calendar/ajax/" + theLink + ".html");
		 $('.periods li').removeClass("on");
		 $(this).parent().addClass(" on");

	return false;
})


/* Dads and Smoking */

$('ul.tabs li a').click( function(){
	
	var theLink = $(this).attr('class');
	
		 $(".tabBoxInnerInner").load("/smoking-and-pregnancy/fathers-and-smoking/ajax/" + theLink + ".html");
		 $('.imageContainerInnerInner').load("/smoking-and-pregnancy/fathers-and-smoking/ajax/image" + theLink + ".html");
		 
		 $('.tabs li').removeClass("on");
		 $(this).parent().addClass(" on");
		
	return false;
})











/* Update of functionality in rightCol.php*/

if (0 < $('#rightCol').length) {
	
	
	
	function rightColFunc() {
		
		$('#rightCol ul.features li').hide();
		$('#rightCol ul.features li ul li').show();
			
		var features = $('#rightCol ul.features li:hidden');
		//var current = Math.floor(Math.random() * features.length);
		var current	= 0;
		if (0 < features.length) {
			$(features[current]).fadeIn('slow');			
		}
			
		
		for(var i = 0; i < features.length; i++){
					
			$('.featureScroll li.last').before('<li class="progress"><span>' + (i + 1) + ' of ' + features.length + '</span></li>');
			
			
		}
		
		
		var progressLength = $('.featureScroll li').length - 2;
		
		var spacing = (122  - (16 * progressLength)) / 2;
		
		$('.goLeft').css({'margin-right': spacing + 'px'});
				
		$('.goRight').css({'margin-left': spacing + 'px'});
		
		//console.log("total length = "+$('.featureScroll li').length);
		//console.log("progressLength = "+progressLength);
		
			
		function showProgress(){
			
			//console.log("current = "+current);
			
			if (progressLength > 2 && current >= 0 && current <= progressLength) {
				
				var increment = current + 1;
				
				$('.featureScroll li:eq('+increment+')').css("background-image","url(/images/featureProgCurrent.gif)");
			
			}
		}

		showProgress();

		// Update of functionality in rightCol.php ( Give the user the option to scroll through features )
	
		if (features.length > 1) {
			$('.featureScroll').show();
			
			$('.goLeft').click(function(){
				$(features[current]).hide();
				if (0 == current) 
					current = features.length;
				$(features[--current]).fadeIn('slow');
				$('.featureScroll li.progress').css("background-image", "url(/images/featureProg.gif)")
				
				showProgress();
				
				return false;
			});
			
			$('.goRight').click(function(){
				$(features[current]).hide();
				if ((features.length - 1) == current) 
					current = -1;
				$(features[++current]).fadeIn('slow');
				$('.featureScroll li.progress').css("background-image", "url(/images/featureProg.gif)")
				
				showProgress();
				
				return false;
			});
			
		}
	
	}
	

	$(document).ready( function(){
		
		rightColFunc();
		
	});
	
}


//--------------------------------------------------------------------------------------------------



	
/* Hover pop ups on stages in Just the Facts*/

$('map area').mouseover( 

	function(){
	
	var id = $(this).attr('id');
	
	$('ol li.' + id).show();
	
	} );
	
$('map area').mouseout(	
	
	function(){

	var id = $(this).attr('id');

	$('ol li.' + id).hide();

});

/* Click pop ups on stages in Just the Facts*/

	$('map area').click( function(){
		var id = $(this).attr('id');
		$(".stageContent").load("/smoking-and-pregnancy/ajax/" + id + ".html");
		return false;
	})
});

/* Updates text on click of Flash animation (stage two)*/

function changeText(text){
	$(document).ready( function(){
		$(".stageContent").load("/smoking-and-pregnancy/ajax/" + text + ".html");		
	});
}

function setCookie(c_name,value){
	var exdate=new Date();
	exdate.setDate(exdate.getTime()+1440000); //24 minutes
	document.cookie=c_name+ "=" +escape(value)+ ";expires=" +exdate.toGMTString();
}

function getCookie(c_name){
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}


// Google Analytics wrapper functions
// There are here to make sure we dont have undefined errors on the unlikely 
// chance that the user clicks on a tracked link before ga has initialised.
function gaHasTrackedAction(action){
	var actionString = getCookie("rrGaEventActions");
	var actions = actionString.split("|");
	
	if (-1 == actions.indexOf(action)) {
		actions.push(action);
		setCookie("rrGaEventActions",  actions.join("|"));
		return false;
	}
	return true;
}
function gaTrackEvent(category, action, optional_label, optional_value){
	try {
		if (!gaHasTrackedAction(action)) {
			pageTracker._trackEvent(category, action, optional_label, optional_value);
		}
	} catch(err){}
}
function gaLink(targetUrl, useHash){
	try {
		pageTracker._link(targetUrl, useHash);
	} catch(err){}
}
function gaTrackPageview(url)
{
	try {
		pageTracker._trackPageview(url);
	} catch(err){}
}

$(document).ready(function() {
	// Open all PDF and txt's in a new window
	$("a[href*=.pdf]").click(function(){
		var filename=this.href.substring(this.href.lastIndexOf('/')+1, this.href.length);
		gaTrackPageview('/downloads/' + filename);
		gaTrackEvent('artemis', 'active', 'pdf'); // ga event tracking
		window.open(this.href);
		return false;
	});
	$("a[href*=.txt]").click(function(){
		var filename=this.href.substring(this.href.lastIndexOf('/')+1, this.href.length);
		gaTrackPageview('/downloads/' + filename);
		gaTrackEvent('artemis', 'active', 'txt'); // ga event tracking
		window.open(this.href);
		return false;
	});
	// Track mpg links
	$("a[href$=.mpg],a[href$=.mpeg]").click(function(){
		var filename=this.href.substring(this.href.lastIndexOf('/')+1, this.href.length);
		gaTrackPageview('/mpegs/' + filename);
		gaTrackEvent('artemis', 'active', 'mpg'); // ga event tracking
		return true;
	});
		
	// Open external links in new windows
	//Get all links with rel="external" and place them into 'external'
	var external = $('a[rel="external"]');														
	if ($(external).attr('title') == "" || $(external).attr('title') == undefined) {
		$(external).attr('title', 'No title');
	}
	external.attr("title", external.attr("title") + " - Link opens in a new window..");		//Take the links current title and append it with the external link message
	external.click( function() {															//When an external link is clicked
		window.open( $(this).attr('href') );												//Open its href in a new window
		return false;																		//Cancel the links default behaviour
	});
	
	//---------------------------------------------------------------------------------
	
	$('.noScript').hide();
	$('#scrollWrapper').show();
	if (0 < $('.scrollerContent').length) $('.scrollerContent').jScrollPane({scrollbarWidth:133, showArrows:true});
	$('.jScrollArrowUp').css('width','16px');
	//$('.jScrollArrowDown').css({'width': '16px','height':'45px'});
	$('.jScrollArrowDown').css({'width': '16px'});
	
	
/* -- New homepage functionality -- */	

	$('hide').hide();
	$('#lense').show();	
	$('#lense').fadeOut(1500);
	
	var madCurrent = 0, 
		madSlides = $('.primaryContentPagination li');
	
	function nextSlide(){
		
		//console.log(madCurrent);
		
		madSlides.eq(madCurrent++).removeClass("active");
		
		if (madCurrent >= madSlides.length){
			madCurrent = 0;
		}
	
		madSlides.eq(madCurrent).addClass("active");
		$('.primarySpotlight').attr('class','primarySpotlight');
		
		
		$('.primarySpotlight').addClass("slide" + madCurrent);
		$('#lense').show();
		$('#lense').fadeOut(1500);
		$('.primaryCalloutWrapper').hide();	
		$('.callout' + madCurrent).show()	
	}
	
	
	var intervalID = setInterval(function(){nextSlide();}, 15000);
	
	
//When clicking ------------------------------------------------	
	
	
	$('.primaryContentPagination li a').click( function(){
		
		
		$('.primaryContentPagination li').removeClass('active');
		var tab = $(this).parent('li').attr('class');	
		$(this).parent('li').addClass('active');
		
		//console.log(tab);
		
		switch(tab){
			case "first tab1":
				//console.log(tab);
				$('.primarySpotlight').attr('class','primarySpotlight');
				$('.primarySpotlight').addClass("slide0");
				$('#lense').show();
				$('#lense').fadeOut(1500);
				$('.primaryCalloutWrapper').hide();	
				$('.callout0').show()
			
				break;
			case "tab2":
				//console.log(tab);			
				$('.primarySpotlight').attr('class','primarySpotlight');
				$('.primarySpotlight').addClass("slide1");
				$('#lense').show();
				$('#lense').fadeOut(1500);
				$('.primaryCalloutWrapper').hide();	
				$('.callout1').show()					
				break;			
			case "tab3":
				//console.log(tab);
				$('.primarySpotlight').attr('class','primarySpotlight');
				$('.primarySpotlight').addClass("slide2");
				$('#lense').show();
				$('#lense').fadeOut(1500);
				$('.primaryCalloutWrapper').hide();	
				$('.callout2').show()						
				break;			
		}
		
				
		clearInterval(intervalID);

		return false;
		
	})


/* -- lsss hide show -- */

	$('#leftContent').addClass('jsEnabled');
	$('.lsssSearchWrapper').addClass('jsLSSSS');
	
	if (1 < $('#lsssResultsHome tbody tr').length) {
		$('.viewAll').show();
	}



	$('.viewAll').click( function(){
		
		if($('#lsssResultsHome tbody tr').is(":hidden")){
			$('#lsssResultsHome tbody tr:not(:first)').show();
			$(this).children('span').children('span').text("Close");
			$(this).addClass('close');
		} else {
			$('#lsssResultsHome tbody tr:not(:first)').hide();
			$(this).children('span').children('span').text("View all");	
			$(this).removeClass('close');
		}
		return false;	
	});
	
	$('#lsssPostcodeChange').click( function(){
		$('#lsssResults').hide();
		$('.viewAll').hide();
		$('#lsssSearchForm').show();
		return false;
	});
});	







