﻿function popWindow(url, width, height, win, scrollbars, track_code) {
	track(track_code);
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	if (win == undefined) win = "_blank";
	if (scrollbars != 1) scrollbars = 0;
	newwindow = window.open(url, win, 'toolbar=0,location=0,status=0,menubar=0,scrollbars=' + scrollbars + ',resizable=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);
	if (window.focus) newwindow.focus();
}
function openWindow(url, win, track_code){
	track(track_code);
	if (win == undefined) win = "_blank";
	newwindow = window.open(url, win);
	if (window.focus) newwindow.focus();
}

function getHeight() {
	var height = window.outerHeight;
	alert(height);
	return height;
}

function popVideoShare(cid, action, video, track_code){
	if (action == "code") {
		popWindow("content/video/videocode.html?cid=" + cid + "&video=" + video, 300, 330, "videoshare", 0, track_code);
	} else if (action == "apple") {
		openWindow("http://www.apple.com/trailers/fox/thesimpsonsmovie/", "apple");
	}
}
function popIcons(cid, image, track_code){
	popWindow("content/icons/icons.html?cid=" + cid + "&image=" + image, 549, 599, "icons", 0, track_code);
}
function popMobile(cid, url, track_code){
	popWindow(url, 549, 599, "icons", 0, track_code);
}
function popWallpaper(cid, image, track_code){
	popWindow("content/wallpapers/wallpaper.html?cid=" + cid + "&image=" + image, screen.width, screen.height, 'wallpaper', 1);
}
function popTickets(track_code){
	popWindow("content/showtimes/index.html", 495, 552, "tickets", 0, track_code);
}
function popSweeps(track_code){
	popWindow("content/sweepstakes/getTrapped.html", 570, 552, "sweepstakes", 1, track_code);
}

function popFeature(cid, action, param1, param2, param3){
	if (action == "3cardmoe") {
		popWindow("content/games/tcm/index.html?cid=" + cid + "&id=" + param1, 800, 600, "3cardmoe", 0);
	} else if (action == "ballofdeath") {
		popWindow("content/games/bod/index.php?cid=" + cid + "&id=" + param1, 800, 550, "ballofdeath", 0);
	} else if (action == "wreckingball") {
		popWindow("content/games/wb/index.php?land=" + cid + "&userid=" + param1, 650, 500, "wreckingball", 0);
	} else if (action == "pong") {
		popWindow("content/games/pong/index.html?cid=" + cid + "&id=" + param1  + "&user=" + param2 + "&pass=" + param3, 820, 620, "pong", 0);
	} else if (action == "skate") {
		popWindow("content/games/skate/index.php?land=" + cid + "&userid=" + param1, 565, 415, "skate", 0);
	} else if (action == "fishing") {
		popWindow("content/games/fishing/index.html?cid=" + cid + "&id=" + param1, 810, 610, "fishing", 0);
	} else if (action == "myspace") {
		openWindow("http://www.myspace.com/simpsonsmovie", "myspace");
	}
}


function track(track_string){
	if (track_string != undefined && track_string != ""){
		var track_array = track_string.split("/");
		if (track_array[0] == "") track_array.shift();
		if (track_array[track_array.length - 1] == "") track_array.pop();
		track_string = "/" + track_string;

		if (track_array.length == 1) {
			FlashTrack('DCS.dcsuri', track_string, 'DCSext.CG1', track_array[0]);
		} else if (track_array.length == 2) {
			FlashTrack('DCS.dcsuri', track_string, 'DCSext.CG1', track_array[0], 'DCSext.CG2', track_array[1]);
		} else if (track_array.length == 3) {
			FlashTrack('DCS.dcsuri', track_string, 'DCSext.CG1', track_array[0], 'DCSext.CG2', track_array[1], 'DCSext.CG3', track_array[2]);
		} else if (track_array.length == 4) {
			FlashTrack('DCS.dcsuri', track_string, 'DCSext.CG1', track_array[0], 'DCSext.CG2', track_array[1], 'DCSext.CG3', track_array[2], 'DCSext.CG4', track_array[3]);
		} else if (track_array.length == 5) {
			FlashTrack('DCS.dcsuri', track_string, 'DCSext.CG1', track_array[0], 'DCSext.CG2', track_array[1], 'DCSext.CG3', track_array[2], 'DCSext.CG4', track_array[3], 'DCSext.CG5', track_array[4]);
		} else if (track_array.length == 6) {
			FlashTrack('DCS.dcsuri', track_string, 'DCSext.CG1', track_array[0], 'DCSext.CG2', track_array[1], 'DCSext.CG3', track_array[2], 'DCSext.CG4', track_array[3], 'DCSext.CG5', track_array[4], 'DCSext.CG6', track_array[5]);
		} else if (track_array.length == 7) {
			FlashTrack('DCS.dcsuri', track_string, 'DCSext.CG1', track_array[0], 'DCSext.CG2', track_array[1], 'DCSext.CG3', track_array[2], 'DCSext.CG4', track_array[3], 'DCSext.CG5', track_array[4], 'DCSext.CG6', track_array[5], 'DCSext.CG7', track_array[6]);
		} else if (track_array.length >= 8) {
			FlashTrack('DCS.dcsuri', track_string, 'DCSext.CG1', track_array[0], 'DCSext.CG2', track_array[1], 'DCSext.CG3', track_array[2], 'DCSext.CG4', track_array[3], 'DCSext.CG5', track_array[4], 'DCSext.CG6', track_array[5], 'DCSext.CG7', track_array[6], 'DCSext.CG8', track_array[7]);
		}
	}
}

function getURLVar(param) {
	var q = document.location.search || document.location.hash;
	if(q) {
		var pairs = q.substring(1).split("&");
		for (var i=0; i < pairs.length; i++) {
			if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
				return pairs[i].substring((pairs[i].indexOf("=")+1));
			}
		}
	}
	return "";
}