var currentMoviesSeason = CURRENT_SEASON;//changes per chosen season
var currentVideosSeason = CURRENT_SEASON;//changes per chosen season
var krishimDivsPositioned = false;// flag that indicated if the divs were positioned
function setUrl(tp,id)
{
	if (InternetExplorer){
		var ifChildFrame = document.getElementById("tvIframe");		
		var oChildFrameDoc = (ifChildFrame.contentDocument) ?ifChildFrame.contentDocument : ifChildFrame.contentWindow.document;
		oChildFrameDoc.parentWindow.Player.controls.stop(); 	
		if (tp == 2)
			oChildFrameDoc.parentWindow.Player.url = promo;								
		
		else if (tp == 3)
			oChildFrameDoc.parentWindow.Player.url = "tmc";							
				
		else
		{
			if (id == null){
				oChildFrameDoc.parentWindow.Player.url = "tmc";			
			}
			else
				if (tp == 0)
					oChildFrameDoc.parentWindow.Player.url = videoDict(id);			
				else if (tp == 1)
					oChildFrameDoc.parentWindow.Player.url = videoDictVideo(id);																	
		}						
		oChildFrameDoc.parentWindow.Player.controls.play(); 
	}
	else{
		if (tp == 2)
			document.getElementById("tvObject").innerHTML = '<iframe id=tvIframe width="332" height="306" MARGINWIDTH=0 MARGINHEIGHT=0 FRAMEBORDER=0 SCROLLING=no src="tvObject.jhtml?ClipURL='+promo+'&PicUrl='+PicUrl+'" frameborder=0></iframe>';							
		else if (tp == 3)
			document.getElementById("tvObject").innerHTML = '<iframe id=tvIframe width="332" height="306" MARGINWIDTH=0 MARGINHEIGHT=0 FRAMEBORDER=0 SCROLLING=no src="tvObject.jhtml?ClipURL=&PicUrl='+PicUrl+'" frameborder=0></iframe>';							
		else
		{
			if (id == null)
				document.getElementById("tvObject").innerHTML = '<iframe id=tvIframe width="332" height="306" MARGINWIDTH=0 MARGINHEIGHT=0 FRAMEBORDER=0 SCROLLING=no src="tvObject.jhtml?ClipURL=&PicUrl='+PicUrl+'" frameborder=0></iframe>';										
			else
				if (tp == 0)
					document.getElementById("tvObject").innerHTML = '<iframe id=tvIframe width="332" height="306" MARGINWIDTH=0 MARGINHEIGHT=0 FRAMEBORDER=0 SCROLLING=no src="tvObject.jhtml?ClipURL='+videoDict(id)+'&PicUrl='+PicUrl+'" frameborder=0></iframe>';							
				else if (tp == 1)
					document.getElementById("tvObject").innerHTML = '<iframe id=tvIframe width="332" height="306" MARGINWIDTH=0 MARGINHEIGHT=0 FRAMEBORDER=0 SCROLLING=no src="tvObject.jhtml?ClipURL='+videoDictVideo(id)+'&PicUrl='+PicUrl+'" frameborder=0></iframe>';							
		}		

	}
}

function setBiography(id)
{
	document.getElementById("biog").innerHTML = contentDict(id);//set biography
	setUrl(0,id);	
}

function setBiographyV(id)
{
	document.getElementById("biogV").innerHTML = contentDictVideo(id);//set biography
	setUrl(1,id);	
}

function gallery()
{
  	currentSection = "gallery";  	
	document.getElementById("contentPar").style.display = "inline";	
	document.getElementById("aboutContent").style.display = "none";	
	document.getElementById("themarkerContent").style.display = "none";	
	document.getElementById("contentVideo").style.display = "none";	
	document.getElementById("commentaryContent").style.display = "none";	
	document.getElementById("tblBut").style.display = "none";	
	setUrl(0,defaultMovie);	
	setBiography(defaultMovie);
}

