/* Toggle #ht-03*/

function hideTout(){
	jQuery('#ht-03').css('display','none');
}

function showTout(){
	jQuery('#ht-03').css('display','inline');
}



/*===================================
  Missing from original bpv3.js begin
=====================================*/
function openWindowNoChrome(pageURL,windowName,pWidth,pHeight,pResize,pScrollbars) {
  positionTop = ((height/2) - (pHeight/2));
  positionLeft = ((width/2) - (pWidth/2));
  if (!pResize) pResize = 0;
  if (!pScrollbars) pScrollbars = 0;
  popup=window.open(pageURL,windowName, config='width=' + pWidth + ',height=' + pHeight + ',left=' + positionLeft + ',top=' + positionTop + ',resizable=' + pResize + ',menubar=0,location=0,directories=0,toolbar=0,scrollbars=' + pScrollbars + ',status=0'); 
	popup.focus();
}
/*===================================
  Missing from original bpv3.js end
=====================================*/


/*===================================
      BPv3 Enhancements begin
=====================================*/

//  Run when page has loaded
bpv3OnLoad = function()
{
    //ChangeSearchImage(document);
    var thisURL = window.location.host;
    
    if(thisURL!= null & thisURL.indexOf("strattera.com") > -1)
    {
        var sa = document.getElementById("site_actions");
        if(sa)
        {
	        sa.style.display = "none";
        }
    }
    
    applyFunction(document);
    //CheckFlashPlayer();
}

function openPopupInterstitial(thisHref)
{
	/*
	var w=500, h=400;
	if (window.showModalDialog)
	{
		window.showModalDialog(this.href, "", "dialogWidth:" + w + "px;dialogHeight:" + h + "px;dialogHide:yes;scroll:no;status:no;");
	}
	else
	{
		var t=(screen.availHeight-h)/2, l=(screen.availWidth-w)/2;
		alert (t + "," + l);
		window.open(this.href, "popupInterstitial", "width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no");
	}
	return false;
	*/
	
	jQuery.fn.colorbox({
		href: thisHref,
		iframe:true,
		width: '457px',
		innerHeight: '277px',
		opacity: '0.65',
		scrolling: false
	});
}

applyURL = function( node ){
	
    var navigateurl = unescape(getParams('URL'));
    var interstitialType = getParams('InterstitialType');

    if (interstitialType == "inline"){
        if ( node.nodeType == 1 && node.tagName == "A" && node.id.toUpperCase().indexOf("YES") == 0){
	        var linkNodeYes = document.getElementById(node.id);
	        linkNodeYes.href = navigateurl;
	        linkNodeYes.url = navigateurl;
	        linkNodeYes.onclick = myOpenWin;
        }
    	
        if ( node.nodeType == 1 && node.tagName == "A" && node.id.toUpperCase().indexOf("NO") == 0){
	        var linkNodeNo = document.getElementById(node.id);
	        //linkNodeNo.href = "#";
	        linkNodeNo.onclick = goBack;
        }
    } else {
        if (node.nodeType == 1 && node.tagName == "A" && node.id.toUpperCase().indexOf("YES") == 0){
	        var linkNodeYes = document.getElementById(node.id);
	        //linkNodeYes.href = navigateurl;
	        //alert(navigateurl);
	        linkNodeYes.onclick = function(){
	        
	        var noProtocol = navigateurl.substr(navigateurl.indexOf("//") + 2);
	        var arr = noProtocol.split("/");
	       
	        
	        	window.open(navigateurl); 
	        	parent.jQuery.fn.colorbox.close();
	        	dcsMultiTrack('DCS.dcssip',arr[0] ,'DCS.dcsuri',(arr.length<2 || arr[1]=="") ? "/" : arr[1],'WT.ti',navigateurl);
	        };	        
	 
	        
	        //Below code is used for IE browser to close the Interstitial Window. In other browsers, the interstital popup remains open
	        //linkNodeYes.onclick = openExternalLink;
        }
    	
        if ( node.nodeType == 1 && node.tagName == "A" && node.id.toUpperCase().indexOf("NO") == 0){
	        var linkNodeNo = document.getElementById(node.id);
	        linkNodeNo.href = "#";
	        linkNodeNo.onclick = closeWin;
        }
    }
}

