var pageRoot = "";
var siteIsOpen = "true";

var punctilioWindow = "";
var snicketReportWindow = "";
var ipixWindow = "";

if (window.opener && window.opener != "null")
{
	punctilioWindow = window.opener;
	snicketReportWindow = window.opener;
	ipixWindow = window.opener;
}

function popWindow( url, width, height, windowName )
{
    //get center coords
    var windowLeft = (screen.width - width) / 2;
    var windowTop = (screen.height - height) / 2;
    
    return window.open(url, windowName, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left=' + windowLeft + ',top=' + windowTop);
}
function popScrollingWindow(url, width, height, windowName)
{
    //get center coords
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    
    return window.open(url, windowName, 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);
}
function openWindow(url)
{
    var rand = "_blank";
    return window.open(url,rand,"directories=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes");
}
function openWindow2(url, width, height)
{
    //get center coords
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;

    var rand = "_blank";
    return window.open(url,rand,'directories=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);
}

function popWindowUpperLeft( url, width, height, windowName )
{
    return window.open(url, windowName, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left=20,top=20');
}

function downloadFile(theFile)
{
    popWindow(pageRoot + "download.html?theFile="+theFile, 300, 100, "downloadWindow");
}

var debugFlag=false;
function debug(string)
{
    if (debugFlag == true)
	{
		alert(string);
	}
}

var flashDebugFlag=false;
var flashDebugBuffer = "";
var flashDebugWindow = "";
function flashDebug(string)
{
	flashDebugBuffer += string + "<br>";
    if (flashDebugFlag == true)
	{
		if (flashDebugWindow == "")
		{
			flashDebugWindow = popScrollingWindow("flash_debug.html",800,500,"flashDebug");
		}

		setTimeout("writeToFlashDebugWindow()", 500);
	}
}
function writeToFlashDebugWindow()
{
	try
	{
		flashDebugWindow.document.getElementById('textDisplay').innerHTML = flashDebugBuffer;
	}
	catch (e)
	{
		flashDebugWindow.document.layers['textDisplay'].document.open();
		flashDebugWindow.document.layers['textDisplay'].document.write(flashDebugBuffer);
		flashDebugWindow.document.layers['textDisplay'].document.close();
	}
}

function popClip(clip, player, size)
{
    player = player.toUpperCase();
    size = size.toLowerCase();

    popWindow(pageRoot + 'clips/clips.html?movie='+clip+'&size='+player+size, 648, 488, clip+"_win");
}

function popAIM(number)
{
    popWindow(pageRoot + "aim/aim.html?icon="+number, 450, 450, "aim_icons");
}

function popWallpaper(number, size)
{
	openWindow(pageRoot + "wallpaper/wallpaper.html?wallpaper=wallpaper_"+number+"_"+size+".jpg");
}

function popTerms()
{
	openWindow(pageRoot + "terms.html");
}

function popPrivacy()
{
	openWindow(pageRoot + "privacy.html");
}

function popRegister()
{
	snicketReportWindow = popWindowUpperLeft(pageRoot + "newsletter/register.html",420,491,"register");
}

function popPunctilio(eyeCount)
{
	//alert("Terrible things are happening within this section.\nPlease come back later...");
	punctilioWindow = popWindow(pageRoot + "punctilio/index.html?eyeCountParameter="+eyeCount, 662, 540, "punctilio");
}

function popVFDKit()
{
	downloadFile(pageRoot + "eye_kit.zip");
}

function underResolution(w,h)
{
	return (screen.width <= w || screen.height <= h);
}

function homePageUrl(query)
{
	if (query == "null" || query == "undefined" /*|| query == undefined*/)
		query = "";

	return pageRoot + "main_flash.html" + query;
}

function popSiteFullscreen(query)
{
	if (query == "null" || query == "undefined" /*|| query == undefined*/)
		query = "";
	return popScrollingWindow(homePageUrl(query), screen.width, screen.height, "lemony_home");
}

function popSite(query)
{
	if (query == "null" || query == "undefined" /*|| query == undefined*/)
		query = "";
	return openWindow(pageRoot + "main.html" + query);
}

function eyeClicked(eyeBannerID)
{
	var query = "?e=" + eyeBannerID;
	if (window.opener && /*window.opener != "null" &&*/ siteIsOpen)
	{
		window.opener.location.href = homePageUrl(query);
		return;
	}

	popSite(query);
}

function notifyPopupsThatSiteWasOpened()
{
	if (punctilioWindow != "")
	{
		punctilioWindow.siteIsOpen = true;
		punctilioWindow.opener = window;
	}
	if (snicketReportWindow != "")
	{
		snicketReportWindow.siteIsOpen = true;
		snicketReportWindow.opener = window;
	}
	if (ipixWindow != "")
	{
		ipixWindow.siteIsOpen = true;
		ipixWindow.opener = window;
	}
}
function notifyPopupsThatSiteWasClosed()
{
	if (punctilioWindow != "")
	{
		punctilioWindow.siteIsOpen = false;
	}
	if (snicketReportWindow != "")
	{
		snicketReportWindow.siteIsOpen = false;
	}
	if (ipixWindow != "")
	{
		ipixWindow.siteIsOpen = false;
	}
}

function popEyeBanner(banner, code)
{
	popWindow(pageRoot + "banner_page/index.html?banner="+banner+"&code="+code, 450, 390, "banners");
}

function popPhotoGallery(queryString)
{
	popWindow(pageRoot + "ls-photos.html?"+queryString, 640, 390, "photoGallery");
}

function popPhotoDownload(image)
{
	openWindow2(pageRoot + "photos/photos.html?wallpaper="+image, 800, 700);
}

function popTradingCardGame()
{
	//popScrollingWindow(pageRoot + "cardcollect/tradingcardgame.html",755,550,"trading");
	openWindow(pageRoot + "cardcollect/tradingcardgame.html");
}

function popFullAppleTrailer()
{
	openWindow("http://www.apple.com/trailers/paramount/lemony_snickets/");
}

function popIpixWindow(ipx,w,h)
{
	if (w==null) w=640;
	if (h==null) h=480;
	ipixWindow = popWindow(pageRoot + "ipix/ipix.html?movie="+ipx+"&w="+w+"&h="+h, w, h, "lemony_ipix");
}
function popIpix(movie)
{
	switch(movie)
	{
	case "cage":
		popIpixWindow('cage:cage_final.ipx',500,400);
		break;
	case "centerroom":
		popIpixWindow('centerroom:centerroom_final.ipx',500,400);
		break;
	case "frontdoor":
		popIpixWindow('frontdoor:frontdoor_final.ipx',500,400);
		break;
	case "kitchen":
		popIpixWindow('kitchen:kitchen_final.ipx',500,400);
		break;
	case "launch":
		popIpixWindow('launch:launch_final.ipx',500,400);
		break;
	case "lobby":
		popIpixWindow('lobby:lobby_final.ipx',500,400);
		break;
	case "olafroom":
		popIpixWindow('olafroom:olafroom_final.ipx',500,400);
		break;
	case "ontrack":
		popIpixWindow('ontrack:ontrack_final.ipx',500,400);
		break;
	case "rear":
		popIpixWindow('rear:rear_final.ipx',500,400);
		break;
	case "store":
		popIpixWindow('store:store_final.ipx',500,400);
		break;
	case "tablejar":
		popIpixWindow('tablejar:tablejar_final.ipx',500,400);
		break;
	case "tower":
		popIpixWindow('tower:tower_final.ipx',500,400);
		break;
	default:
		break;
	}
}

function popDownloadIpix()
{
	openWindow("http://infomedia.ipix.com/support/download/plugin.shtml");
}

function popBoatGame()
{
	popWindow(pageRoot + "boatgame.html",640,480,"boatgame");
}

function alreadyOpenWarning()
{
	//alert("warning!  you already have the site open!");
	window.location.href = "site_already_open.html";
}

function focusWindow()
{
	window.focus();
}

function popStoneSkipping()
{
	popWindow(pageRoot + "ls-rockskipping.html",800,600,"rockskip");
}

function popJosephine_game()
{
	popWindow(pageRoot + "josephine_game.html",640,480,"josephine");
}

function popJosephine_walkthrough()
{
	popWindow(pageRoot + "josephine_walkthrough.html",640,480,"josephine");
}

function popMonty_game()
{
	popWindow("montygame.html",640,480,"montygame");
}

function popScreensavers(os)
{
	switch(os)
	{
	case "windows":
		downloadFile(pageRoot + "screensaver/LS_screensaver_PC.zip");
		break;
	case "osx":
		downloadFile(pageRoot + "screensaver/LS_screensaver_OSX.sit");
		break;
	default:
		break;
	}
}
function popScreensaver2(os)
{
	switch(os)
	{
	case "windows":
		downloadFile(pageRoot + "screensaver/LS_screensaver_PC_02.zip");
		break;
	case "osx":
		downloadFile(pageRoot + "screensaver/LS_screensaver_OSX_02.sit");
		break;
	default:
		break;
	}
}

function popBehindTheScenes()
{
	popWindow(pageRoot + "popup_behind.html", 450, 400, "behind");
}

function popProductionNotes()
{
	popWindow(pageRoot + "popup_production.html", 450, 400, "production");
}

function popTicketsShowtimes()
{
	popWindow(pageRoot + "popups/popup_showtime.html", 450, 400, "showtimes");
}
function popShowtimeLink(showtimeSite)
{
	switch (showtimeSite)
	{
	case "yahoo":
		openWindow("http://movies.yahoo.com/showtimes/movie?mid=1808438230");
		break;
	case "fandango":
		openWindow("http://www.fandango.com/movie_page.asp?mv=85761");
		break;
	case "movie_tickets":
		openWindow("http://www.movietickets.com/movie_detail.asp?movie_id=41794");
		break;
	case "moviefone":
		openWindow("http://movies.channel.aol.com/movie/main.adp?mid=16754");
		break;
	default:
		break;
	}
}

function popReviews()
{
	popWindow(pageRoot + "popups/popup_review.html", 450, 400, "reviews");
}

function popXmasWindow()
{
	popWindow(pageRoot + "popups/xmas_popup.html", 500, 500, "_blank");
}

function popOrderDvd()
{
	openWindow("http://homevideo.paramount.com/Catalog?cmd=display_product_page&release_id=4282");
}

function popPHE()
{
	popOrderDvd();
}