$(document).ready(function(){
	Modules.init();
	PageSetup.init();
});


MiniMenu = {
	gameBoxAmnt: 0,
	videoBoxAmnt: 0,
	gameBoxActive: 1,
	videoBoxActive: 1,
	
	init: function() {
		MiniMenu.gameBoxAmnt = $(".topGameRow").length;
		MiniMenu.videoBoxAmnt = $(".episodeRow").length;
		MiniMenu.setUpBoxes("#gameNavigation", MiniMenu.gameBoxAmnt, MiniMenu.gameBoxActive);
		MiniMenu.setUpBoxes("#videoNavigation", MiniMenu.videoBoxAmnt, MiniMenu.videoBoxActive);
		MiniMenu.setUpArrows();
	},
	
	setUpBoxes: function(moduleNav, boxAmnt, boxActive) {
		for (i = 0; i < boxAmnt; i++) {
			$(moduleNav +  " .boxes ul").append('<li class="box" id="box-' + (i + 1) + '"></li>');
		}
		
		var box = $(moduleNav +  " .box");
		
		$(".box").hover(
			function() {
				if ($(this).hasClass('active') == false) {
					$(this).addClass('box-hover')
				}
			},
			function() {
				$(this).removeClass('box-hover')
			}
		).click(function() {
			if ($(this).hasClass('active') == false) {
				MiniMenu.changeActiveBox($(this).attr('id'), moduleNav);
			}
		})
		
		$(box[boxActive - 1]).addClass("active");
		$(box[(boxAmnt - 1)]).addClass("last");
		
		MiniMenu.calculatePadding(moduleNav);
	},
	
	setUpArrows: function() {
		$(".leftArrow").hover(
			function() {
				$(this).addClass('left-arrow-hover')
			},
			function() {
				$(this).removeClass('left-arrow-hover')
			}
		).click(
			function() {
				MiniMenu.crementBoxes(-1, $(this).parent().attr('id'));
			}
		);
		
		$(".rightArrow").hover(
			function() {
				$(this).addClass('right-arrow-hover')
			},
			function() {
				$(this).removeClass('right-arrow-hover')
			}
		).click(
			function() {
				MiniMenu.crementBoxes(1, $(this).parent().attr('id'));
			}
		);
	},
	
	crementBoxes: function(amnt, moduleNav) {
		moduleNav = "#" + moduleNav;
		var box = $(moduleNav + " .box");

		if (moduleNav == "#gameNavigation") {
			MiniMenu.gameBoxActive += amnt;
			
			if (MiniMenu.gameBoxActive < 1) {
				MiniMenu.gameBoxActive = MiniMenu.gameBoxAmnt;
			}
			else if (MiniMenu.gameBoxActive > MiniMenu.gameBoxAmnt) {
				MiniMenu.gameBoxActive = 1;
			}
			
			$(box).removeClass('active');
			$(box[MiniMenu.gameBoxActive - 1]).addClass('active');
			
			MiniMenu.changeImages(MiniMenu.gameBoxActive, moduleNav);
		}
		else if (moduleNav == "#videoNavigation") {
			MiniMenu.videoBoxActive += amnt;
			
			if (MiniMenu.videoBoxActive < 1) {
				MiniMenu.videoBoxActive = MiniMenu.videoBoxAmnt;
			}
			else if (MiniMenu.videoBoxActive > MiniMenu.videoBoxAmnt) {
				MiniMenu.videoBoxActive = 1;
			}
					
			$(box).removeClass('active');
			$(box[MiniMenu.videoBoxActive - 1]).addClass('active');
			
			MiniMenu.changeImages(MiniMenu.videoBoxActive, moduleNav);
		}
	},
	
	changeActiveBox: function(boxId, moduleNav) {
		var idStr = boxId;
		var idSplit = idStr.split('-')
		var id = idSplit[1];
	
		var box = $(moduleNav + " .box");
	
		if (moduleNav == "#gameNavigation") {
			MiniMenu.gameBoxActive = parseInt(id);
			
			$(box).removeClass('active');
			$(box[MiniMenu.gameBoxActive - 1]).addClass('active');
			
			MiniMenu.changeImages(MiniMenu.gameBoxActive, moduleNav);
		}
		else if (moduleNav == "#videoNavigation") {
			MiniMenu.videoBoxActive = parseInt(id);
				
			$(box).removeClass('active');
			$(box[MiniMenu.videoBoxActive - 1]).addClass('active');
				
			MiniMenu.changeImages(MiniMenu.videoBoxActive, moduleNav);
		}
		
	},
	
	changeImages: function(id, moduleNav) {
		if (moduleNav == "#gameNavigation") {
			var topGameRow = "#top-game-row-" + id;
			var bottomGameRow = "#bottom-game-row-" + id;
			
			$(".game-row-active").addClass('hidden');
			$(".game-row-active").removeClass('game-row-active');
			
			$(topGameRow).addClass('game-row-active');
			$(topGameRow).removeClass('hidden');
			$(bottomGameRow).addClass('game-row-active');
			$(bottomGameRow).removeClass('hidden');
		}
		else if (moduleNav == "#videoNavigation") {
			var videoRow = "#video-row-" + id;
			
			$(".video-row-active").addClass('hidden');
			$(".video-row-active").removeClass('video-row-active');
			
			$(videoRow).addClass('video-row-active');
			$(videoRow).removeClass('hidden');
		}
	},
	
	calculatePadding: function(div) {
		var boxPadding = 14;
		var boxWidth = 16;
		var navWidth = 312;
		
		var boxAmount = $(div + " .box").length;
		var boxes = $(div + " .boxes");
		var rightArrow = $(div + " .rightArrow");
		
		var boxesWidth = (boxWidth * boxAmount) + (boxPadding * (boxAmount - 1));
		
		var boxesPadding = (navWidth / 2) - (boxesWidth / 2)
		
		var rightArrowPadding = navWidth - (boxesPadding + boxesWidth);
		
		boxes.css("padding-left", String(boxesPadding) + "px");
		boxes.css("width", String(boxesWidth) + "px");
		rightArrow.css("margin-left", String(rightArrowPadding) + "px");
	}
}