//  Rewrite <a> to launch a popup
applyPopup = function(node)
{
	if ( node.nodeType == 1 && node.tagName == "A" && (node.id.indexOf("popup_") == 0 ||  node.className.indexOf('external') > -1))
	{
		jQuery(node).click(function(event){
			event.preventDefault();
			openPopupInterstitial(jQuery(this).attr('href'));
		});
	}
}

applyWebTrends = function( node )
{
    if ( node.nodeType == 1 && node.tagName == "A" && node.id.indexOf("webtrends_") == 0)
    {
	    node.url = node.href;
	    node.onclick = myCallWebTrends;
    }
}


/*===================================
-- Begin emailAFriend functionality
====================================*/
function emailafriend() 
{ 
	var currentSite = window.location.href; 
        var url = ""; 
        if (currentSite.indexOf("-authoring.rf.lilly.com") >= 0) {
          // url = "https://emailafriend-d6.xh1.lilly.com/index.jsp?url=" + currentSite;
          url = "https://emailafriend.lilly.com/index.jsp?url=" + currentSite;
        } else if (currentSite.indexOf("-pseudo.rf.lilly.com") >= 0) {
          // url = "https://emailafriend-qa.xh1.lilly.com/index.jsp?url=" + currentSite;
          url = "https://emailafriend.lilly.com/index.jsp?url=" + currentSite;
        } else {
          url = "https://emailafriend.lilly.com/index.jsp?url=" + currentSite;
        }

	window.open(url, 'EmailAFriend', 'height=500, resizable=yes, scrollbars=yes, width=650'); 
}
/*===================================
-- End emailAFriend functionality
====================================*/


/*===================================
      BPv3 Enhancements end
=====================================*/

var secNavArray = new Array();
var floodlightXml;

function floodlightLookup(key, page)
{
	if (!floodlightXml) return;
	if (!page) page = location.href.substring(location.href.lastIndexOf("/") + 1);
	var n = jQuery("page[name='" + page + "'] item[name='" + key + "']", floodlightXml);
	if (n) return n.attr("floodlight");
	return "";
}

function executeSearch(keywords, scope)
{
	var url = "/Pages/results.aspx?k=";
	if (keywords != null)
		url += jQuery.URLEncode(jQuery.trim(keywords));
	if (scope != null)
		url += "&s=" + jQuery.URLEncode(jQuery.trim(scope));
	location.href = url;
}

function updateSearch()
{
	var img = jQuery("img[title='Go Search']");
	img.attr("src", "/PublishingImages/search_button.gif");
	img.removeAttr("onmouseout");
	img.removeAttr("onmouseover");
	img.load(function(){
		jQuery("#search-container").css("display", "block");
		jQuery(this).unbind("load");
	}).each(function(){if (this.complete) jQuery(this).trigger("load");});
	
	var txt = jQuery("#search-controls input:text");
	txt.css("width", "auto");
	txt.addClass("search-box");
	
	var btn = jQuery("#search-controls a[title='Go Search']");
	btn.addClass("search-button");
	
	jQuery("#search-container").append(txt);
	jQuery("#search-container").append(btn);
}

