Rosetta = new Object();
Rosetta.Vimpat = new Object();
Rosetta.Vimpat.modal = new Object();
Rosetta.Vimpat.taking = new Object();
Rosetta.Vimpat.taking.modal = new Object();
Rosetta.Utils = new Object();

$(document).ready(function(){
	Rosetta.Utils.interstitial();
});

Rosetta.Utils.interstitial = function() {

    // declare href to make it global.
    var href;

    // function to bind click events.
    Rosetta.Utils.interstitial.bindEvents = function() {

        // append the new href to the go button.
        $('.ok_btn').attr("href", href);

        // bind the thickbox remove function to the close button
        $(".cancel_btn").click(function() {
            tb_remove();
        });

        return false;
    }

    $(".extLink").click(function() {

        // get href from link
        href = $(this).attr("href");

        //if thick box is avaliable use it.
        tb_show(null, '/hcp/utilities/interstitial.html?modal=true&amp;height=229&amp;width=538', null);


        // bind click functions after ajax content has been loaded.
        setTimeout('Rosetta.Utils.interstitial.bindEvents()', 500);
        
        

        return false;
    });
}


Rosetta.Vimpat.modal = {
	"basePathToBackgroundImages" : "/hcp/images/background/",
	"basePathToImages" : "/hcp/images/content/modals/"
}

Rosetta.Vimpat.modal.nav = {
	"baseUrl" : "/hcp/images/content/modals/",
	"backToSite" : "/",
	"totalNumSteps": 2,
	"activeStep" : 0,
	"images" : {
		"image1" : {
			"stepNum" : "1",
			"srcFileNameActive" : "chevron1_text_active.png",
			"srcFileNameInactive" : "chevron1_text.gif",
			"altText" : "Finding the seizure control you need",
			"prev" : "previous_inactive.png",
			"next" : "next_active.png"
		},
		"image2" : {
			"stepNum" : "2",
			"srcFileNameActive" : "chevron2_text_active.png",
			"srcFileNameInactive" : "chevron2_text.gif",
			"altText" : "Adding Vimpat to other epilepsy medicines",
			"prev" : "previous_inactive.png",
			"next" : "next_active.png"
		},
		"image3": {
			"stepNum" : "3",
			"srcFileNameActive" : "chevron3_text_active.png",
			"srcFileNameInactive" : "chevron3_text.gif",
			"altText" : "Vimpat works in a completely new way",
			"prev" : "previous_inactive.png",
			"next" : "return_to_site.png"
		}
	}
}

