function ShowOverlay(OverlayTitle, OverlayContentArray, RenderContentOnly)
{
    var renderContentOnlyFlag = (RenderContentOnly == undefined ? false : RenderContentOnly);
	infohtml=[]
	if(renderContentOnlyFlag == false)
	{
	    infohtml.push('<div id="infodiv" unselectable="on">')
	    infohtml.push(' <div id="infodivabout" style="float:left;width:525px;margin-left:19px;" unselectable="on">')
	    infohtml.push('  <div style="font-size:16px;color:#5c83b0"><strong unselectable="on">' + OverlayTitle + '</strong></div>')
	    infohtml.push('  <br style="line-height:5px;"/><hr/><br style="line-height:5px;"/>')
	    infohtml.push('<div unselectable="on" style="color:#000000">')
	}
	for(var i = 0; i < OverlayContentArray.length; i++)
	{
	    infohtml.push(OverlayContentArray[i]);
	}
	if(renderContentOnlyFlag == false)
	{
	    infohtml.push('</div>')
	    infohtml.push('</div>')
	    infohtml.push('<br style="clear:both;"/>')
	}

    //showScreenBlock();
	dg("titledetcontent").innerHTML = infohtml.join("")
	setopacity("titledetDiv",0)
	dg("titledetDiv").style.display="block"
	dg("titledetbgDiv").style.display="block"

	newmidh = (dg("titledetcontent").offsetHeight+40)
	newdeth = (dg("titledetcontent").offsetHeight+80)
	if (newmidh<350) {newmidh=350}
	if (newdeth<350+60) {newdeth=350+40}
	dg("titledetbgmid").style.height = newmidh+"px"
	dg("titledetDiv").style.height = newdeth+"px"
	
	fx("titledetDiv",4,false,'setTimeout("fixinfosize()",50)',"opacity,0,100")
} 

function moreinfoover(thisinfo) {
	fx("moreinfoimg_"+thisinfo,3,fx_slidein,null,"backgroundColor,58595b,4a85c8")
	fx("moreinfo_"+thisinfo,3,fx_slidein,null,"color,4a85c8,58595b")
	dg("moreinfotext_"+thisinfo).style.textDecoration="underline"
}

function moreinfoout(thisinfo) {
	fx("moreinfoimg_"+thisinfo,3,fx_slidein,null,"backgroundColor,4a85c8,58595b")
	fx("moreinfo_"+thisinfo,3,fx_slidein,null,"color,58595b,4a85c8")
	dg("moreinfotext_"+thisinfo).style.textDecoration="none"
}

titleinfo_array=[]
lastclicked = -1
var lastMoreInfoPassIdClicked = -1;
function moreinfoclick(thisinfo) {
	lastclicked = thisinfo	
	lastMoreInfoPassIdClicked = currentlist[thisinfo+listoffset].PassID;
	if(currentlist[thisinfo+listoffset].BurnLicCount && currentlist[thisinfo+listoffset].BurnLicAvailable > 0)
	{
	    //return;
	}
	var thistitleid = currentlist[thisinfo+listoffset].TitleID
	if (titleinfo_array[thistitleid]==undefined) {
		ajl(webservices+"Titles.asmx/GetTitle",titlescallback,'TitleID='+thistitleid,ajaxerror,true);
	} else {
		drawmoreinfo(titleinfo_array[thistitleid],lastMoreInfoPassIdClicked)
	}
}

