/* gets list of possible selections for dropdown */
var imageRelationListUpdate = function(v,p){
	if(v == "e"){
		$.get("/events/getSelect",{"preSel":p},function(data){ $("#uploadImageFormRelationId").html(data).slideDown(); },"html");
	}else if(v == "v"){
		$.get("/venues/getSelect",{"preSel":p},function(data){ $("#uploadImageFormRelationId").html(data).slideDown(); },"html");
	}
}

/* opens message pane and enters error messages */
var recordError = function(m,c){
	$("#messagesPanel").html("");
	if(c == 2){ c = "success"; }else{ c = "error"; }
	$("#messagesPanel").html("<li><a href=\"#\" class=\""+c+"\">"+m+"</a></li>").slideDown();
	$("#messagesPanel").click(function(){ $(this).slideUp(); return false; });
	var messageDecayTimer = undefined;
	if(messageDecayTimer != undefined){clearTimeout(messageDecayTimer);}
	messageDecayTimer = setTimeout(function(){
		messageDecayTimer = undefined;
		$("#messagesPanel").fadeOut();
	},10000);
}

/* login sequence */
var loginInit = function(){
	// enable the star raters
	$("input").rating('enable');
	
	// show anything that's login only
	$(".loginDependent").fadeIn();
	$(".logoutDependent").fadeOut();
	
	// show the user toolbox for the left side of the page, if necessary
	$("#userControlPanel div.moduleContent").fadeIn();
}

/* logout sequence */
var logoutInit = function(){
	// enable the star raters
	$(".star").rating('disable');
	
	// clear any userId fields that may be displayed
	$("input[name='userId']").val("");
	
	// hide anything that's login only
	$(".loginDependent").fadeOut();
	$(".logoutDependent").fadeIn();
	
	$("#userControlPanel div.moduleContent").fadeOut();
}

/* routine for page loading */
var init = function(){
	// sets up the user login/toolbox frame
	$("#userTools").html("").css("background","url('/assets/site/images/loading.gif') center no-repeat");
	$.get("/users/",{},function(data){ $("#userTools").css("background","none").html(data); },"html");
	
	// updates list of possible events/venues/galleries when drop down is found or changed
	if($("#uploadImageFormRelationType").val() != ""){ imageRelationListUpdate($("#uploadImageFormRelationType").val(),$("#uploadImageFormRelationIdPreSel").val()); }
	$("#uploadImageFormRelationType").change(function(){ imageRelationListUpdate($(this).val()); });
	
	// runs lightbox on relevant links
	$("a.lightbox").lightBox();
}

$(document).ready(function(){
	init();
	
	<!--[if gte IE 7]>
		$("a#joinMailingList").fancybox({"frameWidth":545,"frameHeight":520,"padding":0,"hideOnContentClick":false});
	<!--[endif]>
	
	
	$("a#upgradeBrowser").fancybox({"frameWidth":545,"frameHeight":520,"padding":0,"hideOnContentClick":false});
});