﻿

function drawNielsen(ref) {
    $("#nielsenTracker").remove();    
    var $tracker = $(document.createElement("img"));
    $tracker.attr("src", ["//secure-us.imrworldwide.com/cgi-bin/m?ci=us-203529h&cg=0&cc=1&si=", escape(window.location.href), "&rp=", escape(document.referrer), "&ts=compact&rnd=", (new Date()).getTime()].join(''));
    $tracker.attr("id", "nielsenTracker").attr("ref", ref).css("width", "1px").css("height", "1px");
    $tracker.appendTo($("body"));
    TVGOL.Events.dispatchEvent("TVGOL.listings.closeup.loaded: " + ref);
    return $tracker;
}

function getCloseupTime(strStamp)
{
	return strStamp.substring(4,6) + "/" + strStamp.substring(6,8) + "/" + strStamp.substring(0,4) + " " + strStamp.substring(8,10) + ":" + strStamp.substring(10,12);
}


function autoOpenCloseup()
{
    var idx = figIndex;
    var row = figRow;
    var osf = figOffsetFudge;
    
    var rht = 40;
    
    if(isIE)
    { rht = 41; }
    
    // alert("idx="+idx+" row="+row+" ads="+ads);
    
    clearFindInGrid();
    iGridScrollTop = (row*rht)+(osf)-80;
    optionGenreFilter = 0;
    optionFavChannels = false;
    f3(idx,row);
    scrollTheGrid();
}


function cu(nIndex, iSeriesID, iMovieID)
{    
	getFlyoverInfo(0);

	var objRowData = objGridData[nIndex];
		
	countGridAction("MoreInfo", objRowData[colProgramTitle]);    
	 
	var theURL = "/detail/generic.aspx";

    var iCategory = objRowData[colCategory];
    
    if(parseInt(iSeriesID,10)>0)
    {
        theURL += "?sourcetype=s&id=" + iSeriesID + "&episodeid=" + objRowData[colProgramID];
    }
    else if(parseInt(iMovieID,10)>0)
    {
        theURL += "?sourcetype=m&id=" + iMovieID;
    }
    else 
    // all other shows
    {
        theURL += "?sourcetype=s&programid=" + objRowData[colProgramID];
    }
    
	var objDetails = xmlDetailData.responseText.split("\t");
	srCountGridEvent(objDetails[colAjaxCategory], objDetails[colAjaxSubCategory], objRowData[colProgramTitle], objRowData[colProgramID], iSeriesID, "ListingsCloseup");
    
    document.location = theURL;
}

// onMouseOver call
function f1(cell)
{
    var idx = parseInt(cell.id.replace("q",""),10);
    if(idx!=nFlyoverIndex) 
    { 
        // no highlight change for already selected
        lastFlyColor = cell.style.backgroundColor;
        cell.style.backgroundColor = "#EEEEEE";
        cell.style.color = "#0000FF";
        cell.style.textDecoration = "underline";
    }
    
    // always update the flyover text
	var objOneRow = objGridData[idx];
	var strTitle = objOneRow[colProgramTitle];    
    window.status = objOneRow[colProgramTitle] + " " + formatTime(getDateFromParam(objOneRow[colStartTime])) + " " + objOneRow[colCallLetters] + " " + objOneRow[colChannelNumber];
}

// onMouseOut cll
function f2(cell)
{
    var idx = parseInt(cell.id.replace("q",""),10);
    if(idx==nFlyoverIndex) { return; }
    cell.style.backgroundColor = lastFlyColor;
    cell.style.color = "#000000";
    cell.style.textDecoration = "none";
    window.status = "";
}

