(function(){
		var header_height = $('#main_header').height();
		var footer_height = $('#main_footer').height();
		var window_height = $(window).height();
		$('#main_body').css({'minHeight':(window_height-(header_height + footer_height)) - 52+'px'});
	})()	

var page = $('#body_content').attr('class');
$(document).ready(function(){

	//get page dimensions and size accordingly					   
	
	//ANCHOR SCROLLER
	//example = <a href="#main_logo" class="anchor_scroll">test</a>
	$('.anchor_scroll').live('click',function(){
		var theAnchor = $(this).attr('href');
		alert(theAnchor);
		var top_pos = $(theAnchor).offset();
		$('html, body').animate({'scrollTop':top_pos.top+'px'},1000);
		return false;
	});
						   
	/***********************
		FOLLOW US DROPDOWN
	***********************/
	var follow_us_dd_email_form_settings = {'parent' : '.follow_us_dd_email_form', 'child' : '.browse_title_dd_child' , animation : {'opacity':'0'}, speed : 300};
	follow_us_dd_email_forme_dropdowns =  new mgmUI.dropdowns.init(follow_us_dd_email_form_settings);
	/***********************
		FOLLOW US EMAIL DROPDOWN
	***********************/
	$('#email_trigger').click(function(e){
		e.stopPropagation();
		$('#follow_us_dd_email').slideDown(200);	
		return false;
	});
	/***************************
		FOLLOW US DROPDOWN
	**************************/
	$('#nav_follow').click(function(e){
		e.stopPropagation();
		$('#follow_us_dd_basic').fadeIn(300);	
	});
	
	$(document).click(function(){
		$('#follow_us_dd_basic').fadeOut(300);						   
	});
	/*****************************
		TWITTER FOOTER THINGY
	*****************************/
	
	$('#twitter_overlay').css({'marginTop':(-1*$('#twitter_overlay').height())+'px'});
	$('#twitter_footer').mouseenter(function(){
		$('#twitter_overlay').fadeIn(400);										 
	});
	$('#twitter_container').mouseleave(function(){
		$('#twitter_overlay').fadeOut(400);											
	});
	
	/****************************
		INPUT CLEAR
	****************************/
	$('.input_clear').click(function(){
		var original_val = $(this).attr('data-original');
		if($(this).val() == original_val){
			$(this).val('');
		}
		$(this).bind('blur',function(){
			if($(this).val() == ''){
				$(this).val(original_val);	
			}
		});
	});
	/**************************************
		EMAIL FORM
	**************************************/
	$('#email_dd_year li a').click(function(){
		var year_text = $(this).text();
		$('#email_dd_year').attr('data-year',year_text);	
		$('#email_dd_year_parent a.dd_trigger').text(year_text);
		$('#email_dd_year').parent().slideUp();
	});
	$('#email_dd_month li a').click(function(){
		var month_text = $(this).text();
		var month_num = $(this).attr('data-month');
		$('#email_dd_month').attr('data-month',month_num);	
		$('#email_dd_month_parent a.dd_trigger').text(month_text);
		$('#email_dd_month').parent().slideUp();
	});
	$('#email_dd_date li a').click(function(){
		var date_text = $(this).text();
		$('#email_dd_date').attr('data-date',date_text);	
		$('#email_dd_date_parent a.dd_trigger').text(date_text);
		$('#email_dd_date').parent().slideUp();
	});
	var monthDay = [31,28,31,30,31,30,31,31,30,31,30,31];
	$('#email_form_submit').click(validateForm);
	var today =new Date();
	var bornBefore = new Date((today.getFullYear() - 18),(today.getMonth()),(today.getDay()));
	function validateForm(){
		var eLog = [];
		var emailVal = $('#email_signup_email').val();
		var zipVal = $('#email_signup_zip').val();
		var genderVal = $('input[name=gender]:radio:checked').val();
		var birthYear = $('#email_dd_year').attr('data-year');
		var birthMonth = $('#email_dd_month').attr('data-month');
		var birthDate = $('#email_dd_date').attr('data-date');
		//checkfor errors
		if(emailVal == 'Email'){eLog.push(' email');}; 
		if(zipVal == 'Zip Code'){eLog.push(' zip code');};
		if(genderVal == undefined){eLog.push(' gender');};
		if(birthYear == undefined){eLog.push(' birth year');};
		if(birthMonth == undefined){eLog.push(' birth month');};
		if(birthDate == undefined){eLog.push(' birth date');};
		//see if we had any errors
		if(eLog.length > 0){
			$('#email_form_error').text('Sorry but you forgot to fill out '+eLog+'.');
		}else{
			//B day check
			var bDay = new Date(parseInt(birthYear),parseInt(birthMonth),parseInt(birthDate));
			if(bDay <= bornBefore){
				$.ajax({
					url : '/dynamic/sendSignup.php',
					type : 'POST',
					data : {email:emailVal,zip:zipVal,gender:genderVal,age:birthYear,month:birthMonth,day:birthDate},
					success: function(data){
						$('#follow_us_dd_email form').text(data);	
					}
				});
			}else{
				createCookie('age','tooyoung',1);
				$('#follow_us_dd_email form').html('<span style="padding:0 20px 0 0">Sorry you are not eligible to sign up at this time</span>');
			}	
		}
		return false;
	};
	/*****************************************
	COOKIE SETTER
	******************************************/
	function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	}
	/**********************************
	COOKIE GETTER
	************************************/
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	if(readCookie('age') == 'tooyoung'){
		$('#follow_us_dd_email form').html('<span style="padding:0 20px 0 0">Sorry you are not eligible to sign up at this time</span>');
	};
	
	/*****************
	PREDICTIVE SEARCH
	******************/
	$('#search_bar').live('keyup',function(event){	
		if(event.keyCode == 13){
			return false;	
		}else if(event.keyCode == 38){
			keyUpDown('up');	
		}else if(event.keyCode == 40){
			keyUpDown('down');			   
		}else{
			var theKeyword = $('#search_bar').val();
			$.ajax({
				type: "POST",
				url: "/dynamic/predictiveSearch.php",
				data: 'keyword='+ theKeyword,
				success: function(data){
					display_predictive_search(data);
				}
			});	
		}
		
		return false;
	});
	
	$('#predictive_search ul a').live('mouseover mouseout' ,function(event){
		if(event.type == 'mouseover'){
			$('#predictive_search ul a').removeClass('selected');
			$(this).addClass('selected');
		}else{
			//$(this).addClass('selected');
		}
	});
	
	function keyUpDown(key){
		var theIndex = $('#predictive_search li a').length;
		var theEq = 0;
		$.each($('#predictive_search li a'), function(stuff){
			if($(this).hasClass('selected')){
				return false;
			}
			theEq ++;
		});
        if(key === 'up'){
			theEq = theEq-1;	
		}else{
			theEq = theEq+1;	
		}
		if(theEq === theIndex +1){theEq = 0;}
		$('#predictive_search ul a').removeClass('selected');
		$('#predictive_search ul a').eq(theEq).addClass('selected');
	}
	
	function display_predictive_search(data){
		$('#predictive_search ul').empty();
		$.each(data,function(item){
			$('#predictive_search ul').append('<li><a href="'+data[item].url+'">'+data[item].keyword+'</a></li>');					 
		});	
		$('body').bind('click',function(){
			hidePredictive();						 
		});
		$('#main_nav_search').click(function(e){
			e.stopPropagation();								   
		});
	}
	
	$('#main_nav_search form').live('submit',function(){
		if($('#predictive_search ul a').hasClass('selected')){
			window.location=$('#predictive_search ul a.selected').attr('href');
			return false;	
		}else{
			return true;
		}									   

	});
	function hidePredictive(){
		$('#predictive_search ul').empty();
		$('body').unbind('click');
	}
	
});

