var name = "#sideNav";
var menuYloc = null;
var persistMenu = false;
jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);

}; 
	
$(document).ready(function(){
	if (persistMenu){
		menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")))
		$(window).scroll(function () {
			var st = $(document).scrollTop();
			if (st>150){
				offset = $(document).scrollTop()-150
				offset = offset+"px";
				$(name).animate({top:offset},{duration:500,queue:false});
				
			} else {
				$(name).animate({top:0},{duration:500,queue:false});
			}
		});
		$("div.sub a").click(function() {
			$(this).parent().parent().parent().find('a').each(function () {
				$(this).css("border", "1px solid #ccc");
			});
			var mainImage = $(this).attr("href");
			$(this).parent().parent().parent().children(":first").children(":first").attr({ src: mainImage });
			$(this).css("border", "1px solid #000");
			return false;
		});
	};
	$("a[rel]").overlay({
		expose: '#456',
		effect: 'apple',
		onBeforeLoad: function() {
			// grab wrapper element inside content
			var wrap = this.getContent().find(".contentWrap");
			// load the page specified in the trigger
			wrap.load(this.getTrigger().attr("href"));
		}
	});
	$('.ui-button').hover(
		function(){ 
			$(this).addClass("ui-state-hover"); 
		},
		function(){ 
			$(this).removeClass("ui-state-hover"); 
		}
	);	
});
function goto(url){
	//$('.close').click();
	var base = $("#base").attr("title");
	var loc =  base+url;
	var delay = setTimeout(function(){relocate(loc)},1000);
	//setTimeout("relocate(loc)", 5000);
}
function relocate(loc){
	window.location.href = loc;
}
function flashError(msg, error, refreshPg){
	if (error){
		msg = "<span class='flash-error'>"+msg+"</span>";
	}
	$('#flash-message').fadeIn("slow");
	$('#flash-message').html(msg);
	var flashMessage = $('#flash-message').expose({api: true, color: '#f0f0f0', opacity:0.8});
	flashMessage.load();
	flashMessage.onLoad(function() {
	  setTimeout(function() {
		  flashMessage.close();
		  //$('#flash-message').html('');
		  $('#flash-message').fadeOut("slow", function(){$(this).html(''); if (refreshPg){location.reload(true);}});
		  
	  }, 1000);
	});
}
function closeMsg(url){
	$('#flash-message').html('');
	$('#flash-message').fadeOut("slow", function(){if (url){relocate(url);}});
}
function promptMsg(msg){
	$('#flash-message').html('');
	$('#flash-message').fadeIn("slow");
	$('#flash-message').html(msg);
	var flashMessage = $('#flash-message').expose({api: true, closeOnClick: false, color: '#f0f0f0', opacity:0.8});
	flashMessage.load();
	/*
	flashMessage.onLoad(function() {
	  setTimeout(function() {
		  flashMessage.close();
		  //$('#flash-message').html('');
		  $('#flash-message').fadeOut("slow", function(){$(this).html(''); if (refreshPg){location.reload(true);}});
		  
	  }, 1000);
	});
	*/
}