// onClick call
function f3(nIndex, nRow)
{ 	   
    // get the hidden table row
    var cutr = document.getElementById("icr" + nRow);
    // get the hidden table cell
    var cutd = document.getElementById("icd" + nRow);
    // get the cell of the clicked program
    var cupc = document.getElementById("q" + nIndex);
    // handle to previous cell
    var cupcold = document.getElementById("q" + nFlyoverIndex);
    
    // insert the animated image
    // cupc.innerHTML += "<div style='position:relative;'><img src='/images/search/loading_15x15.gif'></div>";
    // cupc.style.backgroundImage = "url(/images/search/loading_15x15.gif)";
    
    // reset last flyover tab
    strLastFoTab = "";
        
    if(cutr)
    {
        if((nFlyoverIndex == nIndex)||(nFlyoverIndex == -1))
        {
            // nothing already open OR user clicked the same cell
            if((isFF)||(isSafari))
            {
                if(cutr.style.visibility == "visible")
                {
                    cutd.innerHTML = "";
                    cupc.style.color = "";
                    cupc.style.textDecoration = "";
                    cupc.style.backgroundColor = lastFlyColor;
                    cupc.style.borderBottom = "solid 1px #DCDDCB";
                    cutr.style.visibility = "collapse";
                    nFlyoverIndex = -1;
                }
                else
                {
                    cupc.style.backgroundColor = v2bgColor;
                    cupc.style.color = "#FF0000";
                    cupc.style.textDecoration = "none";
                    cupc.style.borderBottom = ("solid 1px " + v2bgColor);
                    nFlyoverIndex = nIndex;    
                }
            }            
            else
            {                
                if(cutr.style.display == "block")
                {
                    cutd.innerHTML = "";
                    cupc.style.color = "";
                    cupc.style.textDecoration = "";
                    cupc.style.fontWeight = "normal";
                    cupc.style.backgroundColor = lastFlyColor;
                    cupc.style.borderBottom = "solid 1px #DCDDCB";                    
                    cutr.style.display = "none";
                    nFlyoverIndex = -1;
                }
                else
                {
                    cupc.style.backgroundColor = v2bgColor;
                    cupc.style.color = "#FF0000";
                    cupc.style.textDecoration = "none";
                    cupc.style.borderBottom = ("solid 1px " + v2bgColor);
                    nFlyoverIndex = nIndex;
                }
            }
        }
        else
        {
            // user clicked a different cell
            
            // revert previous cell colors
            if(cupcold)
            {
                cupcold.style.borderBottom = "solid 1px #DCDDCB";
                cupcold.style.backgroundColor = lastFlyColor;
                cupcold.style.color = "";
                cupcold.style.textDecoration = "";
            }
                    
            // color this cell
            cupc.style.backgroundColor = v2bgColor;
            cupc.style.color = "#FF0000";
            cupc.style.textDecoration = "none";
            cupc.style.borderBottom = ("solid 1px " + v2bgColor);
        
            // set global current flyover id
            nFlyoverIndex = nIndex;
        }
    }
    else
    {
		// fix cutr===null problems
		nFlyoverIndex = nIndex;
    }
    
    if((nRow!=nFlyoverRow)&&(nFlyoverIndex>=0))
    {
        // close previous row and empty the previous cell
        cutr = document.getElementById("icr" + nFlyoverRow);
        cutd = document.getElementById("icd" + nFlyoverRow);
        if((cutr)&&(cutd))
        {
            if((isFF)||(isSafari))
            {
                cutd.innerHTML = "";
                cutr.style.visibility = "collapse";
            }
            else
            {
                cutd.innerHTML = "";
                cutr.style.display = "none";
            }
        }
    }
    
    if(nFlyoverIndex>=0)
    {
        nFlyoverRow = nRow;
        setTimeout("getFlyoverInfo(1)", 0);
    }
}

function closeFlyover()
{
    if(optionCloseupsFooter)
    {
        var cutr = document.getElementById("icrCloseup");
        var cutd = document.getElementById("icdCloseup");

        if((isFF)||(isSafari))
        {
            cutr.style.visibility = "collapse";	            
            cutd.innerHTML = "";
        }
        else
        {
            cutr.style.display = "none";
            cutd.innerHTML = "";
        }
        
        document.getElementById("gridDiv").style.height = optionGridHeightPx+"px";
        return;
    }
    
    f3(nFlyoverIndex, nFlyoverRow);
    return ;
}