function pageInit()
{
	updateSearch();

	jQuery("li.active img").attr("src", function(){
		var url = this.src, pos = url.lastIndexOf(".");
		return url.substring(0, pos) + "_over" + url.substr(pos);
	});
	

	jQuery("img.rollover, #primary-nav li:not('.active') a img").hover(
		function(){
			var url = this.src, pos = url.lastIndexOf(".");
			this.src = url.substring(0, pos) + "_over" + url.substr(pos);
		}, function(){
			var url = this.src, pos = url.lastIndexOf("_over");
			this.src = url.substring(0, pos) + url.substr(pos + 5);
		}
	);
	
	jQuery("#secondary-nav li:not('.active') a img").each(function(i){
		jQuery(this).attr('id', 'secNav_' + i);
		var src = jQuery(this).attr('src'), pos = src.lastIndexOf(".");

		secNavArray['secNav_' + i] = {
			'norm' : jQuery(this).attr('src'),
			'over' : src.substring(0, pos) + "_over" + src.substr(pos)
		};

		jQuery(this).hover(
			function(){
				jQuery(this).attr('src', secNavArray[jQuery(this).attr('id')]['over']).supersleight({shim: "/PublishingImages/spacer.gif"});
			},
			function(){
				jQuery(this).attr('src', secNavArray[jQuery(this).attr('id')]['norm']).supersleight({shim: "/PublishingImages/spacer.gif"});
			}
		);
		
	});

	if(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 6){
		jQuery("#container").supersleight({shim: "/PublishingImages/spacer.gif"});
	}
	
	jQuery('a.poplink').click(function(event){
		event.preventDefault();
		var rel = jQuery(this).attr('rel');
		jQuery('#' + rel).show();
		jQuery("iframe#floodlight").attr("src", 
			"http://fls.doubleclick.net/activityi;src=2602587;type=strat063;cat=" + 
			floodlightLookup(rel) + 
			";ord=" + (Math.random() * 10000000000000) + "?"
		);
	});
	
	jQuery('a.close').click(function(event){
		event.preventDefault();
		jQuery('#' + jQuery(this).attr('rel')).hide();
	});
	
	// FAQs
	jQuery('#popfaqs').click(function(event){
		event.preventDefault();
		var loc = window.location.pathname;
		var faqfile = (loc.indexOf('/child_') > 0) ? 'child' : 'adult';
		
		jQuery('.popup').hide();
		jQuery('#faqs').load('/Multimedia/faqs/' + faqfile + '_faqs.html', function(){
			
			jQuery('#faqs .close').click(function(event){
				//event.preventDefault();
				jQuery('#faqs').hide();
			});
			jQuery('#accordion').accordion({
				autoHeight: false,
				collapsible: true
			});
			jQuery('#faqs').show();
		});
	});
	
	jQuery.ajax({
		url: "/Multimedia/xml/floodlightLookup.xml", 
		dataType: "xml", 
		success: function(data, textStatus, XMLHttpRequest){floodlightXml = data;}
	});;
	
	// Colapsible ISI
	var isiCallout = jQuery('#importantSafetyCallout').html();
	var headerHeight = 252; // Calculates space for the header
	var defaultHeight = "105px"; // Default height of collapsed view
	var resize = true; // set flag of true so we can resize safety information when opened
	
    if (isiCallout != null) {
        jQuery('body').append(jQuery('#importantSafetyCallout'));
		jQuery('#footer').css('margin-bottom', '180px');  // Add enough margin on bottom so you can still see the footer.
    }

    jQuery('#expandSafetyCallout').click(function(){
		if(jQuery(this).hasClass('inactiveISI')){
			jQuery('#expandSafetyCallout').removeClass('inactiveISI').addClass('activeISI');

	        var windowHeight = jQuery(window).height();
			var safetyCalloutHeight = windowHeight - headerHeight;

			jQuery('.safetyContent').css({'margin-bottom':'15px', 'border-bottom':'1px solid #c6c6c6'});
			jQuery('.safetyContent').stop().animate({
				height: safetyCalloutHeight + 'px'
			}, 500, function(){
				resize = true;
				jQuery(window).resize(resizeSafetyInformation);
				jQuery(window).scroll(resizeSafetyInformation);
			});
			return false;
		} else if(jQuery(this).hasClass('activeISI')){
			resize = false;
			jQuery('#expandSafetyCallout').removeClass('activeISI').addClass('inactiveISI');
			jQuery('.safetyContent').css({'margin-bottom':'0px', 'border-bottom':'none'});			
			jQuery('.safetyContent').stop().animate({ height: defaultHeight }, 500);
			return false;
		}

		function resizeSafetyInformation(){
			if(resize == false){return false;}
			var windowHeight = jQuery(window).height();
			var safetyCalloutHeight = windowHeight - headerHeight;
			jQuery('.safetyContent').css('height', safetyCalloutHeight);
		}
	});
	
}


