function load(href,sel){
	$(sel).load(href,function(){
		html5VideoInit = false;
		// Test the browser for html5 video
		var html5Video = $('video').first().attr('ended');
		$('p.play a').bind('click', function(){
			if(html5Video != undefined){
				if(!html5VideoInit){
					playVideo($(this), 'html5');
				}
			}else{
				playVideo($(this), 'flash');
			}
			return false;
		});
		
		triggerBlock.arm($('#video-area'), null, true);
		
		pageme.init({
			perPage:6,					// items per page
			className:'.answers',		// UL to page
			pagingElement:'.numbering'	// Element to insert pagenumbers within
		});
	});
	return false;
}
function menu_subselect(el,cls){
	$(el).parent().parent().find('li').removeClass(cls);
	$(el).parent().addClass(cls);
	$(el).parent().parent().find('li.selected').prepend($(el).parent().parent().find('span.point'));
	return false;
}
$(document).ready(function(){
	if($('.secondary .ns a').length){
		$('.secondary .ns a').click(function(){
			if($(this).attr('rel')){
				// Show content
				if($('#comments,#transcript,#embed').length)$('#comments,#transcript,#embed').addClass('off');
				if($('#'+$(this).attr('rel')).length)$('#'+$(this).attr('rel')).removeClass('off');
				// Highlight
				$(this).parent().parent().find('a').removeClass('selected');
				$(this).addClass('selected');
				return false;
			}
		});
	}
	if(location.hash=='#transcript'){
		if($('#comments,#embed').length)$('#comments,#embed').addClass('off');
		if($('#transcript').length)$('#transcript').removeClass('off');
		if($('.secondary a').length)$('.secondary a').removeClass('selected');
		if($('.secondary a[rel=transcript]').length)$('.secondary a[rel=transcript]').addClass('selected');
	}
	if(location.hash=='#comments'){
		if($('#transcript,#embed').length)$('#transcript,#embed').addClass('off');
		if($('#comments').length)$('#comments').removeClass('off');
		if($('.secondary a').length)$('.secondary a').removeClass('selected');
		if($('.secondary a[rel=comments]').length)$('.secondary a[rel=comments]').addClass('selected');
	}
	if(location.hash=='#embed'){
		if($('#comments,#transcript').length)$('#comments,#transcript').addClass('off');
		if($('#embed').length)$('#embed').removeClass('off');
		if($('.secondary a').length)$('.secondary a').removeClass('selected');
		if($('.secondary a[rel="embed"]').length)$('.secondary a[rel=embed]').addClass('selected');
	}

	pageme.init({
		perPage:6,					// items per page
		className:'.answers',		// UL to page
		pagingElement:'.numbering'	// Element to insert pagenumbers within
	});

	//resizesubnav();

});
function resizesubnav(){
	// subnav li heights
	$('.ns li li:visible a').each(
		function(){
			//alert($(this).height());
			//if($(this).height()>32)$(this).css({paddingTop:'21px',paddingBottom:'21px',lineHeight:'16px'});
			if($(this).height()>32)$(this).css({paddingTop:'3px',paddingBottom:'2px',lineHeight:'16px'});
			if($(this).height()>40)$(this).css({paddingTop:'13px',paddingBottom:'13px'});
		}
	);
}
function approve(n,el){
	$.get('inc/ajax.php?method=approve&cid='+n,function(data){
		if(data=='1'){
			//$(el).parent().parent().parent().parent().find('p:last').fadeOut();
			var txt=$('li.comment a:not(span)').text().split(' ');
			$('li.comment a:not(span)').text(parseInt(txt[1]+1));
			$(el).parent().remove();
			return false;
		}else{
			alert('Could not approve this comment');
		}
	});
	return false;
}
function remove(n,el){
	if(!confirm('Are you sure you want to remove this comment?'))return false;
	$.get('inc/ajax.php?method=remove&cid='+n,function(data){
		if(data=='1'){
			$(el).parent().parent().parent().parent().fadeOut();
			var txt=$('li.comment a:not(span)').text().split(' ');
			$('li.comment a:not(span)').text(parseInt(txt[1]-1));
			$(el).parent().remove();
			return false;
		}else{
			alert('Could not delete this comment');
		}
	});
	return false;
}
function confirmq(){
	// Client-side sanity check
	var errors=false;
	var e=$('#f-name');
	var n=$('#f-email');
	var q=$('#f-question');
	var c=$('#f-category');
	if(!q.val()||q.val()=='Type your question here'){
		$('p#noq').removeClass('off');
		errors=true;
	}else{
		$('p#noq').addClass('off');
	}
	if(!c.val()||c.val()=='Choose one'){
		$('p#noc').removeClass('off');
		errors=true;
	}else{
		$('p#noc').addClass('off');
	}
	if(!e.val()){
		$('p#noe').removeClass('off');
		errors=true;
	}else{
		$('p#noe').addClass('off');
	}
	if(!n.val()){
		$('p#non').removeClass('off');
		errors=true;
	}else{
		$('p#non').addClass('off');
	}
	return(errors)?false:true;
}
function save(id){
	el=$('#q'+id);
	if(el.length){
		url='inc/ajax.php?method=save&qid='+id;
		//alert(url);
		$.get(url,function(data){
			//alert(data);
			if(data=='1'){
				//el.find('a').text('Saved');
				el.css({width:el.width()+'px',height:el.height()+'px'}).animate({opacity:'0.50'},800,function(){el.find('a').css({width:el.find('a').width()+'px'}).text('Saved')});
				//el.delay(750).find('a').text('Saved');//,function(){el.slideUp(250)});
				//alert('ok');
			}else{
				alert('Could not save question');
			}
			/*
			*/
			return false;
		});
	}
	return false;
}
function submitvideo(){
	var ok=true;
	if(!edit&&!$('#video').val()){
		//$('.novideo').removeClass('off');
		alert('You must provide a video');
		ok=false;
	}
	if(ok){
		if(!$('#f-transcript').val())ok=confirm('You have not entered a transcript. Do you wish to continue?');
		if(ok)if(!$('#f-tags').val())ok=confirm('You have not entered any tags. Do you wish to continue?');
	}

	if(ok){
		$('#f-upload  fieldset').css({opacity:'0.2'});
		$('#f-upload input,#f-upload textarea').attr('disabled','disabled');
		$('#f-upload p.uploading').removeClass('off');
		$('#f-upload').submit();
		return true;
	}
	return false;
}
function fave(id){
	$.get('inc/ajax.php?method=fave&vid='+id,function(data){
		var txt=$('li.fave a').text().split(' ');
		$('li.fave a').text(data);
	});
	return false;
}
function loghit(vid){
	$.get('inc/ajax.php?vid='+vid);
	return;
}