Rosetta.Vimpat.modal.switchState = function(updatedStateNumber){
		
		Rosetta.Vimpat.modal.nav.activeStep=updatedStateNumber;
		activeStep=updatedStateNumber;
		//Updates the background sprite on the ul
		$("#modal_content .navigation ul").removeClass("step1 step2 step3").addClass("step" + (updatedStateNumber+1));
		
		//Attempting to update the images on the modal nav
		var nextPrevLinks = $("#modal_content .pagination a");
		var nextPrevImages = $("#modal_content .pagination a img");
		var navImages = $("#modal_content .navigation ul li a img");
		var baseUrl = Rosetta.Vimpat.modal.nav.baseUrl;
		var backLink = Rosetta.Vimpat.modal.nav.backToSite;
		var images = Rosetta.Vimpat.modal.nav.images;
		var modalScreens = $("#modal_content div.panel");

		$(modalScreens).eq(0).hide();
		$(modalScreens).eq(1).hide();
		$(modalScreens).eq(2).hide();

		switch(activeStep)
		{
			case 0:
				$(navImages).eq(0).attr("src", baseUrl + images.image1.srcFileNameActive);
				$(navImages).eq(1).attr("src", baseUrl + images.image2.srcFileNameInactive);
				$(navImages).eq(2).attr("src", baseUrl + images.image3.srcFileNameInactive);
				$(nextPrevLinks).eq(2).hide();
				$(nextPrevLinks).eq(1)
					.show()
					.mouseover(function(){ imageSwap($(this), baseUrl + "next_over.gif"); })
					.mouseout(function(){ imageSwap( $(this), baseUrl + "next.gif"); });
				$(nextPrevLinks).eq(0).unbind('mouseover');
				$(modalScreens).eq(0).show();
			break;
			
			case 1:
				navImages.eq(0).attr("src", baseUrl + images.image1.srcFileNameInactive);
				navImages.eq(1).attr("src", baseUrl + images.image2.srcFileNameActive);
				navImages.eq(2).attr("src", baseUrl + images.image3.srcFileNameInactive);
				$(nextPrevLinks).eq(2).hide();
				$(nextPrevLinks).eq(1)
					.show()
					.mouseover(function(){ imageSwap($(this), baseUrl + "next_over.gif"); })
					.mouseout(function(){ imageSwap( $(this), baseUrl + "next.gif"); });
				$(nextPrevLinks).eq(0)
					.show()
					.mouseover(function(){ imageSwap($(this), baseUrl + "previous_over.gif"); })
					.mouseout(function(){ imageSwap( $(this), baseUrl + "previous.gif"); });
				$(modalScreens).eq(1).show();
			break;
			
			case 2:
				$(navImages).eq(0).attr("src", baseUrl + images.image1.srcFileNameInactive);
				$(navImages).eq(1).attr("src", baseUrl + images.image2.srcFileNameInactive);
				$(navImages).eq(2).attr("src", baseUrl + images.image3.srcFileNameActive);
				$(nextPrevLinks).eq(2)
					.show()
					.mouseover(function(){ imageSwap($(this), baseUrl + "return_over.gif"); })
					.mouseout(function(){ imageSwap( $(this), baseUrl + "return.gif"); });
				$(nextPrevLinks).eq(1).hide();
				$(nextPrevLinks).eq(0)
					.show()
					.mouseover(function(){ imageSwap($(this), baseUrl + "previous_over.gif"); })
					.mouseout(function(){ imageSwap( $(this), baseUrl + "previous.gif"); });
				$(modalScreens).eq(2).show();
			break;
		}
}



function initContinuumModal(){

    $("#TB_window").css("position", "absolute");
	
	//$("#modal_content .navigation ul").tabs({ selected: 0 });
	
	$("#modal_content .pagination a.previous").click(function(){
			if(Rosetta.Vimpat.modal.nav.activeStep > 0) Rosetta.Vimpat.modal.switchState(--Rosetta.Vimpat.modal.nav.activeStep);
		}
	);
	
	$("#modal_content .pagination a.next").click(function(){
			if(Rosetta.Vimpat.modal.nav.activeStep < (Rosetta.Vimpat.modal.nav.totalNumSteps)) Rosetta.Vimpat.modal.switchState(++Rosetta.Vimpat.modal.nav.activeStep);
		}
	);
	
	//$("#modal_content .navigation a").click(function(){
	//	activeStep = $("#modal_content .navigation ul li a").index(this);
	//	Rosetta.Vimpat.modal.switchState(activeStep);		
	//});
	
	
	
	Rosetta.Vimpat.modal.switchState(0);
	
	initModal();

}

function initModal(){
	$("#modal_top .exit_btn")
		.mouseover(function(){
			imageSwap($(this), "/hcp/images/content/modals/exit_over.gif");})
		.mouseout(function(){
			imageSwap($(this), "/hcp/images/content/modals/exit.gif");});
	$(".interstitial .buttons .ok_btn")
		.mouseover(function(){
			imageSwap($(this), "/hcp/images/content/modals/ok_over.gif");})
		.mouseout(function(){
			imageSwap($(this), "/hcp/images/content/modals/ok.gif");});
	$(".interstitial .buttons .cancel_btn")
		.mouseover(function(){
			imageSwap($(this), "/hcp/images/content/modals/cancel_over.gif");})
		.mouseout(function(){
			imageSwap($(this), "/hcp/images/content/modals/cancel.gif");});

}