function videoGallery()
{
	currentSection = "video";  	
	document.getElementById("contentVideo").style.display = "inline";	
	document.getElementById("aboutContent").style.display = "none";	
	document.getElementById("contentPar").style.display = "none";	
	document.getElementById("themarkerContent").style.display = "none";	
	document.getElementById("commentaryContent").style.display = "none";	
	document.getElementById("tblBut").style.display = "none";	
	setUrl(1,defaultVideo);	
	setBiographyV(defaultVideo);
}

function dailyMovie()
{
	currentSection == "intro";
	document.getElementById("aboutContent").style.display = "inline";	
	document.getElementById("contentPar").style.display = "none";		
	document.getElementById("contentVideo").style.display = "none";	
	document.getElementById("themarkerContent").style.display = "none";	
	document.getElementById("commentaryContent").style.display = "none";	
	document.getElementById("tblBut").style.display = "inline";	
	setUrl(2);	
}

function themarkerTab()
{
	currentSection == "themarkerTab";
	document.getElementById("aboutContent").style.display = "none";	
	document.getElementById("contentPar").style.display = "none";		
	document.getElementById("contentVideo").style.display = "none";	
	document.getElementById("themarkerContent").style.display = "inline";	
	document.getElementById("commentaryContent").style.display = "none";	
	document.getElementById("tblBut").style.display = "none";	
	setUrl(3);	
}

function commentaryTab()
{
	currentSection == "commentaryTab";
	document.getElementById("aboutContent").style.display = "none";	
	document.getElementById("contentPar").style.display = "none";		
	document.getElementById("contentVideo").style.display = "none";	
	document.getElementById("themarkerContent").style.display = "none";	
	document.getElementById("commentaryContent").style.display = "inline";	
	document.getElementById("tblBut").style.display = "none";	
	setUrl(3);	
}

function updateMovieUrl(url)
{
	if (InternetExplorer){
		var ifChildFrame = document.getElementById("tvIframe");		
		var oChildFrameDoc = (ifChildFrame.contentDocument) ?ifChildFrame.contentDocument : ifChildFrame.contentWindow.document;
		oChildFrameDoc.parentWindow.Player.controls.stop(); 	
		oChildFrameDoc.parentWindow.Player.url = url;																	
		oChildFrameDoc.parentWindow.Player.controls.play(); 
	}
	else
		document.getElementById("tvObject").innerHTML = '<iframe id=tvIframe width="332" height="306" MARGINWIDTH=0 MARGINHEIGHT=0 FRAMEBORDER=0 SCROLLING=no src="tvObject.jhtml?ClipURL='+url+'&PicUrl='+PicUrl+'" frameborder=0></iframe>';							
}

function changeColor(sectionId)
{
	if(sectionId == 1)
		dailyMovie();
	else if(sectionId == 2)
		gallery();
	else if(sectionId == 3)
		videoGallery();
	else if(sectionId == 4)
		themarkerTab();
	else if(sectionId == 5)
		commentaryTab();
	
	if (sectionIdTemp != sectionId){		
		document.getElementById("menu"+sectionIdTemp).className = "krishimMenuLink";		
		document.getElementById("arr"+sectionIdTemp).style.display = "none";		
		document.getElementById("menu"+sectionId).className = "krishimMenuHighlightedLink";		
		document.getElementById("arr"+sectionId).style.display = "inline";		
	}
	sectionIdTemp = sectionId;
}

function showMenu(menuDiv)
{
	if(krishimDivsPositioned)
	{
		menuDiv.style.display = "block";
		document.getElementById("sharksMenuTable").className="krishimSubMenuBg";
	}
}

function closeMenu(menuDiv)
{
	menuDiv.style.display = "none";
	document.getElementById("sharksMenuTable").className="";
}

function showVideoMenu(menuDiv)
{
	if(krishimDivsPositioned)
	{
		menuDiv.style.display = "block";
		document.getElementById("videoMenuTable").className="krishimSubMenuBg";
	}
}

