STATIC_SERVER = 'http://www.tdbimg.com/';
//STATIC_SERVER = 'http://candt.static.thedailybeast/';
AJAX_URL = '/include/ajax.php';
_nAuthorInfoDepth = 1000;
_nBFSInfoDepth = 1000;
var ads_gbl_url=window.location.pathname; ads_gbl_url=ads_gbl_url.replace(new RegExp(/\//g),"_");
ord = Math.random()*10000000000000000; // for ad serving 
document.sortOrder = 'ASC';
	
setSortOrder = function(){
	$('#sortarea').addClass('sort_down');
}

	
sortComments= function(p_sDirection,commentFunction){
	document.sortOrder = p_sDirection;
	if(p_sDirection == 'ASC'){
		$('#sortarea').removeClass('sort_up');
		$('#sortarea').addClass('sort_down');
	}
	else{
		$('#sortarea').removeClass('sort_down');
		$('#sortarea').addClass('sort_up');
	}
	eval(commentFunction+"('1')");;
}
	
	
setHovers = function(){
	$('#newsmakerpage .full_cheatsheet_holder  .cheat a,'+
	  '#newsmakerpage .top_quote,'+
	  '#home .cheatsheet_holder .cheat a').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	} );
	
}


setVideoOverlays = function(target){
	
	$(target+' .video_overlay').each(function(){
		
		siblingW = $(this).siblings('.compareImg').width();
		siblingH = $(this).siblings('.compareImg').height();
		 
		//alert(siblingW); 
		 
		 
		if((! ($.browser.safari || $.browser.msie)   ) && $(this).parent().attr('class') == 'article_img float_center'){
			siblingW  = 1;
		}
		if(  siblingW ){
			
			$(this).css({
				
				'visibility':'visible',
				'position':'absolute',
				'margin-left': ((siblingW - 36)/2)+'px',
				'margin-top': ((siblingH - 36)/2)+'px',
				'height':'55px',
				'width':'60px'
				
			});
			
		}
		
	});
	
	$(target+' .gallery_overlay').each(function(){
												
		var l_nLeft = 8;
 		siblingW = $(this).siblings('.compareImg').width();
		siblingH = $(this).siblings('.compareImg').height();
		
		if(target == '#blogsstories_holder'){
			siblingW =1;
			if( $(this).parent().parent().attr('class') == 'article_img float_center'){
				l_nLeft = -45;
				siblingH -= 10;
				
				if($.browser.safari){
					$(this).css({'visibility':'visible' });
					siblingW = 0;
				}
				
			}
		}
		
		if(siblingW ){
			 
			$(this).css({
				
				'visibility':'visible',
				'position':'absolute',
				'margin-left': (l_nLeft)+'px',
				'margin-top': ((siblingH)-  $(this).height() -5 )+'px',
				'height':'17px',
				'width':'80px'
				
			});
			
		}
		
	});
	
	
}



setAskSubmit = function(){
	$('#searchform').submit(function(){
		if( _xGlobal.checkEmpty( $('#searchform #q').val()) || _xGlobal.checkEmpty2( $('#searchform #q').val())  ){
			alert('Please enter a search term');
			$('#searchform #q').val('');
			return false;
		}
		
		if( $('#searchform #q').val() == $('#searchform #q').attr('rel')){
			$('#searchform #q').val('Top News');	
		}
		
		
		searchScope = $('#radios input:checked').val() ;
		
		if(searchScope == 'local'){
			$('#searchform').attr('action','http://news.ask.com/news');
			$('#qsrc_input').attr('value','2443');
		}
		else if(searchScope == 'web'){
			$('#searchform').attr('action','http://www.ask.com/web');
			$('#qsrc_input').attr('value','2444');
		}
		
	});
}




var setBigFatStory = function(){
	
	
	$('#maincontent2 a').each(function(){
		 hrefString = $(this).attr('href');
		 if(hrefString){
			 wwwLocation = hrefString.indexOf('http://');
			 dailybeastLocation = hrefString.indexOf('thedailybeast.com');
			 if( ( wwwLocation  === 0 ) && (dailybeastLocation == -1 ) ){
				$(this).attr('target','_blank');
			 }
		 }
		 
	});
	
	$('#bigfatstory_share_link').click(function(){ 
		$(this).children('.txt').toggleClass('txt_current');
		$('#popup_bigfatstory_share').toggle();
		$('#popup_bigfatstory_share').css('z-index',_nBFSInfoDepth++);
		$('#popup_bigfatstory_share').parent().parent().css('z-index',_nBFSInfoDepth++);
	});
	
	
	
	$('#maincontent2 .middle_holder').hover( function(){
		$(this).addClass('middle_holder_focus');
	},function(){
		$(this).removeClass('middle_holder_focus');
	});
	
	$('#maincontent2  .deepdive').hover( function(){
		$(this).children('.popup_deepdive').show();
	},function(){
		$(this).children('.popup_deepdive').hide();
	});
	
	
	
	
	$('#maincontent2 .module_holder').hover( function(){
													  
		$('#bigfatstory_share_link').children('.txt').removeClass('txt_current');												  	
		$('#popup_bigfatstory_share').hide();
		$('#maincontent2 .middle_holder_focus').removeClass('middle_holder_focus');
		$('#maincontent2 .current_focus').removeClass('current_focus').removeClass('partial_focus');
		$('#maincontent2 .popup_moreinfo').hide();
		
		$(this).addClass('partial_focus');
		
		if( $(this).children('.popup_moreinfo').length ){
			$(this).addClass('current_focus');
			 
			 
			$(this).children('.popup_moreinfo').fadeIn('normal',function(){ 
				if(! $(this).parent('.current_focus').length ){
					$(this).hide();
				}
					
			 });
			
			$(this).parent().css('z-index',_nBFSInfoDepth++);
			$(this).css('z-index',_nBFSInfoDepth++);
			if(  $(this).parent().attr('class') == 'old_post_module_holder' )
				$('#prevposts_holder').css('z-index',_nBFSInfoDepth++); 
	 	
			
			 
		}
	},function(){
		$(this).removeClass('current_focus');
		$(this).removeClass('partial_focus');
		$(this).children('.popup_moreinfo').hide();
	});
	
	
	
	
	$('#prevposts_holder .older_post_link').click( function(){  
		
		$(this).find('.txt').toggleClass('icon_minus');
		$(this).siblings('.old_post_module_holder').children('.module_holder').toggle();
		 
		setVideoOverlays('.old_post_module_holder');
		$('#prevposts_holder').css('z-index',_nBFSInfoDepth++);
		
	});
	
	
	$('#prevposts_link').click( function(){  
		$(this).toggleClass('prevposts_link_open');
		$('#prevposts_holder').toggle();
	});
	
	
	if( $('#maincontent2 .bottom_middle_2').length  ){
		$('#maincontent').addClass('double');
	}
	else{
		$('#maincontent').addClass('single');
	}
	
	
	
}












