
//open jquery
$(function() {
	/*gets drop down nav to work in ie, sent only to ie*/
	if($.browser.msie){
		$(".section").hover(function() {
			$(this).children("ul").addClass("iepopup");
		},function(){
			$(this).children("ul").removeClass("iepopup");
		});
	}
	
	$("div.nav ul.menu li").hover(
	// mouseenter
		function () {
			$(this).addClass("active");
		},
	// mouseleave
		function () {
		$(this).removeClass("active");
		}
	);
	
// This is for the FMA on the PCG homePage	
	if($('body.pcg .fma').length > 0 || $('body.hcp .fma').length > 0) {
  
	
	$('.slideshow')
		.cycle({
        after: function(currSlideElement, nextSlideElement, options, forwardFlag) { 
			$('.slideshow .fma-content').css('zIndex', '');
		}, 
		cleartype:    true,
		cleartypeNoBg: false,
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout:  5000	
	});
	
	$('.fma-tagline, .btn-watchVideo').hover(function() {
		$('.slideshow').cycle('pause');
	},function(){
		$('.slideshow').cycle('resume');
	});

	
	$('.slideshow-small').after('<div class="slideshow-nav">').cycle({ 
	    fx:     'fade', 
	    speed:  'slow', 
		pause:  1,
	    timeout: 5000, 
	    pager:  '.slideshow-nav' 
	});
	
	$('.col-two').hover(function() {
		$('.slideshow-small').cycle('pause');
	},function(){
		$('.slideshow-small').cycle('resume');
	});

	} // end of if
	
	// This keeps the left nav links from going forward when the 
	// element is active
	$(".wrapper-relatedLinks li.active a, .wrapper-relatedLinks a.active").click(function(){
		return false;
	});

	/*functioning link for print button*/
 	$("#print").children("a").click(function(){
		window.print();
		return false;
	});
	
	/*HCP FMA button*/
 	$(".hcp .slideshow .btn-watchVideo").live('click', function() {
		location.href = $(this).attr('rel')
	});

	

/*
form controls
*/
	/*show the rest of the form if you have or know someone who has CF is clicked yes*/
	//when you click on the yes cf diagnosis radio button
	$("#CF_diagnosis_yes").click(function(){
		//remove the class hidden on the second part of the form
		//to make it visible
		$("#if-diagnosed").slideDown(1000);
	});
	
	//if the yes cf diagnosis radio button is already selected, show it as well
	if ( $("#CF_diagnosis_yes").length > 0 ) {
		if($("#CF_diagnosis_yes")[0].checked){
			$("#if-diagnosed").show();
		}
	}
	
	//if the no cf diagnosis radio button is clicked
	$("#CF_diagnosis_no").click(function(){
		//hide the second part of the form
		$("#if-diagnosed").hide();
	});
	//note -- the second part is hidden by default
	if ( $("#Treatment_pulmozyme").length > 0 ) {
		/*if you are taking pz, show the third part of the form*/
		//if you come to the page with treatment checked, show the section
		if($("#Treatment_pulmozyme")[0].checked){
			$("#if-taking-pz").slideDown("fast");
		//if you come to the page with treatment not checked, hide the section
		}else{
			$("#if-taking-pz").hide("fast");
		}
		//after the default state, if someone clicks the checkbox, toggle the hidden class
		$("#Treatment_pulmozyme").click(function(){
			$("#if-taking-pz").slideToggle("fast");
		});
	}
	
	$("#relationship-container input[name=relationship]").click(function(){
		var i = $(this).attr("class");
		$("#relationship-container .wrapper-form-element").hide();
		$("#"+i).slideDown("fast");
	});
	
	// show a preselcted radio button on reload of the page
	if ( $("#relationship-container input[name=relationship]").length > 0 ) {
		var i = $("#relationship-container input[name=relationship]:checked").attr("class");
		$("#"+i).show();
	} // end IF
	
	
	$("a.openWin").click(function(){
			var rel = $(this).attr("rel");
			var href = $(this).attr("href");
			if(rel == 'genint838c') {
				window.open(href+rel+".html", 'DigitalMagazine','scrollbars=no,status=no,resizable=no,location=no,menubar=no,titlebar=no,top=0,left=0,height=540,width=950');
			} else if (rel == 'roundtable') {
				window.open(href, 'Pulmozyme_Round_Table_Program','scrollbars=no,status=no,resizable=no,location=no,menubar=no,titlebar=no,top=0,left=0,height=640,width=905');

			}
			return false;
		});
	
	
	if ( $(".interiorPages .cf-confirm").length > 0 ) {
		var el = $('.wrapper-content').children('div[eq(0)][eq(1)]');
		sameHeight(el);
	}
	// opens the saftey copy container and pauses the video
	 $("a.safetyVideo").click(function(){
		$("#wrapper-video").hide();
		$("#safetyCopy").show();
		return false;
		//pauseVideo();
	});
	
	// closes the saftey copy container
	$("a#safetyVideoClose").click(function(){
		$("#safetyCopy").hide();
		$("#wrapper-video").show();
		return false;
	});
	
    // opens the saftey copy container and pauses the video
    $("a.safetyVideo-CF").click(function(){
           $("#wrapper-video-CF").hide();
           $("#safetyCopy-CF").show();
           //pauseVideo-CF();
       		//alert('test');
       		//var videoPlayer = document.getElementById("videoflash1"); 
       		//videoPlayer.stop();
       		//alert(videoPlayer);
           return false;
    });

    

    // closes the saftey copy container
    $("a#safetyVideoClose-CF").click(function(){
           $("#safetyCopy-CF").hide();
           $("#wrapper-video-CF").show();
           return false;

    });


	
	// <video> tag tracking firing commands
	if($('#wrapper-mp4').length > 0) {
		
		$('video').bind("play" ,function(){
			var video = document.getElementsByTagName('video')[0];
			var src = video.src;
			var time = video.currentTime;
			if(time === 0) {
				geneVideoTrack(src,'start');
			}
		});
		
		$('video').bind("ended" ,function(){
			var video = document.getElementsByTagName('video')[0];
			var src = video.src;
			geneVideoTrack(src,'complete');
		});
	}
	

//close jquery
});

