var linkPrefix = "#pseudo_";


function lbVideo(url,subFeature) { // checks to see if browser is fast enough to render heavy scripts
	var width = (subFeature) ? 520 : 940;
	var height= (subFeature) ? 280 : 565;
	var lb = document.getElementById('lightBoxContent');
		//lightBox(517,305,'<iframe width="100%" height="100%" frameborder="0" style="" src="'+url+'" id="shadowIframe" name="shadowIframe"></iframe>');
		lightBox(width,height,'iframe:'+url);
	if (!lb) {
		/*
		if (document.all) { // Internet Explorer
			var screenWidth = document.body.clientWidth;
			var screenHeight = document.body.clientHeight;
		} else { // FF, Opera etc.
			var screenWidth = window.innerWidth;
			var screenHeight = window.innerHeight;
		}
		if (BrowserDetect.browser=="Explorer" && BrowserDetect.version <= 7) {
			newScreenWidth = 15;
		}
		var newScreenWidth 	= parseInt((screenWidth/2) -(517/2));
		$("#lightbox").animate({
			"width": 517,
			"height": 305,
			"marginLeft": (newScreenWidth-15)
		},500);
		lb.innerHTML = '<iframe width="100%" height="100%" frameborder="0" style="" src="'+url+'" id="shadowIframe" name="shadowIframe"></iframe>';
		*/
		
	} else {
		//lightBox(517,305,'<iframe width="100%" height="100%" frameborder="0" style="" src="'+url+'" id="shadowIframe" name="shadowIframe"></iframe>');
	}
}


if (document.images) {
	img1 = new Image();
	img2 = new Image();
	img3 = new Image();
	img4 = new Image();
	img5 = new Image();
	img6 = new Image();
	img7 = new Image();
	img1.src = "http://media.worldvision.org/home/images/shadows_bg_full.png";
	img2.src = "http://media.worldvision.org/home/images/buttons_left_off.png";
	img3.src = "http://media.worldvision.org/home/images/buttons_center_off.png";
	img4.src = "http://media.worldvision.org/home/images/buttons_right_off.png";
	img5.src = "http://media.worldvision.org/home/images/buttons_left_on.png";
	img6.src = "http://media.worldvision.org/home/images/buttons_center_on.png";
	img7.src = "http://media.worldvision.org/home/images/buttons_right_on.png";
}


if (BrowserDetect.browser == "Explorer" && parseInt(BrowserDetect.version) <= 6) {
	sfHover = function() {
		var sfEls = document.getElementById("nav").getElementsByTagName("li");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className="";
			}
		}
	}
	if (window.attachEvent) window.attachEvent("onload", sfHover);
	// insert gif instead of png for window "x"
	window_x_src = "http://media.worldvision.org/home/images/window_x2.gif";
}

function correctPNG() { // correctly handle PNG transparency in Win IE 5.5 & 6.
	if (BrowserDetect.browser == "Explorer" && parseInt(BrowserDetect.version) <= 6) {
	   var arVersion = navigator.appVersion.split("MSIE")
	   var version = parseFloat(arVersion[1])
	   if ((version >= 5.5 && version < 7) && (document.body.filters)) {
		  for(var i=0; i<document.images.length; i++) {
			 var img = document.images[i]
			 var imgName = img.src.toUpperCase()
			 if (imgName.substring(imgName.length-3, imgName.length) == ("PNG" || "png"))
			 {
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML
				i = i-1
			 }
		  }
	   }
	}
}

var arrowHover = function() {
	var featureShorts = getElementsByClassName(document,"div","featureShort");
	for(var i=0;i<featureShorts.length;i++) {
		featureShorts[i].onmouseover = function() {
			var arrElements = (this.all)? this.all : this.getElementsByTagName("img");
			for(j =0;j<arrElements.length;j++) {
				if (arrElements[j].className == "arrowRight") {
					arrElements[j].src = "http://media.worldvision.org/home/images/right_arrow_orange.gif";
				}
			}
		}
		featureShorts[i].onmouseout = function() {
			var arrElements = (this.all)? this.all : this.getElementsByTagName("img");
			for(j =0;j<arrElements.length;j++) {
				if (arrElements[j].className == "arrowRight") {
					arrElements[j].src = "http://media.worldvision.org/home/images/right_arrow_grey.gif";
				}
			}
		}
	}
}