var showDebug = null;
function drawmoreinfo(thistitleobj,inPassId) {
    var selectedTitle = null;
    
	libraryarray.forEach(function (title) 
	    {
	        if (title.PassID == inPassId) 
	        {
	            selectedTitle = title;
	        }
	    });
	    
    // When the resulting title object does not have the name property defined, then it is
    // an empty result.  If we don't have the passId, we must abort processing.
    if(!thistitleobj.Name && selectedTitle == null)
    {
        return;
    }
    
    if(showDebug == null)
    {
        if(String(window.location).toLowerCase().indexOf("debug=1") != -1)
        {
            showDebug = true;
        }
        else
        {
            showDebug = false;
        }
    }
    
	infohtml=[]
	infohtml.push('<div id="infodiv">')
	infohtml.push(' <img id="titleinfoboxart" onload="try{dg(\'titleinfoboxartv\').style.top=this.offsetHeight+\'px\'}catch(e){}" src="' + protocol + '://www.cinemanow.com/images/boxart/175/'+selectedTitle.BoxArt+'175.jpg" border="0" width="175" style="float:left;margin-bottom:20px;border:1px solid #dedede;"/>')
	infohtml.push(' <div id="infodivabout" style="float:left;width:370px;margin-left:19px;">')
	infohtml.push('  <div style="font-size:16px;color:#5c83b0"><strong>'+selectedTitle.Name+'</strong></div>')
	infohtml.push('  <div style="float:left"><strong>Download Locations:</strong> ')
	infohtml.push('  </div>')
	if(selectedTitle.DDIDS != null)
	{
	    infohtml.push('<table style="color:inherit">');
	    infohtml.push('<thead />');
	    infohtml.push('<tbody>');
	    //Need to parse out the download destinations.
	    var downloadInstances = String(selectedTitle.DDIDS).split(',');
	    var ddToTranslate = [];
	    for(var i=0;i<downloadInstances.length;i++)
	    {
	        var instanceData = [];
	        instanceData = downloadInstances[i].split('|');
	        //Confirmed we have the DQID, SKUID, DDID
	        if(instanceData.length == 3)
	        {
	            ddToTranslate.push(instanceData[instanceData.length-1]);
	        }
	    }
	    // Keep track of valid download locations.
	    var validDownloads = 0;
	    for(var i=0;i<ddToTranslate.length;i++)
	    {
	        for(var ddIndex=0;ddIndex<destinationarray.length;ddIndex++)
	        {
	            if(destinationarray[ddIndex].DDID == ddToTranslate[i])
	            {
	                infohtml.push('<tr>');
                    infohtml.push('<td>');
                    infohtml.push('<span style="color:#60676c">');
	                infohtml.push(destinationarray[ddIndex].Loc);
	                infohtml.push('</span>');
                    infohtml.push('</td>');
                    infohtml.push('</tr>');
                    validDownloads++;
	                break;
	            }
	        }
	    }
	    // No valid downloads found, enter empty area in it's place.
	    if(validDownloads == 0)
	    {
	       infohtml.push('<tr><td><span> </span><br/></td></tr>');
	    }
	    infohtml.push('</tbody>');
	    infohtml.push('</table>');
        downloadInstances = null;
        ddToTranslate = null;
	}
	
	infohtml.push('  <div><strong>Download Licenses:</strong> ')
	if(selectedTitle.LicCount != null)
	{
	    infohtml.push(parseInt(selectedTitle.LicAvailable-selectedTitle.LicCount) + ' left ');
	}
	infohtml.push('  </div>')
	if(showDebug == true)
	{
	    infohtml.push('  <div><strong>Download Count:</strong> ')
	    if(selectedTitle.DLCount != null)
	    {
	        infohtml.push(parseInt(selectedTitle.DLCount));
	    }
	    infohtml.push('  </div>')
	    infohtml.push('  <div><strong>Max License Available:</strong> ')
	    if(selectedTitle.LicAvailable != null)
	    {
	        infohtml.push(parseInt(selectedTitle.LicAvailable));
	    }
	    infohtml.push('  </div>')
	}
	
	
	if(thistitleobj.Description!=undefined && thistitleobj.Description != '')
	{
	    infohtml.push('  <br style="line-height:5px;"/><hr/><br style="line-height:5px;"/>')
	    infohtml.push('  <div style="color:#777a7d"><strong style="width:60px;display:block;float:left;">Synopsis:&nbsp;</strong>')
	    infohtml.push(thistitleobj.Description)
	    infohtml.push('  </div>')
	}
	else
	{
	    infohtml.push('  <br style="line-height:5px;"/><hr/><br style="line-height:5px;"/>')
	    infohtml.push('  <div style="color:#777a7d">')
	    infohtml.push('Additional Information Unavailable.')
	    infohtml.push('  </div>')
	}

	if (thistitleobj.Rating!=undefined && thistitleobj.Rating!=null) {
		infohtml.push('  <div><strong style="width:90px;display:block;float:left;">Rating:</strong>'+thistitleobj.Rating+'</div>')
	}
	if (thistitleobj.ReleaseYear!=null) {
		infohtml.push('  <div><strong style="width:90px;display:block;float:left;">Release Year:</strong>'+thistitleobj.ReleaseYear+'</div>')
	}
	if (thistitleobj.Starring!=null) {
		if (thistitleobj.Starring.length>1) {plural="s"}else{plural=""}
		for (var i=0;i<thistitleobj.Starring.length;i++) {
			if (i==0) {thishead='Actor'+plural+':'}else{thishead='&nbsp;'}
			infohtml.push('  <div><strong style="width:90px;display:block;float:left;">'+thishead+'</strong><a href="http://www.cinemanow.com/SearchResults.aspx?q='+escape(thistitleobj.Starring[i])+'">'+thistitleobj.Starring[i]+'</a></div>')
		}
	}
	if (thistitleobj.Directors!=null) {
		if (thistitleobj.Directors.length>1) {plural="s"}else{plural=""}
		for (var i=0;i<thistitleobj.Directors.length;i++) {
			if (i==0) {thishead='Director'+plural+':'}else{thishead='&nbsp;'}
			infohtml.push('  <div><strong style="width:90px;display:block;float:left;">'+thishead+'</strong><a href="http://www.cinemanow.com/SearchResults.aspx?q='+escape(thistitleobj.Directors[i])+'">'+thistitleobj.Directors[i]+'</a></div>')
		}
	}
	if (thistitleobj.Producers!=null) {
		if (thistitleobj.Producers.length>1) {plural="s"}else{plural=""}
		for (var i=0;i<thistitleobj.Producers.length;i++) {
			if (i==0) {thishead='Producer'+plural+':'}else{thishead='&nbsp;'}
			infohtml.push('  <div><strong style="width:90px;display:block;float:left;">'+thishead+'</strong><a href="http://www.cinemanow.com/SearchResults.aspx?q='+escape(thistitleobj.Producers[i])+'">'+thistitleobj.Producers[i]+'</a></div>')
		}
	}
	if (thistitleobj.Writers!=null) {
		if (thistitleobj.Writers.length>1) {plural="s"}else{plural=""}
		for (var i=0;i<thistitleobj.Writers.length;i++) {
			if (i==0) {thishead='Writer'+plural+':'}else{thishead='&nbsp;'}
			infohtml.push('  <div><strong style="width:90px;display:block;float:left;">'+thishead+'</strong><a href="http://www.cinemanow.com/SearchResults.aspx?q='+escape(thistitleobj.Writers[i])+'">'+thistitleobj.Writers[i]+'</a></div>')
		}
	}
	if (thistitleobj.RunningTimeSeconds!=null) {
		if (thistitleobj.RunningTimeSeconds>0) {
			infohtml.push('  <div><strong style="width:90px;display:block;float:left;">Run Time:</strong>'+Math.round(thistitleobj.RunningTimeSeconds/60)+' Minutes</div>')
		}
	}
	if (thistitleobj.Copyright!=null) {
		infohtml.push('  <div><strong style="width:90px;display:block;float:left;">Copyright:</strong>'+thistitleobj.Copyright+'</div>')
	}

	infohtml.push('<br/> ')
	infohtml.push('</div>')
	infohtml.push('<br style="clear:both;"/>')
	infohtml.push('<div id="werecommendDiv" style="background-color:transparent;position:relative;clear:both;width:566px;z-index:200;">')
	infohtml.push(' <strong style="color:#5c83b0;background-color:white;">We Recommend:</strong><br/>')
	infohtml.push(' <div id="werecommendcontentDiv" style="background-color:transparent;"></div>')
	infohtml.push('</div>')
	infohtml.push('<img src="img/mmgr2/vboxfade.png" id="titleinfoboxartv" onload="fixpng();try{this.style.top=dg(\'titleinfoboxart\').offsetHeight+\'px\'}catch(e){};" width="175" height="60" border="0" style="position:absolute;top:0px;left:1px;z-index:150;height:60px;background-color:white;background-image:url(images/boxart/175v/'+selectedTitle.BoxArt+'175.jpg);"/>')
	
	similarSKUID = currentlist[lastclicked+listoffset].FileType.split(",")[0].split(":")[1]

	if (similarSKUID!=0) {	
		//if (similars[similarSKUID]==undefined) {
			ajl(webservices+"remoteq.asmx/GetRelatedPurchases",drawsimilar_callback,'SKUID='+similarSKUID,ajaxerror,true);
		//} else {
		//	drawsimilar(similarSKUID)
		//}
	}

	if (dg("titledetDiv").style.display=="block") {
	
		setopacity("titledetDiv",0)

		var lasttitledetcontentheight = (dg("titledetbgmid").offsetHeight)
		var lasttitledetDivheight = (dg("titledetDiv").offsetHeight)

		dg("titledetcontent").innerHTML = infohtml.join("")
		
	} else {
		dg("titledetcontent").innerHTML = infohtml.join("")
		setopacity("titledetDiv",0)
		dg("titledetDiv").style.display="block"
		dg("titledetbgDiv").style.display="block"

		newmidh = (dg("titledetcontent").offsetHeight+40)
		newdeth = (dg("titledetcontent").offsetHeight+80)
		if (newmidh<350) {newmidh=350}
		if (newdeth<350+60) {newdeth=350+40}
		dg("titledetbgmid").style.height = newmidh+"px"
		dg("titledetDiv").style.height = newdeth+"px"

		fx("titledetDiv",4,false,'setTimeout("fixinfosize()",50)',"opacity,0,100")
	}
}

