// Set Main Window name
window.name="main";


// Life balance pop-up
function life(targetURL) {

    if(targetURL != null) 
	{
	    window.open(targetURL,'popup','width=840,height=840,menubar=off,top=0,left=0')
	}
	else
	{
	    document.location.href = "/impact_of_modern_lifestyles/article/life_balance/tool/index_new.html"
	}
}

//Homepage TV overlay
function tv() {
	Lightview.show({			
		href: 'http://www.imodium.co.uk/assets/flash/imodium.swf',
        rel: 'flash'
		});
}


// Disclaimer Overlay
function disclaimer(targetURL) {

var arr = targetURL.split("&target=");

	// Set up iFrame Src
	if(arr[1].length > 0) 
	{
		iframehref = "/disclaimer?target=" + arr[1];	
	}
	else {
		iframehref = "/disclaimer";
	}

	Lightview.show({
		href: iframehref,
		rel: 'iframe',
		options: {
			autosize: false,
			topclose: false,
			fullscreen: false,
			overflow: 'hidden',
			width: 350,
			height: 225
			}
		});

	return false;
}


// Send to a colleague overlay
function sendpage(pageTitle) {
    
    var arr = pageTitle.split("&title=");
    var targetURL = window.location.href;
    
	// Set up iFrame Src
	if(arr[1].length > 0) 
	{
		iframehref = "/sendpage?target=" + targetURL + "&title=" + arr[1];	
	}
	else {
		iframehref = "/sendpage";
	}

	Lightview.show({			
		href: iframehref,
		rel: 'iframe',
		options: {
			autosize: false,
			topclose: false,
			fullscreen: false,
			overflow: 'hidden',
			width: 550,
			height: 440 
			}
		});

	return false;
	
}