var setInfoInterace = function(targetArea){
	$(targetArea+' .icon_infocircle').unbind();
	$(targetArea+' .icon_infocircle').click( function(){
		$(this).parent().siblings('.popup_author').toggle();
		$(this).parent().siblings('.popup_author').css('z-index',_nAuthorInfoDepth++);
		$(this).css('z-index',_nAuthorInfoDepth++);
		 
		
		
		return false;
	});
	$(targetArea+' .author_close').unbind();
	$(targetArea+' .author_close').click( function(){
		$(this).parent().parent().hide();
	});
	 
	
}



 
updateShareThisCheat = function( p_nCount){
		var l_nLeft = $('#master').position();
		var l_nTop = 250;
		for(i=1; i<= p_nCount; i++){
			l_nTop += $('#cheatholder_'+i).height(); 
		}
		if( $('#comments_'+p_nCount).length ){
			hrefString = $('#comments_'+p_nCount).attr('rel');
		}else{
			hrefString = $('#urlgrab').attr('rel');
		}
		
		var l_sBody = Base64.encode(strip_tags($('#cheatholder_'+p_nCount+' .text p').html()).substr(0,255));
		var l_sUrl = Base64.encode(hrefString);
		var l_sTitle = Base64.encode($('#cheatholder_'+p_nCount).attr('rel'));
	  
		$('#shareThisHolder').css('top',l_nTop).css('z-index','1000').css('left',l_nLeft['left'] + 300).show();
		$('#shareThisHolderIFrame').attr('src','/templates/sharethis.php?&beastfull=1&url='+l_sUrl+'&title='+l_sTitle+ '&encode=1&content=' +l_sBody );
		
		
}
	
hideShareThisCheat = function(){
		$('#shareThisHolder').hide();
		$('#shareThisHolderIFrame').attr('src','');
}
	

var suggestScrollBack = null;
var submitScrollBack = false;

var setCheatLinks = function(targetArea){
	$('.sharethis a').click( function(){
			tmpRel = $(this).attr('rel'); 
			updateShareThisCheat( tmpRel ); 
	});
	
	
	$(targetArea+' .gotBetterLinkPopup_link').click( function(){ 													  
		if(document.cookie.indexOf("tdb_info=") != -1){	 //if the user is logged in when you click										  
			$(this).siblings('.popup_gotbetterlink').toggle();
			$(this).children('.txt').toggleClass('txt_current');
			var id = $(this).siblings('.popup_gotbetterlink').children('.popup_content').children('form').attr('id');
			resetBetterLinkForm(id);
			showAllFormElements(id);
		} else {
			$.scrollTo('#header', 800);
			displayLogin();	
			suggestScrollBack = $(this).parent().parent().parent().parent().attr("id"); //this is dependent on the structure remaining the same
		}
	});
	$(targetArea+' .popup_gotbetterlink .closebtn').click( function(){ 
		$(this).parents('.popup_gotbetterlink')
			.toggle();
		$(this).parents('.popup_gotbetterlink').siblings('.gotBetterLinkPopup_link').children('.txt')
			.toggleClass('txt_current');
	});
	
	$(targetArea+' .shareItPopup_link').click( function(){ 
		if(document.cookie.indexOf("tdb_info=") != -1){ //if the user is logged in when you click	
			$('.show_email').hide();
		} else {
			$('.show_email').show();
		}
		$(this).siblings('.popup_sharelink').toggle();
		$(this).css('z-index',_nBFSInfoDepth++);
		$(this).children('.txt').toggleClass('txt_current');
		var id = $(this).siblings('.popup_sharelink').children('.popup_content').children('form').attr('id');
		resetShareLinkForm(id);
		showAllFormElements(id);
	});
	$(targetArea+' .popup_sharelink .closebtn').click( function(){ 
		$(this).parents('.popup_sharelink')
			.toggle().css('z-index',_nBFSInfoDepth++);
		$(this).parents('.popup_sharelink').siblings('.shareItPopup_link').children('.txt')
			.toggleClass('txt_current');
	});
	
	
	$(targetArea+ '#submitnewstory_link').click(function(){
 		if(document.cookie.indexOf("tdb_info=") != -1){
			$('#popup_submitnewstory').toggle();
			$(this).children('.txt').toggleClass('txt_current');			
			resetNewStoryForm();
			showAllFormElements('form_newstory');			
		} else {
			$.scrollTo('#header', 800);
			displayLogin();	
			submitScrollBack = true;
		}
	});
	$(targetArea+' #popup_submitnewstory .closebtn').click( function(){ 
		$('#popup_submitnewstory')
			.toggle();
		$('#submitnewstory_link').children('.txt')
			.toggleClass('txt_current');
	});
	
	
	$(targetArea+ '#submitnewstory_link2').click(function(){
 		if(document.cookie.indexOf("tdb_info=") != -1){
			$('#popup_submitnewstory2').toggle();
			$(this).children('.txt').toggleClass('txt_current');			
			resetNewStoryForm();
			showAllFormElements('form_newstory');			
		} else {
			$.scrollTo('#header', 800);
			displayLogin();	
			submitScrollBack = true;
		}
	});
	$(targetArea+' #popup_submitnewstory2 .closebtn').click( function(){ 
		$('#popup_submitnewstory2')
			.toggle();
		$('#submitnewstory_link2').children('.txt')
			.toggleClass('txt_current');
	});
	
	
	
	
	$('.cheatholder').each(function(){ 
		
		if( $(this).children('.insight').length )  {
			
			var insightDiv = $(this).children('.insight');
			
			textHeight = $(this).children('.text').height();
			titleHeight = $(this).children('.title').height();
			
			insightHeight = $(insightDiv).height();
			
			if(textHeight+titleHeight-insightHeight  > 0){
				$(insightDiv).css('margin-top', (textHeight+titleHeight-insightHeight)/2);
			}
			
			$('#jshelper').animate({ opacity: .9999}, 0001, '', function() { 
				$(insightDiv).css('display','none');
				$('#jshelper').animate({ opacity: .9999}, 0001, '', function() { 
					$(insightDiv).css('visibility','visible');
					$('#jshelper').animate({ opacity: .9999}, 0001, '', function() { 
						$(insightDiv).fadeIn();
					});
				});
			});
			
		}
		
		
		
	});
	
	
	
	
	
	
	
	
}