function imageSwap(elem, newSrc){

	if( $(elem).length == 1 )
	{
		if( $(elem).is("img") )
		{
			//Single image passed in
			$(elem).attr("src", newSrc);
		}
		else
		{
			$(elem).find("img").attr("src",newSrc);
		}
	}
	else if ( $(elem).length > 1 )
	{
		alert("More than one object found");
	}
	else
	{
		alert("Not enough objects found");
	}	
}

function hoverBgImageSwap(elem){
	$(elem)
		.mouseover(function(){
			$(this).addClass("mouseover");
		})
		.mouseout(function(){$(this).removeClass("mouseover");});

}

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
function callToActionscript(flash, str) {
	getFlashMovie(flash).sendToActionscript(str);
}
function pageInit() {
     callToActionscript('navigation', isPage)
}




Rosetta.Vimpat.taking.modal = {
	"basePathToBackgroundImages" : "/hcp/images/background/",
	"basePathToImages" : "/hcp/images/content/modals/"
}

Rosetta.Vimpat.taking.modal.nav = {
	"baseUrl" : "/hcp/images/content/modals/",
	"backToSite" : "/",
	"totalNumSteps": 2,
	"activeStep" : 0,
	"images" : {
		"image1" : {
			"stepNum" : "1",
			"srcFileNameActive" : "chevron1_text_active2.png",
			"srcFileNameInactive" : "chevron1_text2.gif",
			"altText" : "Finding the seizure control you need",
			"prev" : "previous_inactive.png",
			"next" : "next_active.png"
		},
		"image2" : {
			"stepNum" : "2",
			"srcFileNameActive" : "chevron2_text_active2.png",
			"srcFileNameInactive" : "chevron2_text2.gif",
			"altText" : "Adding Vimpat to other epilepsy medicines",
			"prev" : "previous_inactive.png",
			"next" : "next_active.png"
		},
		"image3": {
			"stepNum" : "3",
			"srcFileNameActive" : "chevron3_text_active2.png",
			"srcFileNameInactive" : "chevron3_text2.gif",
			"altText" : "Vimpat works in a completely new way",
			"prev" : "previous_inactive.png",
			"next" : "return_to_site.png"
		}
	}
}

Rosetta.Vimpat.taking.modal.switchState = function(updatedStateNumber){
		
		Rosetta.Vimpat.taking.modal.nav.activeStep=updatedStateNumber;
		activeStep=updatedStateNumber;
		//Updates the background sprite on the ul
		$("#modal_content .navigation ul").removeClass("step1 step2 step3").addClass("step" + (updatedStateNumber+1));
		
		//Attempting to update the images on the modal nav
		var nextPrevLinks = $("#modal_content .pagination a");
		var nextPrevImages = $("#modal_content .pagination a img");
		var navImages = $("#modal_content .navigation ul li a img");
		var baseUrl = Rosetta.Vimpat.taking.modal.nav.baseUrl;
		var backLink = Rosetta.Vimpat.taking.modal.nav.backToSite;
		var images = Rosetta.Vimpat.taking.modal.nav.images;
		var modalScreens = $("#modal_content div.panel");

		$(modalScreens).eq(0).hide();
		$(modalScreens).eq(1).hide();
		$(modalScreens).eq(2).hide();

		switch(activeStep)
		{
			case 0:
				$(navImages).eq(0).attr("src", baseUrl + images.image1.srcFileNameActive);
				$(navImages).eq(1).attr("src", baseUrl + images.image2.srcFileNameInactive);
				$(navImages).eq(2).attr("src", baseUrl + images.image3.srcFileNameInactive);
				$(nextPrevLinks).eq(2).hide();
				$(nextPrevLinks).eq(1)
					.show()
					.mouseover(function(){ imageSwap($(this), baseUrl + "next_over.gif"); })
					.mouseout(function(){ imageSwap( $(this), baseUrl + "next.gif"); });
				$(nextPrevLinks).eq(0).unbind('mouseover');
				$(modalScreens).eq(0).show();
			break;
			
			case 1:
				navImages.eq(0).attr("src", baseUrl + images.image1.srcFileNameInactive);
				navImages.eq(1).attr("src", baseUrl + images.image2.srcFileNameActive);
				navImages.eq(2).attr("src", baseUrl + images.image3.srcFileNameInactive);
				$(nextPrevLinks).eq(2).hide();
				$(nextPrevLinks).eq(1)
					.show()
					.mouseover(function(){ imageSwap($(this), baseUrl + "next_over.gif"); })
					.mouseout(function(){ imageSwap( $(this), baseUrl + "next.gif"); });
				$(nextPrevLinks).eq(0)
					.show()
					.mouseover(function(){ imageSwap($(this), baseUrl + "previous_over.gif"); })
					.mouseout(function(){ imageSwap( $(this), baseUrl + "previous.gif"); });
				$(modalScreens).eq(1).show();
			break;
			
			case 2:
				$(navImages).eq(0).attr("src", baseUrl + images.image1.srcFileNameInactive);
				$(navImages).eq(1).attr("src", baseUrl + images.image2.srcFileNameInactive);
				$(navImages).eq(2).attr("src", baseUrl + images.image3.srcFileNameActive);
				$(nextPrevLinks).eq(2)
					.show()
					.mouseover(function(){ imageSwap($(this), baseUrl + "return_over.gif"); })
					.mouseout(function(){ imageSwap( $(this), baseUrl + "return.gif"); });
				$(nextPrevLinks).eq(1).hide();
				$(nextPrevLinks).eq(0)
					.show()
					.mouseover(function(){ imageSwap($(this), baseUrl + "previous_over.gif"); })
					.mouseout(function(){ imageSwap( $(this), baseUrl + "previous.gif"); });
				$(modalScreens).eq(2).show();
			break;
		}
}