window.onload = function(){
   // Homepage Columns make same size
	if ($('.fma-bottom .wrapper-content').length > 0) {
		var el = $('.fma-bottom .wrapper-content').children('div');
		sameHeight(el);
	// place the nav buttons at the bottom and resize the columns
		
		el.each(function(i) {
			var h = $(this).innerHeight();
			var r = (h + 30);
			$(this).css('height', r);
		});
		var i = $('.fma-bottom .wrapper-content .col-two').innerHeight();
		var top = (i-20);
		$('.slideshow-nav').css('marginTop', top);
		
	}
	// Error input field highlight and scroll to action
	if ($('#cfForm-errors').length > 0) {
	
		$.scrollTo("#cfForm-errors", 400);
		
		$('#cfForm-errors li').each(function(i) {
			var i = $(this).attr('rel');
			if(i.length > 2) {
				$('#'+i).addClass('error');
			}
		});
	}
	
	/*popup link for external links had to add a .not() statement for IE 7 was seeing the fma links */	
	$("a:not('.slideshow-nav a')").live('click', function() {
		str = $(this).attr("href");
		hrefString = str.toLowerCase();
		//this line checks to see if the url in the link is offsite (http), 
		//and not on the whitelist (currently: gene.com, pulmozyme.com and accesssolutions.com [including pulmozymeaccesssolutions.com, and all variants])
		//note, whitelist does not contain all gene sites, including other drug sites. 
		if(	hrefString.indexOf("http") == 0 
			&& hrefString.indexOf("gene.com") == -1 
			&& hrefString.indexOf("pulmozyme.com") == -1 
			&& hrefString.indexOf("accesssolutions.com") == -1
			&& hrefString.indexOf("cfliving.com") == -1
			&& hrefString.indexOf("kadium") == -1 ){
				var response = confirm("You are leaving the Pulmozyme Web site:\n\nThe link you have selected will take you away from this site to one that is not owned or controlled by Genentech, Inc. Genentech, Inc makes no representation as to the accuracy of the information contained on sites we do not own or control. Genentech does not recommend and does not endorse the content on any third-party websites. Your use of third-party websites is at your own risk and subject to the terms and conditions of use for such sites.");
				if(response){
					offsiteWin = window.open(hrefString,"offsiteLink");
					offsiteWin.focus()
					return false;
				}else{
					return false;
				}
		}else if ((hrefString.indexOf("http") == 0) && (hrefString.indexOf("pulmozyme.com") == -1) && (hrefString.indexOf("kadium.net") == -1)){
			offsiteWin = window.open(hrefString,"offsiteLink");
			offsiteWin.focus()
			return false;
		}
	});
	
	/*popup question when you leave to go to the hcp side*/
	$("a.to-hcp").click(function(){
		hrefString = $(this).attr("href");
		var response = confirm("The information contained in this section of the site is intended for U.S. healthcare professionals only. Select OK if you are a U.S. healthcare professional.");
		if(!response){
			return false;
		}
	});
	
	
	
	/* * *
	These are the tracking helper click events that are needed for Omniature
	
	I used the .live method just as a best practice even though we do not have ajax
	updates happening to the site
	* * */
	
	// Track the Print this page function
	$("div.btn-print a").live('click', function(){ 
		window.print();
		trackPrint();
		return false;
	});
	
	
};