/******************
MOVIE Title PAGE
******************/
if(page === 'movie_title'){
	
	$('#watch_it').live('click',function(){
		var top_pos = $('#title_buy_header').offset();
		$('html, body').animate({'scrollTop':top_pos.top+'px'},1000);
		return false;
	});
	
	var flash_slide_show_false = true;
	var flash_slide_show_clicked = false; 
	/*************************
		LIGHTBOX
	*************************/
	var title_lightbox_settings = {'theItem':'.media_player_item','thumb':'.title_slide_overlay','next_btn':'#mgm-lightbox-next','back_btn':'#mgm-lightbox-back','slideshow':'#mgm-lightbox-slideshow','lb_path':'/js/lightbox/title_lb.html','load_area':'#mgm-lightbox-load','close_btn':'#mgm-lightbox-close','speed':500};
	title_lightbox = mgmUI.lightbox;
	title_lightbox.init(title_lightbox_settings);
	var image_click = function(params) {
		mgmUI.lightbox.load_content(params.full_size_preview,title_lightbox_settings);
	};
	
	var video_complete = function(params) {
		vidAnalyticsTracking('finished',params.content_type,params.item_title,params.item_id);		
	}	
	/************************
		FLASH NEXT CLICKED
	***************************/
	var next_clicked = function(params) {
		if( (title_lightbox.theSettings.slide_count +1)< title_lightbox.theSettings.mplayer_image){
			title_lightbox.theSettings.slide_count++;
			var initParams = {content_path: title_lightbox.theSettings.reg_image[title_lightbox.theSettings.slide_count],content_type: 'image',full_size_preview: title_lightbox.theSettings.slide_imgs[title_lightbox.theSettings.slide_count],item_id: 4,download_path: '',item_title: 'title',autoplay:true,hd_disabled:true,share_in_flash:false};
			mgmUI.media_player.load_content('flash_media_player',initParams);	
		}
	}	
	/*************************
		FLASH PREV CLICKED
	*************************/
	var prev_clicked = function(params) {
		if(title_lightbox.theSettings.slide_count > 0){
			title_lightbox.theSettings.slide_count--;
			var initParams = {content_path: title_lightbox.theSettings.reg_image[title_lightbox.theSettings.slide_count],content_type: 'image',full_size_preview: title_lightbox.theSettings.slide_imgs[title_lightbox.theSettings.slide_count],item_id: 4,download_path: '',item_title: 'title',autoplay:true,hd_disabled:true,share_in_flash:false};
			mgmUI.media_player.load_content('flash_media_player',initParams);	
		}
	}	
	/**************************************
		FLASH IMAGE FULL SCREEN CLICKED
	**************************************/
	var full_screen_clicked = function(params) {
		flash_slide_show_false = false;
		mgmUI.lightbox.load_content(params.full_size_preview,title_lightbox_settings);
	}	
	/***************************
		FLASH SLIDESHOW CLICKED
	****************************/
	var slideshow_clicked = function(params){
		if(flash_slide_show_clicked === false){
			run_slideshow(params);
			flash_slide_show_clicked = true;
		}else{
			flash_slide_show_clicked = false;
			flash_slide_show_false = false;
		}	
	};
	var run_slideshow = function(params){
		if(flash_slide_show_false === true){
			flash_slide_show_timer = setTimeout(function(){
				if((title_lightbox.theSettings.slide_count + 1) < title_lightbox.theSettings.slide_ids.length){
					title_lightbox.theSettings.slide_count++;
				}else{
					title_lightbox.theSettings.slide_count = 0;
				}
				if(flash_slide_show_false === true){
					var initParams = {content_path: title_lightbox.theSettings.reg_image[title_lightbox.theSettings.slide_count],content_type: 'image',full_size_preview: title_lightbox.theSettings.slide_imgs[title_lightbox.theSettings.slide_count],item_id: 4,download_path: '',item_title: 'title',autoplay:true,hd_disabled:true,share_in_flash:false};
					mgmUI.media_player.load_content('flash_media_player',initParams);	
				}
				run_slideshow(params);
				
			},4000);	
		}else{
			clearTimeout(flash_slide_show_timer);	
			flash_slide_show_false = true;	
			flash_slide_show_clicked = false;
		}
	}
	
	/****************************
	MEDIA SLIDER FILTERS
	****************************/
	$('.media_slider_filter_item').click(function(){
		if($(this).hasClass('empty')){
			return false;				
		}else{
			var theElem = $(this);
			var theType = theElem.attr('id');
			$('.media_slider_filter_item').removeClass('selected');
			theElem.addClass('selected');
			mediaFilterSwapper(theElem);
			return false;
		}
	});
	
	function mediaFilterSwapper(theElem){
		$('#flash_media_slider_wrapper').animate({'opacity':'0'},250,function(){			
			var theContent;
			var counter = 0;
			var theHtml = '';
			var wrapperCount = 0;
			if(theElem.attr('id') === 'media_filter_vid'){
				theContent = title_slider.theSettings.vids;
			}else if(theElem.attr('id') === 'media_filter_img'){
				theContent = title_slider.theSettings.imgs;	
			}else if(theElem.attr('id') === 'media_filter_all'){
				theContent = title_slider.theSettings.vids.concat(title_slider.theSettings.imgs);
			}else if(theElem.attr('id') === 'media_filter_audio'){
				theContent = title_slider.theSettings.audio;	
			}

			$.each(theContent, function(count){
				if(counter === 0){
					theHtml = theHtml + '<div class="flash_media_slider_item">';
					wrapperCount++;
				}
					theHtml = theHtml + '<a href="#" class="media_player_item" data-type="'+theContent[count].type+'" data-path="'+theContent[count].path+'" data-prev-img="'+theContent[count].prev+'" data-id="2" data-title="the title" data-dload="" style="display:block">';
					//theHtml = theHtml + theContent[count].html;
					theHtml = theHtml + '<img src="'+theContent[count].overlay_path+'" alt="'+theContent[count].overlay_type+'" class="title_slide_overlay" style="position:absolute;" data_slide_pos="" />';
					theHtml = theHtml + '<img src="'+theContent[count].content_path+'" alt="sample" class="title_slide_image" width="113" height="70" />';
					theHtml = theHtml + '</a>';
				if( (counter === 3) || (counter === (theContent.length - 1))){
					theHtml = theHtml + '</div>';
					counter = 0;
				}else{
					counter++;	
				}
			});
			title_slider.theSettings.wrapper_width = wrapperCount * 113;
			$('#flash_media_slider_wrapper').css({'width':((wrapperCount * 113) + ((wrapperCount) * 8))+'px','marginLeft':'0px'});
			$('#flash_media_slider_count').attr('data-pages',wrapperCount).text('1/'+wrapperCount);
			$('#flash_media_slider_wrapper').empty();
			$('.title_slide_image').css({'opacity':'1'});
			$('#flash_media_slider_wrapper').append(theHtml).animate({'opacity':'1'});
		});	
	}
	
	//TOOLTIP
	media_filter_tip_settings = {trigger:'.tooltip',html:'<div style="filter:alpha(enabled=\'false\');width:59px;height:49px;background:url(/images/main_imgs/tooltip.png) no-repeat"><p class="tooltip_message" style="color:#9fa2a5;font-size:9px;padding:10px;line-height:10px"></p></div>',message_attr:'data-tooltip'};
	mgmUI.tooltip.init(media_filter_tip_settings);
};	
/*********************
HOME PAGE
***********************/
if(page === 'home'){
	$(document).ready(function(){
		/**************************
			FP WATCH NOW SLIDER
		**************************/
		var fp_watch_slider_settings = {nextBtn :'#fp_watch_now_slider_next', backBtn :'#fp_watch_now_slider_back', pic_box : '#fp_watch_now_slider_body', wrapper : '#fp_watch_now_wrapper',thumb_item : '.fp_watch_now_item', thumb_margin : '25', speed : '1000',travel : '655'};
		fp_watch_slider = new mgmUI.slider.init(fp_watch_slider_settings);
	});
};
/*********************
WATCH NOW
**********************/
if(page === 'watch_now'){
	$(document).ready(function(){
		/**************************
			Browse Dropdown
		**************************/
		var browse_title_dropdown_settings = {'parent' : '.browse_title_dd_genre', 'child' : '.browse_title_dd_child' , animation : {'opacity':'0'}, speed : 300};
		browse_title_dropdowns =  new mgmUI.dropdowns.init(browse_title_dropdown_settings);
		
		$('.browse_title_item a').click(function(){
			loadWatchNowVids($(this));
			vidAnalyticsTracking('loaded','hulu',$(this).attr('data-title'),$(this).attr('data-id'));
		});
	
	loadWatchNowVids($('.browse_title_item a').eq(0));
	vidAnalyticsTracking('loaded','hulu',$('.browse_title_item a').attr('data-title'),$('.browse_title_item a').attr('data-id'));
	});
	
	
	
	function loadWatchNowVids(theElem){
		if($(theElem).attr('data-type') === 'hulu'){
			var theGuid = $(theElem).attr('data-path');
			var thePoster = $(theElem).attr('data-poster');
			var theTitle = $(theElem).attr('data-title');
			var theRating = $(theElem).attr('data-rating');
			var theID = $(theElem).attr('data-id');
			var theSynopsis = $(theElem).attr('data-synopsis');
			var theYear = $(theElem).attr('data-year');
			$('.hulu_player').show(function(){
				setTimeout(function(){
					mgmUI.media_player.loadHuluContent(theGuid);
				},1000);								
			});
			$('#watch_now_poster').attr('src',thePoster).attr('alt',theTitle);
			$('#watch_now_title').text(theTitle);
			$('#watch_now_rating').attr('src',theRating);
			$('.watch_now_link').attr('href','/view/movie/'+theID+'/'+theTitle.replace(/ /g, '-')+'/');
			$('#watch_now_synopsis').html('<p>'+unescape(theSynopsis)+'</p>');
			$('#watch_now_year').text(theYear);
		}	
	}
	
	$('#watch_now_synopsis_toggle').click(function(){
		$('#watch_now_synopsis').slideToggle(250);	
		$('#watch_now_about_arrow_side').toggle(1);
		$('#watch_now_about_arrow_down').toggle(1);
		return false;
	});
};
/*******************************
PORTAL PAGES
********************************/
if((page ==='movies') || (page === 'series')){
	$(document).ready(function(){						   
		/**************************
			BROWSE TITLES DROPDOWN
		**************************/
		var browse_title_dropdown_browse_settings = {'parent' : '.browse_title_dd_browse', 'child' : '.browse_title_dd_child' , animation : {'opacity':'0'}, speed : 300};
		browse_title_dropdowns_browse =  new mgmUI.dropdowns.init(browse_title_dropdown_browse_settings);
		
		var browse_title_dropdown_avail_settings = {'parent' : '.browse_title_dd_avail', 'child' : '.browse_title_dd_child' , animation : {'opacity':'0'}, speed : 300};
		browse_title_dropdowns_avail =  new mgmUI.dropdowns.init(browse_title_dropdown_avail_settings);
		
		var browse_title_dropdown_settings = {'parent' : '.browse_title_dd_genre', 'child' : '.browse_title_dd_child' , animation : {'opacity':'0'}, speed : 300};
		browse_title_dropdowns =  new mgmUI.dropdowns.init(browse_title_dropdown_settings);
		/************************
			BROWSE TITLES THING	
		************************/
		(function(){
			/******************************
				MODULE FILTERS
			******************************/
			var title_offset = 50;
			var title_count = 0;
			var scroller_offset = $('.more-titles').offset();
			var getting_data = false;
			var genre_filter = '';
			var alpha_filter = '';
			var pause_loading = false;
			
			$('#pause_loading').live('click',function(){
				if(pause_loading === false){
					pause_loading = true;	
					$(this).html('<img src="/images/main_imgs/start-loading.png" alt="Start Loading"/>');
				}else{
					pause_loading = false;	
					$(this).html('<img src="/images/main_imgs/stop-loading.png" alt="Stop Loading"/>');
				}
				return false;
			});
			function refresh_loading(){
				pause_loading = false;
				$('#pause_loading').html('<img src="/images/main_imgs/stop-loading.png" alt="Stop Loading"/>');
			}
			/*********************
				EVENT HANDLERS
			*********************/
			//Genre List
			
			var genreList = new Object();
			genreList["COM"] = "Comedy";
			genreList["DRAMA"] = "Drama";
			genreList["ANIMA"] = "Animated";
			genreList["THRIL"] = "Thriller";
			genreList["ACTAD"] = "Action Adventure";
			genreList["HOR"] = "Horror";
			genreList["FAMIL"] = "Family";
			genreList["SCIFI"] = "Sci-Fi";
			genreList["ADVEN"] = "Adventure";
			genreList["DOCMT"] = "Documentary";
			genreList["Weste"] = "Westerns";
			genreList["CLASS"] = "Classics";
			
			function convert_genre(theGenre){
				for(var description in genreList) {  // print out the bands with descriptions
					if(theGenre === description){
					  return genreList[description];
					}
				}
			}
			
			
			//ALPHA_FILTER
			$('.alpha_filter').live('click',function(){
				$('.alpha_filter').removeClass('activeAlphaFilter');													
				$(this).addClass('activeAlphaFilter');
				alpha_filter = $(this).attr('meta_alpha');
				build_title_holder();
				$('#browse_filter_mover').animate({'marginTop':'0px'},1500);
				$('html, body').animate({'scrollTop':'500px'},1500);
				refresh_loading();
				return false;
			});
			//GENRE_FILTER
			$('.genre_filter').live('click',function(){
				genre_filter = $(this).attr('meta_genre');
				build_title_holder();
				$('#browse_filter_mover').animate({'marginTop':'0px'},1500);
				$('html, body').animate({'scrollTop':'500px'},1500);
				refresh_loading();
				return false;
			});
			//RESET_FILTERS
			$('#reset_filters').live('click',function(){
				alpha_filter = '';
				genre_filter = '';
				build_title_holder();
				$('#browse_filter_mover').animate({'marginTop':'0px'},1500);
				$('html, body').animate({'scrollTop':'500px'},1500);
				refresh_loading();
				return false;
			});
			//REMOVE_ALPHA_FILTERS
			$('#browse_filter_remove_alpha').live('click',function(){
				alpha_filter = '';
				build_title_holder();
				$('#browse_filter_mover').animate({'marginTop':'0px'},1500);
				$('html, body').animate({'scrollTop':'500px'},1500);
				refresh_loading();
				return false;						  
			});
			//REMOVE_GENRE_FILTERS
			$('#browse_filter_remove_genre').live('click',function(){
				genre_filter = '';
				build_title_holder();
				$('#browse_filter_mover').animate({'marginTop':'0px'},1500);
				$('html, body').animate({'scrollTop':'500px'},1500);
				refresh_loading();
				return false;						  
			});
			//RETURN TO TOP
			$('#browse_scroll_top').live('click',function(){
				$('html, body').animate({'scrollTop':'500px'},1500);
				return false;
			});
			//HANDLES SCROLLING CHECK
			
			$(window).scroll(function(){				  
				browse_filter_mover();
				if(pause_loading === false){	
					if( getting_data === false){
						title_scroll();
					};
				}
			});
			var box_pos = $('#browse_filter_mover').offset();
			$('#browse_filter_mover').attr('top',box_pos.top);
			function browse_filter_mover(){
				
				var window_pos = $(window).scrollTop();
				if(parseInt(window_pos) > (parseInt(box_pos.top))){
					$('#browse_filter_mover').stop().animate({'marginTop':(window_pos-box_pos.top+25)+'px'}, 500);	
				}else{
					$('#browse_filter_mover').stop().animate({'marginTop':0}, 500);		
				}
			}
			/*************************************
				Main Functions for BROWSE TITLES
			**************************************/
			//RUNS WHILE SCROLLING
			function title_scroll(){
				//finds window position so we can match it againse when we wanna load more data
				var where_at = $(this).scrollTop() + $(this).height();
				//If where we are at is where the get more titles thing is, then get more titles
				
				if(where_at >= scroller_offset.top){
					getting_data = true;
					//We set this to true so we can't load more stuff until original stuff is loaded, One at a time guys
					scroller_offset = 199999999999999999999999999999999999999999999999999;
					//Just keeping track of where we are so we can adjust the offset properly
					title_count = parseInt(title_count) + parseInt(title_offset);
					//get the next set of titles
					get_titles();
				};
			};
			//GET THE TITLES WITH AJAX!!
			function get_titles(){
				//use AJAX to get titles in JSON format
				$.getJSON('/browse/'+page+'/output/json/offset/'+title_count+'/limit/'+title_offset+'/title/'+alpha_filter+'/genre/'+genre_filter+'/index.html',function(data){
					//hide the more titles thing, so we cant get more until its all loaded
					$('.more-titles').hide();
					//Run function that builds the html from the Json we recieved
					create_title_items(data,title_count);
					if(data.length < 50){
						pause_loading = true;	
					}
				});
			};
			//REBUILDS THUMB AREA
			function build_title_holder(){
				//Delete current title holder area
				$('#browse_title_thumb_holder').fadeOut(function(){					   
					$(this).remove();
					title_count = 0;
					//Makes new area for titles to be loaded into 
					$('<div id="browse_title_thumb_holder"></div>').appendTo('#browse_title_area').css({'display':'none'});
					//Write out which filters are being used
					theHtml =' <hr style="border-bottom:none;border-left:none;border-right:none;border-top:1px solid #94979;"/><br /><h3 style="margin:0 0 10px 0">Showing Titles:</h3>';
					if(genre_filter != ''){
						var converted_genre = convert_genre(genre_filter);
						theHtml+='<p><b style="color:#94979b"><a href="#" id="browse_filter_remove_genre"><img src="/images/main_imgs/filter_close.png" alt="Remove Filter" /></a>&nbsp;&nbsp; in '+converted_genre+'</b></p>';
					}
					if(alpha_filter != ''){
						theHtml += '<p><b style="color:#94979b"><a href="#" id="browse_filter_remove_alpha"><img src="/images/main_imgs/filter_close.png" alt="Remove Filter" /></a>&nbsp;&nbsp; starting with '+alpha_filter+'</b></p>';
					}
					theHtml += '<a href="#" id="reset_filters" style="margin:10px 0 0 0;display:block">Start Over</a>';
					$('#filter_notice').html(theHtml);
					get_titles();
				});
			};
			//WRITES NEW TITLES TO PAGE
			function create_title_items(items,count){
				var everyFive = 1;
				$.each(items, function(i, item){
					//Appending loaded data into page
					var linkPage;
					if(page == 'movies'){
						linkPage = 'movie'; 
					}else{
						linkPage = page;	
					}
					 if(everyFive == 6){
						everyFive = 1;
					 }
					 if(everyFive==5){
						 $('#browse_title_thumb_holder').append('<div class="browse_title_item browse_title_item_last"><a href="/view/'+linkPage+'/'+item.titleid+'/'+item.title.replace(/ /g,'-')+'/"  style="font-weight:normal;font-size:11px;line-height:12px;"><img src="'+item.preview+'" width="80" height="120"/><br />'+item.title+'</a></div>');
					}else{
						$('#browse_title_thumb_holder').append('<div class="browse_title_item "><a href="/view/'+linkPage+'/'+item.titleid+'/'+item.title.replace(/ /g,'-')+'/" style="font-weight:normal;font-size:11px;line-height:12px;"><img src="'+item.preview+'" width="80" height="120"/><br />'+item.title+'</a></div>');
						//Once Titles are loaded and stuff Show teh more titles button so we can start loading more stuff
					}
					everyFive++;
				});
				//Allows us to get more titles again
				$('#browse_title_thumb_holder').fadeIn(function(){
					$('#browse_title_thumb_holder .browse_title_item').fadeIn();
					$('.more-titles').show(function(){
						getting_data = false;
						scroller_offset = $('.more-titles').offset();
					});								  
				});					 
			};
		})();
	});
};