function initContinuumModal(){
    
    $("#TB_window").css("position", "absolute");
	
	//$("#modal_content .navigation ul").tabs({ selected: 0 });
	
	$("#modal_content .pagination a.previous").click(function(){
			if(Rosetta.Vimpat.modal.nav.activeStep > 0) Rosetta.Vimpat.modal.switchState(--Rosetta.Vimpat.modal.nav.activeStep);
		}
	);
	
	$("#modal_content .pagination a.next").click(function(){
			if(Rosetta.Vimpat.modal.nav.activeStep < (Rosetta.Vimpat.modal.nav.totalNumSteps)) Rosetta.Vimpat.modal.switchState(++Rosetta.Vimpat.modal.nav.activeStep);
		}
	);
	
	//$("#modal_content .navigation a").click(function(){
	//	activeStep = $("#modal_content .navigation ul li a").index(this);
	//	Rosetta.Vimpat.modal.switchState(activeStep);		
	//});
	
	
	
	Rosetta.Vimpat.modal.switchState(0);
	
	initModal();

}
function initContinuumModal2(){

    $("#TB_window").css("position", "absolute");
	
	//$("#modal_content .navigation ul").tabs({ selected: 0 });
	
	$("#modal_content .pagination a.previous").click(function(){
			if(Rosetta.Vimpat.taking.modal.nav.activeStep > 0) Rosetta.Vimpat.taking.modal.switchState(--Rosetta.Vimpat.taking.modal.nav.activeStep);
		}
	);
	
	$("#modal_content .pagination a.next").click(function(){
			if(Rosetta.Vimpat.taking.modal.nav.activeStep < (Rosetta.Vimpat.taking.modal.nav.totalNumSteps)) Rosetta.Vimpat.taking.modal.switchState(++Rosetta.Vimpat.taking.modal.nav.activeStep);
		}
	);
	
	//$("#modal_content .navigation a").click(function(){
	//	activeStep = $("#modal_content .navigation ul li a").index(this);
	//	Rosetta.Vimpat.modal.switchState(activeStep);		
	//});
	
	
	
	Rosetta.Vimpat.taking.modal.switchState(0);
	
	initModal();

}