Modules = {
	init: function(){
		Modules.entireModuleClick("#boardsModule", "#boardsModule .moduleMore a");
		Modules.bigImageHover();
	},
	
	entireModuleClick: function(module, link) {
		$(module).click(function () { 
			var moduleLink = $(link).attr("href");
			location = moduleLink;
		});
	},
	
	bigImageHover: function() {
		$("#bigImageModule .genericImg a").hover(
			function(){
				$(this).css('background-position', '-100% 0');
			},
			function() {
				$(this).css('background-position', '0 0');
			}
		);
	}
}

PageSetup = {
	init: function() {
		PageSetup.showFeatured();
		PageSetup.setUpOmniture();
	},
	
	showFeatured: function() {
		$(".topGameRow li, .bottomGameRow li").each(function(i) {
			$(this).mouseover(function() {
				var idStr = $(this).attr('id');
				var idSplit = idStr.split('-')
				var id = idSplit[1];
				var div = "#featured-game-" + id;
		
				$(".featured-game-active").addClass('hidden');
				$(".featured-game-active").removeClass('featured-game-active');
				
				$(div).addClass('featured-game-active');
				$(div).removeClass('hidden');
			});
		})
		
		$(".episodeRow li").each(function(i) {
			$(this).mouseover(function() {
				var idStr = $(this).attr('id');
				var idSplit = idStr.split('-')
				var id = idSplit[1];
				var div = "#featured-video-" + id;
		
				$(".featured-video-active").addClass('hidden');
				$(".featured-video-active").removeClass('featured-video-active');
				
				$(div).addClass('featured-video-active');
				$(div).removeClass('hidden');
			});
		})
	},
	
	setUpOmniture: function() {
		$(".outbound").click(function() {
			s.linkTrackVars = "prop11";
			s.referrer = "";
			s.prop11 = $(this).attr("name");
		});
	}
}