/***********************
CORPORATE STUFF
************************/
if(page ==='corp_info'){
	$(document).ready(function(){
		/*************************
			LIGHTBOX
		*************************/
		var corp_lightbox_settings = {'theItem':'.media_player_item','thumb':'.title_slide_overlay','next_btn':'#mgm-lightbox-next','back_btn':'#mgm-lightbox-back','slideshow':'#mgm-lightbox-slideshow','lb_path':'/js/lightbox/poster_lb.html','load_area':'#mgm-lightbox-load','close_btn':'#mgm-lightbox-close','speed':500};
		mgmUI.lightbox.init(corp_lightbox_settings);
		$('#tower_box').live('click',function(){
			var full_size_preview = $(this).attr('data-lightbox');
			mgmUI.lightbox.load_content(full_size_preview,corp_lightbox_settings);
		});			   
	});
}


/*************************************YOUTUBE TESTING******************************************/

$(document).ready(function(){
	$('#play_btn').hide();
	$('#unmute_btn').hide();
	
	$('.vidLink').live('click',function(){
		loadNewVideo($(this).attr('id'),0);
		$('#play_btn').hide();
		$('#pause_btn').show();
	});
	$('#play_btn').live('click',function(){
		play();
		$('#play_btn').hide();
		$('#pause_btn').show();
	});
	$('#pause_btn').live('click',function(){
		pause();
		$('#play_btn').show();
		$('#pause_btn').hide();
	});
	$('#mute_btn').live('click',function(){
		mute();
		$('#unmute_btn').show();
		$('#mute_btn').hide();
	});
	$('#unmute_btn').live('click',function(){
		unMute();
		$('#mute_btn').show();
		$('#unmute_btn').hide();
	});
	$('#share_btn').live('click',function(){
		getEmbedCode();
	});
	var scrubber_width = $('#scrubber').width() - $('#vid_scrubber').width();
	var vid_scrubber_pos = $('#scrubber').offset();
	var vol_scrubber_pos = $('#vol_scrubber').offset();
	var vol_scrubber_width = $('#vol_scrubber').width()- $('#vid_scrubber').width();
	

	$('#scrubber').live('click',function(e){
		var vid_scrubber_pos = $('#scrubber').offset();
		seekTo(parseInt(getDuration() * ((e.pageX-vid_scrubber_pos.left-5)/316)));
	});

	$('#vol_scrubber').live('click', function(e){
		var vol_scrubber_pos = $('#vol_scrubber').offset();
		setVolume(e.pageX - vol_scrubber_pos.left);
	});
});
function animateScrubber(total,loaded){
	$('#vid_scrubber').css({'marginLeft':parseInt((loaded/total) * 316)+'px'});
	$('#scrubber_progress').css({'width':parseInt((loaded/total) * 316)+'px'});
};
function animateVolumeScrubber(vol){
	$('#vol_scrub').css({'marginLeft':parseInt((vol/100)*87)+'px'});
	$('#vol_scrubber_progress').css({'width':parseInt((vol/100)*87)+'px'});
};