// On DOM ready
jQuery(document).ready(function(){

	// Disclaimer Overlay
	if (jQuery.url.param("disclaimer") != null) {
              
		// Check Disclaimer is to load
		if (jQuery.url.param("disclaimer") == "load")
		{  		
			// Check target URL
			if (jQuery.url.param("target") != null) {
				jQuery(window).load(function() {
				
					// Check browser in-case of issues
					jQuery.each(jQuery.browser, function(i, val) {
					  if(i=="mozilla" && jQuery.browser.version.substr(0,3)=="1.9")
					  {
					     // FF 3
					     disclaimer(jQuery.url.param("target"));
					  }
					  // Tested in: IE6, IE7, IE8, Chrome 1.0.1, Opera 9.6.2, Safari 3.2.1
					  else {
					   	document.observe('lightview:loaded', function() {
							disclaimer(jQuery.url.param("target"));
						});
					   
					   }
					});
				});
				
			}
			else {
				jQuery(window).load(function() {
					// Check browser in-case of issues
					jQuery.each(jQuery.browser, function(i, val) {
					  if(i=="mozilla" && jQuery.browser.version.substr(0,3)=="1.9")
					  {
					     // FF 3
					     disclaimer();
					  }
					  // Tested in: IE6, IE7, IE8 Chrome 1.0.1, Opera 9.6.2, Safari 3.2.1
					  else {
					   	document.observe('lightview:loaded', function() {
							disclaimer();
						});
					   }
					});

				});
			}

		}		
	}
		
	// Disclaimer Overlay
	var elemdisclaimer = jQuery(".disclaimer");

	if (elemdisclaimer.length){
		elemdisclaimer.click(

			  function () {		  	
			  	disclaimer(jQuery(this).attr('href'));
				return false;
		});
	}
	// End Disclaimer Overlay
	
	// Disclaimer Overlay Close
	var elemDisclaimerEnd = jQuery(".disclaimerEnd");
	if (elemDisclaimerEnd.length != 0)
	{	
		elemDisclaimerEnd.click( 
		  function () {
		  	if (jQuery(this).attr('href').length > 0)
		  	{
				window.parent.location.href=jQuery(this).attr('href');
				window.parent.Lightview.hide();
			}
			else {
				window.parent.Lightview.hide();
			}
		});
	}	
	// End Disclaimer Overlay Close
	
	

    // sendpage Overlay
	if (jQuery.url.param("sendpage") != null) {
              
		// Check sendpage is to load
		if (jQuery.url.param("sendpage") == "load")
		{  		
			// Check target URL
			if (jQuery.url.param("target") != null) {
				jQuery(window).load(function() {
				
					// Check browser in-case of issues
					jQuery.each(jQuery.browser, function(i, val) {
					  if(i=="mozilla" && jQuery.browser.version.substr(0,3)=="1.9")
					  {
					     // FF 3
					     sendpage(jQuery.url.param("target"));
					  }
					  // Tested in: IE6, IE7, IE8, Chrome 1.0.1, Opera 9.6.2, Safari 3.2.1
					  else {
					   	document.observe('lightview:loaded', function() {
							sendpage(jQuery.url.param("target"));
						});
					   
					   }
					});
				});
				
			}
			else {
				jQuery(window).load(function() {
					// Check browser in-case of issues
					jQuery.each(jQuery.browser, function(i, val) {
					  if(i=="mozilla" && jQuery.browser.version.substr(0,3)=="1.9")
					  {
					     // FF 3
					     sendpage();
					  }
					  // Tested in: IE6, IE7, IE8 Chrome 1.0.1, Opera 9.6.2, Safari 3.2.1
					  else {
					   	document.observe('lightview:loaded', function() {
							sendpage();
						});
					   }
					});

				});
			}

		}		
	}
		
	// sendpage overlay
	var elemsendpage = jQuery(".sendpage");

	if (elemsendpage.length){
		elemsendpage.click(

			  function () {		  	
			  	sendpage(jQuery(this).attr('href'));
				return false;
		});
	}
	// End sendpage Overlay
	
	// sendpage Overlay Close
	var elemsendpageEnd = jQuery(".SendPageEnd");
	if (elemsendpageEnd.length != 0)
	{	
		elemsendpageEnd.click( 
		  function () {
		  	if (jQuery(this).attr('href').length > 0)
		  	{
				window.parent.location.href=jQuery(this).attr('href');
				window.parent.Lightview.hide();
			}
			else {
				window.parent.Lightview.hide();
			}
		});
	}	
	// End sendpage Overlay Close
	
	
	// Accordion Toggles
	jQuery('.accordion').click(function() {
		if (jQuery(this).hasClass("accordion-close")) {
			jQuery(this).addClass("accordion").removeClass("accordion-close");
			jQuery(this).attr('title', 'Open');
		}
		else {
			jQuery(this).addClass("accordion-close").removeClass("accordion");
			jQuery(this).attr('title', 'Close');
		}
		jQuery(this).next().toggle();
		return false;
	}).next().hide();
	

	// Opens link in a new window based on class name: 'newwindow'
	if (jQuery(".newwindow").length)
	{	
		jQuery(".newwindow").each(function(){
			jQuery(this).attr({
			    target: "_blank",
			    title: "Opens in a new window"
			 });	
		});
	}
	
	// Expand all accordion's
	if (jQuery("#expandall").length)
	{
		jQuery("#expandall").click(
			function() {
			jQuery(".accordion").each(function(){
				jQuery(this).click();
			});
			return false;
		});
	}

	// Close all accordions
	if (jQuery("#closeall").length)
	{
		jQuery("#closeall").click(
			function() {
			jQuery(".accordion-close").each(function(){
				jQuery(this).click();
			});
			return false;
		});
	}
	
	// Life balance pop-up
	var elemlife = jQuery(".life");

	if (elemlife.length){
		elemlife.click(

			  function () {		  	
			  	life(jQuery(this).attr('href'));
				return false;
		});
	}
	// End Life balance pop-up
	
	
	
});


//PSD2HTML png "fix"
if (document.all && !window.opera) attachEvent("onload", fixTrans);

/*--- IE6 png fix ---*/
var transparentImage = "http://imodium.realadventure.net/assets/images/transparent.gif";
function fixTrans(){
	if (typeof document.body.style.maxHeight == 'undefined'){
	var imgs = document.getElementsByTagName("img");
	for (i = 0; i < imgs.length; i++){	
		if (imgs[i].src.indexOf(transparentImage) != -1) return;
		if (imgs[i].src.indexOf(".png") != -1){
				var src = imgs[i].src;
				imgs[i].src = transparentImage;
				imgs[i].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
				imgs[i].style.display = "inline-block";
			}
		}	
	}
}