function getFlyoverInfo(nDirection)
{
    if(nDirection===0)
    {
        var theRow = document.getElementById("icr"+nFlyoverRow);
        var cutd = document.getElementById("icd" + nFlyoverRow);
        var cupcold = document.getElementById("q" + nFlyoverIndex);
        
        if(cupcold) { cupcold.style.backgroundColor = lastFlyColor; }
        
        nFlyoverIndex = -1;

        if(theRow)
        {
            if((isFF)||(isSafari))
            {
                theRow.style.visibility = "collapse";	            
                cutd.innerHTML = "";
            }
            else
            {
                theRow.style.display = "none";
                cutd.innerHTML = "";
            }
        }
        return;
    }
    if(objGridData[nFlyoverIndex])
    {
        var objRowData = objGridData[nFlyoverIndex];	
        getDetailData(objRowData[colProgramID]);
    }    
}

function adjustCloseupSize()
{
    var cutr = document.getElementById("icrCloseup");
    var cutd = document.getElementById("icdCloseup");
    var gridDiv = document.getElementById("gridDiv");
    gridDiv.style.height = (optionGridHeightPx - cutd.offsetHeight)+"px";
    // gridDiv.style.height = (optionGridHeightPx - 220)+"px";
}


function drawFlyoverDesc(strDescription)
{	
    //
    // object info is first line
    // amazon info is second line
    // amazon line is empty now 5/1/09
    //
    var objData = strDescription.split("\n");
    var objDetails = objData[0].split("\t");
    var objAmazon = null;
    var strCastList = "";
    
    var bDoMetrics = false;

    if (objData.length >= 3) 
    {
        strCastList = objData[rowCastList];
    }
    
    strDescription = objDetails[colAjaxEpDesc];
    
    var strShowTitle = "";
    var strAirTime = "";
    var strEpisodeTitle = "";
    var objDIV = null;
    
    var iSeriesID = 0;
    var iMovieID = 0;
    var iTvObjectID = 0;

	var strAjaxObjectUrl = "";
    
	if((strDescription===null)||(strDescription.length<=0))
	{
		strDescription = "Program description not available.";
	    objDIV = document.getElementById("fomoreinfo");
	    if(objDIV)
	    {
	        objDIV.style.visibility = "hidden"; 
            objDIV.style.display = "none"; 
	    }
	}
	else
	{
		// no "more" link for iPad
		if(!isAppleMobile)
		{
			objDIV = document.getElementById("fomoreinfo");
			if(objDIV)
			{
				objDIV.style.visibility = "visible"; 
				objDIV.style.display = "block"; 
			}
		}
	}

	if(objGridData[nFlyoverIndex])
	{

        strAjaxObjectUrl = objDetails[colAjaxObjectUrl];

		//var theDiv = document.getElementById("ProgramDesc");	
		//if(theDiv === null) { return; }
		
		var objRowData = objGridData[nFlyoverIndex];
		
		strShowTitle = objDetails[colAjaxTitle];
		strAirTime = formatTime(getDateFromParam(objRowData[colStartTime])) + "&nbsp;&nbsp;" + objRowData[colCallLetters];
			
		if(objRowData[colChannelNumber].length>0)
		{
			strAirTime += "&nbsp;&nbsp;ch:" + objRowData[colChannelNumber];
		}
        
        if(objDetails[colAjaxEpisode])
        {
		    if(objDetails[colAjaxEpisode].length>0)
		    {
		        strEpisodeTitle = objDetails[colAjaxEpisode];
		    }
	    }	
	    
        iSeriesID = objDetails[colAjaxSeriesID];
        iMovieID = objDetails[colAjaxMovieID];
	    iTvObjectID = objRowData[colTVObjectID];

	    var iDuration = objRowData[colDuration];
	    
	    objDIV = document.getElementById("fotitle");
	    if (objDIV !== null) 
        {
	        objDIV.innerHTML = strShowTitle;
            objDIV.style.cursor = "pointer"; 
            if(strAjaxObjectUrl)
            {
				if(strAjaxObjectUrl.length>0)
				{
					objDIV.href = strAjaxObjectUrl;
				}
				else
				{               
					objDIV.href = "javascript:cu(" + nFlyoverIndex + "," + iSeriesID + "," + iMovieID + ")";
				}
            }
            else
            {               
                objDIV.href = "javascript:cu(" + nFlyoverIndex + "," + iSeriesID + "," + iMovieID + ")";
            }
	    }
	    else { alert('no title div'); }
	    
	    objDIV = document.getElementById("fodvrlink");
	    if((objDIV) && (objDetails[colAjaxDvrLink]) && (!isAppleMobile))
        {
			if(objDetails[colAjaxDvrLink].length > 20) {
			    //alert(objDetails[colAjaxDvrLink]);
			    objDIV.innerHTML = objDetails[colAjaxDvrLink];
			    objDIV.style.display = "inline";
			}

        }

        objDIV = document.getElementById("checkinbutton");
        if ((objDIV) && (!isAppleMobile)) {
            objDIV.innerHTML = "<div class='ch-b-w tvo-" + objRowData[colTVObjectID] + " epprog-" + objDetails[colAjaxProgramID] + "' data-checkintype='" + getCheckinType(objDetails[colAjaxCategoryId], objDetails[colAjaxSeriesID], objDetails[colAjaxIsSportsNonEvent]) + "' data-sourcetype='2' style='display:inline;text-align:right;'><span class='ch-b-t' style='display:none'>" + strShowTitle + "~" + strEpisodeTitle + "~" + strAjaxObjectUrl + "~" + objRowData[colCallLetters] + "~" + modifyShareDate(getDateFromParam(objRowData[colStartTime])) + "~" + objDetails[colAjaxShowBadgeURL] + "</span></div>";
			getCheckIns();
        }   
	    	    
	    if(iDuration>0)
	    {
	        strAirTime += "&nbsp;&nbsp;" + iDuration + "min";
	    }

        if(parseInt(objDetails[colAjaxReleaseYr],10)>0)
        {
            strAirTime += "&nbsp;&nbsp;" + objDetails[colAjaxReleaseYr];
        }
	    
	    var strRating;
	    try {
			var tmp = objRowData[colRating].split('@');
			switch(tmp.length) {
				case 2:
					strRating = tmp[0] + "&nbsp;(";
					for(var ri=0;ri<tmp[1].length;ri++) {
						if(ri>0){strRating+=",";}
						strRating+=tmp[1].substring(ri,ri+1);
					} 
					strRating+=")";
					break;
				default :
					strRating = objRowData[colRating];
				break;
			}	
		} catch(e) { strRating = objDetails[colAjaxTvRating]; }
	    
	    if((strRating)&&(strRating.indexOf("None")<0))
	    {
	        strAirTime += "&nbsp;&nbsp;" + strRating;
	    }
	    else
	    {
	        strRating = objDetails[colAjaxMvRating];
	        if((strRating)&&(strRating.indexOf("None")<0))
	        {
	            strAirTime += "&nbsp;&nbsp;" + strRating;
	        }
	    }
	    
        objDIV = document.getElementById("foairtime");
        if (objDIV !== null) { objDIV.innerHTML = strAirTime; }
        else { alert("NO foairtime"); }
        
        objDIV = document.getElementById("foepisode");
	    if(objDIV)
	    {
	        if(strEpisodeTitle.length>0)
	        {
	            objDIV.innerHTML = strEpisodeTitle;
	            objDIV.style.visibility = "visible";
	            objDIV.style.display = "inline-block";
	            objDIV.style.width = "100%";
                if(isProgramNew(objRowData))
                {
                    objDIV.innerHTML += "&nbsp;<span style='font-size:12px;color:#FF0000;font-weight:normal'>New</span>"; 
                }                            
	        }
	        else
	        {
	            objDIV.innerHTML = "";
	            objDIV.style.visibility = "hidden";
	            objDIV.style.display = "none";
	        }
	    }

        objDIV = document.getElementById("fosummary");
	    if(objDIV){objDIV.innerHTML = strDescription; }
	    
        objDIV = document.getElementById("moreInfoLink");
	    if(objDIV)
        {
            if((strAjaxObjectUrl)&&(strAjaxObjectUrl.length<=0))
            {
                objDIV.href = "javascript:cu(" + nFlyoverIndex + "," + iSeriesID + "," + iMovieID + ")"; 
            }
            else
            {
                objDIV.href = strAjaxObjectUrl;
            }
            objDIV.innerHTML = "See more about " + strShowTitle + " &raquo;";
        }
		
		/* NEW! add Watch Videos link */
		var tmpfomoreinfo = document.getElementById('watchVideosLink');
		if(tmpfomoreinfo) 
		{
			var vidlink = strAjaxObjectUrl.replace(/\d+$/,"videos/");
			vidlink += iTvObjectID;
			tmpfomoreinfo.href = vidlink;
			tmpfomoreinfo.innerHTML = "Watch " + strShowTitle + " videos &raquo;"
		}
	            
	    var objTabCell = document.getElementById("foObjectTabsCell");
	    if (objTabCell !== null) 
	    {
	        objTabCell.innerHTML = objData[rowObjectTabs];
	    }        

        var theDescDiv = document.getElementById("ProgramDesc");
        
        var cutr = document.getElementById("icr" + nFlyoverRow);
        //if(optionCloseupsFooter)
        //{
        //    cutr = document.getElementById("icrCloseup");
        //    document.getElementById("gridDiv").style.height = (optionGridHeightPx - 220)+"px";
        //}    

		//
		// Open the row (make visible)
		//
        if (cutr !== null) 
        {
            if ((isFF) || (isSafari)) 
            {
				cutr.style.visibility = "visible";
            }
            else 
            {
                cutr.style.display = "block";
            }
        }
        
        var bi;
        
        if(objDetails[colAjaxShowBadgeURL]!="NO-IMAGE")
        {
            bi = document.getElementById("badgeImageCell");
            if (bi) {
            	//bi.style.display = "block";
            	bi.parentNode.className = "has-image";
            }            
            
            bi = document.getElementById("badgeImage");
            if(bi) 
            { 
                bi.src = objDetails[colAjaxShowBadgeURL]; 
                bi.style.onclick = "javascript:cu(" + nFlyoverIndex + "," + iSeriesID + "," + iMovieID + ")";
                bi.onmouseover = "window.status=\"click for more "+ strShowTitle + " info\"";
                bi.onmouseout = "window.status=''";                  
            }
        }
        else
        {
            bi = document.getElementById("badgeImageCell");
            if(bi)
            {
            	//bi.style.display = "none";
            	bi.parentNode.className = "no-image";
            }
        }            

		var adCell = document.getElementById("closeupAd");
        
		if(adCell) 
		{
			if(bCloseupAd)
			{
				var adsrc = getDARTag("closeup");
				adCell.src = adsrc.replace(/ord=/,"program=" + escape(strShowTitle) + ";ord=");
			}
			else
			{
				adCell.style.display = "none";
				adCell.style.visibility = "hidden";
			}
		}        

        // get the expanded row and just stuff the closeup into it
        var cutd = document.getElementById("icd" + nFlyoverRow);
        if(optionCloseupsFooter)
        {
			cutd = document.getElementById("icdCloseup");
        }        
		
        if (cutd !== null) 
        {        
            // because we are inserting a copy, we need to change the IDs to be unique
            
            // the string we replace into the div
            var strNewID = "id=\"ID_fo";
            
            // IE removes the quotes - we need to do the same (fixed in IE9)
            if((isIE)&&(nBrowserVersion<9)) { strNewID = "id=ID_fo"; }
            
            // now do the replacement, preceding each id with "ID_"
			cutd.innerHTML = theDescDiv.innerHTML.replace(/id=[\"\']*fo/gi, strNewID);
			cutd.style.color = "#000000";
			cutd.style.textAlign = "left";
        }

        try 
        { 
			wtdtCategory = objDetails[colAjaxCategory]; 
			wtdtSubCategory = objDetails[colAjaxSubCategory];
			wtdtShowTitle = strShowTitle;
			wtdtProgramID = objDetails[colAjaxProgramID];
			wtdtSeriesID = iSeriesID;
			wtdtObjectID = iTvObjectID;
			bDoMetrics = true;
        } 
        catch (err) { }
	}
	
	/* FILL IN CHECK-IN VALUES HERE */
	
	/*
		objectID	... objRowData[colTVObjectID]
		ProgramID	...	objDetails[colAjaxProgramID]
		objectName	...	strShowTitle
		epiTitle	... strEpisodeTitle (may be blank!)
		URL			... strAjaxObjectUrl (may be blank!)
		Network		...	objRowData[colCallLetters]
		Airtime		... objRowData[colStartTime]
		BadgeImg	... objDetails[colAjaxShowBadgeURL]
	
		<div class="ch-b-w tvo-[tvobjectid] epprog-[EpisodeProgramid]">                 
				<span class="ch-b-t" style="display:none">
      			  [Object Name]~[Episode Title]~[Episode URL or Object Url]~[Network]~[AirTime]~[Badge Url]
      		</span>             
		</div	
	*/	
    
    var tst = "";
	tst +=	"objectID\t...\t"		+ objRowData[colTVObjectID];
	tst +=	"\nProgramID\t...\t"	+ objDetails[colAjaxProgramID];
	tst +=	"\nobjectName\t...\t"	+ strShowTitle;
	tst +=	"\nepiTitle\t...\t"		+ strEpisodeTitle;
	tst +=	"\nURL\t...\t"			+ strAjaxObjectUrl;
	tst +=	"\nNetwork\t...\t"		+ objRowData[colCallLetters];
	tst +=	"\nAirtime\t...\t"		+ objRowData[colStartTime];
	tst +=	"\nBadgeImg\t...\t"		+ objDetails[colAjaxShowBadgeURL];
    
    doCuLayer(null,'synopsis');
    
    //alert(tst);

	if(bDoMetrics)
	{
		setTimeout("doCloseupMetrics()", 10);
	}	        
    
    // setTimeout("adjustCloseupSize()", 0);
}

function doCloseupMetrics()
{
    try 
    { 
		drawNielsen("ProgramCloseup_" + wtdtProgramID);
		countFlyoverEx(wtdtCategory, wtdtSubCategory, wtdtShowTitle, wtdtProgramID, wtdtSeriesID, "ListingsCloseup", wtdtObjectID);
		callRSI(wtdtShowTitle, wtdtCategory, wtdtSubCategory);	
		countGridAction("Inline Closeup", wtdtShowTitle);    
	}
	catch (err) { }

	wtdtCategory=""; wtdtSubCategory=""; wtdtShowTitle=""; wtdtProgramID=""; wtdtSeriesID=""; wtdtObjectID="";
}

function xmlDetailEvent()
{
	if (xmlDetailData.readyState==4 || xmlDetailData.readyState=="complete")
	{
		PastCloseups[nFlyoverIndex] = xmlDetailData.responseText;
		drawFlyoverDesc(xmlDetailData.responseText);
	}
}

function isProgramNew(objOneRow)
{
    if((objOneRow[colAttributes] & 4) == 4)
    {
        return true;
    }
    return false;
}

function isProgramRepeat(objOneRow)
{
    if((objOneRow[colAttributes] & 2) == 2)
    {
        return true;
    }
    return false;
}

function isProgramCC(objOneRow)
{
    if((objOneRow[colAttributes] & 8) == 8)
    {
        return true;
    }
    return false;
}

function getDetailData(nProgramID)
{
	if(PastCloseups[nFlyoverIndex])
	{
        // use the cached version to draw the flyover
		drawFlyoverDesc(PastCloseups[nFlyoverIndex]);
		return;
	}
    
    // not in cache - go get the closeup
    
	var objOneRow = objGridData[nFlyoverIndex];
	var urlData = "/listings/data/detailcache.aspx";
	var qparams = "";
    	
	qparams += "Qr=" + nProgramID;
	qparams += "&tvoid=" + objOneRow[colTVObjectID];
    
    
    // add NEW, REPEAT, CC flags
    var strFlags = "";

    // add repeat flag
    if(isProgramRepeat(objOneRow))
    { strFlags += "R"; }
    
    // add New Flag
    if(isProgramNew(objOneRow))
    { strFlags += "N"; }
    
    // add CC flag
    if(isProgramCC(objOneRow))
    { strFlags += "C"; }
    
    // add flags to query if needed
    if(strFlags.length>0)
    {
        qparams += "&flags=" + strFlags;
    }    
        
    qparams += "&v2=1";    
    
    // specify which closeup 'tabs' to return - or nothing for all
    // valid: synopsis,blog,recaps,videos,news,photos,episodes,cast,review
    if(isAppleMobile)
    {
		qparams += "&tabs=synopsis";
    }
        
            	
	xmlDetailData = GetXmlHttpObject(xmlDetailEvent);
	if(xmlDetailData)
	{
        xmlDetailData.open("GET", urlData + "?" + qparams , true);
        xmlDetailData.send(null);
	}
}

function doCuLayer(obj, strLayer) 
{
    // don't allow the cell to close
    if(strLastFoTab == strLayer)
    { return; }
    
    var i = 0;
    var o = document.getElementById("ID_fosubtab" + i);
    var a = document.getElementById("ID_fosubtab" + i + "img");
    
    if(obj)
    {
        while(o)
        {
            i++;
            o.style.color = "#006699";
            a.src = "/images/home/home_arrow.gif";
            o = document.getElementById("ID_fosubtab" + i);
            a = document.getElementById("ID_fosubtab" + i + "img");
        }
        obj.style.color = "#CC0000"; 
    }
    
    var layerCell = document.getElementById("ID_foLayerCell");
    
    if(layerCell===null)
    { return; }
    
    if(strLastFoTab == strLayer)
    {
        // user clicked on the open tab
        layerCell.style.display = "none";
        strLastFoTab = "";
        return;
    }
        
    var cells = PastCloseups[nFlyoverIndex].split("\n");

    if(obj)
    {   
        // clear styles that may have been set
        //layerCell.style.overflowX = "visible";
        //layerCell.style.overflowY = "visible";
        //layerCell.style.overflow = "visible";
        //layerCell.style.height = "auto";        

        a = document.getElementById(obj.id + "img");
        if(a)
        { a.src = "/images/home/home_arrow_down.gif"; }
        else { alert('no image'); }
    }
    
    switch (strLayer) 
    {
        case "synopsis":
            if((cells[rowSynopsis])&&(cells[rowSynopsis].length>0))
            {
                layerCell.innerHTML = cells[rowSynopsis];
                if(obj) 
                {
                    countGridAction("SubTabClick", "Episode Info");
                }
            }
            break;
        case "blog":
            layerCell.innerHTML = cells[rowBlog];
            countGridAction("SubTabClick", "Show Blog");
            break;
        case "castdetails":
            layerCell.innerHTML = cells[rowCastList];
            countGridAction("SubTabClick", "Cast");
            break;
        case "videos":
            layerCell.innerHTML = cells[rowVideoList];
            countGridAction("SubTabClick", "Videos");            
            break;
        case "episodes":
            layerCell.innerHTML = cells[rowEpisodeList];
            countGridAction("SubTabClick", "Episode List");         
            break;
        case "recaps":
            layerCell.innerHTML = cells[rowRecaps];
            countGridAction("SubTabClick", "Latest Recap");         
            break;            
        case "news":
            layerCell.innerHTML = cells[rowNews];
            countGridAction("SubTabClick", "News");         
            break;            
        case "photos":
            layerCell.innerHTML = cells[rowPhotoList];
            countGridAction("SubTabClick", "Photos");         
            break;    
        case "review":
            layerCell.innerHTML = cells[rowReview];
            countGridAction("SubTabClick", "Review");         
            break;    
                  
        default:
            layerCell.innerHTML = "";
            break;        
    }

    strLastFoTab = strLayer;
    
    // setTimeout("adjustCloseupSize()", 1);
}


function getCheckinType(TVGOLCategoryId, ParentProgramId, isNonEvent) {
    var chkType = 0;
    if (TVGOLCategoryId == 1)
        chkType = 3;
    else if (TVGOLCategoryId == 2 && isNonEvent.toLowerCase() == 'false')
        chkType = 4;
    else if (ParentProgramId > 0)
        chkType = 1;
    else if (ParentProgramId === 0)
        chkType = 2;

    return chkType;
}