function closeVideoMenu(menuDiv)
{
	menuDiv.style.display = "none";
	document.getElementById("videoMenuTable").className="";
}


	function initialize(){			
		if ((window.scrollspeed!=0) && (currentSection == "gallery")){						
			speed=window.scrollspeed
			scrollwindow()
		}
	}
	
	function stopInterval()
	{
		window.clearInterval (interval);
		interval = "";
	}

	function scrollwindow(){
		maxScroll = document.all['galleries'].scrollLeft;			
		temp=(document.all)?document.getElementById("galleries").scrollRight : window.pageXOffset
		alt=(alt==0)? 1 : 0
		 if (alt==0)
			curpos1=temp
		 else
			curpos2=temp
		document.all['galleries'].scrollLeft=document.all['galleries'].scrollLeft+speed;
		
		if(document.all['galleries'].scrollLeft == 0){
			document.getElementById("imgLeft").src = "/tmc/i/marketing/hakrishim/move_left_dis.gif";
			document.getElementById("arrowL").style.cursor='default';				
		}
		else{
			document.getElementById("imgLeft").src = "/tmc/i/forecast/move_left.gif";
			document.getElementById("arrowL").style.cursor='hand';				
		}
			
		if(maxScroll == document.all['galleries'].scrollLeft && maxScroll != 0){
			document.getElementById("imgRight").src = "/tmc/i/marketing/hakrishim/move_right_dis.gif";
			document.getElementById("arrowR").style.cursor='default';				
		}
		else{
			document.getElementById("imgRight").src = "/tmc/i/forecast/move_right.gif";
			document.getElementById("arrowR").style.cursor='hand';				
		}
	}

function toggleMoviesSeason(season)
{
	if(season != currentMoviesSeason)
	{
		document.getElementById("sectionMoviesTitle").innerHTML = seasonMoviesTitles.get(season);
		buildMovies(seasonToMovies.get(season));
		currentMoviesSeason = season;
	}
	changeColor(2);
	closeMenu(document.getElementById("sharksMenu"));
}

function buildMovies(moviesArray)
{
	var count = moviesArray.length;
	var tableWidth = count*108;		
	var str = "";
	str+='<table cellpadding="0" cellspacing="0" width="'+tableWidth+'" height="92" align="right" id="pictures" border="0"><tr><td height="2"></td></tr><tr>';
	for(var i=0;i<moviesArray.length;i++)
	{
		str+='<td style="width:5;height:92;"><img src="/tmc/i/c/0.gif" width="5" height="105"></td><td valign=top align=right class="krishimBox"><table cellpadding="0" cellspacing="0" width="100%" style="height:92px;"><tr><td style="height:61px;">';
		str+='<table cellpadding=0 cellspacing=0 width=100% height=100% class=krishimPicFrame><tr><td><a style=cursor:hand; onclick=top.setBiography("'+moviesArray[i].picId+'")><img src='+moviesArray[i].gifPath+' width=101 height=67></a></td></tr></table>';
		str+='</td></tr><tr><td class="krishimBoxDown"><table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0"><tr><td height="1"></td></tr><tr><td class="picText" align="center" valign="middle"><b>'+moviesArray[i].name+'</b></td></tr><tr><td height="1"></td></tr></table></td></tr></table></td>';
	}
	str+='</tr><tr><td height="2"></td></tr></table>';
	document.getElementById("galleries").innerHTML = str;
	maxScroll = document.body.scrollLeft;
	if ((count!="") && (count < 3))
		document.getElementById("imgLeft").src = "/tmc/i/marketing/hakrishim/move_left_dis.gif";
	else
		interval = setInterval("initialize()",10)
	defaultMovie=moviesArray[0].picId;
}

	function initializeV(){			
		if ((window.scrollspeedV!=0) && (currentSection == "video")){						
			speedV=window.scrollspeedV
			scrollwindowV()
		}
	}
	
	function stopIntervalV()
	{
		window.clearInterval (intervalV);
		intervalV = "";
	}

	function scrollwindowV(){
		maxScrollV = document.all['videos'].scrollLeft;			
		tempV=(document.all)?document.getElementById("videos").scrollRight : window.pageXOffset
		altV=(altV==0)? 1 : 0
		 if (altV==0)
			curpos1V=tempV
		 else
			curpos2V=tempV
		document.all['videos'].scrollLeft=document.all['videos'].scrollLeft+speedV;
		
		if(document.all['videos'].scrollLeft == 0){
			document.getElementById("imgLeftV").src = "/tmc/i/marketing/hakrishim/move_left_dis.gif";
			document.getElementById("arrowLV").style.cursor='default';	
		}
		else{
			document.getElementById("imgLeftV").src = "/tmc/i/forecast/move_left.gif";
			document.getElementById("arrowLV").style.cursor='hand';	
		}
			
		if(maxScrollV == document.all['videos'].scrollLeft && maxScrollV != 0){
			document.getElementById("imgRightV").src = "/tmc/i/marketing/hakrishim/move_right_dis.gif";
			document.getElementById("arrowRV").style.cursor='default';	
		}
		else{
			document.getElementById("imgRightV").src = "/tmc/i/forecast/move_right.gif";
			document.getElementById("arrowRV").style.cursor='hand';	
		}
	}

