Browse = {
	_nTotalPages: 1,
	_objVidz: {},
	bOverrideBlur: false, // boolean to override blur action when user hits enter
	bOverrideNP: false,
	bOverrideVid: false,
	collection: {},
	itemCount: 0,
	itemTotal: 1,
	maxItemsPerPage: 20,//19,
	MaxVideos: 20,//20, //http://staging.adultswim.tv/astv/mvpd/services/getAllEpisodes.do?offset=0&limit=200&id=49053
	pageNumber: COOKIE_VAL_page,
	strDirection: '',//used for next prev btns
	strFilterOn: 'recent',//used for filter buttons
	strPagination:'',
	strCurrCollection: '',
	strAuthFailStatement: '',
	videoId: {},
	newvid:{},
	uri: '',
	xmlObj: {},

	init: function(){
		$('#topCap a').click(function(){
//			if(TVEUtil.authBool){
				//when user clicks top cap, clear cookies
				Utilities.cookieMonster();
				//and remove cvp
				//$('#adultswim-video-body').hide();
				//showMarketingSWF();
				document.location.reload();
//			}

		});
	},
	updatePage: function(num){
		//Utilities.log('111 @@@ ### updatePage ' + num + ' : ' + Browse.strPagination + ' :: ' + Browse.pageNumber);
		switch (num) {
			case '':
			case '0':
				$('.pageNo').val(Browse.strPagination);
				break;
			default:
				if (parseInt(num) > Browse._nTotalPages) {
					$('.pageNo').val(Browse.strPagination);
				} else {
					Browse.pageNumber = parseInt(num);
					Browse.strDirection='';
//					Browse.addVideos();
					////alert(COOKIE_VAL_collection + ' :: ' + Browse.strCurrCollection);
					Thumbnails.loadVideos(COOKIE_VAL_collection);//Browse.strCurrCollection
				}
				break;
		}
	}
}

PageControlsSetup = {
	pathArray: window.location.pathname.split('/'),
	newPathname: [],
	init: function(){
		PageControlsSetup.newPathname = PageControlsSetup.pathArray[2];
		PageControlsSetup.updateShowTitle();
	},
	updateShowTitle: function(){
		showNameText = $.cookie("TVEshowName") == null ? "Adult Swim TV" : $.cookie("TVEshowName");
		Utilities.log('|-o-| |-o-| PageControlsSetup.updateShowTitle: $.cookie("TVEshowName") ' + $.cookie("TVEshowName") + ' : ' + showNameText);
		$('h2.browse').html(showNameText);
	}
};


PageControls = {
	bRetryCVP:false,
	videoId:'',
	PageUrl: 'http://ctnp1devfill1.turner.com:9492/' + PageControlsSetup.newPathname,
	NavUrl: '/astv/mvpd/services/getCollections.do?id=49047',
	CollectionUrl: COOKIE_VAL_collectionUrl,//'/astv/mvpd/services/getAllEpisodes.do',//?offset=0&limit=200&id=49053
	RelatedUrl: '/astv/mvpd/services/getRelatedByFranchise.do?videoGrouperContentType=294',
	GrouperUrl: '/astv/mvpd/services/getVideoById.do',
	VideoJsonUrl: '',
	SendToFriendUrl: '',
	SearchUrl: '',
	TodaysTopId: COOKIE_VAL_collection, //'39573',
	strBgColor: '#FFF076',
	
	init: function(){

		/* ------- Cookie Show Name Sniffer -------- */
		PageControlsSetup.init();
		/* -------------- end Show Name Sniffer ----- */

		Browse.init()
		$.ajax({
			type: "GET",
			url: PageControls.NavUrl,
			cache: true,
			dataType: "xml",
			success: function(data){
				//////Utilities.log("succeseclipse helios"+data)
				navXml = data;
				////alert('|-o-| TVEUtil.waitingSection ' + TVEUtil.waitingSection);
				try{
  				if (TVEUtil.waitingSection !== "") {
  					// if there was a section waiting for the nav to load, load it now
  					//////Utilities.log("in TVEUtil.waitingSection"+TVEUtil.waitingSection)
  					SectionNav.load(TVEUtil.waitingSection);
  				}
  		} catch(e){}
			},
			error: function(){
				Utilities.log("DVinit error")
			}
		});
		BrowseButtons.setupClicks();
		
		TVEUtil.init();		
	},
	playVideo: function(videoId, teaserMap){
		currentVideoId = videoId;
		queueVideoId = null;
		currentPlaylistMap = teaserMap;

		if(TVEUtil.AUTHBOOL){
		
			Utilities.log("@!@!@!playVido0: " + videoId);
			Utilities.log("@@!playVido1: " + teaserMap[videoId]);
			Utilities.log("@@!@@!playVido2 teaserMap[videoId].segments: " + teaserMap[videoId].segments);
			Utilities.log("@@!@@!playVido2 teaserMap[videoId].tveMode: " + teaserMap[videoId].tveMode);
			Utilities.log("@@!@@!playVido2 teaserMap[videoId].authType: " + teaserMap[videoId].authType);
			
	//		TVEUtil.TURNERPLAYER.play(currentVideoId);
	
	/* */
			switch(teaserMap[videoId]){
				case null:
				case undefined:
				case '':
					$('#videoTitle').empty();
					$('#videoexpirationDate').empty();
					$('#videoBlurb').empty();
					break;
				default:
					$('#introSwfContainer').hide();
					$('#adultswim-video-body').show();
					tveModeCall = teaserMap[videoId].tveMode;
					authTypeCall = teaserMap[videoId].authType;
					//Utilities.log("[-oo-] " + teaserMap[videoId] + ' :: ' + teaserMap[videoId].showTitle);
				
					currentVideoObj = teaserMap[videoId];
					// check for scenes; if they exist, play the first one; if no scenes, play the video
					if (teaserMap[videoId].segments.length > 0) {
						currentScenesArray = teaserMap[videoId].segments;
						
						Scenes.load(teaserMap[videoId].segments);
						//////Utilities.log("before playScene"+currentScenesArray[0].videoId)
						PageControls.playScene(currentScenesArray[0].videoId);
						//////Utilities.log("after playScene")
					
					} else {
						currentScenesArray = [];
						//////Utilities.log("in else")
						Scenes.empty();
						PageControls.playScene(videoId);
					}
					
					var myvid = teaserMap[videoId];
					var myvidurl = PageControls.PageUrl + "?oid=" + videoId;
					
					// close video button area
					// $("#videoButtonArea").slideUp(200);
					//VideoButtons.reset();
					
					// fill in video info
					$('#videoThumb').html('<img width="96" height="72" src="'+myvid.thumb+'">');
					$('#videoTitle').html('<span class="showTitle">' + myvid.showTitle + '</span>: <span class="episodeTitle">' + myvid.episodeTitle + '</span>');
					$('#ancillary').html('<span class="expiration">Expires ' + myvid.expirationDate + '</span><span class="rating">' + myvid.rating + '</span>');
					$('#whatItsAbout').html(myvid.description);
	
					Thumbnails.highlightPlaying();
					$("#hdstatus").unbind('click')
					$("#hdstatus").bind('click', function(){
						HQ.hqReady();
					});
	
				break;
			}
		}else {
			
		}
	},
	playNext: function(){
		// find the next video id for playing one after another
		
		// play the next scene if one exists
		var sceneReached = false;
		if (currentScenesArray.length > 0) {
			for (var i = 0; i < currentScenesArray.length; i++) {
				if (sceneReached) {
					PageControls.playScene(currentScenesArray[i].videoId);
					return;
				}
				if (currentScenesArray[i].videoId == currentSceneId) {
					sceneReached = true;
				}
			}
		}
		
		// play the next video
		var videoReached = false;
		if (currentPlaylistMap.orderArray != undefined) {
			for (var i = 0; i < currentPlaylistMap.orderArray.length; i++) {
				if (videoReached) {
					//Utilities.log('00000');
					PageControls.playVideo(currentPlaylistMap.orderArray[i], currentPlaylistMap);
					break;
				}
				if (currentPlaylistMap.orderArray[i] == currentVideoId) {
					videoReached = true;
				}
			}
		}
	},
	playScene: function(videoId){
		Utilities.log('|-0-| playScene!! ' + TVEUtil.AUTHBOOL);
		if(TVEUtil.AUTHBOOL){
			$('#adultswim-video-body').show();
			TVEUtil.strVideoId = videoId;
			TVEUtil.bReloadCVP = false;
			Utilities.log('|-oo-| TVEUtil.authBool : TVEUtil.cvpReady :: ' + TVEUtil.authBool + ' : ' + TVEUtil.cvpReady + ' :: ' + TVEUtil.AUTH.getAccessToken() + ' : ' + TVEUtil.AUTH.getProviderID());
	
				currentSceneId = videoId;
				Scenes.highlightPlaying(currentSceneId);
			
				TVEUtil.getAuthorization(videoId);
		}else{
//			jQuery.facebox(Utilities.getAuthFailStatement());
			Utilities.log('You must sign in before accessing full length episodes.  Click the Login button to sign in.')
			$.cookie(CookieJar.cookie_name, $('.nowPlaying').attr('id'), options);
			$.cookie(CookieJar.cookie_name_id, videoId, options);
			$.cookie(CookieJar.cookie_name_page, $('.pageNo').val(), options);
			Utilities.log('@@@@@@ |-o-| cookie_name_collection ' + $.cookie(CookieJar.cookie_name_collection));
		}
	},
	parseDeepLinkedVideo: function(data){
		// parse the xml to play the video
		var deepLinkedVideoMap = {};
		var orderArray = [];
		
		if ($(data).find('episode').length > 0) {
			$(data).find('episode').each(function(){
				Browse.newvid = Util.storeVideoNode($(this));
				orderArray.push(Browse.newvid.videoId);
				deepLinkedVideoMap[Browse.newvid.videoId] = Browse.newvid;
			});
			
			// keep up with the order the video objects are stored in the array; used for playing through a list
			deepLinkedVideoMap.orderArray = orderArray;
			
			if (deepLinkedVideoMap.orderArray[0] !== undefined && deepLinkedVideoMap.orderArray[0] !== "") {
					//Utilities.log('11111');
				PageControls.playVideo(deepLinkedVideoMap.orderArray[0], deepLinkedVideoMap);
			} else {
				currentVideoId = "";
				TodaysTop.playFirstVideo();
			}
		}
	},
	Track: function(obj){
		// 'page' tracking; video tracking is handled in /files/tnt_driver_trigger_commands.js
		/*window.s = window.s ||
		{
			tl: function(){
			},
			t: function(){
			}
		};
		
		var tmp = "";
		for (var name in obj) {
			s[name] = obj[name];
			tmp += " **" + name + ":" + obj[name];
		}
		//////Utilities.log(tmp);
		
		if (obj.pageName == undefined) {
			// track as event
			//s.tl('video event', 'o', 'video event');
			s.t();
		} else {
			// track as page
			s.t();
		}*/
	}
};

