var pageRoot = "";

function popWindow( 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=0,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);
}
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 downloadFile(theFile)
{
    popWindow(pageRoot + "download.html?theFile="+theFile, 300, 100, "downloadWindow");
}

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

function track(trackString)
{
switch (trackString)
    {
    case "XXXXX":
        debug(trackString);
        break;
    default:
        debug(trackString);
        _hbPageView(trackString, "/incredibles_bvhe_uk");
        break;
    }
}

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

	track("view+clip+-+"+clip+"+-+"+player+"+"+size);

	if (player == "QT" && ( clip == "teaser_trailer" || clip == "trailer1") )
	{
		var appleSize = "";
		if (size == "huge")
			appleSize = "fullscreen";
		else
			appleSize = size;

		if (clip == "teaser_trailer")
		{
			if (appleSize == "fullscreen")
				openWindow("http://phobos.apple.com/WebObjects/MZStore.woa/wa/redirect?url=itms://www.apple.com/moviesxml/s/disney/623/fullscreen.xml");
			else
				openWindow("http://www.apple.com/trailers/disney/the_incredibles/teaser_"+appleSize+".html");
		}
		else if (clip == "trailer1")
		{
			if (appleSize == "fullscreen")
				openWindow("http://phobos.apple.com/WebObjects/MZStore.woa/wa/redirect?url=itms://www.apple.com/moviesxml/s/disney/929/fullscreen.xml");
			else
				openWindow("http://www.apple.com/trailers/disney/the_incredibles/"+appleSize+".html");
		}
	}
	else
	{
		popWindow('clips/clips.html?movie='+clip+'&size='+player+size, 650, 450, "trailer");
	}
}

function popAppleTrailer()
{
	openWindow("http://www.apple.com/trailers/disney/the_incredibles");
}

function popAIM()
{
    popWindow("aim/aim.html", 670, 520, "aim_icons");
   	track("download+buddy+icons");
}

function popInLine()
{
	popWindow("trailer/index.html",650,450,"firstinline");
}

function popXbox()
{
	popWindow("comp/index.html",770,550,"xbox_comp");
}

function popStrength()
{
    popWindow("superstrength.html", 777, 565, "superstrength");
	track("test+your+strength");
}

function popName()
{
    popWindow("name_game.html", 770, 530, "namegame");   
    track("superhero+name");
}

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

function popEcard(number)
{
	track("download+ecard+"+number);
	openWindow("ecards/ecards.html?card="+number);
}

function linkMain(level)
{
	if (level == undefined)	{
		level = "";
	}
	var destination = "main" + level + ".html";
	window.location.replace(destination);
}

function popGetVideoPlayer(format)
{
	debug("get video player: " + format);
	format = format.toUpperCase();
	if (format == "QT")
	{
		openWindow("http://disney.go.com/help/software_center/index.html#quicktime");
	}
	else if (format == "RM")
	{
		openWindow("http://disney.go.com/help/software_center/index.html#realplayer");
	}
	else if (format == "WM")
	{
		openWindow("http://www.microsoft.com/windows/windowsmedia/download/default.asp");
	}
}
function PopTrailer()
{
    popScrollingWindow("trailer/index.html", 670, 450, "clip");
}