function fixinfosize() {
		newmidh = (dg("titledetcontent").offsetHeight+40)
		newdeth = (dg("titledetcontent").offsetHeight+80)
		if (newmidh<350) {newmidh=350}
		if (newdeth<350+40) {newdeth=350+40}
		fx("titledetbgmid",5,fx_slideout,null,"height,"+dg("titledetbgmid").offsetHeight+","+newmidh )
		fx("titledetDiv",5,fx_slideout,null,"height,"+dg("titledetDiv").offsetHeight+","+newdeth )
}

function closetitledet() 
{
	fx("titledetDiv",4,false,"dg('titledetDiv').style.display='none';dg('titledetbgDiv').style.display='none'","opacity,100,0");
	if(dg("screenblockDiv").style.display.toLowerCase() == "block")
    {
        setTimeout('dg("screenblockDiv").style.display="none"',50);
    }
}

function getElementPosition(theElement, rootElement)
{
    var posX = 0;
    var posY = 0;
    var breakOutAfterElement = (rootElement != undefined ? true : false);
    while(theElement != null)
    {
        posX += theElement.offsetLeft;
        posY += theElement.offsetTop;
        theElement = theElement.offsetParent;
        if(breakOutAfterElement == true)
        {
            if(theElement.offsetParent != null)
            {
                if(theElement.id == rootElement.id)
                {
                    break;
                }
            }
        }
        
    }
    return {X:posX,Y: posY};
}
function ShowFaqItem(FaqItemTarget)
{
    if(browser=="ie")
    {
        dg(helpDivId).scrollTop = getElementPosition(dg(FaqItemTarget), dg(helpDivId)).Y;
    }
    else
    {
        dg(FaqItemTarget).scrollIntoView();
    }
}
var helpDivId = 'helpOverLayDiv';

