
function openVideoPlayer(){
	var vid_page = window.open('/video/','video','width=550,height=365,resizable=yes,status=yes,scrollbars=yes');
}

// returns events for display in minibox
function ajax_request_events(offset) {
	// Dont do if no ajax holder exists
	if( $("#ajaxEventsHolder").length == 0)
	  return;
	  
	if (offset == null)
		offset = 0;
	
	$.get(
		'/ajax/events/' + offset + '/', {}, function(data){
			if (data.count == 0)
				$('#ajaxEventsHolder').fadeOut();
		 	else{
				$("#ajaxEvents").html(data.content).fadeIn();				
			}
	}, "json");
		
}

function handleSearchFocus(){
	if( $('#search').val() == 'Search' )
		$('#search').val("");
}
function handleSearchBlur(){
	
	if( $('#search').val() == '' )
		$('#search').val( 'Search' );
}

// Scans for verse spans and adds a link to an ajax call to display the verse
function verse_scan(){

  uniq_id = Math.floor(Math.random() * 10000000);
  
	$(".verse").hover( function(){
		verse = $(this).html();
		
		// If already open, dont reopen
		if ($(this).find(".verse_box").length > 0 ){
		  clearTimeout(remove_box_timer);
		  return;
		}
		verse_box = $("<div>")
			.addClass("verse_box").attr("id", uniq_id)
			.append( $("<img>").attr("src", "/img/system/progress_indicator.gif") );
		  
		$(this).append( verse_box );
		
		// get the verse
		$.get("/ajax/verse/" + verse, function(data){
			verse_box.html(data)
		});
		
	}, function(){
		remove_box_timer = setTimeout("remove_verse("+uniq_id+")", 300);
	})
}

function remove_verse( id ){
  $(".verse_box#"+id).fadeOut( function(){
		$(this).remove();
	});
}
function verse_link_scan(){  
	$(".verse_link").each(function(i,o){
	  $(o).click( function(){open_verse_page( $(o).html() )} )
	});
}
function open_verse_page(verse){
  var a = window.open('/verse/'+verse,'verse','width=700,height=400,resizable=yes,status=yes,scrollbars=yes');
}

$(document).ready( function(){
	ajax_request_events();
	verse_scan();
	verse_link_scan();
});

