// set to true to enable hit box tracking
var hitboxEnabled = true;

// ACCOUNT NUMBER(S)
// should be something like: 'DM570627ECNC38EN3;DM57050997CW38EN3' 
var hitboxAccountNumber = 'DM570716PJBZ38EN3;DM57050997CW38EN3';          

// MULTI-LEVEL CONTENT CATEGORY
// should be something like: '/creativeservicestestacct;/Test+Do+Not+Use/creativeservicestestacct' 
var hitboxMultiLevelContentCategory = '/getsmart;/Entertainment+movie+dvd/getsmart';     


//LIGHTBOX Code

var win = null;
var index = 1;
function openDialog(id,w,h) {
    Dialog.alert($(id).innerHTML, {className: "alphacube",  width:w, height:h, id: "d" + index})
    index++;
	document.getElementById('castFlash').style.display = 'none';
}

function lastDialog(id) {
    Dialog.confirm($(id).innerHTML, {className: "alphacube",  width:250, okLabel: "Close All", ok: closeAllModalWindows})
}

function closeAllModalWindows() {
    Windows.closeAllModalWindows();
	document.getElementById('castFlash').style.display = 'inline';
    //return true;
}


function contestLogCheck () {
	if (isLoggedIn > 0) {
	openDialog(ohYeah, 550, 500);
	} else {
		alert ("Please log into your MySpace account before entering the sweepstakes");
	}
}


//skin tooggle function
function CssToggler(choice) {
	//switches the css
	var filePath="http://creative.myspace.com/Client/WarnerBros/GetSmart/";
	document.getElementById('styleURLSkin').href = filePath+choice+"mainLayout2.css";
		
	//swaps out the correct cast image on the right
	var castContainer = document.getElementById('castFlash');
    castContainer.innerHTML = '<embed src="http://creative.myspace.com/Client/WarnerBros/GetSmart/Flash/'+choice+'Flash.swf" width="500" height="477" id="getSmart" wmode="transparent" />'; 	
}
	

//does a log in check and writes the quiz if true
function quizSwapper() {
	if (isLoggedIn > 0) {
		document.getElementById('quizSection').style.display = 'none';
		document.getElementById('quizFlashSection').style.display = 'inline';
		window.onload = ConstrainRankingImages();
	} else {
		alert ("Please log into your MySpace account before taking the quiz!");
	}
}

function kaosQuizSwapper() {
	if (isLoggedIn > 0) {
		document.getElementById('quizSectionKaos').style.display = 'none';
		document.getElementById('quizFlashKaos').style.display = 'inline';
		window.onload = ConstrainRankingImagesKaos();
	} else {
		alert ("Please log into your MySpace account before taking the quiz!");
	}
}
	

// loads the trailer video player
function loadVideo(videotype) {
	var aspetRatio = videotype;
	var videoPlayerContainer = document.getElementById('videoHolder');
	var boxHeight = '508px';

// change the hd video source 
if (aspetRatio == 'hd') {  
	videoPlayerContainer.innerHTML = '<div style="margin-top:-15px; margin-left:-35px;"><embed src="http://lads.myspace.com/videos/vplayer.swf" allowScriptAccess="always" allowFullScreen="true" flashvars="m=33365683&v=2&type=video&a=1&sr=0&nl=1&mainColor=0x333333" type="application/x-shockwave-flash" width="852" height="508" wmode="transparent"></embed></div>';
	document.getElementById('trailerPanel').style.height = boxHeight;
	document.getElementById('trailerLinksContainer').style.display = 'none';

// or for the standard video source
} else if (aspetRatio == 'standard') {
	videoPlayerContainer.innerHTML = '<embed src="http://lads.myspace.com/videos/vplayer.swf" allowScriptAccess="always" allowFullScreen="true" flashvars="m=33476983&type=video&a=1&sr=0&nl=0&mainColor=0x333333" type="application/x-shockwave-flash" width="785" height="370" wmode="transparent"></embed>';
	document.getElementById('trailerPanel').style.height = '453px';
}

	//hides the right cast image and displays the new logo and close buttons
	document.getElementById('castFlash').style.display = 'none';
	document.getElementById('logoClose').style.display = 'inline';

}


// loads the trailer video player
function loadClips(videoID) {
	var videoPlayerContainer = document.getElementById('videoHolder');

	videoPlayerContainer.innerHTML = '<embed src="http://lads.myspace.com/videos/vplayer.swf" allowScriptAccess="always" allowFullScreen="true" flashvars="m='+videoID+'&type=video&a=1&sr=0&nl=0&mainColor=0x333333" type="application/x-shockwave-flash" width="785" height="370" wmode="transparent"></embed>';

	//hides the right cast image and displays the new logo and close buttons
	document.getElementById('castFlash').style.display = 'none';
	document.getElementById('logoClose').style.display = 'inline';

}
	
	
//removes the trailer videos with a close button
function removeVideo() {
	var videoPlayerContainer = document.getElementById('videoHolder');
	videoPlayerContainer.innerHTML = '<div id="controlLink"><a href="javascript:CssToggler(&#39;control&#39;);" name="&lid=controlStyleToggle" title="Control" id="controlToggle"></a></div><div id="kaosLink"><a href="javascript:CssToggler(&#39;kaos&#39;);" name="&lid=kaosStyleToggle" title="Kaos" id="kaosToggle"></a></div>';
	document.getElementById('trailerPanel').style.height = '453px';
	document.getElementById('logoClose').style.display = 'none';
	document.getElementById('castFlash').style.display = 'inline';
	document.getElementById('trailerLinksContainer').style.display = 'inline';
}
	
	