var linkToStory = function() {
	var linkToStories = getElementsByClassName(document,"a","linkToStory");
	for(var i=0;i<linkToStories.length;i++) {
		document.getElementById('anchorContainer').innerHTML += "<a name='"+linkToStories[i].href.substr(linkToStories[i].href.lastIndexOf("#"),linkToStories[i].href.length)+"'></a>";
		if (linkToStories[i].href.indexOf(linkPrefix+"story") == -1) {
			linkToStories[i].href = linkPrefix+linkToStories[i].href.substr(linkToStories[i].href.lastIndexOf("#")+1,linkToStories[i].href.length);
		}
	}
}

var lightBoxOnLoadBIT = true;
var lightBoxOnLoad = function() {
	if (lightBoxOnLoadBIT) {
		lightBoxOnLoadBIT=false;
		if (document.location.href.indexOf(linkPrefix) >= -1) {
			var loc = document.location.href;
			var storyId = loc.substr(loc.lastIndexOf(linkPrefix)+linkPrefix.length,loc.length);
			if (document.getElementById(storyId)) {
				var article_id = storyId.replace(/[^0-9]/g,'');
				lightBox(915,460,'ajax-article.php?article_id='+article_id);
			}
		}
	}
}

var featureShort = function() {
	var featureShorts = getElementsByClassName(document,"div","featureShort");
	for(var i=0;i<featureShorts.length;i++) {
		featureShorts[i].onclick = function() {
			storyContent = this.className.split(" ")[1].replace(/[^0-9]/g,'');
			lightBox(915,460,'ajax-article.php?article_id='+storyContent);
		}
	}
}

var searchField = function() {
	var search_field1 = document.getElementById("search_field1");
	search_field1.onfocus = function() {
		if (this.value == " search site") {
			this.value = "";
		}
	}
	search_field1.onblur = function() {
		if (this.value == "") {
			this.value = " search site";
		}
	}
}
/*
function callShadowBox(storyContent,src,width,height) {
	width = (width) ? width : 900;
	height= (height)?height : 450;
	var sc = (storyContent) ? document.getElementById(storyContent.substr(storyContent.lastIndexOf("#")+1,storyContent.length)) : null;
	setBoxOpacity = setOpacity;
	var shadowBoxObj = document.getElementById("floatingStory");
	if (heavyJsBrowserCheck() && (!shadowBoxObj || shadowBoxObj.style.left == "-999em")) { // run heavy js animations if browser can handle it
		shadowBox("floatingStory", sc, width, height, null,false,true,true,src);
	} else { // browser cannot handle heavy js animations
		shadowBox("floatingStory", sc, width, height, null,false,true,true,src);
		document.getElementById("floatingStory").style.opacity = 1;
	}
	return false;
}
*/


function referfriend(){
	var refer = window.location;
	var targeturl = 'https://www.worldvision.org/worldvision/guest.nsf/friend?OpenForm&lid=refer&lpos-refer&target=\'' + refer + '\'';
	window.open(targeturl,"Tellafriend",'menubars=no,toolbars=no,status=no,scrollbars=no,width=430,height=530,left=115,top=40');
}



if (document.location.href.indexOf("page=nonflash") == -1) {
	var MM_contentVersion = 8;
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if ( plugin ) {
			var words = navigator.plugins["Shockwave Flash"].description.split(" ");
			for (var i = 0; i < words.length; ++i)
			{
			if (isNaN(parseInt(words[i])))
			continue;
			var MM_PluginVersion = words[i]; 
			}
		var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
	}
	else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
		document.write('on error resume next \n');
		document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
		document.write('</SCR' + 'IPT\> \n');
	}
	if ( MM_FlashCanPlay ) {
		if (typeof(campaign)!='undefined') {
			campaign=campaign;
		} else {
			campaign='';
		}
		window.location.replace("http://www.worldvision.org/?OpenDocument"+campaign);
	}
}

function swapImg(oImg,newSrc) {oImg.src = newSrc;}