Slideshow = {
	init: function(){
		////Utilities.log('Slideshow');
			var oSlideshow = $('<div id="slideshow"><span id="deck"></span></div><div id="overlay"><div id="controlPanel"><ul class="clearfix"><li><a href="#" class="ssprev"></a></li><li class="last"><a href="#" class="ssnext"></a></li></ul></div>');
			$('#introSwfContainer').css("height","442px");
			$('#introSwfContainer').append(oSlideshow);
			Slideshow.addSlides();
	},
	addSlides: function(){
		$.ajax({
			type: "GET",
			url: '/astv/mvpd/services/marketOutput.do?contentId=49046',
			dataType: "xml",
			success: function(xml) {
				//////Utilities.log('b1 success');
				Slideshow.parseXML(xml);
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				//////Utilities.log('b1 addVideos() parse error: ' + XMLHttpRequest + '\n' + textStatus + '\n' + errorThrown);
			},
			complete: function(xml){
				Slideshow.evanHandlerLanding();
//				Slideshow.setupSlideshowLinks();
			}
		}); //close $.ajax
	},
	parseXML: function(xml){
		$(xml).find('item').each(function(i){
			i++;
			$('#deck').append('<div id="slide' + i + '" class="slide" style="background-image:url(' + $(this).attr("image") + ')"><p><span class="showname">' + $(this).attr("title") + '</span> <span class="copy">' + $(this).attr("subtitle") + '</span></p></div>');
			$('#introSwfContainer .last').before('<li id="nav' + i + '"><a class="nav' + i + ' ssnav" href="#"></a></li>');
			////Utilities.log('|-o-| xml: ' + i + ' :: ' + $(this).attr("image"))
		})
	},
	setupSlideshowLinks: function() {
		$("#overlay").click(function(e) {
			var target = $(e.target);
			
			if (target.is('#overlay')) {
				e.stopPropagation();               
				e.preventDefault();
			}
			
			var idStr = $("#controlPanel .on").attr('id');
			var idSplit = idStr.split('nav')
			var id = idSplit[1];
			
			if(e.ctrlKey) {
				window.open($("#deck #slide" + id + " a").attr('href'), "_blank");
			} 
			else {
				window.open($("#deck #slide" + id + " a").attr('href'), "_self");
			}
		})
		
		$("#controlPanel a").click(function(e) {
			var target = $(e.target);
			
			if (target.is('#controlPanel a')) {
				e.stopPropagation();               
				e.preventDefault();
			}
			////Utilities.log(target)
		})
	},
	sniffImgStatus: function(){
		if ($.imagesLoaded()) {
			clearInterval(intSniffStatus);
			//$('#slideshow').pngFix();
			
			var controlPanelWidth = 0;
			
			$('#controlPanel ul li').each(function(i) {
				controlPanelWidth += $(this).innerWidth();
			})
			
			$('#controlPanel').css('width', controlPanelWidth);
			
			$('#deck').width($('#deck').children('div').width() * $('#deck').children('div').length);
			
			
			$('#slideshow #deck .slide p span').each(function(){
				$(this).css('width', $(this).width());
			})
			
			/**** browse ****/
			
			
		}
	},
	overlay: function() {
		$('#slideshow').width('1000px');
		var slideshowLeft = $('#slideshow').position()['left'];
		var slideshowMarginLeft = $('#slideshow').css('margin-left');
		var slideshowTop = $('#slideshow').position()['top'];
		var slideshowMarginTop = $('#slideshow').css('margin-top');
		
		var newSlideshowLeft = parseInt(slideshowLeft) + parseInt(slideshowMarginLeft);
		var newSlideshowTop = parseInt(slideshowTop) + parseInt(slideshowMarginTop);
		
		$("#overlay").css('left', newSlideshowLeft).css('top', newSlideshowTop);
		$("#overlay").show();
	},
	evanHandlerLanding: function(){
		try {
			//////Utilities.log('sliding');
			$('#introSwfContainer').serialScroll({
				target: '#slideshow',
				items: 'div', // Selector to the items ( relative to the matched elements, '#sections' in this case )
				prev: 'a.ssprev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
				next: 'a.ssnext',// Selector to the 'next' button (absolute too)
				axis: 'xy',// The default is 'y' scroll on both ways
				navigation: '.ssnav',
				duration: 3000,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
				force: true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
				queue: true,// We scroll on both axes, scroll both at the same time.
				stop: true,// Each click will stop any previous animations of the target. (false by default)
				lock: false, // Ignore events if already animating (true by default)		
				interval: 5000, // It's the number of milliseconds to automatically go to the next
				constant: false
			});
		}catch(e){
			////Utilities.log('evanHandlerLanding err ' + e.name + ' : ' + e.message)
		}
		try {
			intSniffStatus = setInterval("Slideshow.sniffImgStatus()", 500);
			Slideshow.overlay()
		} catch(e){}
		$(window).resize(function(){
			Slideshow.overlay();
		})
	}
}// controller for video info buttons

