var mp3Link="http://rivchurch.com/resources/mp3player/?link=http://www.rivwarehouse.com/resources/messages/";
var vidLink="http://rivchurch.com/resources/videoplayer/"

var defaultFocus=function() {
	if($(this).val()==this.defaultValue) $(this).val('');
	$(this).css("color","");
}

var defaultBlur=function() {
	if($(this).val()=='') $(this).val(this.defaultValue);
	$(this).css("color","");
}

var venue=function(name) {
	$.cookie('venue', name, {'expires': 365, path: '/'})
	
	name=new String(name);
	
	$("#choiceMSU").removeClass("selectedVenue");
	$("#choiceHolt").removeClass("selectedVenue");
	
	$("#choice"+name).addClass("selectedVenue");
	
	$("#venues").css("backgroundImage","selected_venue.png");
	$("#venueChoices").css("backgroundImage","url('/images/"+name.toLowerCase()+"_selected.gif')");
	
	if(strCount(document.location, '/')==3){
		$("#contentBack").load('/process/venue/', {}, function() { renderTextProject(); setClickHandlers();});
	} else {
		try {
			msgsRefresh();
		} catch(err) {
			redirect('/');
		}
	}
	
	$('button').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	)
}

var search=function() {
	$("#frmSearch").submit();
}
var scrollTo=function(selector) {
	var targetOffset = $(selector).offset().top;
	$('html,body').animate({scrollTop: targetOffset}, 500);
}

function redirect(location) {
	document.location=location;
}

function loading(id) {
	height=$('#'+id).height();
	$('#'+id).height(height);
	
	$('#'+id).html('<img src="/images/loading.gif"> <b>Loading...</b>');

}

function strCount(str, search) {
	var haystack=new String(str);
	var count=-1;
	
	for(var pos=0; pos<haystack.length && pos!=-1; pos=haystack.indexOf(search, pos)) {
		count++;
		pos++;
	}
	
	return count;
}

$(function(){
	$.cookie('series', '', {'expires': -1, path: '/'})
	//if(!$.support.opacity) $("img[@src$=png]").ifixpng(); 
	
	//hover states on the static widgets
	$('button').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	)
	.mousedown(function(){
		$(this).addClass("ui-state-active"); 
	})
	.mouseup(function(){
		$(this).removeClass("ui-state-active");
	});
	
	$("#navLinkHelp").hover(function(){$("#menuHelp").show();}, function(){$("#menuHelp").hide();});
	$("#menuHelp").hover(function(){$("#menuHelp").show();}, function(){$("#menuHelp").hide();});

	$("#navLinkGrow").hover(function(){$("#menuGrow").show();}, function(){$("#menuGrow").hide();});
	$("#menuGrow").hover(function(){$("#menuGrow").show();}, function(){$("#menuGrow").hide();});

	$("#navLinkServe").hover(function(){$("#menuServe").show();}, function(){$("#menuServe").hide();});
	$("#menuServe").hover(function(){$("#menuServe").show();}, function(){$("#menuServe").hide();});

	$("#navLinkGo").hover(function(){$("#menuGo").show();}, function(){$("#menuGo").hide();});
	$("#menuGo").hover(function(){$("#menuGo").show();}, function(){$("#menuGo").hide();});

	$("#navLinkAbout").hover(function(){$("#menuAbout").show();}, function(){$("#menuAbout").hide();});
	$("#menuAbout").hover(function(){$("#menuAbout").show();}, function(){$("#menuAbout").hide();});
	
	$("#search").focus(defaultFocus);
	$("#search").blur(defaultBlur);


	$("#search").bind('keypress', function(e) {
        if(e.which == 13) search();
    });
	
	$("#btnSearch").click(search);

});
