//Callback for returned video data.  Renders the results in the right column
function vidJSONCallback(jsonResult)
{
	var contentDiv = document.getElementById("rightJSONContent");
	contentDiv.innerHTML = "";
	for(var i = 0; i < jsonResult.video.length && i < 3; i++)
	{
		var itemDiv = contentDiv.appendChild(document.createElement("div"));
		if(i < jsonResult.video.length - 1 && i < 2)
			itemDiv.className = "vidItem";
		var vidItem = jsonResult.video[i];
		
		var videoThumbnailSrc = "";
		for(var j = 0; j < vidItem.files.file.length; j++)
		{
			if(vidItem.files.file[j].$formatCode == "2007")
			{
				videoThumbnailSrc = vidItem.files.file[j].uri.$;
				break;
			}
		}
		
		var url = "/video.aspx?tab=1&videoid=" + vidItem.uuid.$;
		
		var imgA = itemDiv.appendChild(document.createElement("a"));
		imgA.href = url;
		imgA.onclick = playRightVideo;
		imgA.vidUuid = vidItem.uuid.$;
		imgA.className = "image";
		
		var img = imgA.appendChild(document.createElement("img"));
		img.src = videoThumbnailSrc;
		
		var titleA = itemDiv.appendChild(document.createElement("a"));
		titleA.href = url;
		titleA.onclick = playRightVideo;
		titleA.vidUuid = vidItem.uuid.$;
		
		var title = titleA.appendChild(document.createElement("span"));
		title.title = vidItem.title.$;
		title.innerHTML = vidItem.title.$.truncate(40);
		
		var description = itemDiv.appendChild(document.createElement("div"));
		description.title = vidItem.description.$;
		description.innerHTML = vidItem.description.$.truncate(120);
		description.className = "description";

		var clearDiv = itemDiv.appendChild(document.createElement("div"));
		clearDiv.style.clear = "both";
		clearDiv.style.height = "0";
		clearDiv.style.fontSize = "0";
	}
}

function playRightVideo()
{
 //window.open('http://ninemsn.video.msn.com/v/en-au/v.htm?g=' + this.vidUuid,'msnVDWd','width=788,height=428,status=1,scrollbars=0,resizable=0');
}

//Makes JSON call to retreive data for right video
function renderRightVideo()
{

	Ninemsn.Global.ContentManager.GetContent("http://edge1.catalog.video.msn.com/videoByTag.aspx?ns=Publisher&tag=SplashNews&mk=en-nz&responseEncoding=json&callbackName=vidJSONCallback&cache=" + parseInt((new Date()).getTime()/1000/60/60*10), function(){});
}

//Truncates E! News main story and top 5 links on the E! ONLINE VIDEO home page
function truncateHomeAutoNews()
{
	var newsDiv = document.getElementById("top5otherstories");
	if(newsDiv)
	{
		var links = newsDiv.getElementsByTagName("a");
		for(var i = 0; i < links.length; i++)
			links[i].innerHTML = links[i].innerHTML.truncate(28);
	}
	var newsSpan1 = document.getElementById("enewsmainstorytitle");
	if(newsSpan1)
	{
		var links = newsSpan1.getElementsByTagName("a");
		for(var j = 0; j < links.length; j++)
			links[j].innerHTML = links[j].innerHTML.truncate(45);
	}
	var newsSpan2 = document.getElementById("enewsmainstorytext");
	if(newsSpan2)
	{
		var links = newsSpan2.getElementsByTagName("p");
		for(var k = 0; k < links.length; k++)
			links[k].innerHTML = links[k].innerHTML.truncate(122);
	}


	
}


function truncateRightColGalleries()
{
	var newsDiv = document.getElementById("cat_hl_88182");
	if(newsDiv)
	{
		var links = newsDiv.getElementsByTagName("a");
		for(var i = 0; i < links.length; i++)
			links[i].innerHTML = links[i].innerHTML.truncate(30);
	}
	
}


//Truncates a given string to a given length
String.prototype.truncate = function(len)
{
	if(this.length > len + 3)
		return this.substring(0, len) + "...";
	else
		return this;
}


//Set nav selected tab color
function setNavSelectedTab() {

switch (JS_SECTIONID)
{
case '6481': //Daily Fix
  document.getElementById("nav_cele").style.color='#000000';
  document.getElementById("nav_df").style.color='#393939';
  break;
case '6476': // Video
  document.getElementById("nav_video").style.color='#000000';
  //document.getElementById("nav_ev").style.color='#393939';
  break;
case '3203': // Home  
  document.getElementById("nav_video").style.color='#000000';
  //document.getElementById("nav_ev").style.color='#393939';
  break;
case '6480': // Article Index  
  document.getElementById("nav_cele").style.color='#000000';
  document.getElementById("nav_en").style.color='#393939';
  break;
case '6467': // ENews  
  document.getElementById("nav_cele").style.color='#000000';
  document.getElementById("nav_en").style.color='#393939';
  break;
case '6554': // Gallery  
  document.getElementById("nav_galleries").style.color='#000000';
  document.getElementById("nav_cg").style.color='#393939';
  break;
case '6547': // TV  
  document.getElementById("nav_tv").style.color='#000000';
  break;
}

}


//Update Ninemsn info in Blog control guidelines content
function setBlogGuidelineContent() {

        if ( document.getElementById("ugc_guidlines_content") != undefined ) {
        var el=document.getElementById("ugc_guidlines_content");

el.innerHTML="<DIV class=text><STRONG>Thank you for sharing your opinions with other users of MSN NZ. People will find your comments more helpful if you include relevant information and avoid some common pitfalls.</STRONG></DIV><DIV class=text>Please note: All reviews and comments submitted are subject to moderation, MSN NZ reserves the right to alter and / or remove any content that does not comply with usage guidelines.</div><DIV class=text><B>What to include in your comment:</B><ul><LI>A title that briefly summarises the opinion expressed in the comment.</LI><LI>Additional comments adding more detail.</LI><LI>Comparisons to other similar products, if this is relevant.</LI><LI>To create a new paragraph, press the Enter key twice.</LI></ul></div><DIV class=text><B>What not to include:</B><ul><LI>Information that will quickly go out of date.</LI><LI>Comments on other comments or commenters.</LI><LI>Language that other users may find offensive.</LI><LI>comments of one sentence or less. Provide information to support your opinion.</LI><LI>Personal information like your email address or telephone number.</LI><LI>HTML coding. Tags like &lt;b&gt; or &lt;i&gt; will not be recognised.</LI></ul></div>";
      }   

}

function addTooltipToSlideshowDescription() {
	var div = document.getElementById("slide_content");
	if(div!=null) {
		div.title = div.innerText;
	}
}

addEvent(window, 'load', addTooltipToSlideshowDescription);