var RANKING_MAX_WIDTH = 106;
var RANKING_MAX_HEIGHT = 123;
var RANKING_CONTAINER_ID = 'profileImage'


function GetSize(size) 
{
	if (imageUrl.indexOf("_s") > -1)
		return imageUrl.replace(/_s/,"_" + size);
	
	if (imageUrl.indexOf("s_") > -1)
		return imageUrl.replace(/s_"/, size + "_" );

	if (imageUrl.indexOf("_m") > -1)
		return imageUrl.replace(/_m/,"_" + size);
	
	if (imageUrl.indexOf("m_") > -1)
		return imageUrl.replace(/m_/, size + "_" );

	else

	return null;
}
	var imageUrl = GetSize('l');
	document.write('<div id="profileImage"><img name="profileImg" src="'+imageUrl+'" style="position:absolute; top:-2000px;"></div>');


var RANKING_MAX_WIDTH = 106;
var RANKING_MAX_HEIGHT = 123;
var RANKING_CONTAINER_ID = 'profileImage'

function ConstrainImageSize(img, maxHeight, maxWidth)
{
    var changeFactor;
    if (isLoggedIn < 0)
	{
		changeFactor = 1;
		return {height:RANKING_MAX_HEIGHT, width: RANKING_MAX_WIDTH};	
	}
    // if both width and height are too big, constrain off the biggest one
    if (img.height > maxHeight && img.width > maxWidth)
    {
        // find what factor to constrain by
        if (img.height > img.width)
            changeFactor = maxHeight / img.height;
        if (img.height <= img.width)
         {
		    //changeFactor = maxWidth / img.width;
			changeFactor = 1;
			return {height:maxHeight, width: maxWidth};
		}
    }
    // if width is too big constrain off it
    else if (img.width > maxWidth)
        changeFactor = maxWidth / img.width;
    // if height is too big constrain off it	
    else if (img.height > maxHeight)
        changeFactor = maxHeight / img.height;
    
    // otherwise everything is fine
    else
        changeFactor = 1;


    // now set the new size is
    return {height:img.height * changeFactor, width: img.width * changeFactor};

}

function ConstrainRankingImages() {
	var images = document.getElementById(RANKING_CONTAINER_ID).getElementsByTagName('img');
    for (i=0; i<images.length; i++)
    {
        var imageDimensions = ConstrainImageSize(images[i], RANKING_MAX_HEIGHT, RANKING_MAX_WIDTH);
        images[i].style.width = imageDimensions.width + 'px';
        images[i].style.height = imageDimensions.height + 'px';
    }
		
		
		document.getElementById('quizFlashSection').innerHTML = '<embed src="http://creative.myspace.com/Client/WarnerBros/GetSmart/Flash/XMLQuiz.swf?image='+imageUrl+'&imageWidth='+imageDimensions.width+'&imageHeight='+imageDimensions.height+'&maxHeight='+RANKING_MAX_HEIGHT+'&maxWidth='+RANKING_MAX_WIDTH+'&imageWidth='+imageDimensions.width+'&imageHeight='+imageDimensions.height+'" width="590" height="264" allowScriptAccess="always" wmode="transparent" />';
}
	
	
function ConstrainRankingImagesKaos() {
	var images = document.getElementById(RANKING_CONTAINER_ID).getElementsByTagName('img');
    for (i=0; i<images.length; i++)
    {
        var imageDimensions = ConstrainImageSize(images[i], RANKING_MAX_HEIGHT, RANKING_MAX_WIDTH);
        images[i].style.width = imageDimensions.width + 'px';
        images[i].style.height = imageDimensions.height + 'px';
    }
		
		
		document.getElementById('quizFlashKaos').innerHTML = '<embed src="http://creative.myspace.com/Client/WarnerBros/GetSmart/Flash/XMLQuiz.swf?image='+imageUrl+'&imageWidth='+imageDimensions.width+'&imageHeight='+imageDimensions.height+'&maxHeight='+RANKING_MAX_HEIGHT+'&maxWidth='+RANKING_MAX_WIDTH+'&imageWidth='+imageDimensions.width+'&imageHeight='+imageDimensions.height+'" width="590" height="264" allowScriptAccess="always" wmode="transparent" />';
}
	

