	var cookieOrdName = "ui_st_ord";
	var cookieColName = "ui_st_col";
	var cookieLanName = "ui_st_lan";
	var selector = ".boxes";
	var cookieAge = 365;
	var st = new Array();	
	var cookieCol = $.cookie(cookieColName);
	if (cookieCol) {
		st = cookieCol.split(",");
	}
	function updateSt() {
                $.cookie(cookieColName, st, { expires: cookieAge, path: "/" });
        }
	function getOrder() {				 	
		$.cookie(cookieOrdName, $(selector).sortable("toArray"), { expires: cookieAge, path: "/" });
	}
	function restoreOrder() {

		var list = $(selector);
		if (list == null) return
		var cookie = $.cookie(cookieOrdName);
		if (!cookie) return;
 
		var IDs = cookie.split(",");
		var items = list.sortable("toArray");
		var rebuild = new Array();
		for ( var v=0, len=items.length; v < len; v++) {
			rebuild[items[v]] = items[v];
		}
		for (var i = 0, n = IDs.length; i < n; i++) {
			var itemID = IDs[i];
			if (itemID in rebuild) { 
				var item = rebuild[itemID];
				var child = $(selector+".boxes").children("#" + item);
				var savedOrd = $(selector+".boxes").children("#" + itemID);
				child.remove();
				$(selector+".boxes").filter(":first").append(savedOrd);
			}
		}
	}	

	$(function() {			
	
		$(".boxes").sortable({
			handle: ".info-box-title",
			update: function sortUpdate() { 
				getOrder(); 
			}			
		});
		
		restoreOrder();		

		$(".boxes .info-box") 	
			.find(".info-box-title") 
			.css("cursor","move")
			.prepend('<span class="collapseBox">[-]</span><span class="expandBox">[+]</span>')			  
			.end()				
			.find(".collapseBox").css("display","block")			
			.find(".info-box-content"); 


		$(".boxes .info-box-title").hover(
			function() {
				$(this).parent().addClass('info-box-hover');
			}, 
			function() {
  				$(this).parent().removeClass('info-box-hover');
			}
		);

		for (var i = 0; i < st.length; ++i) {
			$("#"+st[i]).find(".info-box-content").hide();	
			$("#"+st[i]).find(".info-box-title").find(".collapseBox").css("display","none");
			$("#"+st[i]).find(".info-box-title").find(".expandBox").css("display","block");
		}
			
		$(".info-box-title .collapseBox").click(function() {									
			$(this).parents(".info-box:first").find(".info-box-title").find(".collapseBox").css("display","none");
			$(this).parents(".info-box:first").find(".info-box-title").find(".expandBox").css("display","block");
			$(this).parents(".info-box:first").find(".info-box-content").hide("fast");

			var id = $(this).parents(".info-box:first").attr("id");
			if (st.length > 0) {
				for (var i=0; i < st.length; ++i) {			
					if (st[i] == id) {										
						break;
					}
					if (i == st.length-1) {				
						st[st.length] = id;
						updateSt();
					}
				}
			} 
			else {
				st[st.length] = id;
				updateSt();
			}			
		});
		
		$(".info-box-title .expandBox").click(function() {
		
			$(this).parents(".info-box:first").find(".info-box-title").find(".collapseBox").css("display","block");
			$(this).parents(".info-box:first").find(".info-box-title").find(".expandBox").css("display","none");
			$(this).parents(".info-box:first").find(".info-box-content").show("fast");
			
			var id = $(this).parents(".info-box:first").attr("id");									
			for (var i=st.length-1; i >= 0; --i) {								
				if (st[i] == id) {					
					st.splice(i, 1);						
					updateSt();					
				}
			}			
		});
	
	});	
	
	
		function checkLink(checksum) {
			$.get("/gfis/checklink.faces", { checksum: checksum });
		}    
		function hideAll() {
			$("#popAll").css("display", "none");
			$("#popNews").css("display", "none");
			$("#popEvents").css("display", "none");
			$("#popPubs").css("display", "none");			
			$(".tab").css("font-weight","normal");
			$(".tab").css("border-color","#000000");
			$(".tab").css("background","#9a9a9a");
			$(".tab").css("background-image","url('/gfis/img/gray_bg.jpg')");
			$(".tab").css("background-repeat","repeat-x");					
		}
		function selectAll() {
			hideAll();
			$("#popAll").show("fast");
			$("#allTab").css("font-weight","bold");
			$("#allTab").css("border-color","orange");
			$("#allTab").css("background","lightgray");
		}
		function selectNews() {
			hideAll();
			$("#popNews").show("fast");		
			$("#newsTab").css("font-weight","bold");
			$("#newsTab").css("border-color","orange");
			$("#newsTab").css("background","lightgray");			
		}
		function selectEvents() {
			hideAll();
			$("#popEvents").show("fast");
			$("#eventsTab").css("font-weight","bold");
			$("#eventsTab").css("border-color","orange");
			$("#eventsTab").css("background","lightgray");
		}
		function selectPublications() {
			hideAll();
			$("#popPubs").show("fast");
			$("#publicationsTab").css("font-weight","bold");
			$("#publicationsTab").css("border-color","orange");
			$("#publicationsTab").css("background","lightgray");			
		}