function buildVideos(videosArray)
{
	var countV = videosArray.length;		
	var tableWidth = countV*108;		
	var str = "";
	str+='<table cellpadding="0" cellspacing="0" width="'+tableWidth+'" height="92" align="right" id="picturesV" border="0""><tr><td height="2"></td></tr><tr>';
	for(var i=0;i<videosArray.length;i++)
	{
		str+='<td style="width:5;height:92;"><img src="/tmc/i/c/0.gif" width="5" height="105"></td><td valign=top align=right class="krishimBox"><table cellpadding="0" cellspacing="0" width="100%" style="height:92px;"><tr><td style="height:61px;">';
		str+='<table cellpadding=0 cellspacing=0 width=100% height=100% class=krishimPicFrame><tr><td><a style=cursor:hand; onclick=top.setBiographyV("'+videosArray[i].picId+'")><img src='+videosArray[i].gifPath+' width=101 height=67></a></td></tr></table>';
		str+='</td></tr><tr><td class="krishimBoxDown"><table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0"><tr><td height="1"></td></tr><tr><td class="picText" align="center" valign="middle"><b>'+videosArray[i].name+'</b></td></tr><tr><td height="1"></td></tr></table></td></tr></table></td>';
	}
	str+='</tr><tr><td height="2"></td></tr></table>';
	document.getElementById("videos").innerHTML = str;
	maxScrollV = document.body.scrollLeft;
	if ((countV!="") && (countV < 3))
		document.getElementById("imgLeftV").src = "/tmc/i/marketing/hakrishim/move_left_dis.gif";
	else
		intervalV = setInterval("initializeV()",10);
	defaultVideo=videosArray[0].picId;
}

function toggleVideosSeason(season)
{
	if(season != currentVideosSeason)
	{
		document.getElementById("sectionVideosTitle").innerHTML = seasonMoviesTitles.get(season);
		buildVideos(seasonToVideos.get(season));
		currentVideosSeason = season;
	}
	changeColor(3);
	closeVideoMenu(document.getElementById("videoMenu"));
}

function positionKrishimDivs()
{
	var refPosArr = getAbsolutePos(document.getElementById("sharksMenuTable"));
	document.getElementById("sharksMenu").style.left = refPosArr[0]-76;
	document.getElementById("sharksMenu").style.top = refPosArr[1]+13;
	refPosArr = getAbsolutePos(document.getElementById("videoMenuTable"));
	document.getElementById("videoMenu").style.left = refPosArr[0]-94;
	document.getElementById("videoMenu").style.top = refPosArr[1]+13;
	krishimDivsPositioned = true;
}