/*===================================
  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);
}

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;
		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;
}

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;
	        linkNodeYes.onclick = function(){ parent.window.location = 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)
	{
		jQuery('#' + node.id).click(function(event){
			event.preventDefault();
			openPopupInterstitial(jQuery(this).attr('href'));
		});
	}
}*/

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").css("display", "block");
		jQuery(this).unbind("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").append(txt);
	jQuery("#search").append(btn);
}

function pageInit()
{
	updateSearch();
	
	//Experimental - Remove WebPart <table> wrapper
	jQuery("*[webpartid]").each(function(){
		var wp=jQuery(this), t=wp.parents("table");
		t.before(wp.children());
		t.remove();
	});
	
	//AutoScroll ISI
	startScrollingIsi();
	
	jQuery("img.rollover, #tnav li:not('.active') a img, #side-nav li:not('.active') a img").hover(
		function(){
			var url = ((this.rel != null) && (this.rel.length-this.rel.indexOf(".png") == 4)) ? this.rel : this.src;
			var pos = url.lastIndexOf(".");
			this.src = url.substring(0, pos) + "_over" + url.substr(pos);
			jQuery(this).supersleight({shim: "/PublishingImages/spacer.gif"});
		}, function(){
			var url = ((this.rel != null) && (this.rel.length-this.rel.indexOf(".png") == 4)) ? this.rel : this.src;
			var pos = url.lastIndexOf("_over");
			this.src = url.substring(0, pos) + url.substr(pos + 5);
			jQuery(this).supersleight({shim: "/PublishingImages/spacer.gif"});
		}
	);

	jQuery("#tnav li.active img, #side-nav li.active img").attr("src", function(){
		var url = this.src, pos = url.lastIndexOf(".");
		return url.substring(0, pos) + "_over" + url.substr(pos);
	});
	
	jQuery("a.colorboxChart").each(function(){
		var me = jQuery(this);
		me.colorbox({inline: true, href: me.attr("href")});
		me.attr("href", "#");
	});
	jQuery("a.colorboxLink").colorbox();
	jQuery("a.videoLink").each(function(){
		var me = jQuery(this);
		var arr = me.attr("coords").split(",");
		if (arr.length<2) return;
		me.colorbox({innerWidth: parseInt(arr[0], 10), innerHeight: parseInt(arr[1], 10), scrolling: false});
	});
	
	jQuery("#container").supersleight({shim: "/PublishingImages/spacer.gif"});
}

