var pageState = "home";
var contentId = "104092";
var homeContentId = "124793";

jQuery(document).ready(function() {

	jQuery.ajax({
		// get the property meta XML
		type: "GET",
		url: "/cnservice/cartoonsvc/content/xml/getContentById.do?contentId=" + contentId + "&depth=5" + previewFormat,
		dataType: "xml",
		error: function (request, error) {
			// do this on AJAX error
		},
		success: function(data) {
			var aCards = jQuery(data).find('a_space_slate:lt(3)');

			var swfURL 		= "tools/media/aSpaceShell.swf";
			var swfID 		= "atpage_fo";
			var flashVars 	= { pageID: homeContentId }

			var swfParams 	= { allowScriptAccess	: "always",
								allowFullScreen		: "false",
								wmode 				: "opaque" };

			swfobject.embedSWF(swfURL, "flash_content", "100%", "330", "10,0,0,0", "swf/expressInstall.swf", flashVars, swfParams, {
								id	: swfID,
								name: swfID });
			
			jQuery(data).find('Property_Master').each(function() {
				showName = jQuery(this).find('Short_Title:first').text().toUpperCase();
				var tuneIn = jQuery(this).find('tuneInMsg').text();
				var subPropBgSrc = jQuery(this).find('SubPropertyBackground:first').find('srcUrl').text();
				var subPropBgClr = "#" + jQuery(this).find('SubPropertyBackground:first').find('BackGround_PageColor').text();
				var subPropFloatSrc = jQuery(this).find('Floating_BG_Img:first').find('srcUrl').text();
				var subPropLogoSrc = jQuery(this).find('showlogo:first').find('srcUrl').text();
				var subPropLogoLink = jQuery(this).find('showlogo:first').find('URL').text();
				var subPropLogoAlt = jQuery(this).find('showlogo:first').find('altText').text();
				metaStringOne = '<meta name="title" content="' + showName + '"/>';
//				jQuery('head').prepend(metaStringOne);
				if (tuneIn != '') {
					jQuery('div.tuneinTxt').html('<div><span class="downArrow"><img src="http://i.cdn.turner.com/toon/tools/img/pixel.gif" alt="" class="pixel" /></span> ' + tuneIn.toUpperCase() + ' <span class="downArrow"><img src="http://i.cdn.turner.com/toon/tools/img/pixel.gif" alt="" class="pixel" /></span></div>');
				}
			
				if (pageState != "home") {
					if (subPropBgClr == "#") {
						subPropBgClr = "#333333";
					}
					jQuery('#contentWrapper').css('background-image','url(' + cmaImgBasePath + subPropBgSrc + ')')
					jQuery('#contentWrapper').css('background-repeat','no-repeat');
					jQuery('#contentWrapper').css('background-position','top center');
					jQuery('#contentWrapper').css('background-color',subPropBgClr);
					jQuery('.logoTunein div.char').html('<img src="' + cmaImgBasePath + subPropFloatSrc + '" alt="">');
				}
				jQuery('<a></a>').attr('href',subPropLogoLink).html('<img src="' + cmaImgBasePath + subPropLogoSrc + '" alt="' + subPropLogoAlt + '">').prependTo('div.logoTunein');
			});
			/*****************************************************************
			/* Disabled by Brendellya 7/25/2011.  Switch to seo include.
			jQuery(data).find('Sub_Property').each(function() {
				var navText = jQuery(this).find('NavName').text().toUpperCase();
				var navUrl = jQuery(this).find('Page_URL:first').text();

				jQuery('<li></li>').appendTo('div.showNav ul');
				jQuery('<a></a>').attr('href',navUrl).text(navText).appendTo('div.showNav li:last');
				if (pageState.toUpperCase() == navText.toUpperCase()) {
					jQuery('div.showNav li:last').addClass('active');
					var metaDesc = jQuery(this).find('Long_Description').text();
					var metaKeys = jQuery(this).find('Metatag_Keywords').text();
					var winTitle = jQuery(this).find('Window_Title').text();
					var metaCanon = jQuery(this).find('CanonicalTag').text();
					metaStringTwo = '<meta name="keywords" content="' + metaKeys + '" />';
					metaStringThree = '<meta name="description" content="' + metaDesc + '" />';
					metaStringFour = '<title>' + winTitle + '</title>';
					metaStringFive = '<link rel="canonical" href="' + metaCanon + '"/>';
					//jQuery('head').prepend(metaStringTwo,metaStringThree,metaStringFour,metaStringFive);
				}
			});
			 	- Added by Brendellya 7/25/2011.  This jquery replaces code above, adds highlighted state */			
			jQuery('div.showNav ul').find('li').each(function(){
				var navText = jQuery(this).find('A').text();
				if (pageState.toUpperCase() == navText.toUpperCase()) {
					jQuery(this).addClass('active');
				}
			});
			/**********************************************************************/
			var gameGenre = jQuery(data).find('game_genre:first').text();
			getGames(data, pageState, gameGenre);
/*
	// no related games on this page
			jQuery(data).find('game_genre:first').each(function() {
				getRelatedGenreGames(contentId,jQuery(this).attr('contentName'),10);
			});
*/
			jQuery(data).find('VMA_Collection_ID:first').each(function() {
				getVideoCollection(jQuery(this).text(),jQuery(data).find('Short_Title:first').text().toUpperCase());
			});
			var targetCells = 0;
			jQuery(data).find('Sub_Property').each(function() {
				if ((jQuery(this).attr('contentName').indexOf(pageState.toLowerCase()) > -1)||(jQuery(this).attr('contentName').indexOf(pageState.toUpperCase()) > -1)||(jQuery(this).attr('contentName').indexOf(pageState) > -1)) {
					targetCells = jQuery(data).find('Sub_Property').index(this);
				}
			});
			getCCells(jQuery(data).find('Sub_Property:eq(' + targetCells + ')'));
			getFooterContent(jQuery(data).find('Genre:first'));
			getShowListings(jQuery(data).find('Scarlett_ID:first').text(), jQuery(data).find('Scarlett_Search_Term:first').text());
		}
	});
});