var setBlogsStoriesArticle = function(){
	
	$('#blogsstories_share_link').click(function(){ 
		$(this).children('.txt').toggleClass('txt_current');
		$(this).children('.icon_sharehover').toggleClass('icon_minus');
		$('#popup_blogsstories_share').toggle();
	});
	
	
	this.col1 = false;
	this.col2 = false;
	
	
	
 	$('.shareItPopup_link').click( function(){ 
		
		if( $(this).attr('rel') == 1 ){
			
			if(parent.col1){
				parent.col1 = false;
				parent.col2 = false;
				$('.popup_sharelink').hide();
				
			}else{ 
				$('.popup_sharelink').css({'top': '140px' ,  'left':'-200px'}  );
				
				if(this.col2){
					parent.col1 = true;
					parent.col2 = false;
					
				}else{
					parent.col1 = true;
					parent.col2 = false;
					$('.popup_sharelink').show();
					
				}
			}
			
		}
		
		if( $(this).attr('rel') == 2 ){
			
			if(parent.col2){
				parent.col2 = false;
				parent.col1 = false;
				$('.popup_sharelink').hide();
				
			}else{
				l_nHeight= $('#content_wrap').height() - 250 ;
				$('.popup_sharelink').css({'top': l_nHeight ,  'left':'25px'}  );
				
				if(parent.col1){
					parent.col2 = true;
					parent.col1 = false;
					
				}else{
					parent.col2 = true;
					parent.col1 = false;
					$('.popup_sharelink').show();
					
				}
			}
			
		}
		
		if(document.cookie.indexOf("tdb_info=") != -1){ //if the user is logged in when you click	
			$('.show_email').hide();
		} else {
			$('.show_email').show();
		}
		
		var id = $('.popup_sharelink').children('.popup_content').children('form').attr('rel');
		
		resetShareLinkForm(id);
		showAllFormElements(id);
	});
	$('.popup_sharelink .closebtn').click( function(){ 
		parent.col2 = false;
		parent.col1 = false;
		
		$(this).parents('.popup_sharelink')
			.toggle();
	});
	
	
	/** Text size Stuff **/
	
	
	var tmpCookie = getCookie('tdb_textsize');
	switch(tmpCookie){
		case '1':
			l_sDefaultSize = 'big';
			break;
		case '2':
			l_sDefaultSize = 'bigger';
			break;
		default:
			l_sDefaultSize = 'default';
		break;
	}
	
	$('#maincontent').addClass(l_sDefaultSize);
	
	
	$('#text_plus').click( function(){
		l_xOptions = { expires: 30 , path: '/'};
		var tmpCookie = getCookie('tdb_textsize');
		
		if(tmpCookie == ''){
			$.cookie('tdb_textsize', 1, l_xOptions);
			
			$('#maincontent').removeClass('default');
			$('#maincontent').addClass('big');
		}
		
		if( tmpCookie == 1 ){
			$.cookie('tdb_textsize', 2, l_xOptions);
			
			$('#maincontent').removeClass('big');
			$('#maincontent').addClass('bigger');
			
		}
		
	});
	
	
	$('#text_minus').click( function(){
		l_xOptions = { expires: 30, path: '/' };
		
		var tmpCookie = getCookie('tdb_textsize');
		
		if( tmpCookie == 1 ){
			$.cookie('tdb_textsize', '', l_xOptions);
			
			$('#maincontent').removeClass('big');
			$('#maincontent').addClass('default');
		}
		if( tmpCookie == 2 ){
			$.cookie('tdb_textsize', 1, l_xOptions);
			
			$('#maincontent').removeClass('bigger');
			$('#maincontent').addClass('big');
		}
		
	});
	
	
}



var setBlogsStories = function(){
	$('#blogsstories .featured_top .arrow').click(function(){ 
     	_xBlog.scrollTopFeature($(this).attr('rel'));
	});
}
 

  
var setAutofills = function(){
	$('input.autofill').each(function(){
		$(this).val(  $(this).attr('rel') ) ;
	});
	$('input.autofill').focus(function(){
		if( $(this).val() == $(this).attr('rel')  ){
			$(this).val( '' );
			$(this).addClass('active');
		}
	});
	$('input.autofill').blur(function(){
		if( $(this).val() === '' ){
			$(this).val(  $(this).attr('rel') ) ;
			$(this).removeClass('active');
		}
	});
	
}

var things = new Object();
things.length = 0;

var setFooterLink = function(target){
	
	if(!things[target]){
		things[target] = target;		
		things.length++;
		$('#'+target+' .dropdown_content').addClass('dropdown_content_ready');
		$('#'+target+' .closebtn').click( function (){
			$('#'+target+' .dropdown_content').hide();	
			$('#footer').removeClass('footer_popup_open');								
		});
	}
	
	//hide popups that has already been opened. 
	if(things.length > 0){
		for (var thing in things){
			$('#'+things[thing]+' .dropdown_content').hide();
		}
	}
	
	//show popups we clicked
	$('#'+target+' .dropdown_content').show();
	$('#footer').addClass('footer_popup_open');
}

var setFooterPopups = function(target){
	
	//if we've never opened this popup before
	if(!things[target]){		
		//call ajax to get the page dynamically
		$.ajax({
			type:       "POST",
			url:        AJAX_URL,
			data:       'a=getFooterText&type='+target,
			success:    function(p_sMsg) {
				
				if(p_sMsg){	//if we get back an ajax response
					$('#'+target+' .inner_scrollarea').html(p_sMsg);	
					$('#footer').addClass('footer_popup_open');								
				} else {
					return;	//if it doesn't popup, let the user hit the button again. maybe they'll think they didn't hit it right the first time, and the call will fix itself								
				}		
				
				if(!things[target]){ //if the response did not contain code to set the variable, something went wrong, make them click again
					return;
				}
				
				//this is the fixed height of the popups
				var maxHeight = 200;	
				$('#jshelper').animate({ opacity: .9999}, 0001, '', function() { 
					$('#'+target+' .scrollarea').each( function(){ 
						if( $(this).height() > maxHeight ){
							//alert( $(this).height()+' '+maxHeight );
							 $(this).height(maxHeight);						 
							//alert( $(this).html() );
						}
					});
					
					//Hack to set scroll pane off window, and then place in right area	
					$('#jshelper').animate({ opacity: .9999}, 0100, '', function() { 
						$('#'+target+' .scrollarea').jScrollPane({scrollbarMargin:0, animateTo:true});
						$('#'+target+' .dropdown_content').addClass('dropdown_content_ready');
					 });
					
					$('#'+target+' .closebtn').click( function (){
						$('#'+target+' .dropdown_content').hide();	
						$('#footer').removeClass('footer_popup_open');								
					});
				});
			}
		});	
	} 
	
	//hide popups that has already been opened. 
	if(things.length > 0){
		for (var thing in things){						
			$('#'+things[thing]+' .dropdown_content').hide();
		}
	}
	
	//show popups we clicked
	$('#footer').css('z-index',_nBFSInfoDepth++);
	$('#'+target+' .dropdown_content').show();
	$('#footer').addClass('footer_popup_open');	
}






var setDropDowns = function(){
	
	//Fix height:
	var maxHeight = 300;
	
	$('#filterrow .scrollarea').each( function(){ 
		if( $(this).height() > maxHeight ){
			 $(this).height(maxHeight);
		}
	});
	
	
	//Hack to set scroll pane off window, and then place in right area	
	$('#jshelper').animate({ opacity: .9999}, 0001, '', function() {
		$('#filterrow .scrollarea').jScrollPane();
		$('#filterrow .dropdown_content').hide();
		$('#filterrow .dropdown_content').addClass('dropdown_content_ready');
	});
	
	
	setTimeout(function(){
	//Set clickzone for head:
		$('#filterrow  .dropdown').click( function(){
			$(this).siblings('.dropdown_content').toggle();
			$(this).toggleClass('dropdown_open');
		});
	},100);
	
	//Set hover for items:
	$('#filterrow .name').hover( function(){
		$(this).addClass('name_hover');
	}, function(){
		$(this).removeClass('name_hover');
	});
	
		$('#filterrow .name').click( function(){
			$(this).parents('.dropdown_holder').children('.dropdown')
				.toggleClass('dropdown_open')
				.html( $(this).html() )
				.attr( 'rel', $(this).attr('rel') );
			$(this).parents('.dropdown_content')
				.toggle();
			
			$(this).parents('.dropdown_holder').siblings('.dropdown_holder').each(function(){
				
		//		originalHolder = $(this).find('.original');
				
		//		$(this).children('.dropdown')
		//			.html( $(originalHolder).html() )
		//			.attr( 'rel', $(originalHolder).attr('rel') );
				
			});
			
			$(this).parents('.dropdown_holder').siblings('.picktypes').children('.current')
				.removeClass('current');
			$(this).parents('.dropdown_holder').siblings('.picktypes').children('.original')
				.addClass('current');
			
			
		});
	
};



_xPagination = {

	update : function(p_xObject){
		
		l_sDirection = $(p_xObject).attr('rel');
		
			//alert($(p_xObject).parent().attr('rel'));
			//alert( $(p_xObject).parent().find('.pagination').attr('rel'));
			//alert('update');
	}
	
	
}