VideoButtons = {
	init: function(){
		// activate play info buttons
		$("#sceneSelectionBtn").bind("click", function(e){
			VideoButtons.activate(this, $("#sceneContent"));
			TVEUtil.checkExTime();
			e.preventDefault();
		});
		$("#videoButtonAreaClose").bind("click", function(e){
			$("#videoButtonArea").slideUp(200);
			VideoButtons.reset();
			e.preventDefault();
		});
		$("#embedCopyBtn").bind("click", function(e){
			Util.copyToClipboard($("#embedContent textarea"));
			e.preventDefault();
		});
		$("#linkCopyBtn").bind("click", function(e){
			Util.copyToClipboard($("#linkContent textarea"));
			e.preventDefault();
		});
		$("#shareSendBtn").bind("click", function(e){
			if (Validate.validateEmailForm(document.shareVideo)) {
				var inputs = [];
				$(':input', '#shareVideo').each(function(){
					inputs.push(this.name + '=' + escape(this.value));
				});
				
				var pageName = currentVideoObj.heading + ":(" + currentVideoObj.videoId + ")";
				PageControls.Track({
					eVar2: pageName,
					eVar3: pageName,
					events: "event6"
				});
				
				$.ajax({
					url: PageControls.SendToFriendUrl,
					data: inputs.join('&'),
					dataType: 'html',
					cache: false,
					error: function(req){
						var msg = (req.readyState !== 4) ? "incomplete request" : req.statusText;
						$("#shareConfirmation").html("There was an error sending your request.<br><br>Please try again later.");
						$("#shareContent").hide();
						$("#shareConfirmation").show();
					},
					success: function(html){
						$("#shareConfirmation").html("Your email has been sent.<br><br>Keep watching videos on TBS.com and share often!");
						$("#shareContent").hide();
						$("#shareConfirmation").show();
					}
				});
			}
			e.preventDefault();
		});
	},
	activate: function(btn, parent){
		// highlight the active button
		VideoButtons.reset();
		$(btn).css("background-color", "#7D4E08");

		$(btn).css("cursor", "default");
		
		/* Clear "friend" fields, but leave "your" fields populated */
		for (var i = 2, l = $("#shareContent input[@type='text']").length; i < l; i++) {
			$("#shareContent input[@type='text']")[i].value = "";
		}
		$("#shareContent textarea")[0].value = "";
		$("#shareConfirmation").hide();
		
		$(parent).show();
		$("#videoButtonArea").fadeIn(200);
		
	},
	deactivate: function(btn, parent){
		// remove button highlight
		$(btn).css("background-color", "#0C0C0C");
		$(btn).css("cursor", "pointer");
		$(parent).hide();
	},
	reset: function(){
		// remove button highlights
		VideoButtons.deactivate($("#sceneSelectionBtn"), $("#sceneContent"));
	}
}

Scenes = {
	numScenes: 0,
	numPerPage: 4,
	currentPage: 0,
	divPad: 15,
	
	init: function(){
	},
	activate: function(){
		// activate play links
		$("#sceneContent .teaserPlay").bind("click", function(e){
			var videoId = $(this).attr('href');
			PageControls.playScene(videoId.split("?oid=")[1]);
			TVEUtil.checkExTime();
			e.preventDefault();
			return false;
		});
	},
	load: function(segments){
	
		//////Utilities.log("in scene load");
		// populate the scenes
		$("#sceneContent #sceneTeasers").empty();
		$("#sceneContent #sceneTeasers").css("margin-left", Scenes.divPad + "px");
		Scenes.numScenes = 0;
		Scenes.currentPage = 0;
		var sceneHtml = "";
		
		for (var i = 0; i < segments.length; i++) {
			var segment = segments[i];
			Scenes.numScenes++;
		}
		
		$("#sceneContent #sceneTeasers").append(sceneHtml);
		
		Scenes.activate();
		Scenes.updateSlideButtons();
		if (Scenes.numScenes > 1) $("#sceneSelectionBtn").show();
		else $("#sceneSelectionBtn").hide();
	},
	slidePrev: function(){
		// slide to the previous page
		Scenes.currentPage--;
		if (Scenes.currentPage < 0) {
			Scenes.currentPage = 0;
		} else {
			Scenes.updateSlideButtons();
		}
		Scenes.slide();
	},
	slideNext: function(){
		// slide to the next page
		var numPages = Math.ceil(Scenes.numScenes / Scenes.numPerPage);
		Scenes.currentPage++;
		if (Scenes.currentPage >= numPages) {
			Scenes.currentPage = (numPages - 1);
		} else {
			Scenes.updateSlideButtons();
		}
		Scenes.slide();
	},
	slide: function(){
		var left = -1 * $("#sceneContent #sceneContainer").width() * Scenes.currentPage + Scenes.divPad;
		// no need to animate if we're already there
		if (left != parseInt($("#sceneContent #sceneTeasers").css("margin-left"))) {
			$("#sceneContent #sceneTeasers").animate({
				'marginLeft': left
			}, 'slow');
		}
	},
	updateSlideButtons: function(){
		// decide whether or not to display the pointer cursor
		var numPages = Math.ceil(Scenes.numScenes / Scenes.numPerPage);
		if (Scenes.currentPage > 0) {
			$("#sceneContent #scenePrevBtn").css("display", "block");
			$("#sceneContent #scenePrevBtn").css("cursor", "pointer");
		} else {
			$("#sceneContent #scenePrevBtn").css("cursor", "default");
			$("#sceneContent #scenePrevBtn").css("display", "none");
		}
		if (numPages > 1 && Scenes.currentPage < (numPages - 1)) {
			$("#sceneContent #sceneNextBtn").css("cursor", "pointer");
			$("#sceneContent #sceneNextBtn").css("display", "block");
		} else {
			$("#sceneContent #sceneNextBtn").css("cursor", "default");
			$("#sceneContent #sceneNextBtn").css("display", "none");
		}
	},
	highlightPlaying: function(videoId){
		// highlight the currently playing scene
		$("#sceneTeasers div").css("background-color", "#7D4E08");
		$("#sceneTeaserItem_" + videoId).css("background-color", "#4380B7");
	},
	empty: function(){
		// remove the scenes and hide the scene selection button
		$("#sceneContent #sceneTeasers").empty();
		$("#sceneSelectionBtn").hide();
	}
}
// controller for the teaser area