function fixpng(scaling){if((browser=="ie")&&(bver<7)){if(event.srcElement.src.indexOf("spacer.gif")!=-1){return};event.srcElement.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+event.srcElement.src+"', sizingMethod='"+((scaling==undefined||scaling==false)?"image":"scale")+"')";event.srcElement.src="img/spacer.gif"}}
function fixpng_background(thisid){if((browser=="ie")&&(bver<7)){if(dg(thisid).background.indexOf("spacer.gif")!=-1){return};dg(thisid).style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+dg(thisid).background+"', sizingMethod='scale')";dg(thisid).background=""}}
function fixpng_bg_style(thisid){if((browser=="ie")&&(bver<7)){if(dg(thisid).style.backgroundImage.indexOf("spacer.gif")!=-1){return};dg(thisid).style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+dg(thisid).style.backgroundImage.replace(/url\(/g,"").replace(/\)/g,"")+"', sizingMethod='scale')";dg(thisid).style.backgroundImage="url(img/spacer.gif)"}}
function fixpng_cssbg(cssselector){if((browser=="ie")&&(bver<7)){thiscss=getstyle(cssselector);if(thiscss.style.backgroundImage.indexOf("spacer.gif")!=-1){return};thiscss.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+thiscss.style.backgroundImage.replace(/url\(/g,"").replace(/\)/g,"")+"', sizingMethod='scale')";thiscss.style.backgroundImage="url(img/spacer.gif)"}}