_xGlobal = {
	
	printPage : function(p_sPage){
		
		if(!window.open(p_sPage,'Print','location=0,status=0,scrollbars=1,width=800,height='+($(window).height()-200)  ) ){
			alert('Your browser has disabled a popup window, please disable the blocker and click again')
		}
	
	},
	
	checkEmpty : function(p_sVal){
		l_sVal = escape(p_sVal);
		l_sVal = l_sVal.replace(/\s*((\S+\s*)*)/, "$1");
		l_sVal = l_sVal.replace(/((\s*\S+)*)\s*/, "$1");
		return l_sVal.length < 1;
	},
	
	checkEmpty2: function(p_sVal){
		l_sVal = (p_sVal);
		l_sVal = l_sVal.replace(/\s*((\S+\s*)*)/, "$1");
		l_sVal = l_sVal.replace(/((\s*\S+)*)\s*/, "$1");
		return l_sVal.length < 1;
	},
	
	showGallery : function(p_nId){
		showGallery (p_nId);
	},
	
	echeck: function(str) {
		 var l_aEmails = str.split(",");
		 var l_bValid = true;
		 for(i=0; i<l_aEmails.length; i++){
			 
			 if(! this.singleEmailCheck(jQuery.trim(l_aEmails[i]))){
				l_bValid = false;
				break;
			 }
			 
			 
		 }
		 
		 return l_bValid;
	},
	
	singleEmailCheck: function(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){ return false }
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false }
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false }
		if (str.indexOf(at,(lat+1))!=-1){ return false }
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false }
		if (str.indexOf(dot,(lat+2))==-1){ return false }
		if (str.indexOf(" ")!=-1){return false }
		return true;				
	},
	
	printErrors: function(p_asErrors){
		r_sError =  "<div class=\"gap10\"></div>";
		r_sError += "<div class=\"error\">";
		r_sError += "<strong>ERROR:</strong>";
		r_sError += "<div class=\"clear\"><!--comment--></span>";
		for(var i=0; i < p_asErrors.length; i++){
			r_sError += "<span class=\"error list\"><span class=\"validation_error\">"+p_asErrors[i]+"</span></span>";
			r_sError += "<div class=\"clear\"><!--comment--></span>";
		}
		r_sError += "</div>";
		
		return r_sError;
	}	
}

function fullscreenExitFix() {
	_xVideo.performFullScreenExitFix();
}