function updateHTML(elmId, value) {
  document.getElementById(elmId).innerHTML = value;
};

function setytplayerState(newState) {
  updateHTML("playerstate", newState);
};

function onYouTubePlayerReady(playerId) {
  ytplayer = document.getElementById("myytplayer");
  //setInterval(updateytplayerInfo, 250);
  updateytplayerInfo();
  ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
  ytplayer.addEventListener("onError", "onPlayerError");
};

function onytplayerStateChange(newState) {
  setytplayerState(newState);
};

function onPlayerError(errorCode) {
  alert("An error occured: " + errorCode);
};

function updateytplayerInfo() {
  animateScrubber(getDuration(),getCurrentTime());
  animateVolumeScrubber(getVolume());
};

// functions for the api calls
function loadNewVideo(id, startSeconds) {
  if (ytplayer) {
	ytplayer.loadVideoById(id, parseInt(startSeconds));
  };
};

function cueNewVideo(id, startSeconds) {
  if (ytplayer) {
	ytplayer.cueVideoById(id, startSeconds);
  };
};

function play() {
  if (ytplayer) {
	ytplayer.playVideo();
  };
};

function pause() {
  if (ytplayer) {
	ytplayer.pauseVideo();
  };
};

function stop() {
  if (ytplayer) {
	ytplayer.stopVideo();
  };
};