sameHeight = function(el) {
	var Array = [];
		
	sortNumber = function (a,b) {
		return b - a;
	};
	el.each(function(i) {
		var h = $(this).innerHeight();
		Array.push(h);
	});
		
	Array.sort(sortNumber);
	var h = Array[0];
		
	el.each(function(i) {
		$(this).css('height', h);
	});
}

/*ppk create and read cookie functions www.quirksmode.com*/
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 = "";
	document.cookie = 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 trackflash(str) {
	var s_account="genedev"
	if (window.location.hostname.indexOf('pulmozyme-qa.gene.com') > -1) {
		s_account= "geneqa";
	} else {
		if (window.location.hostname.indexOf('pulmozyme-ua.gene.com') > -1) {
			s_account="geneua";
		} else {
			if (window.location.hostname.indexOf('www.pulmozyme.com') > -1) {
				s_account="genepulmozyme,geneexternal";
			}
		}
	}
	
	var s=s_gi(s_account);s.prop1=str;s.linkTrackVars='prop1';void(s.tl(true,'o',str));
}









// Create the tooltips only on document load
$(document).ready(function() 
{
   // Use the each() method to gain access to each elements attributes


      $('.pcg span.glossary').qtip(
      {
         content: {
            // Set the text to an image HTML string with the correct src URL to the loading image you want to use
            text: 'Loading ....',
            url: '/includes/glossary.jsp', // Use the rel attribute of each element for the url to load
            title: {
               text: 'Pulmozyme Glossary', // Give the tooltip a title using each elements text
					button: false
            }
         },
         position: {
            corner: {
               target: 'bottomMiddle'
            },
				adjust: {
					y: 10,
					screen: true
				}
				
         },
         style: {
           border: {
					color: '#002255'
            },
				classes: {
					title: 'titleBar'
				},
            width: 250 // Set the tooltip width
         },
			api: {
         // Retrieve the content when tooltip is first Shown
				onShow: function()
				{
					var rel = this.elements.target.attr('rel');
					//this.elements.content.childern('li').show();
					this.elements.tooltip.find('li#'+rel).show();
					
				//	$('.qtip-active #'+rel).show();
				//	alert(rel);
				}
			}
      });
   
});