_xVideo = {
	_nHomeVideoWidth : 300,
	_nHomeVideoHeight : 297,
	_nGalleryVideoWidth : 417,
	_nGalleryVideoHeight : 342,
	_nVideoPageVideoWidth :  398,
	_nVideoPageVideoHeight : 372,
	_nNewsmakerVideoWidth : 393,
	_nNewsmakerVideoHeight : 278,
	_nNewsmakerVideoHeightExternal : 262,
	_nLastVideoType : 0,
	
	enableVideoMouseUpFix : function() {
		$('body').mouseup( function() {
			if ( $('#tdbvideo').html() != null ) {
				//$('#tdbvideo')[0].videoMouseUpFix();
			}
		} );
	},
	
	performFullScreenExitFix : function() {
		$('#jshelper').height(1);
		setTimeout(function(){ $('#jshelper').height(0); }, 200);
	},
	
	initHomeVideo : function(p_nVideoAssetId) {
		document.currentVideopageId = p_nVideoAssetId;
		this.changeHomeVideoInteral(p_nVideoAssetId, 'false');
	},
	
	changeHomeVideo : function(p_nVideoAssetId) {
		this.changeHomeVideoInteral(p_nVideoAssetId, 'true');
		
		$('#home_video_thumbs .overlay_on').removeClass('overlay_on');
		$('#video_row_'+p_nVideoAssetId).addClass('overlay_on');
		
		document.currentVideopageId = p_nVideoAssetId;
	},
	
	checkVideopageOverlays: function(){
		
		$('#home_video_thumbs .vid').each(function(){ 
			if ( $(this).attr('rel') == document.currentVideopageId ){
				$(this).addClass('overlay_on');
			}
		});
	
	},
	
	
	
	
	changeHomeVideoInteral : function(p_nVideoAssetId, p_sAutoplay){
		
		
		document.currentVideoId = p_nVideoAssetId;
		
		$('.popup_sharelink').hide();
		$('.shareItPopup_link').children('.txt').removeClass('txt_current');
				
		$('.shareItPopup_link').unbind();
		$('.shareItPopup_link').click( function(){ 
			
			if(document.cookie.indexOf("tdb_info=") != -1){ //if the user is logged in when you click	
				$('.show_email').hide();
			} else {
				$('.show_email').show();
			}
			$(this).siblings('.popup_sharelink').toggle();
			$(this).css('z-index',_nBFSInfoDepth++);
			$(this).children('.txt').toggleClass('txt_current');
			var id = $(this).siblings('.popup_sharelink').children('.popup_content').children('form').attr('id');
			resetShareLinkForm(id);
			showAllFormElements(id);
		});
		
		$(' .popup_sharelink .closebtn').unbind();
		$(' .popup_sharelink .closebtn').click( function(){ 
			$(this).parents('.popup_sharelink')
				.toggle().css('z-index',_nBFSInfoDepth++);
			$(this).parents('.popup_sharelink').siblings('.shareItPopup_link').children('.txt')
				.toggleClass('txt_current');
		});
		

		
		
		
		
		var l_sVideoContent = g_aHomeVideoDetails[p_nVideoAssetId]; // see VideoManager.php
		var l_aVideoContent = l_sVideoContent.split('~:|:~');
		var l_sTitle = l_aVideoContent[0];
		var l_sDescription = l_aVideoContent[1];
		var l_nVideoType = l_aVideoContent[2];
		var l_sVideoUri = l_aVideoContent[3];
		var l_sStillUri = l_aVideoContent[4];
		var l_nCommentCount = l_aVideoContent[5];
		var l_sTimeStamp = l_aVideoContent[6];
		var l_sEmbeddable = l_aVideoContent[7];
		var l_sAllowFullscreen = l_aVideoContent[8];
		var l_sSlug = l_aVideoContent[9];
		
		$('#homevidholder_control').height( $('#homevidholder').height()   );
		
		//$('.currentvid h4').html(l_sTitle);
		$('#homevidholder .title').html(l_sTitle);
		$('#homevidholder p.description').html(l_sDescription);
		$('#homevidholder .permalink').attr('href','/video/item/'+l_sSlug);
		$('#homevidholder .commentcount').html(l_nCommentCount);
		$('#homevidholder .timestamp').html(l_sTimeStamp);
		
		setTimeout(function(){
			$('#homevidholder_control').animate({
				height: $('#homevidholder').height()+'px'   },400);
		}, 10);
		
		
		
		if ( this._nLastVideoType == 1 && l_nVideoType == 1 ) {
			//alert ( 'check for embed: ' + $('#tdbvideo').html() + ' ' + $('#tdbvideo')[0] );
			$('#tdbvideo')[0].changeVideo(l_sVideoUri,l_sStillUri,l_sTitle,l_sEmbeddable,l_sAllowFullscreen,'true');
		}
		else if ( l_nVideoType == 1 ) {
			//$('#flashvideo').html(this.getHomeInHouseEmbed(l_sVideoUri, l_sStillUri,l_sTitle));
			$('#flashvideo').html('<div id=\"tdbhomevideotarget\"></div>');
			this.addHomeInHouseVideo(l_sVideoUri, l_sStillUri,l_sTitle, 'tdbhomevideotarget', l_sEmbeddable,l_sAllowFullscreen,p_sAutoplay);
		}
		else if ( l_nVideoType == 2 ) {
			$('#flashvideo').html(this.getHomeExternalEmbed(l_sVideoUri));
		}
		else {
			// Should never happen...
		}
		this._nLastVideoType = l_nVideoType;
	},
	
	
	getHomeExternalEmbed : function(p_sVideoUri) {
		return this.resizeHomeEmbeddedVideo(p_sVideoUri);
	},
	getNewsmakerExternalEmbed : function(p_sVideoUri) {
		return this.resizeNewsmakerEmbeddedVideo(p_sVideoUri);
	},
	
	getVideoPageExternalEmbed : function(p_sVideoUri) {
		return this.resizeVideoPageEmbeddedVideo(p_sVideoUri);
	},
	
	addGalleryExternalEmbed : function(p_sVideoUri, p_sTargetDivId) {
		$('#'+p_sTargetDivId).html(p_sVideoUri);
	//	setTimeout(function(){
							
			if ( $('#' + p_sTargetDivId + ' object').attr('width') > this._nGalleryVideoWidth ||
				 $('#' + p_sTargetDivId + ' object').attr('height') > this._nGalleryVideoHeight ) {
				var l_aResizedDimensions = this.getResizedDimensions( $('#' + p_sTargetDivId + ' object').attr('width'),
																 $('#' + p_sTargetDivId + ' object').attr('height'),
																 this._nGalleryVideoWidth, this._nGalleryVideoHeight);
				$('#' + p_sTargetDivId + ' object').attr('width',l_aResizedDimensions[0]).attr('height',l_aResizedDimensions[1]);
			}
			if ( $('#' + p_sTargetDivId + ' embed').attr('width') > this._nGalleryVideoWidth ||
				 $('#' + p_sTargetDivId + ' embed').attr('height') > this._nGalleryVideoHeight ) {
				
				var l_aResizedDimensions = this.getResizedDimensions( $('#' + p_sTargetDivId + ' embed').attr('width'),
																 $('#' + p_sTargetDivId + ' embed').attr('height'),
																 this._nGalleryVideoWidth, this._nGalleryVideoHeight);
				$('#' + p_sTargetDivId + ' embed').attr('width',l_aResizedDimensions[0]).attr('height',l_aResizedDimensions[1]);
			}
			if ( $('#' + p_sTargetDivId + ' iframe').attr('width') > this._nGalleryVideoWidth ||
				 $('#' + p_sTargetDivId + ' iframe').attr('height') > this._nGalleryVideoHeight ) {
				var l_aResizedDimensions = this.getResizedDimensions( $('#' + p_sTargetDivId + ' iframe').attr('width'),
																 $('#' + p_sTargetDivId + ' iframe').attr('height'),
																 this._nGalleryVideoWidth, this._nGalleryVideoHeight);
				$('#' + p_sTargetDivId + ' iframe').attr('width',l_aResizedDimensions[0]).attr('height',l_aResizedDimensions[1]);
			}
	//	}, 200);	
		
	},
	
	addInHouseVideoInternal : function (p_sVideoUri, p_sStillUri, p_sTitle, p_sSize, p_nWidth, p_nHeight, p_sTargetDivId, p_sEmbeddable, p_sAllowFullscreen, p_sAutoplay) {
		var so = new SWFObject(STATIC_SERVER+'swf/TheDailyBeastVideoPlayer.swf?r=11','tdbvideo', p_nWidth, p_nHeight, '9', '#eeeeee');
		so.useExpressInstall('swf/expressinstall.swf');
		so.addParam('menu', 'false');            
		so.addParam('wmode', 'transparent');            
		so.addParam('allowfullscreen', 'true');
		so.addParam("allowScriptAccess", "always");
		var l_sFlashParams = 'default=true&video='+p_sVideoUri+'&still='+p_sStillUri+'&title='+escape(p_sTitle)+'&autoplay='+p_sAutoplay+'&embeddable='+p_sEmbeddable+'&allowFullscreen='+p_sAllowFullscreen+p_sSize;
		so.addParam('flashvars', l_sFlashParams);
		so.write(p_sTargetDivId);
	},
	
	addVideoPageInHouseVideo : function (p_sVideoUri, p_sStillUri, p_sTitle, p_sTargetDivId, p_sEmbeddable, p_sAllowFullscreen, p_sAutoplay) {
		this.addInHouseVideoInternal(p_sVideoUri, p_sStillUri, p_sTitle, '&medium=true', this._nVideoPageVideoWidth, this._nVideoPageVideoHeight, p_sTargetDivId, p_sEmbeddable, p_sAllowFullscreen, p_sAutoplay);
	},
	
	addHomeInHouseVideo : function (p_sVideoUri, p_sStillUri, p_sTitle, p_sTargetDivId, p_sEmbeddable, p_sAllowFullscreen, p_sAutoplay) {
		this.addInHouseVideoInternal(p_sVideoUri, p_sStillUri, p_sTitle, '', this._nHomeVideoWidth, this._nHomeVideoHeight, p_sTargetDivId, p_sEmbeddable, p_sAllowFullscreen, p_sAutoplay);
	},
	
	
	addNewsmakerInHouseVideo : function (p_sVideoUri, p_sStillUri, p_sTitle, p_sTargetDivId, p_sEmbeddable, p_sAllowFullscreen, p_sAutoplay) {
		this.addInHouseVideoInternal(p_sVideoUri, p_sStillUri, p_sTitle, '&newsmaker=true', this._nNewsmakerVideoWidth, this._nNewsmakerVideoHeight, p_sTargetDivId, p_sEmbeddable, p_sAllowFullscreen, p_sAutoplay);
		
	},
	
	
	
	addGalleryInHouseVideo : function (p_sVideoUri, p_sStillUri, p_sTitle, p_sTargetDivId, p_sEmbeddable, p_sAllowFullscreen, p_sAutoplay) {
		this.addInHouseVideoInternal(p_sVideoUri, p_sStillUri, p_sTitle, '&large=true', this._nGalleryVideoWidth, this._nGalleryVideoHeight, p_sTargetDivId, p_sEmbeddable, p_sAllowFullscreen, p_sAutoplay);
	},
	
	resizeHomeEmbeddedVideo : function(p_sEmbedText) {
		return this.resizeEmbbedVideo(p_sEmbedText, this._nHomeVideoWidth, this._nHomeVideoHeight);
	},
	
	resizeVideoPageEmbeddedVideo : function(p_sEmbedText) {
		return this.resizeEmbbedVideo(p_sEmbedText, this._nVideoPageVideoWidth, this._nVideoPageVideoHeight);
	},
	
	resizeGalleryEmbeddedVideo : function(p_sEmbedText) {
		return this.resizeEmbbedVideo(p_sEmbedText, this._nGalleryVideoWidth, this._nGalleryVideoHeight);
	},
	resizeNewsmakerEmbeddedVideo : function(p_sEmbedText) {
		return this.resizeEmbbedVideo(p_sEmbedText, this._nNewsmakerVideoWidth, this._nNewsmakerVideoHeightExternal);
	},
	
	resizeEmbbedVideo : function(p_sEmbedText, p_nWidth, p_nHeight) {
		var r_sEmbedText = p_sEmbedText.replace(/width=["']?( )*([0-9])+( )*["']?/gi, 'width=\"'+p_nWidth+'\"');
		r_sEmbedText = r_sEmbedText.replace(/height=["']?( )*([0-9])+( )*["']?/gi, 'height=\"'+p_nHeight+'\"');
		r_sEmbedText = r_sEmbedText.replace(/name=["']?( )*(wmode)( )*["']?/gi, 'remove=\"\"');
		r_sEmbedText = r_sEmbedText.replace(/<embed/gi, '<param name="wmode" value="transparent"></param><embed wmode=\"transparent\"');  
		r_sEmbedText = r_sEmbedText.replace(/<\/object/gi, '<param name="wmode" value="transparent"></object');  
	 
		return r_sEmbedText;
	},
	
	getResizedDimensions : function (p_nInputWidth, p_nInputHeight, p_nTargetWidth, p_nTargetHeight) {
		var l_nScale = 1;
		var l_nWidthRatio = p_nInputWidth / (1.0 * p_nTargetWidth);
		var l_nHeightRatio = p_nInputHeight / (1.0 * p_nTargetHeight);
		if ( l_nWidthRatio > l_nHeightRatio ) {
			l_nScale = p_nTargetWidth / (1.0 * p_nInputWidth);
		}
		else {
			l_nScale = p_nTargetHeight / (1.0 * p_nInputHeight);
		}
		var r_nWidth = p_nInputWidth * l_nScale;
		var r_nHeight = p_nInputHeight * l_nScale;
		return [r_nWidth, r_nHeight];
	}
}

_xAudio = {
	_aAudioPlayerDivIds : [],
	
	playAudioCalled: function(p_sAudioPlayerId) {
		if ( this._aAudioPlayerDivIds.length > 0 ) {
			for ( var l_nIndex in this._aAudioPlayerDivIds ) {
				var l_sId = this._aAudioPlayerDivIds[l_nIndex];
				if ( l_sId != p_sAudioPlayerId ) {
					var l_xSwf = $('#'+l_sId)[0];
					if ( l_xSwf != null ) { 
						l_xSwf.stopAudio();
					}
				}
			}
		}
	},

	stopAllAudioPlayers : function() {
		this.playAudioCalled('');
	},

	addAudioPlayer: function(p_sEmbedDiv, p_sTargetDiv, p_sAudioFile) {
		this._aAudioPlayerDivIds.push(p_sEmbedDiv);
	
		var so = new SWFObject(STATIC_SERVER+'swf/TheDailyBeastAudioPlayer.swf',p_sEmbedDiv, 20, 20, '8', '#eeeeee');
		so.addParam('menu', 'false');            
		so.addParam('wmode', 'transparent');            
		so.addParam('allowfullscreen', 'true');
		so.addParam("allowScriptAccess", "always");
		var l_sFlashParams = 'audio='+p_sAudioFile+'&id='+p_sEmbedDiv;
		//var l_sFlashParams = 'audio='+p_sAudioFile;
		so.addParam('flashvars', l_sFlashParams);
		so.write(p_sTargetDiv);
	}
}

bfsPostComment = function(p_xObject){
	
	disableCommentForm();
	
	var l_sForm = $(p_xObject).attr('name');
	var l_nId = $(p_xObject).attr('rel');
	var l_sComment = $('#'+l_sForm+' #comment').val();
	
	if(_xGlobal.checkEmpty(l_sComment)){
		enableCommentForm();
		return false;
	}
	
	DailybeastAjax._xArgs.data = 'a=postComment';
	DailybeastAjax._xArgs.data += '&comment='+escape(l_sComment);
	DailybeastAjax._xArgs.data += '&type='+3;
	DailybeastAjax._xArgs.data += '&id='+l_nId;
	DailybeastAjax._xArgs.data += '&sortOrder='+document.sortOrder;
	DailybeastAjax._xArgs.data += '&callback='+escape('DailybeastAjax.getBfsComments');
	DailybeastAjax._xArgs.returnDiv = '#commentarea .comments-holder-area';
	DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
	$('#'+l_sForm+' #comment').val('');
	
	return false;
}



DailybeastAjax.getBfsComments = function(p_nPage){
	
	var l_nId = document.currentBfsId;
	
    DailybeastAjax._xArgs.data = 'a=getComments';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&type='+3;
    DailybeastAjax._xArgs.data += '&id='+l_nId;
	DailybeastAjax._xArgs.data += '&sortOrder='+document.sortOrder;
    DailybeastAjax._xArgs.data += '&callback='+escape('DailybeastAjax.getBfsComments');
	DailybeastAjax._xArgs.returnDiv = '#commentarea .comments-holder-area';
//	DailybeastAjax._xArgs.callBack = DailybeastAjax.getVideoComments_callback;
	DailybeastAjax._xArgs.callBack = checkCommentFocus;
	DailybeastAjax._xArgs.loader = true;
	
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
		
}


cheatPostComment = function(p_xObject){
	
	disableCommentForm();
	
	var l_sForm = $(p_xObject).attr('name');
	var l_nId = $(p_xObject).attr('rel');
	var l_sComment = $('#'+l_sForm+' #comment').val();
	
	if(_xGlobal.checkEmpty(l_sComment)){
		enableCommentForm();
		return false;
	}
	
	DailybeastAjax._xArgs.data = 'a=postComment';
	DailybeastAjax._xArgs.data += '&comment='+escape(l_sComment);
	DailybeastAjax._xArgs.data += '&type='+4;
	DailybeastAjax._xArgs.data += '&id='+l_nId;
	DailybeastAjax._xArgs.data += '&sortOrder='+document.sortOrder;
	DailybeastAjax._xArgs.data += '&callback='+escape('DailybeastAjax.getCheatComments');
	DailybeastAjax._xArgs.returnDiv = '#commentarea .comments-holder-area';
	DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
	$('#'+l_sForm+' #comment').val('');
	
	return false;
}



DailybeastAjax.getCheatComments = function(p_nPage){
	
	var l_nId = document.currentCheatId;
	
    DailybeastAjax._xArgs.data = 'a=getComments';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&type='+4;
    DailybeastAjax._xArgs.data += '&id='+l_nId;
	DailybeastAjax._xArgs.data += '&sortOrder='+document.sortOrder;
    DailybeastAjax._xArgs.data += '&callback='+escape('DailybeastAjax.getCheatComments');
	DailybeastAjax._xArgs.returnDiv = '#commentarea .comments-holder-area';
	DailybeastAjax._xArgs.callBack = checkCommentFocus;
	DailybeastAjax._xArgs.loader = true;
	
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
		
}


newsmakerPostComment = function(p_xObject){
	
	disableCommentForm();
	
	var l_sForm = $(p_xObject).attr('name');
	var l_nId = $(p_xObject).attr('rel');
	var l_sComment = $('#'+l_sForm+' #comment').val();
	
	if(_xGlobal.checkEmpty(l_sComment)){
		enableCommentForm();
		return false;
	}
	
	DailybeastAjax._xArgs.data = 'a=postComment';
	DailybeastAjax._xArgs.data += '&comment='+escape(l_sComment);
	DailybeastAjax._xArgs.data += '&type='+6;
	DailybeastAjax._xArgs.data += '&id='+l_nId;
	DailybeastAjax._xArgs.data += '&sortOrder='+document.sortOrder;
	DailybeastAjax._xArgs.data += '&callback='+escape('DailybeastAjax.getNewsmakerComments');
	DailybeastAjax._xArgs.returnDiv = '#commentarea .comments-holder-area';
	DailybeastAjax.makeAjaxCall('/include/ajax.php');
	$('#'+l_sForm+' #comment').val('');
	
	return false;
}

_xNewsmaker = {

	addViewCount : function(p_nId){		
	
		$.ajax({
			type: "POST",
			url:  AJAX_URL,
			data: 'a=addNewsmakerViewCount&id='+p_nId,
			success: function(p_sMsg){}			
		});
	}
}

DailybeastAjax.getNewsmakerComments = function(p_nPage){
	
	var l_nId = document.newsmakerId;
	
    DailybeastAjax._xArgs.data = 'a=getComments';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&type='+6;
    DailybeastAjax._xArgs.data += '&id='+l_nId;
	DailybeastAjax._xArgs.data += '&sortOrder='+document.sortOrder;
    DailybeastAjax._xArgs.data += '&callback='+escape('DailybeastAjax.getNewsmakerComments');
	DailybeastAjax._xArgs.returnDiv = '#commentarea .comments-holder-area';
	DailybeastAjax._xArgs.callBack = checkCommentFocus;
	DailybeastAjax._xArgs.loader = true;
	
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
		
}



buzzPostComment = function(p_xObject){
	
	disableCommentForm();
	
	var l_sForm = $(p_xObject).attr('name');
	var l_nId = document.currentId;
	var l_sComment = $('#'+l_sForm+' #comment').val();
	
	if(_xGlobal.checkEmpty(l_sComment)){
		enableCommentForm();
		return false;
	}
	
	DailybeastAjax._xArgs.data = 'a=postComment';
	DailybeastAjax._xArgs.data += '&comment='+escape(l_sComment);
	DailybeastAjax._xArgs.data += '&type='+5;
	DailybeastAjax._xArgs.data += '&id='+l_nId;
	DailybeastAjax._xArgs.data += '&sortOrder='+document.sortOrder;
	DailybeastAjax._xArgs.data += '&callback='+escape('DailybeastAjax.getBuzzComments');
	DailybeastAjax._xArgs.returnDiv = '#commentarea .comments-holder-area';
	DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
	$('#'+l_sForm+' #comment').val('');
	
	return false;
}



DailybeastAjax.getBuzzComments = function(p_nPage){
	
	var l_nId = document.currentId;
	
    DailybeastAjax._xArgs.data = 'a=getComments';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&type='+5;
    DailybeastAjax._xArgs.data += '&id='+l_nId;
	DailybeastAjax._xArgs.data += '&sortOrder='+document.sortOrder;
    DailybeastAjax._xArgs.data += '&callback='+escape('DailybeastAjax.getBuzzComments');
	DailybeastAjax._xArgs.returnDiv = '#commentarea .comments-holder-area';
	DailybeastAjax._xArgs.callBack = checkCommentFocus;
	DailybeastAjax._xArgs.loader = true;
	
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
		
}

DailybeastAjax.authorpageMoreUsers = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=authorpageMoreUsers';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&authorid='+document.authorId;
	
//	alert(DailybeastAjax._xArgs.data);
	
	DailybeastAjax._xArgs.returnDiv = '.relatedauthors_container';
	DailybeastAjax._xArgs.callBack = DailybeastAjax.authorpageMoreUsers_callback;
	DailybeastAjax._xArgs.loader = true;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
}
DailybeastAjax.authorpageMoreUsers_callback = function(){
	setInfoInterace('');
}



DailybeastAjax.getNewsmakerBfs = function(p_nPage){
	$('#bigfatstorynav').height($('#bigfatstorynav').height());
    DailybeastAjax._xArgs.data = 'a=getNewsmakerBfs';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&newsmakerid='+document.newsmakerId;
	
	DailybeastAjax._xArgs.returnDiv = '#bigfatstorynav';
	DailybeastAjax._xArgs.loader = true;
	DailybeastAjax._xArgs.callBack = DailybeastAjax.getNewsmakerBfs_callback;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}

DailybeastAjax.getNewsmakerBfs_callback = function(){
	$('#bigfatstorynav').height('auto');
}


loadNewsmakerVideo = function(p_nId){
	$('#flashpiece_navigation .current').removeClass('current');
	$('#flashpiece_navigation .videoblock_'+p_nId).addClass('current');
	DailybeastAjax.loadNewsmakerVideo (p_nId)
}
DailybeastAjax.loadNewsmakerVideo = function(p_nId){
    DailybeastAjax._xArgs.data = 'a=loadNewsmakerVideo';
    DailybeastAjax._xArgs.data += '&videoid='+p_nId;
	
	DailybeastAjax._xArgs.returnDiv = '.flashpiece_main';
	DailybeastAjax._xArgs.loader = true;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
}


DailybeastAjax.getNewsmakerFlashNav = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=getNewsmakerFlashNav';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&p_nId='+document.newsmakerId;
    DailybeastAjax._xArgs.data += '&p_nCurrentVid='+document.currentvideoid;
	
	DailybeastAjax._xArgs.returnDiv = '.flashpiece_navigation';
	DailybeastAjax._xArgs.loader = true;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}


DailybeastAjax.getNewsmakerBuzzModule = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=getNewsmakerBuzzModule';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&p_nId='+document.newsmakerId;
	
	DailybeastAjax._xArgs.returnDiv = '#newsmaker_beast_module';
	DailybeastAjax._xArgs.loader = true;
	DailybeastAjax._xArgs.callBack = DailybeastAjax.getNewsmakerBuzzModule_callback;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}

DailybeastAjax.getNewsmakerBuzzModule_callback = function(){
	setInfoInterace('#newsmaker_beast_module');
}



DailybeastAjax.getNewsmakerHighlightsModule1 = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=getNewsmakerHighlightsModule';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&p_nId='+document.newsmakerId;
    DailybeastAjax._xArgs.data += '&p_nModule=1';
	DailybeastAjax._xArgs.data += '&p_nHighlightsPerPage='+document.g_nHighlightsPerPage;
	DailybeastAjax._xArgs.returnDiv = '#newsmaker_highlights_1';
	DailybeastAjax._xArgs.loader = true;
	//DailybeastAjax._xArgs.callBack = DailybeastAjax.getNewsmakerHighlightsModule_callback;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}

DailybeastAjax.getNewsmakerHighlightsModule2 = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=getNewsmakerHighlightsModule';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&p_nId='+document.newsmakerId;
	DailybeastAjax._xArgs.data += '&p_nHighlightsPerPage='+document.g_nHighlightsPerPage;
    DailybeastAjax._xArgs.data += '&p_nModule=2';
	DailybeastAjax._xArgs.returnDiv = '#newsmaker_highlights_2';
	DailybeastAjax._xArgs.loader = true;
	//DailybeastAjax._xArgs.callBack = DailybeastAjax.getNewsmakerHighlightsModule_callback;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}

DailybeastAjax.getNewsmakerHighlightsModule_callback = function(){
	
	$('#newsmaker_highlights_holder').animate({height: $('#newsmaker_highlights').height()+30}, 1000, function(){});
	
}

DailybeastAjax.getNewsmakerGalleryPage = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=getNewsmakerGalleryPage';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&p_nId='+document.newsmakerId;
	
	DailybeastAjax._xArgs.returnDiv = '#galleriesholder';
	DailybeastAjax._xArgs.loader = true;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}

DailybeastAjax.getNewsmakerOriginalsModule = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=getNewsmakerOriginalsModule';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&p_nId='+document.newsmakerId;
	
	DailybeastAjax._xArgs.returnDiv = '#newsmaker_beast_holder';
	DailybeastAjax._xArgs.loader = true;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}

DailybeastAjax.getNewsmakerExtra1Page = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=getNewsmakerExtraPage';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&p_nId='+document.newsmakerId;
    DailybeastAjax._xArgs.data += '&p_nSection=1';
	
	DailybeastAjax._xArgs.returnDiv = '#newsmaker_extra_1';
	DailybeastAjax._xArgs.loader = true;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}