function getPlayerState() {
  if (ytplayer) {
	return ytplayer.getPlayerState();
  };
};

function seekTo(seconds) {
  if (ytplayer) {
	ytplayer.seekTo(seconds, true);
  };
};

function getBytesLoaded() {
  if (ytplayer) {
	return ytplayer.getVideoBytesLoaded();
  };
};

function getBytesTotal() {
  if (ytplayer) {
	return ytplayer.getVideoBytesTotal();
  };
};

function getCurrentTime() {
  if (ytplayer) {
	return ytplayer.getCurrentTime();
  };
};

function getDuration() {
  if (ytplayer) {
	return ytplayer.getDuration();
  };
};

function getStartBytes() {
  if (ytplayer) {
	return ytplayer.getVideoStartBytes();
  };
};

function mute() {
  if (ytplayer) {
	ytplayer.mute();
  };
};

function unMute() {
  if (ytplayer) {
	ytplayer.unMute();
  };
};

function getEmbedCode() {
  alert(ytplayer.getVideoEmbedCode());
};

function getVideoUrl() {
  alert(ytplayer.getVideoUrl());
};

function setVolume(newVolume) {
  if (ytplayer) {
	ytplayer.setVolume(newVolume);
  };
};

function getVolume() {
  if (ytplayer) {
	return ytplayer.getVolume();
  };
};

function clearVideo() {
  if (ytplayer) {
	ytplayer.clearVideo();
  };
};
