var tempImg; /*for videos images*/
var tempImgSrc; 
/* function for flash navigation */
var url;

function sendQueryString()
{
	var url;
	
	url = document.location.href;
	return url;
}


/* Methods for resizing the div from Flash at runtime */
function setDivSize(newW, newH)
{
	document.getElementById('toolbar').style.width = newW+"px";
	document.getElementById('toolbar').style.height = newH+"px";

	document.getElementById('toolbar').firstChild.style.width = newW+"px";
	document.getElementById('toolbar').firstChild.style.height = newH+"px";
	
}

/* setting the zIndex */
function setZIndex(num)
{
    var toolbar = document.getElementById('toolbar');
    if(toolbar && toolbar != null){
        toolbar.parentNode.className = (parseInt(num) == 1) ? 'parent chrome4 xycontainer share sp3874 pzindex': 'parent chrome4 xycontainer share sp3874 nzindex';
    }	
}

/* Print it */
function printIt()
{
	window.print(); 
}

/* Im it */
function imFriend(url)
{
    var result = false;
    try
	{
	    var msgr = new ActiveXObject("MSNMessenger.Hotmail2Control");
        msgr.InstantMessage2("", url, 0);
        result = true;
    }
    catch (ex)
    {
	    msgr=null;
    }
    return result;
}

/* for test */
function showAlert(value)
{
	//alert(value);
}
	
function getFlashObject()
{
	var flashObj;

	if (navigator.appName.indexOf("Microsoft") != -1) {
		flashObj = window["flash_videoobj"];
	}
	else {
		if (document["flash_videoobj"].length) {
			flashObj = document["flash_videoobj"][1];
		}
		else {
			flashObj = document["flash_videoobj"];
		}
	}
	
	return flashObj;
}

//function to call clicked video
function callToActionscript() 
{

    var id = this.id;     
      	
    var splitLinkId = id.split('_');
    if(splitLinkId[1] == "img")	{
		if(!tempImg || tempImg == null) {
			tempImg = this;	
		}
		else{
			tempImg.childNodes[0].src = tempImgSrc;
			tempImg = this;	
		}
	}
	else if(splitLinkId[1] == "text") {
	    if(!tempImg || tempImg == null) {
			tempImg =  document.getElementById( "playvideo_img_" + splitLinkId[2] );
		}
		else{
			tempImg.childNodes[0].src = tempImgSrc;
			tempImg =  document.getElementById( "playvideo_img_" + splitLinkId[2] );
		}
}
	
	   tempImgSrc = tempImg.childNodes[0].src;
	   tempImg.childNodes[0].src = 			"http://stc.sandblu.msn-int.com/br/dd/school-food-trust/images/" + 			splitLinkId[2]+"-Active.jpg";		
	
    if( splitLinkId.length == 3){
	  	
    	var flashObj = getFlashObject();
	if(flashObj != null)
		flashObj.sendToActionscript(parseInt(splitLinkId[2]));
	}
	return false;
}


/* Start of the function for videoplayer Fullscreen */

if(!window.Msn)window.Msn={};Msn.FlashWithVars=new function(){var b=this,a=null,me=b,flv=a,d=document,w=window;function E(a){return d.getElementById(a)}function flVer(){if(flv===a){flv=0;var i,f=a,p=w.navigator.plugins;if(p&&p.length){f=p["Shockwave Flash"]||p["Shockwave Flash 2.0"];if(f&&(i=f.description))flv=parseInt(i.substring(i.indexOf(".")-2))}else if(w.ActiveXObject)for(i=15;i>2&&!f;--i){eval("try{f=new ActiveXObject('ShockwaveFlash.ShockwaveFlash.'+i);}catch(e){}");if(f)flv=i}}return flv}b.Version=function(){return flVer()};b.BuildWithVars=function(l,f,c,k,j,e,i){var g=5;if(c){var a=c.lastIndexOf(" ");if(a>0)a=parseInt(c.substring(a));else a=parseInt(c);g=isNaN(a)?g:a}if(g<=flVer()){var b='<object id="'+e+'obj" type="application/x-shockwave-flash" width="'+k+'" height="'+j+'" data="'+l+'">';for(var a in f)if(f[a])b+='<param name="'+a+'" value="'+f[a]+'"/>';b+='<param name="allowFullScreen" value="True"/>';b+='<param name="flashvars" value="'+i+'"/>';b+="</object>";var h=e?d.getElementById(e):a;if(h)h.innerHTML=b;else d.write(b)}};return b};

/* End of the function for videoplayer Fullscreen */

window.onload = function()
{
	var contentarea = document.getElementById('area1');
	var printdiv = document.getElementById('printbtn');
 if(contentarea  != null)
  {
	var video_links =  contentarea.getElementsByTagName("a");
	for(var i  =0 ; i<video_links.length;i++)
           {
		var linkId =  video_links[i].id;
		var splitLinkId = linkId.split('_');
		if( splitLinkId.length > 1){
			if(splitLinkId[0] == "playvideo"){ 
				video_links[i].onclick = callToActionscript; 
				//video_links[i].href = "";
				video_links[i].removeAttribute("href");
				video_links[i].style.cursor = "pointer";
			}
		}
	   }
	var abstractDivs =  contentarea.getElementsByTagName("td");
	for(var i  = 0 ; i< abstractDivs.length;i++)
           {
		if(abstractDivs[i].className == "abstract"){ 

			var anchorDivs = abstractDivs[i].getElementsByTagName("a");
			for(var j  =0 ; j< anchorDivs.length;j++)
           		{
				anchorDivs[j].target = "_blank";
			}		
	
		}
	    }
   }
   if(printdiv && printdiv != null){
	
	printdiv.onclick = printIt;
	}
	
  
}
/* Start: Gallery Page JS - To apply a class when big images are shown */
function validateURL(form) {
    var v = new RegExp();
    v.compile("^([A-Za-z]+)(://[A-Za-z0-9-_\]+).([A-Za-z0-9-_%&\?\/#:.=\\s]+)$");
    if (!v.test(form)) {
        return false;
    }
    return true;
}
function alterBodyClass() {

    if (validateURL(document.location.href)) {
        //Let's set the class attribute of body if we're in the large image scene of the flash
        if (-1 != document.location.href.indexOf("imageindex")) {
            /*document.body.setAttribute("className", "wide glargeimg");*/
		//if(navigator.appName=='Microsoft Internet Explorer')
		//{
		    //document.getElementById('wrapper').setAttribute("className", "page7 region9 glargeimg");
		//}
		//else
		//{
			//var area1 = document.getElementById('area1');
			/*area1.childNodes[5].style.display='none';*/
			//area1.childNodes[7].style.display='none';
			//area1.childNodes[9].className+=' ffpgallery';
			//document.getElementById('page').style.height='1100px';
			//document.getElementById('wrapper').style.background = 'url("http://st.sand.msn-int.com/br/dd/UnitedBiscuits/images/bg/UB_Gallery_largeBG.jpg") center top';
		//}
			var wrapperDiv = document.getElementById("wrapper");
			wrapperDiv.className = "page7 region9 glargeimg";
        }
		else{
			var wrapperDiv = document.getElementById("wrapper");
			wrapperDiv.className = "page7 region9 gsmallimg";	
		}
    }
}

function waitForPageLoad() {
    if (document.getElementById('foot') == null) {
        setTimeout(waitForPageLoad, 100);
    } else {
        alterBodyClass();
    }
}

waitForPageLoad();
/* End: Gallery Page JS */