DailybeastAjax.getNewsmakerExtra2Page = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=getNewsmakerExtraPage';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&p_nId='+document.newsmakerId;
    DailybeastAjax._xArgs.data += '&p_nSection=2';
	
	DailybeastAjax._xArgs.returnDiv = '#newsmaker_extra_2';
	DailybeastAjax._xArgs.loader = true;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}


DailybeastAjax.getGalleryPageSection = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=getGalleryPageSection';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&p_nId='+document.newsmakerid;
	
	DailybeastAjax._xArgs.returnDiv = '#moregalleries_inside';
	DailybeastAjax._xArgs.loader = true;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}



DailybeastAjax.getLandingModuleTop = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=getLandingModuleTop';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
	DailybeastAjax._xArgs.returnDiv = '#landing_top';
	DailybeastAjax._xArgs.loader = true;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}


DailybeastAjax.getLandingModuleSecond = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=getLandingModuleSecond';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
	DailybeastAjax._xArgs.returnDiv = '#landing_second';
	DailybeastAjax._xArgs.loader = true;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}


DailybeastAjax.getNewsmakerCheatsheetViewall = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=getNewsmakerCheatsheetViewall';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&p_nId='+document.newsmakerid;
	DailybeastAjax._xArgs.returnDiv = '#cheatsheet_holder';
	DailybeastAjax._xArgs.callBack = DailybeastAjax.getNewsmakerCheatsheetViewall_callback;
	DailybeastAjax._xArgs.loader = true;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}