function WatchCinemaNowWhereYouWant()
{
    var content = [];
    content.push('<div style="color:#000000;padding-right:15px; ">');    
    content.push('<div style="float:left;padding-top:5px;padding-bottom:18px;"><a href="http://www.cinemanow.com/devices.aspx" target="_blank"><img src="/theme/std2/img/icon_3devices_wportable.gif" border="0"></a></div>');
    content.push('<br />');
    content.push('<br />');
    content.push('<div style="float:left;width:250px"><span style="font-size:15px;font-weight:bold">Computers</span>');
    content.push('<br />');
    content.push('<a href="https://selfserve.roxio.com/cinemanow/default.aspx?id=000002CN" target="_blank">System Requirements</a>');
    content.push('<br />');
    content.push('<br /></div>');            
    content.push('<div style="float:left;width:250px"><span style="font-size:15px;font-weight:bold">TVs</span>');
    content.push('<br />');
    content.push('<a href="http://www.cinemanow.com/Devices.aspx" target="_blank">TV-Connected devices</a>');    
    content.push('<br />');
    content.push('<a href="http://www.cinemanow.com/tivo/info" target="_blank">Watch on your TiVo DVR</a>');
    content.push('<br />');
    content.push('<a href="http://www.cinemanow.com/pclaptop1.aspx" target="_blank">How to connect your computer to your TV </a>');
    content.push('<br />');
    content.push('<br /></div>');
    content.push('<div style="float:left; width:250px"><span style="font-size:15px;font-weight:bold">Portable Players</span>&nbsp;&nbsp;<span style="font-size:11px;">(play on up to 2 players)</span>');
    content.push('<br />');
    content.push('<a href="http://www.cinemanow.com/Devices.aspx" target="_blank">Compatible Portable players </a>');
    content.push('<br />');
    content.push('<br /></div>');        
    //content.push('<br />this is a test7');
    content.push('</div>');

    ShowOverlay("Watch CinemaNow Where You Want ", content);
}

function WatchCinemaNowWhereYouWant_noPortables() {
    var content = [];
    content.push('<div style="color:#000000;padding-right:15px; ">');
    content.push('<div style="float:left;padding-top:5px;padding-bottom:18px;"><a href="http://www.cinemanow.com/devices.aspx" target="_blank"><img src="/theme/std2/img/icon_pcDevicesOnly.gif" border="0"></a></div>');
    content.push('<br />');
    content.push('<br />');
    content.push('<div style="float:left;width:250px"><span style="font-size:15px;font-weight:bold">Computers</span>');
    content.push('<br />');
    content.push('<a href="https://selfserve.roxio.com/cinemanow/default.aspx?id=000002CN" target="_blank">System Requirements</a>');
    content.push('<br />');
    content.push('<br /></div>');
    content.push('<div style="float:left;width:250px"><span style="font-size:15px;font-weight:bold">TVs</span>');
    content.push('<br />');
    content.push('<a href="http://www.cinemanow.com/Devices.aspx" target="_blank">TV-Connected devices</a>');
    content.push('<br />');
    content.push('<a href="http://www.cinemanow.com/tivo/info" target="_blank">Watch on your TiVo DVR</a>');
    content.push('<br />');
    content.push('<a href="http://www.cinemanow.com/pclaptop1.aspx" target="_blank">How to connect your computer to your TV </a>');
    content.push('<br />');
    content.push('<br /></div>');
    content.push('</div>');

    ShowOverlay("Watch CinemaNow Where You Want ", content);
}