var currentInfoContainerIndex;

$(function()
{
	if($('div#fourCalloutSectionContainer').length || $('div#threeCalloutSectionContainer').length)
	{
		jQuery.preLoadImages("/assets/images/home/infoContainerMainDGP.png", "/assets/images/home/infoContainerMainOBGYN.png", "/assets/images/home/infoContainerMainRE.png");
	}
	
	$('#heroContainer .calloutContainer .calloutAction').click(function()
	{
		if(!$(this).attr('href'))
		{
			var calloutIndex = $('.calloutContainer').index($(this).parent('.calloutContainer'));
			initInfoContainer(calloutIndex);
			
			if($('div#fourCalloutSectionContainer').length)
			{
				$('#mainNavContainer').css(
				{
					opacity: 0,
					visibility: 'visible',
					width: 898
				}).animate(
				{
					opacity: 1
				}, 500);
			}
		}
		
		else
		{
			return true;
		}
	});
	
	$('.backToHomeBtn').click(function()
	{
		closeInfoContainer();
		
		if($('div#fourCalloutSectionContainer').length)
		{
			$('#mainNavContainer').css(
			{
				visibility: 'hidden'
			}).animate(
			{
				opacity: 0
			}, 500);
		}
	});
});

// Image Preloader
(function($)
{
	var cache = [];
  
	// Arguments are image paths relative to the current page.
	$.preLoadImages = function()
	{
		var args_len = arguments.length;
    
		for (var i = args_len; i--;)
		{
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
})(jQuery)

function initInfoContainer(index)
{
	currentInfoContainerIndex = index;
	var calloutPosition = $('#homeContentContainer').offset();
	var calloutWidth = $('#homeContentContainer').width();
	
	$('#homeContentContainer .infoContainer').hide();
	
	if(!$.browser.msie)
	{
		$('#homeContentContainer .infoContainer').eq(index).css(
		{
			display:'block',
			left:calloutWidth,
			opacity:0
		});
		
		$('#heroContainer').animate(
		{
			opacity:0
		});
		
		$('#homeContentContainer .infoContainer').eq(index).animate(
		{
			left:0,
			opacity:1
		}, 500);
	}
	
	else
	{
		$('#homeContentContainer .infoContainer').eq(index).css(
		{
			display:'block',
			left:calloutWidth,
			visibility:'hidden'
		});
		
		$('#heroContainerHeadline, #heroContainerCalloutSection').css(
		{
			visibility:'hidden'
		});
		
		$('#homeContentContainer .infoContainer').eq(index).css(
		{
			visibility:'visible'
		});
		
		$('#homeContentContainer .infoContainer').eq(index).animate(
		{
			left:0
		});
	}
}

function closeInfoContainer()
{	
	var calloutWidth = $('#homeContentContainer').width();
	
	if(!$.browser.msie)
	{
		$('#homeContentContainer .infoContainer').eq(currentInfoContainerIndex).animate(
		{
			left:calloutWidth,
			visibility:'hidden'
		}, 500);
		
		$('#heroContainer').animate(
		{
			opacity:1
		});
	}
	
	else
	{	
		$('#homeContentContainer .infoContainer').eq(currentInfoContainerIndex).animate(
		{
			left:calloutWidth
		}, 500, function()
		{
			$('#heroContainerHeadline, #heroContainerCalloutSection').css(
			{
				visibility:'visible'
			}, function()
			{
				if(this.style.removeAttribute)
				{
					this.style.removeAttribute('filter');
				}
			});
		});
	}
}

function set_cookie(name, value, exp_y, exp_m, exp_d, path, domain, secure)
{
	var cookie_string = name + "=" + escape(value);
	
	if(exp_y)
	{
		var expires = new Date(exp_y, exp_m, exp_d);
		cookie_string += "; expires=" + expires.toGMTString();
	}
	
	if(path)
	{
		cookie_string += "; path=" + escape(path);
	}
	
	if(domain)
	{
		cookie_string += "; domain=" + escape(domain);
	}
	
	if(secure)
	{
		cookie_string += "; secure";
	}
	
	document.cookie = cookie_string;
}
				

function get_cookie(cookie_name)
{
  	var results = document.cookie.match( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

  	if(results)
  	{
    	return(unescape(results[2]));
  	}
  	else
  	{
    	return null;
  	}
}

// set up and use swfobject to emebed flash in the homepage
var flashvars = {
		SiteRoot: "/",
		Debug: "false",
	    xmlPath: "assets/xml/CirclesV.xhtml",
	    //xmlPath: "assets/xml/Circles.xml",
		DeepLink: "",
		videoEmbedPath: "assets/flash/VideoHostEmbed.swf"
};
var params = {
    allowScriptAccess: "all",
    play: "true",
    type: "application/x-shockwave-flash",
    wmode: "transparent",
    quality: "high",
    bgcolor: "#FFFFFF"
}; 
var attributes = {
    align: "left",
    id: "Serono_HomePage",
    name: "hero"
};

/*var videoHostParams = {
    allowScriptAccess: "all",
    play: "true",
    type: "application/x-shockwave-flash",
    wmode: "transparent",
    quality: "high",
    bgcolor: "#FFFFFF"
}; 

var videoHostAttributes = {
    align: "left",
    name: "hostPlayer"
};

var videoHostFlashvars = {
	xmlPath: "/assets/flash/xml/videoHosts.xml",
    testImagePath:"/assets/images/home/2mB.png"
};*/

/*function loadSectionHost(sectionId)
{
    
    if(navigator.appName.indexOf("Microsoft") != -1) 
    {
       myflash = window.hostPlayer;
    }
    else 
    {
       myflash = window.document.hostPlayer;
    }
        
    myflash.playVideo();
}*/

//swfobject.embedSWF("/assets/flash/VideoHostPlayer.swf", "hostPlayer", "420", "486", "9.0.28", "playerProductInstall.swf", videoHostFlashvars, videoHostParams, videoHostAttributes);
swfobject.embedSWF("/assets/flash/Serono_HomePageV.swf", "hero", "944", "330", "9.0.28", "playerProductInstall.swf", flashvars, params, attributes);

/* Initialize everything */
/*$(document).ready(function() { 
});

window.onload = function() 
{
  if(navigator.appName.indexOf("Microsoft") != -1) 
  {
       myflash = window.hostPlayer;
  }
  else 
  {
       myflash = window.document.hostPlayer;
  }
}*/
    
	