DailybeastAjax.getNewsmakerCheatsLinks = function(p_nPage){
	
    DailybeastAjax._xArgs.data = 'a=getNewsmakerCheatsLinks';
    DailybeastAjax._xArgs.data += '&page='+p_nPage;
    DailybeastAjax._xArgs.data += '&p_nId='+document.newsmakerId;
	DailybeastAjax._xArgs.returnDiv = '#cheatslinks';
	DailybeastAjax._xArgs.callBack = DailybeastAjax.getNewsmakerCheatsheetViewall_callback;
	DailybeastAjax._xArgs.loader = true;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');
	
}

DailybeastAjax.getNewsmakerCheatsheetViewall_callback = function(){
	
	setCheatLinks(''); 
	initCheatVote();
	loadCheatVotes();
	
	setTimeout(function(){
		setVideoOverlays('');
	},500);
	
}




indexNewsmakerFixNav = function(p_sChar){
		
	$('#indexrow .current').removeClass('current');
	$('#indexrow .index_'+p_sChar).addClass('current');
}

indexNewsmakerLanderOn = function(p_sChar){
	
	indexNewsmakerFixNav(p_sChar);
	
	if(p_sChar == 'viewall')
		DailybeastAjax.indexNewsmakerLanderOn('');
	else
		DailybeastAjax.indexNewsmakerLanderOn(p_sChar);
}