function initModal(){
	$("#modal_top .exit_btn")
		.mouseover(function(){
			imageSwap($(this), "/hcp/images/content/modals/exit_over.gif");})
		.mouseout(function(){
			imageSwap($(this), "/hcp/images/content/modals/exit.gif");});
	$(".interstitial .buttons .ok_btn")
		.mouseover(function(){
			imageSwap($(this), "/hcp/images/content/modals/ok_over.gif");})
		.mouseout(function(){
			imageSwap($(this), "/hcp/images/content/modals/ok.gif");});
	$(".interstitial .buttons .cancel_btn")
		.mouseover(function(){
			imageSwap($(this), "/hcp/images/content/modals/cancel_over.gif");})
		.mouseout(function(){
			imageSwap($(this), "/hcp/images/content/modals/cancel.gif");});

}

function imageSwap(elem, newSrc){

	if( $(elem).length == 1 )
	{
		if( $(elem).is("img") )
		{
			//Single image passed in
			$(elem).attr("src", newSrc);
		}
		else
		{
			$(elem).find("img").attr("src",newSrc);
		}
	}
	else if ( $(elem).length > 1 )
	{
		alert("More than one object found");
	}
	else
	{
		alert("Not enough objects found");
	}	
}

function hoverBgImageSwap(elem){
	$(elem)
		.mouseover(function(){
			$(this).addClass("mouseover");
		})
		.mouseout(function(){$(this).removeClass("mouseover");});

}

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
function callToActionscript(flash, str) {
	getFlashMovie(flash).sendToActionscript(str);
}
function pageInit() {
     callToActionscript('navigation', isPage)
}


//************************************ CALLOUT HOVER FUNCTIONALITY ************************************
$(document).ready(function() {
	$(".side_group .ctas .cta").hover(function() {
		$(this).find(".cta_link a").css("background-position", "center -17px");
	}, function() {
		$(this).find(".cta_link a").css("background-position", "center top");
	});
	
	$(".main_callouts .callouts .call").hover(function() {
		$(this).find(".action a").css("background-position", "center -17px");
	}, function() {
		$(this).find(".action a").css("background-position", "center top");
	});
});
//*****************************************************************************************************

//************************************ Registration Brand Name Content ********************************
$(document).ready(function() {
    //Show Keppra question
	$("#ctl00_ContentPlaceHolder1_Q65_Container td:eq(0) input").bind("click", function() {
		$(".keppra_xtracont").show();
		brandStyle($("#ctl00_ContentPlaceHolder1_Q65_Container th"));
	});
	//Hide Keppra question
	$("#ctl00_ContentPlaceHolder1_Q65_Container td:gt(0) input").bind("click", function() {
		$(".keppra_xtracont").hide();
		unBrandStyle($("#ctl00_ContentPlaceHolder1_Q65_Container th"));
	});
	//Show Keppra XR question
	$("#ctl00_ContentPlaceHolder1_Q64_Container td:eq(0) input").bind("click", function() {
		$(".keppra_xr_xtracont").show();
		brandStyle($("#ctl00_ContentPlaceHolder1_Q64_Container th"));
	});
	//Hide Keppra XR question
	$("#ctl00_ContentPlaceHolder1_Q64_Container td:gt(0) input").bind("click", function() {
		$(".keppra_xr_xtracont").hide();
		unBrandStyle($("#ctl00_ContentPlaceHolder1_Q64_Container th"));
	});
	//Show Vimpat question
	$("#ctl00_ContentPlaceHolder1_Q614_Container td:eq(0) input").bind("click", function() {
		$(".vimpat_xtracont").show();
		brandStyle($("#ctl00_ContentPlaceHolder1_Q614_Container th"));
	});
	//Hide Vimpat question
	$("#ctl00_ContentPlaceHolder1_Q614_Container td:gt(0) input").bind("click", function() {
		$(".vimpat_xtracont").hide();
		unBrandStyle($("#ctl00_ContentPlaceHolder1_Q614_Container th"));
	});
});