function popUp(URL){
	window.open(URL, "mywindow", "toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=250,height=325");
}


function loadVideoPlayer(url, xml) {
	var swfwidth = 620;
	var swfheight = 247;
	
	//var xmlFile = XML;
	
	var descColor = "0xaa4330";
	
	var movieID = "A1";
	
	var so = new SWFObject(url, movieID, swfwidth, swfheight, "8", "#00FF00");
			//this is to allow a target to open in a window besides _blank
		so.addParam("allowScriptAccess", "always");
		so.addParam("wmode", "transparent");
	   
			//set omniture to true to turn on omniture
		so.addVariable("omniture", "false");
		
		so.addVariable("omniAccount", "adultswimdevelopment");
		so.addVariable("omniVisitorNamespace", "adultswim");
		so.addVariable("omniMovieID", movieID);
		
		so.addVariable("omniPageName", "Home : A1");
		so.addVariable("omniSubSection", "Home : Home");
		so.addVariable("omniSection", "Home");
		so.addVariable("omniPageURL", "");
		
			//set omniTrackSwf to true to track the loading of the swf itself 
		so.addVariable("omniTrackSwf", "false");
		so.addVariable("omniTrackLinks", "true");
		so.addVariable("omniTrackPlays", "true");
		so.addVariable("omniTrackButtons", "true");
		
		so.addVariable("swfHeight", swfheight);
		so.addVariable("swfWidth", swfwidth);
	   
			//flv loads in a single video file
			//if you use "flv" you have to comment out "xml"
		//so.addVariable("flv", "test2.flv");
			//url defines a link for clicking on the video area of the flv player
			//to disable it, comment it out
		so.addVariable("url", "test.html");
			//target defines where the url will open
			//choices are _self, _parent, _top, _blank
		so.addVariable("target", "_self");
	   
			//xml loads in a playlist with flvs and urls
			//if you use "xml", you have to comment out "flv"
		so.addVariable("xml", xml);
	   
			//flvWidth and flvHeight are required variables - don't comment them out
			//they define the width and height of the videoArea
			//To fill up the entire area set them to one pixel less than the swf size
			//to allow for the control area, set the height minus the height of the control area
			//never have the height more than 29 pixels difference from the swfheight if you are using the playlist controls
		so.addVariable("flvWidth", 440);
		so.addVariable("flvHeight", 247);
	   
			//the alignment for the video player in the swf window
			//must be defined: set to left, right or center
		so.addVariable("alignment", "left");
			//controlWidth and Height are required, but if you want the controls to not be streched, include them
			//usually set the width to the width of the flv and the height to around 30 or whatever you need
		so.addVariable("controlWidth", 378);
		so.addVariable("controlHeight", 24);
			//use this to add or subtract to the control area y position
			//set it to 0 to use the default
		so.addVariable("controlY", 0);
	   
			//autoplay is required - it must not be commented out
			//true automatically plays the video, false requires you a click before playing
		so.addVariable("autoplay", "true");
	   
			//loop is required - it must not be commented out
			//true sets the entire video and video list to replay
			//false will play through the video once and the entire playlist once
		so.addVariable("loop", "true");
	   
	   		//buffer variables
			//to have no buffer, comment out bufferingMessage
			//bufferingAlignment can be "insideBottomLeft",
		//so.addVariable("bufferingMessage", "Buffering, bitch...");
		so.addVariable("bufferingAlignment", "insideBottomLeft")
		so.addVariable("bufferingFont", "Arial");
		so.addVariable("bufferingFontSize", 14);
		so.addVariable("bufferingFontColor", 0xFFFFFF);
	   
			//controls is required - it must not be commented out
			//if true, the main controls under the video area is visible
			//if false, there is no main control area
			//if controls == true, make sure to turn off innerControls & vice versa
		so.addVariable("controls", "false");
			//innerControls is required - it must not be commented out
			//if true, the play/pause is visible inside the video area
			//if false, there is no inner controls
			//if innerControls == true, make sure to turn off controls & vice versa 
		so.addVariable("innerControls", "false");
			//playlistControls is required - it must not be commented out
			//if false they are not active
			//if bottom, the prev/next controls are on the very bottom of the swf
			//if insidebottom, the controls are on the bottom of inside the flv area
			//if leftbottom, the controls are on the left of the video area towards the bottom
		so.addVariable("playlistControls", "leftbottom");
	   
			//descriptionAreaAlign is required - it must not be commented out
			//describes where the description area can be in relation to the player
			//if bottom, it's under the player
			//if lefttop, it's to the left and towards the top
		so.addVariable("descriptionAreaAlign", "lefttop");
	   
	   
			//still image is the image that displays in the video area if the autoplay is turned off
			//to have no still image, comment this out
		//so.addVariable("stillImage", "images/still.jpg");
			//playerbg is the background image behind the video area
			//to have no bg, comment this out
		//so.addVariable("playerbg", "images/bgtest.jpg");
		//so.addVariable("offsetBgX", 20);
		//so.addVariable("offsetBgY", 20);
		//so.addVariable("bgWidth", 200);
		//so.addVariable("bgHeight", 500);
	   
			//for videoBorderColor - must use 0x000001 for a black movieBorderColor 
		//so.addVariable("videoBorderColor", 0x000001);
	   
	 
			//the next six variables can be commented out if you want to use the default icons 
			//controlsbg is the bg for the entire main control area
		//so.addVariable("controlsbg", "tools/img/a1/controlsbg.jpg");
			//set this to true if you want to see the play/pause button
		//so.addVariable("playPause", "true");
			//playImage is the image for the play button
		//so.addVariable("playImage", "tools/img/a1/play_unselected.png");
			//pauseImage is the image for the pause button
		//so.addVariable("pauseImage", "tools/img/a1/pause_unselected.png");
	  
		//so.addVariable("playImageRO", "tools/img/a1/play_selected.png");
		//so.addVariable("pauseImageRO", "tools/img/a1/pause_selected.png");
			//playX is for the X coord of the play/pause area in pixels
		so.addVariable("playX", 20);
	  
			//set this to true if you want to see the scrubber track
		so.addVariable("track", "true");
			//thumbImage is the image for the scrubber thumb
			//if you use one of the next 3, you  have to use them all
		//so.addVariable("thumbImage", "tools/img/a1/thumb.jpg");
			//loadedTrackImage is the image for the loaded scrub bar
		//so.addVariable("loadedTrackImage", "tools/img/a1/loadedtrack.jpg");
			//trackImage is the image for the unloaded scrub bar
		//so.addVariable("trackImage", "tools/img/a1/track.jpg"); 
			//trackX is for the X coord of the track in pixels
		so.addVariable("trackX", 90);
	   
			//the following 6 are required parameters
			//set elapsed and/or to true if you want the elapsed time and false if not
		so.addVariable("elapsed", "true");
		so.addVariable("duration", "true");
			//timeFont is for the font face of the time displays
		so.addVariable("timeFont", "Verdana");
			//timeSize is for the size of the time displays font
		so.addVariable("timeSize", 10);
			//elapsedX is the X coord for the elapsed time
		so.addVariable("elapsedX", 45);
			//durationX is the X coord for the duration time
		so.addVariable("durationX", 275);
	  		//if controls is turned on and no images are set above these must not be commented out
			//these control the color of the default icons on the control areas
		so.addVariable("elapsedColor", 0xFF0F56);
		so.addVariable("durationColor", 0xF0F0FF);
	  
			//set the start volume of the video
			//from 0 to 100  (you can set higher, but the volume becomes distorted)
		so.addVariable("startVolume", 0);
			//if you add a volumeImage, you have to add them all or comment them all out
			//set volumeIcon to true/false to turn it on or off
		so.addVariable("volumeIcon", "true");
			//volumeImage is the image for the speaker icon
		//so.addVariable("volumeImage", "tools/img/a1/volumeimagetest.png");
			//volumeIconX is for the X coord of the volume Icon in pixels
		so.addVariable("volumeIconX", 357);
			//soundWavesImage is the image for the waves coming out of the speaker
		//so.addVariable("soundWavesImage", "tools/img/a1/soundwavesimagetest.png");
			//muteImage is the image for the mute icon
			//if one of these next 3 is commented out, all them have to be
		//so.addVariable("muteImage", "tools/img/a1/muteimagetest.png");
			//volumeThumbImage is the image for the thumb on the scrubber bar
		//so.addVariable("volumeThumbImage", "tools/img/a1/volumethumbtest.jpg");
			//set volumeTrack to true/false to turn it on or off
		so.addVariable("volumeTrack", "true");
			//volumeTrackImage is the image for the scrubber bar
		//so.addVariable("volumeTrackImage", "tools/img/a1/volumetracktest.jpg");
			//volumeTrackX is for the X coord of the volume track in pixels
		so.addVariable("volumeTrackX", 310);
	  
			//if innerControls is turned on, these must not be commented out
			//innerPause if the image for the pause icon on the inner controls
		//so.addVariable("innerPauseImage", "tools/img/a1/innerpausetest.png");
			//innerPlay is the image for the play icon on the inner controls
		//so.addVariable("innerPlayImage", "tools/img/a1/innerplaytest.png");
	   
			//if playlistControls is turned on, these control the images being on that controls
			//use left center or right
		so.addVariable("playlistAlign", "center");
			//for setting the closeness of the playlist buttons
			//use close or far 
			//far can only use center aligned
		so.addVariable("playlistKerning", "far");
			//the space in pixels between the playlist controls
		so.addVariable("playlistButtonSpace", 10);
			//the space in pixels from the left
		so.addVariable("playlistOffsetX", 5);
	 
			//for playlistCtrlsBg, put in a transparent gif/png with the appropriate height & width if you don't want a bg to show up
		so.addVariable("playlistCtrlsBg", "http://i.cdn.turner.com/adultswim/tools/img/a1/controlsBg.png");
			//comment out the next 4 variables if you don't want a next/previous control area
		so.addVariable("playlistCtrlsPrev", "http://i.cdn.turner.com/adultswim/tools/img/a1/a1LeftArrow.png");
		so.addVariable("playlistCtrlsPrevRO", "http://i.cdn.turner.com/adultswim/tools/img/a1/a1LeftArrowRO.png");
		so.addVariable("playlistCtrlsNext", "http://i.cdn.turner.com/adultswim/tools/img/a1/a1RightArrow.png");
		so.addVariable("playlistCtrlsNextRO", "http://i.cdn.turner.com/adultswim/tools/img/a1/a1RightArrowRO.png");
			//these 3 must not be commented out
		so.addVariable("playlistSelected", "http://i.cdn.turner.com/adultswim/tools/img/a1/a1Active.png");
		so.addVariable("playlistUnselectedRO", "http://i.cdn.turner.com/adultswim/tools/img/a1/a1BoxRO.png");
		so.addVariable("playlistUnselected", "http://i.cdn.turner.com/adultswim/tools/img/a1/a1Box.png");
	   
			//if you want to select a set color for all of the text description on playlist,
			//use this to override the xml sheet.  Use this for if you have different stylesheets for the same page
			//comment out to not use it
		//so.addVariable("descColorOverride", descColor);
	   
		so.write("videoPlayer");
}