Thumbnails = {
	videoNumber:0,
	init: function(){
		
		//player.emptyQueue();
		Utilities.log('{-o-} Thumbnails.init');
		$(".listItem").unbind("click");
		// activate teaser play links
		$(".listItem").bind("click", function(e){
			$('.tn').each(function(){
				$(this).removeClass('nowPlaying').css({
					'background-color': '#fff'
				});
			});
			Thumbnails.clickMethod(this);
			if( !Browse.bOverrideVid){
				if(TVEUtil.AUTHBOOL){
					Utilities.log('|-o-| |-o-| |-o-| !Browse.bOverrideVid ' + COOKIE_VAL_collectionUrl);
				}else{
					Utilities.log('You must sign in before accessing full length episodes.  Click the Login button to sign in.');
					$.cookie(CookieJar.cookie_name, $('.nowPlaying').attr('id'), options);
					$.cookie(CookieJar.cookie_name_id, $(this).find('img').attr('class').split('*')[0], options);
					$.cookie(CookieJar.cookie_name_page, $('.pageNo').val(), options);

					Utilities.log('@@@@@@ |-o-| CookieJar.cookie_name :: ' + CookieJar.cookie_name + ' : ' + $.cookie(CookieJar.cookie_name));
					Utilities.log('@@@@@@ |-o-| CookieJar.cookie_name_id :: ' + CookieJar.cookie_name_id + ' : ' + $.cookie(CookieJar.cookie_name_id));
					Utilities.log('@@@@@@ |-o-| CookieJar.cookie_name_page :: ' + CookieJar.cookie_name_page + ' : ' + $.cookie(CookieJar.cookie_name_page));
					Utilities.log('@@@@@@ |-o-| CookieJar.cookie_name_collection :: ' + CookieJar.cookie_name_collection + ' : ' + $.cookie(CookieJar.cookie_name_collection));
					
					Utilities.log('###### |-o-| Utilities.getAuthFailStatement() ' + Utilities.getAuthFailStatement());
					
					TVEUtil.authenticateUser();
				}
			}
			e.preventDefault();
			return false;
		});
		
		Thumbnails.highlightPlaying();
		Thumbnails.tnHovers();
	},
	clickMethod: function(obj){
			Browse.videoId = $(obj).addClass('nowPlaying').css({
				'background-color': '#FFF076'
			}).find('img').attr('class').split('*')[0];
			Browse.videoNum = $(obj).attr('id').split('_')[1];
			setShowName($(obj).find('.episode-name').text());
			PageControlsSetup.updateShowTitle();

			if(!bInitPlay){
				Utilities.log('!!!!!! Thumbnails.clickMethod : $.cookie(CookieJar.cookie_name) :: ' + $.cookie(CookieJar.cookie_name));
				if($.cookie(CookieJar.cookie_name) != '' || $.cookie(CookieJar.cookie_name) != null){
					CookieJar.cookie_name = Browse.videoNum;
					$.cookie(CookieJar.cookie_name);
					Utilities.log('!!!!!! Thumbnails.clickMethod : $.cookie(CookieJar.cookie_name) :: ' + $.cookie(CookieJar.cookie_name));
				}
			}
			Thumbnails.bOverrideVid = true;
			Utilities.log('{-o-} Browse.bOverrideVid ' + Browse.bOverrideVid + ' : ' + Thumbnails.bOverrideVid);
			
			//Utilities.log('33333');
			Thumbnails.loadDescripData(Browse.videoNum);
			TVEUtil.checkExTime();
	},
	loadDescripData: function(offset){
		//Utilities.log('|-o-| loadDescripData ' + offset + ' : ' + Browse.collection);
		$.ajax({
			type: "GET",
			url: COOKIE_VAL_collectionUrl + "?limit=1&offset=" + offset + "&id=" + Browse.collection,
			cache: true,
			dataType: "xml",
			success: function(data){
				//Utilities.log("!!!!!! loadDescripData success"+data)
				Thumbnails.parseDescrip(data);
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				//Utilities.log('!!!!!! b1 loadDescripData() parse error: ' + XMLHttpRequest + '\n' + textStatus + '\n' + errorThrown);
//				Thumbnails.doOmni();
				PageControls.playVideo(Browse.videoId, currentTeaserMap);
			},
			complete: function(data){
			}
		});
	},
	parseDescrip: function(data){
		if ($(data).find('episode').length > 0) {
			$(data).find('episode').each(function(i){
				////alert($(this) + ' :: ' + $(this).children("title").text());
				Browse.newvid = Util.storeVideoNode($(this));
				Utilities.log('@@@@@ Browse.newvid ' + Browse.newvid);
				currentTeaserMap[Browse.newvid.videoId] = Browse.newvid;
				Thumbnails.doOmni();
				PageControls.playVideo(Browse.videoId, currentTeaserMap);
				//orderArray.push(Browse.newvid.videoId);
			});
			
		}
	},
	doOmni: function(){
		strPageName = $('.nowPlaying .episode-title').text();
		strSubSectionName = $('.nowPlaying .episode-name').text();

		/*s.server = strSectionName;
		
		if (strSubSectionName != "") {
			s.channel = strSectionName + " : " + strSubSectionName;
			s.pageName = strSectionName + ' : ' + strSubSectionName + ' : ' + strPageName;
		} else {
			s.channel = strSectionName + " : Home";
			s.pageName = strSectionName + ' : ' + strPageName;
		}
		s.t();*/
	},
	loadVideos: function(collection){
		Browse.collection = collection;
		//Utilities.log('222a (-oo-) collectionzz: ' + Browse.pageNumber + ' : ' + Browse.collection + ' :: ' + Browse.strCurrCollection);
		if (Browse.strCurrCollection != collection) {
			Browse.strCurrCollection = collection;
		}
		$('.pageNo').val(Browse.pageNumber);
		// get the teaser xml file
		$('#teaserContent').html('<br>loading...');
		//Utilities.log('222b (-oo-) collectionzzz: ' + Browse.pageNumber + ' : ' + collection + ' : ' + currentSectionMap[collection].name + ' :: ' +  +currentSectionMap[collection].expirationDate);
		try {
			$('#teaserAreaTitle').html(currentSectionMap[collection].name);
		} catch (e) {}
		try {
			$('#teaserAreaSubTitle').html(currentSectionMap[collection].expirationDate);
		} catch (e) {}
		//var pageName = "/video/" + currentSectionMap[collection].name;
		//PageControls.Track({pageName:pageName, prop1:pageName, prop2:""});
		//Utilities.log('\\-o-\\ ' + collection + ' : &offset=' + ((Browse.pageNumber - 1) * (Browse.maxItemsPerPage)) + ' :: ' + (Browse.pageNumber - 1) + ' * ' + (Browse.maxItemsPerPage));
		$.ajax({
			type: "GET",
			url: COOKIE_VAL_collectionUrl + "?limit=" + Browse.MaxVideos + '&offset=' + ((Browse.pageNumber - 1) * Browse.maxItemsPerPage) + "&id=" + collection,
			cache: true,
			dataType: "xml",
			success: function(data){
				////Utilities.log("loadVideos success"+data)
				Thumbnails.populate(data);
			},
			error: function(){
				Utilities.log("loadVideos error");
			}
		});
	},
 	populate: function(data){
		// parse the xml and display the teasers
		currentTeaserMap = {};
		var videoCount = 0;
		var orderArray = [];

		try{
				$(data).find('episodes').each(function(){
					Browse._nTotalPages = parseInt(Math.ceil($(this).attr('totalItems') / Browse.maxItemsPerPage));
				});
				$('.pageControls .allDaPages').text(Browse._nTotalPages);
		} catch(e){
			Utilities.error(e.name + ' : ' + e.message);
		};
		
		if ($(data).find('episode').length > 0) {
			$('#teaserContent').empty();
			$(data).find('episode').each(function(i){
			
				//Utilities.log('[[-o-]] ' + $(this))
				Browse.newvid = Util.storeVideoNode($(this));
				orderArray.push(Browse.newvid.videoId);
				currentTeaserMap[Browse.newvid.videoId] = Browse.newvid;
				
				 escapedTitle = Browse.newvid.showTitle.replace(/\'/g,"\\'");
				$('#teaserContent').append('<span class="tn br_false listItem " id="listItem_' + i + '"><div class="thumbnail ' + PageControls.PageUrl + '"><img src="' + Browse.newvid.thumb + '" width="120" height="90" class="' + Browse.newvid.videoId + '*' + Browse.newvid.franchiseId + '"><div class="sash"></div></div><div class="showtext clearfix"><p class="episode-name">' + Browse.newvid.showTitle + '</p><p class="episode-title">' + Browse.newvid.episodeTitle + '</p><span class="episode-exp">Expires: ' + Browse.newvid.expirationDate + '</span><span class="episode-rating">' + Browse.newvid.rating + '</span><p></p></div></span>');
				videoCount++;
				
			});
			// keep up with the order the video objects are stored in the array; used for playing through a list
			currentTeaserMap.orderArray = orderArray;
			
			Browse.bOverrideVid = false;
			Thumbnails.init();
					$('#all-adultswim-videos-container').height(parseInt($('#all-adultswim-videos').height() + 60));

		//Utilities.log('{-o-} all-adultswim-videos height: ' + $('#all-adultswim-videos').height() + ' :: ' + $('.pagBot').height() + ' : ' + $('.pagBot').css('top'));

			if (deepLinkedCategory !== "" && currentVideoId === "" && waitingVideo === "") {
				//////Utilities.log("in playVideo");
				// if we just loaded a deeplinked category, play the first video if there isn't a deeplinked video
				deepLinkedCategory = "";
				PageControls.playVideo(currentTeaserMap.orderArray[0], currentTeaserMap);
			}
			
		} else {
			Thumbnails.error();
		}
	},
	resize: function(){
		$("#teaserArea").css("height", $("#sectionNavArea").height());
	},
	error: function(){
		// handle error retrieving videos or an empty video list
		$('#teaserContent').empty();
		$('#teaserContent').html('<br>There are no videos for your selection.');
	},
	highlightPlaying: function(){
		// highlight the currently playing video
		////Utilities.log('|-o-| currentVideoId ' + currentVideoId)
		$('#listItem').removeClass("teaserActive");
		$('#listItem_' + currentVideoId).addClass("teaserActive");
	},
	tnHovers: function(){
		$('.tn').corner("round 6px").hover(function(){
			PageControls.strBgColor = '#FFF076';
			$(this).css({
				'background': PageControls.strBgColor
			});
			////Utilities.log('wax on ' + $(this).attr('class'));
		}, function(){
			($(this).hasClass('nowPlaying')) ? PageControls.strBgColor = '#FFF076' : PageControls.strBgColor = '#fff';
			$(this).css({
				'background': PageControls.strBgColor
			});
			////Utilities.log('wax off ' + $(this).attr('class'));
		});
	}
}
// controller for the section navigation

SectionNav = {
	init: function(){
		// activate the div clicks
		$(".sectionNavCell").click(function(e){
			setShowName($(this).text());
			Utilities.log('{-oo-} ' + $(this).text());
			if($(this).text().toLowerCase() === "All Shows".toLowerCase() || $(this).text().toLowerCase() === "All Episodes".toLowerCase()){
				COOKIE_VAL_collectionUrl = '/astv/mvpd/services/getAllEpisodes.do';
			} else {
				COOKIE_VAL_collectionUrl = '/astv/mvpd/services/getCollectionByContentId.do';
			}
			
		
			COOKIE_VAL_page = 1;
			COOKIE_VAL_collection = $(this).attr('id');
			$.cookie(CookieJar.cookie_name_collection, COOKIE_VAL_collection,options);
			$.cookie(CookieJar.cookie_name_collectionUrl, COOKIE_VAL_collectionUrl,options);
			Browse.pageNumber = 1;
//			Browse._nTotalPages = 1;
//			$('.pageNo').val(1);
//			$('.pageNo').text(1);
			//Utilities.log('333 {-o-} .sectionNavCell id ' + $(this).attr('id'));
			SectionNav.toggle(this);
			$('h2.browse').html($(this).text());
			if ($(this).next(".sectionNavSubGroup").length == 0) {
				// get the collection id from the div name attribute
				Thumbnails.loadVideos(COOKIE_VAL_collection);
			}
			TVEUtil.checkExTime();
			e.preventDefault();
			return false;
		});
		
		$(".sectionNavCellActive").click(function(e){
			SectionNav.toggle(this);
			e.preventDefault();
			return false;
		});
		
		$(".sectionNavSubCell").click(function(e){
			SectionNav.toggle(this);
			if ($(this).next(".sectionNavSubGroup").length == 0) {
				// get the collection id from the div name attribute
				Thumbnails.loadVideos($(this).attr('id'));
			}
			e.preventDefault();
			return false;
		});
		
		$(".sectionNavSubSubCell").click(function(e){
			SectionNav.resetSubSubNavCells();
			$(this).removeClass("sectionNavSubSubCell").addClass("sectionNavSubSubCellActive");
			
			// get the collection id from the div name attribute
			Thumbnails.loadVideos($(this).attr('id'));
			e.preventDefault();
			return false;
		});
		
		// resize the teaser area to match the height of the section nav
		Thumbnails.resize();
	},
	toggle: function(div){
		// open or close the divs
		if ($(div).hasClass("sectionNavCell")) {
			SectionNav.resetNavCells();
			$(div).next(".sectionNavSubGroup").show("slow", Thumbnails.resize);
			$(div).removeClass("sectionNavCell").addClass("sectionNavCellActive");
		} else if ($(div).hasClass("sectionNavSubCell")) {
			SectionNav.resetSubNavCells();
			$(div).next(".sectionNavSubGroup").show("slow", Thumbnails.resize);
			$(div).removeClass("sectionNavSubCell").addClass("sectionNavSubCellActive");
		}
	},
	resetNavCells: function(){
		// close all the divs
		$(".sectionNavCellActive").each(function(){
			$(this).next(".sectionNavSubGroup").hide("slow", Thumbnails.resize);
			$(this).removeClass("sectionNavCellActive").addClass("sectionNavCell");
		});
		SectionNav.resetSubNavCells();
	},
	resetSubNavCells: function(){
		// close all the subnav divs
		$(".sectionNavSubCellActive").each(function(){
			$(this).next(".sectionNavSubGroup").hide("slow", Thumbnails.resize);
			$(this).removeClass("sectionNavSubCellActive").addClass("sectionNavSubCell");
		});
		SectionNav.resetSubSubNavCells();
	},
	resetSubSubNavCells: function(){
		// close all the subnav divs
		$(".sectionNavSubSubCellActive").each(function(){
			$(this).removeClass("sectionNavSubSubCellActive").addClass("sectionNavSubSubCell");
		});
	},
	load: function(section){
		// load the selected collection
		$("#sectionNavArea").html("loading....");
		if (navXml === "") {
			// if nav is still loading, store the section
			TVEUtil.waitingSection = section;
			
			// should only happen when a user clicks so we can remove the deep linked category
			deepLinkedCategory = "";
		} else {
			// traverse xml to find section belonging to deepLinkedCategory; if none remove deeplinked status
			if (deepLinkedCategory !== "") {
				var foundSelectedSection = MainNav.findSection(deepLinkedCategory, navXml);
				
				// once we find the section set it as selectedSection and run main nav highlight; also set section
				if (foundSelectedSection !== "") {
					selectedCollection = foundSelectedSection.toUpperCase();
					section = foundSelectedSection;
					MainNav.highlightSelected();
				} else {
					// if we don't find it set deepLinkedCategory = "";
					deepLinkedCategory = "";
					
					// didn't find the deeplinked category so play the default video from today's top
					TodaysTop.playFirstVideo();
				}
			}
			
			// find the collection in the xml create the nav display
			var firstcollectionid = "";
			currentSectionMap = {};
			
			$(navXml).find('collection').each(function(){
				var mycollection = $(this).children('name').text();
				if (mycollection.toUpperCase() == section.toUpperCase()) {
					var mycollectionid = $(this).attr('id');
					firstcollectionid = mycollectionid;
					
					$("#sectionNavArea").empty();
					if ($(this).children('subcollection').length < 1) {
						var newsection = {};
						newsection.name = $(this).children('title').text();
						newsection.expirationDate = $(this).children('expirationDate').text();
						currentSectionMap[$(this).attr('id')] = newsection;
						
						Thumbnails.loadVideos(COOKIE_VAL_collection);//mycollectionid;
						
					} else {
					
						var navhtml = '<dt id="sectionNavTitle" class="sectionNavCell"><a href="javascript:void();">All Shows</a></dt>';
						//var navhtml = '<dt id="sectionNavTitle">' + mycollection + '</dt>';
						var numcollections = 0;
						
						$(this).children('subcollection').each(function(){
							if (numcollections === 0) {
								firstcollectionid = $(this).attr('id');
								
							}
							var newsection = {};
							newsection.name = $(this).children('title').text();
							newsection.expirationDate = $(this).children('expirationDate').text();
							currentSectionMap[$(this).attr('id')] = newsection;
							var mysubcollectionname = $(this).children('title').text();
							theShowName = $(this).children('name').text();
							navhtml = navhtml.concat('<dd class="sectionNavCell" id="' + $(this).attr('id') + '"><a href="javascript:void();">' + theShowName + '</a></dd>');
							if ($(this).children('subcollection').length > 0) {
								var subgroup = '<dl class="sectionNavSubGroup">';
								var numsubcollections = 0;
								$(this).children('subcollection').each(function(){
									if (numcollections === 0 && numsubcollections === 0) {
										firstcollectionid = $(this).attr('id');
										
									}
									subgroup = subgroup.concat('<dd class="sectionNavSubCell" id="' + $(this).attr('id') + '"><a href="javascript:void();">' + $(this).children('name').text() + '</a></dd>');
									var newsection = {};
									newsection.name = mysubcollectionname + ": " + $(this).children('name').text();
									newsection.expirationDate = $(this).children('expirationDate').text();
									currentSectionMap[$(this).attr('id')] = newsection;
									var mysubsubcollectionname = $(this).children('name').text();
									
									if ($(this).children('subcollection').length > 0) {
										var subsubgroup = '<div class="sectionNavSubGroup">';
										var numsubsubcollections = 0;
										$(this).children('subcollection').each(function(){
											if (numcollections === 0 && numsubcollections === 0 && numsubsubcollections === 0) {
												firstcollectionid = $(this).attr('id');
												
											}
											subsubgroup = subsubgroup.concat('<div class="sectionNavSubSubCell" id="' + $(this).attr('id') + '"><b>' + $(this).children('name').text() + '</b></div>');
											var newsection = {};
											newsection.name = mysubcollectionname + ": " + mysubsubcollectionname + ": " + $(this).children('name').text();
											newsection.expirationDate = $(this).children('expirationDate').text();
											currentSectionMap[$(this).attr('id')] = newsection;
											numsubsubcollections++;
											
										});
										subsubgroup = subsubgroup.concat('</div>');
										subgroup = subgroup.concat(subsubgroup);
									}
									numsubcollections++;
								});
								subgroup = subgroup.concat('</div>');
								navhtml = navhtml.concat(subgroup);
							}
							numcollections++;
						});
//						navhtml = navhtml.concat('</dl>');
						$("#sectionNavArea").append(navhtml);
						
						//////Utilities.log("firstcollectionid="+firstcollectionid)
						
//						Thumbnails.loadVideos(firstcollectionid); //added per defect 195
						Thumbnails.loadVideos(COOKIE_VAL_collection);

					}
				}
			});
			SectionNav.init();
			
			
			
			
			// if currentTeaserMap is empty, load the deeplinked category or the first collection with videos
			if (Util.isEmptyObject(currentTeaserMap)) {
				if (deepLinkedCategory !== "") {
					// load the videos for the deeplinked category
					Thumbnails.loadVideos(COOKIE_VAL_collection);//deepLinkedCategory

					
					// open up the category in the left nav
					var div = $("#" + deepLinkedCategory);
					if ($(div).hasClass("sectionNavCell")) {
						$(div).removeClass("sectionNavCell").addClass("sectionNavCellActive");
						
					} else if ($(div).hasClass("sectionNavSubCell")) {
						$(div).parent(".sectionNavSubGroup").show("slow", Thumbnails.resize);
						$(div).parent(".sectionNavSubGroup").prev(".sectionNavCell").removeClass("sectionNavCell").addClass("sectionNavCellActive");
						$(div).removeClass("sectionNavSubCell").addClass("sectionNavSubCellActive");
						
					} else if ($(div).hasClass("sectionNavSubSubCell")) {
						$(div).parent(".sectionNavSubGroup").prev(".sectionNavSubCell").parent(".sectionNavSubGroup").show("slow", Thumbnails.resize);
						$(div).parent(".sectionNavSubGroup").prev(".sectionNavSubCell").parent(".sectionNavSubGroup").prev(".sectionNavCell").removeClass("sectionNavCell").addClass("sectionNavCellActive");
						$(div).parent(".sectionNavSubGroup").show("slow", Thumbnails.resize);
						$(div).parent(".sectionNavSubGroup").prev(".sectionNavSubCell").removeClass("sectionNavSubCell").addClass("sectionNavSubCellActive");
						$(div).removeClass("sectionNavSubSubCell").addClass("sectionNavSubSubCellActive");
					}
				} else {
					Utilities.log('!! ' + COOKIE_VAL_collection + ' : ' + firstcollectionid);
					Thumbnails.loadVideos(COOKIE_VAL_collection);//firstcollectionid
					
				}
			}
		}
	}
}
// basic utility functions

Util = {
	formatDate: function(str){
		return $.format.date(str, "MM/dd/YY")
	},
	storeVideoNode: function(node){
		Browse.newvid = {};
		Browse.newvid.videoId = $(node).attr("id");
		Browse.newvid.showTitle = $(node).children("SeriesName").text();
		Browse.newvid.episodeTitle = $(node).children("episodeTitle").text();
		Browse.newvid.seasonNumber = $(node).children("seasonNumber").text();
		Browse.newvid.episodeNumber = $(node).children("episodeNumber").text();
		Browse.newvid.franchiseId = $(node).children("franchiseId").text();
		Browse.newvid.collectionId = $(node).attr("collectionId");
		Browse.newvid.thumb = $(node).children("thumbnailUrl").text();
		Browse.newvid.heading = $(node).children("title").text();
		Browse.newvid.blurb = $(node).children("shortBlurb").text();
		Browse.newvid.description = $(node).children("description").text();
		Browse.newvid.expirationDate = Util.formatDate($(node).children("expirationDate").text());
		Browse.newvid.embeddable = $(node).children("embeddable").text();
		Browse.newvid.mavenExternalId = $(node).children("mavenExternalId").text();
		Browse.newvid.franchiseName = $(node).children("franchiseName").text();
		Browse.newvid.playlistId = $(node).children("mavenPlaylistId").text();
		Browse.newvid.rating = $(node).children("tvRatingCode").text();
		Browse.newvid.tveMode = $(node).children("tveMode").text();
		
		var segments = [];
		$(node).find('segment').each(function(){
			var segment = {};
			segment.videoId = $(this).attr("id");
			segment.thumb = $(this).children("thumbnailUrl").text();
			segment.heading = $(this).children("title").text();
			segment.blurb = $(this).children("shortBlurb").text();
			segment.description = $(this).children("description").text();
			segment.expirationDate = Util.formatDate($(this).children("expirationDate").text());
			segments.push(segment);
		});
		Browse.newvid.segments = segments;
		
		return Browse.newvid;
	},
	isEmptyObject: function(obj){
		// check if an object is empty
		for (var i in obj) {
			return false;
		}
		return true;
	},
	copyToClipboard: function(textarea){
		// copy text from a textarea to the clipboard
		$(textarea).css("background-color", "#0A3256");
		window.setTimeout(function(){
			$(textarea).css("background-color", "#FFF");
		}, 60);
		
		var txt = $(textarea)[0].value;
		if (txt.createTextRange) {
			range = txt.createTextRange();
			if (range && (BodyLoaded == 1)) {
				range.execCommand("Copy");
			}
		} else {
			$('#clipboardProxy').html('<embed id=clipboardFlash" src="<c:out value="${imagePath}" />/flash/clipboardProxy.swf" FlashVars="clipboard=' + encodeURIComponent(txt) + '" width="0" height="0" type="application/x-shockwave-flash"></embed>');
		}
	}
}

// form validation functions
Validate = {
	isEmpty: function(fieldValue){
		if ((fieldValue.length == 0) || (fieldValue == null)) {
			return true;
		} else {
			return false;
		}
	},
	isEmptyRadio: function(field){
		for (i = 0; i < field.length; i++) {
			if (field[i].checked) {
				return false;
			}
		}
		return true;
	},
	isNumeric: function(fieldValue){
		var ValidChars = "0123456789.";
		var IsNumber = true;
		var Char;
		
		for (i = 0; i < fieldValue.length && IsNumber == true; i++) {
			Char = fieldValue.charAt(i);
			if (ValidChars.indexOf(Char) == -1) {
				IsNumber = false;
			}
		}
		return IsNumber;
	},
	isEmail: function(fieldvalue){
		var i = 1;
		var sLength = fieldvalue.length;
		
		// look for @
		while ((i < sLength) && (fieldvalue.charAt(i) != "@")) {
			i++
		}
		
		if ((i >= sLength) || (fieldvalue.charAt(i) != "@")) {
			return false;
		} else {
			i += 2;
		}
		
		// look for .
		while ((i < sLength) && (fieldvalue.charAt(i) != ".")) {
			i++
		}
		
		// there must be at least one character after the .
		if ((i >= sLength - 1) || (fieldvalue.charAt(i) != ".")) {
			return false;
		} else {
			return true;
		}
	},
	validateEmailForm: function(form){
		var valid = true;
		var msg = "Please correct the following information - \n\n";
		
		if (Validate.isEmpty(form.fp_sender.value)) {
			msg += "- Your name is required \n";
			valid = false;
		}
		if (Validate.isEmpty(form.fp_sender_email.value)) {
			msg += "- Your email is required \n";
			valid = false;
		} else if (!Validate.isEmail(form.fp_sender_email.value)) {
			msg += "- Your email is not a valid email address \n";
			valid = false;
		}
		if (Validate.isEmpty(form.fp_friend.value)) {
			msg += "- Friend's name is required \n";
			valid = false;
		}
		if (Validate.isEmpty(form.fp_friend_email.value)) {
			msg += "- Friend's email is required \n";
			valid = false;
		} else if (!Validate.isEmail(form.fp_friend_email.value)) {
			msg += "- Friend's email is not a valid email address \n";
			valid = false;
		}
		
		if (!valid) {
			////Utilities.log(msg);
		}
		return valid;
	}
};

BrowseButtons = {
	setupClicks: function(){
	// page nav
		//next page
			$('.navNext').click(function(){
				//Utilities.log('NEXT! ' + (Browse.pageNumber<= Browse._nTotalPages) + ' :: ' + Browse.pageNumber + ' : ' + Browse._nTotalPages);
				if (Browse.pageNumber < Browse._nTotalPages) {
					Browse.pageNumber++;
					Browse.strDirection = 'next';
					Browse.bOverrideBlur = false;
					Browse.bOverrideVid = true;
					//Utilities.log('_BROWSE_NEXT CLICKED');
					//Browse.addVideos();
					Thumbnails.loadVideos(Browse.strCurrCollection);
					Browse.bOverrideVid;
					//Browse.updatePage();
				}
			});
		// prev page
			$('.navPrev').click(function(){
				if (Browse.pageNumber > 1) {
					Browse.pageNumber--;
					Browse.strDirection = 'prev';
					Browse.bOverrideBlur = false;
					Browse.bOverrideVid = true;
					//Utilities.log('_BROWSE_PREV CLICKED');
					//Browse.addVideos();
					Thumbnails.loadVideos(Browse.strCurrCollection);
					Browse.bOverrideVid
					//Browse.updatePage();
				}
			});
			
		//page nav actions (focus/blur/keypress)
		$('.pageNo').focus(function(){
			Browse._objVidz['_ncount'] = 0;
			Browse.bOverrideBlur = false;
			Browse.bOverrideVid = true;
			Browse.strPagination = $(this).val();
			$('.pageNo').val('');
		});
		$('.pageNo').blur(function(){
				//////Utilities.log('Blurr: ' + Browse.bOverrideBlur + ' : ' + $(this).val());
				Browse._nTotalPages = $('.pagTop .allDaPages').text();
				Browse.bOverrideVid = true;
				if (!Browse.bOverrideBlur) {
					Browse._objVidz['_ncount'] = 0;
					Browse.updatePage($(this).val());
				}
		});
		$('.pageNo').keypress(function (e) {
			switch(e.which){
				case 48: // 0
				case 49: // 1
				case 50: // 2
				case 51: // 3
				case 52: // 4
				case 53: // 5
				case 54: // 6
				case 55: // 7
				case 56: // 8
				case 57: // 9
					return true;
					break;
				case 0:  //nav
				case 8:  // backspace
					return true;
					break;
				case 13:  // enter
					//////Utilities.log('case 13: ' + $(this).val());
					Browse.bOverrideBlur = true;
					Browse.bOverrideVid = true;
					Browse.updatePage($(this).val());
					$('.pageNo').blur();
					return false;
					break;
				default:
					return false;
					break;
			}
		});
	}
};
/**
 * Unobtrusive Image Rollovers
 * By: Paul McLanahan <paul dot mclanahan at digital insight>
 * Usage: Include this script in the head of the HTML document with a <script>
 *		and include the class "rollover" on any link tag with an image as its only child.
 */

var Rollover = {
	
	imgObjects: [],
	
	initRollovers: function(){
		if(!document.getElementsByTagName)return;
		all_links = document.getElementsByTagName('a');
		for(var i = 0; i < all_links.length; i++){
			var linkObj = all_links[i]; 
			if (linkObj.className && (' ' + linkObj.className + ' ').indexOf(' rollover ') != -1){
				if (linkObj.childNodes && 
					linkObj.childNodes.length == 1 && 
					linkObj.childNodes[0].nodeName.toLowerCase() == 'img' &&
					/-off\.[a-z]{3}$/.test(linkObj.childNodes[0].src)){
					// preload rollover images
					Rollover.	imgObjects[Rollover.	imgObjects.length] = new Image();
					Rollover.	imgObjects[Rollover.	imgObjects.length-1].src = linkObj.childNodes[0].src.replace(/-off(\.[^.]{3})$/,"-on$1");
					
					// add mouseover and mouseout event handlers to links
					diLib.addEvent(linkObj,'mouseover',Rollover.	imgOn,false);
					diLib.addEvent(linkObj,'mouseout',Rollover.	imgOff,false);
				}
			}
		}
	},
	
	imgOn: function(e){
		linkObj = diLib.getTarget(e,'a');
		if(!linkObj)return;
		linkObj.childNodes[0].src = linkObj.childNodes[0].src.replace(/-off(\.[a-z]{3})$/,"-on$1");
	},
	
	imgOff: function(e){
		linkObj = diLib.getTarget(e,'a');
		if(!linkObj)return;
		linkObj.childNodes[0].src = linkObj.childNodes[0].src.replace(/-on(\.[a-z]{3})$/,"-off$1");
	}
	
}

/**
 * diLib: Object containing helper functions
 * by: Paul McLanahan <paul dot mclanahan at digital insight>
 */

diLib = {
	getTarget: function(e,tag){
		tag = tag.toLowerCase();
		
		// Get the object that fired the event
		var t = window.event ? window.event.srcElement : e ? e.target : null;
		if(!t) return;
		
		// Climb the DOM untill we find the object we're looking for
		while(t != document.body && t.nodeName.toLowerCase() != tag)
			t = t.parentNode;
		
		// Make sure it is the one we're looking for
		if(t.nodeName.toLowerCase() != tag)
			return null;

		return t;
	},
	/**
	 * Cross-browser event handling for IE5+ (Win & Mac), NS6+ and Mozilla/Gecko
	 * By Scott Andrew
	 */
	addEvent: function(obj, evType, fn, useCapture) {
		if (obj.addEventListener) {
			obj.addEventListener(evType, fn, useCapture);
			return true;
		} else if (obj.attachEvent) {
			var r = obj.attachEvent('on' + evType, fn);
			return r;
		} else {
			obj['on' + evType] = fn;
		}
	}
}

// have the rollovers initialize on page load
diLib.addEvent(window,'load',Rollover.	initRollovers,false);
jQuery.imagesLoaded = function() {
	var bImgLoaded = true;
		$('.vidImg').each(function(){
			if ($(this).complete == false) {
				bImgLoaded = false;
			}
		})
	return bImgLoaded;
}