function openActive() {
    //Conditional statements that show the appropriate question when the Keppra, Keppra XR, or Vimpat brand name radio buttons are checked.
    if($("#ctl00_ContentPlaceHolder1_Q64_Container td:eq(0) input").attr("checked")) {
        $(".keppra_xr_xtracont").show();
		brandStyle($("#ctl00_ContentPlaceHolder1_Q64_Container th"));
    }
    if($("#ctl00_ContentPlaceHolder1_Q65_Container td:eq(0) input").attr("checked")) {
        $(".keppra_xtracont").show();
		brandStyle($("#ctl00_ContentPlaceHolder1_Q65_Container th"));
    }
    if($("#ctl00_ContentPlaceHolder1_Q614_Container td:eq(0) input").attr("checked")) {
        $(".vimpat_xtracont").show();
		brandStyle($("#ctl00_ContentPlaceHolder1_Q614_Container th"));
    }
}

//Style the element
function brandStyle(element) {
	element.css("border", "none");
	element.css("padding", "0px 3px 6px 0px");
	element.css("margin", "0px 0px 4px 0px");
	element.children("span").css("font-weight", "bold").css("color", "#cc5e28");
	element.children("div").css("padding", "12px 6px 8px 8px").css("border", "1px solid #cc5e28").css("margin", "2px 2px 2px 0px").css("width", "190px");
	element.children("select").css("width", "178px;")
}
//Remove the styles
function unBrandStyle(element) {
	element.css("border", "none");
	element.css("padding", "0px");
	element.css("margin", "0px");
	element.children("span").css("font-weight", "normal").css("color", "#000");
	element.children("div").css("padding-top", "0px");
}
//*****************************************************************************************************
//**************************** Remember form data throughout the session ******************************
$(document).ready (function() {
	var name;
	var value;
	
	//I make a cookie called "first_time" at the end of this script. The cookie won't be made until the user visits the page at least one time.
	//On the first visit, the script creates a cookie for each input field to be remembered with their initial values.
	if(readCookie("first_time") == null) {
		$("input").each(function() {

			//from the webpage, get whether the input is checked or not
			if($(this).attr("type") == 'radio')
			{
			    name = $(this).attr("name");			
			    value = $(this).attr("id");
			}
			else
			{
				name = $(this).attr("name") + $(this).attr("value");
			    value = $(this).attr("checked");
			}
			//create a cookie to store these values
			createCookie(name, value);
		});
	}
	
	//If the user has visited the page multiple times, this segment runs. When the page loads it reads in the values from each cookie
	//and populates the form with those values.
	if(readCookie("first_time") != null) {
		$("input").each(function() {
			//for each input, get the unique id (the name and value attributes concatenated)
			name = $(this).attr("name")

			//from the cookie, get whether it was checked or not
			value = readCookie(name);
			
			if(value == $(this).attr("id"))
			{
			    $(this).attr("checked", true);
			}
//			if(value == "true") {
//				//if, according to the cookie, the input was checked previously, check the actual element in the page
//				$(this).attr("checked", true);
//			}
		});
	}
	
	openActive();       //call function that checks to see if the brand drugs are checked and if so, show the extra content
	
	//This runs if a user clicks on the input fields, thereby changing their states. If the state of an input changes,
	//that change is reflected in the appropriate cookie.
	$("input").click(function() {
		//get the row where the input that was clicked resides
		var row = $(this).attr("name");
		var oldname;
		
		//inspect each input in that row
		$(this).parent().parent().children("td").each(function() {
			oldname = $(this).find("input").attr("name") + $(this).find("input").attr("value");
			//update each input's cookie to be false, meaning it is not checked anymore
			createCookie(oldname, false);
		});
		
		name = $(this).attr("name") + $(this).attr("value");
		//update the cookie for the input that was clicked to show that it is now checked
		createCookie(name, true);
	});
	
	//A cookie that helps tell whether the user is returing to the page or visiting it for the first time
	createCookie("first_time", false);
});
//*****************************************************************************************************
//************************************ Cookie utilities/functions *************************************
function createCookie(name,value,days) {

    if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	//Use the escape, if not Firefox gives hangs on load and gets Bad Request Error on refresh.
	document.cookie = escape(name)+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
//*****************************************************************************************************