DailybeastAjax.indexNewsmakerLanderOn =function(p_sChar){

    DailybeastAjax._xArgs.data = 'a=getNewsmakerIndexRows';
    DailybeastAjax._xArgs.data += '&index='+p_sChar;
	
	DailybeastAjax._xArgs.returnDiv = '#newsmakers_inside';
	DailybeastAjax._xArgs.loader = true;
    DailybeastAjax.makeAjaxCall('/include/ajax.php');

}




switchDateAddedBlogs = function(){
	if(document.blogsAdded == 'DESC'){
		document.blogsAdded = 'ASC';
	}else{
		document.blogsAdded = 'DESC';
	}
	_xBlog.getAuthorpageBlogs(1);
}

switchDateAddedPicks = function(){
	if(document.picksAdded == 'DESC'){
		document.picksAdded = 'ASC';
	}else{
		document.picksAdded = 'DESC';
	}
	_xBlog.getAuthorpagePicks(1);
}




getCookie =  function (c_name)
{
	
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
	{ 
	c_start=c_start + c_name.length+1; 
	c_end=document.cookie.indexOf(";",c_start);
	if (c_end==-1) c_end=document.cookie.length;
	return unescape(document.cookie.substring(c_start,c_end));
	} 
  }
return "";
} 





checkTextArea = function(l_xField){
 
 
	if($(l_xField).val().length > $(l_xField).attr('rel')){ 
		$(l_xField).val($(l_xField).val().substr(0, $(l_xField).attr('rel'))); 
	}
	
	//$(l_xField).parent().find('.'+p_sClassName).html('You have ' + ($(l_xField).attr('rel') - $(l_xField).val().length) + ' characters remaining').show(); 
	
}


function strip_tags(str, allowed_tags) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Luke Godfrey
    // +      input by: Pul
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strip_tags('<p>Kevin</p> <br /><b>van</b> <i>Zonneveld</i>', '<i>,<b>');
    // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
    // *     example 2: strip_tags('<p>Kevin <img src="someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');
    // *     returns 2: '<p>Kevin van Zonneveld</p>'
    // *     example 3: strip_tags("<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>", "<a>");
    // *     returns 3: '<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>'
    
    var key = '', tag = '', allowed = false;
    var matches = allowed_array = [];
    var allowed_keys = {};
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_tags  = allowed_tags.replace(/[^a-zA-Z,]+/g, '');;
        allowed_array = allowed_tags.split(',');
    }
    
    // Match tags
    matches = str.match(/(<\/?[^>]+>)/gi);
    
    // Go through all HTML tags 
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;
        }
        
        // Save HTML tag
        html = matches[key].toString();
        
        // Is tag not in allowed list? Remove from str!
        allowed = false;
        
        // Go through all allowed tags
        for (k in allowed_array) {
            // Init    
            allowed_tag = allowed_array[k];
            i = -1;
            
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
            
            // Determine
            if (i == 0) {
                allowed = true;
                break;
            }
        }
        
        if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }
    
    return str;
}
 
 
var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}


_xOmniture = {
	
	e : function(p_xObj,p_sStr){
			//cheat
			
			var l_sTitle = this.cleanVars($(p_xObj).text());
			var l_sLink = this.cleanVars($(p_xObj).attr('href'));
			
			alert(l_sTitle+"\n"+l_sLink);
			return;
			//alert(p_sStr);
			//var s=s_gi(s_account);
			var s= new Object();
			s.products=';ad2'; 
			s.events='event7'; 
			s.eVar3 = l_sTitle;
			s.eVar4 = l_sLink;
			this.fireTrack(s);
			 
			//s.eVar18="Thumbs up"
			//s.tl(this,'o',p_sStr + ' Click');
			
			return false;
	},
	
	cleanVars : function(p_sStr){
		return p_sStr;
	},
	
	fireTrack : function(p_xObj){
		var l_sStr = '';
		for(x in p_xObj){
			l_sStr += x + '=>' + p_xObj[x] + "\n";
		}
		alert(l_sStr);
	}

}
