// prevent enter in field to submit form
function noenter(event)
{
	if (event && event.keyCode == 13)
	{
		$(event.target).nextAll(':input:first').focus();
		return false;
	}
	else
		return true;
}

$(document)
	.ready(function()
	{
		// expand tables as requested in cookie
		/*var expanded_string = $.cookie('store_expanded_table_state');
		if (expanded_string)
		{
			$(expanded_string).next().toggle();
			$(expanded_string).toggleClass("expanded");
			$(expanded_string).find('.icon.expanding').children().toggle();
		}*/
		

		// expand (show) the next line in table
		$(".expanding").click(
			function(event)
			{
				// expand and set class
				event.stopPropagation();
				$(this).parent().parent().next().toggle();
				$(this).parent().parent().toggleClass("expanded");
				$(this).children().toggle();

				// save state
				var expanded = [];
				$('.expanded').each( function() { expanded.push('#' + $(this).attr('id')); } );
				$.cookie('store_expanded_table_state', expanded.join());
				
				return false;
			}
		);

		// regard as a link and relocate to the given page
		$(".navigate").click(
			function(event)
			{
				event.stopPropagation();
				top.location = $(this).attr("uri");
				return false;
			}
		);
		
		// stop bubbling of events for clickable things in clickable class
		$(".stoppropagation").click(
			function(event)
			{
				event.stopPropagation();
				return false;
			}
		);

		// toogle children on hover (used for show/hide)
		$(".hovertoggle").bind("mouseenter mouseleave", function(event)
			{
				event.stopPropagation();
				$(this).children().toggle();
				return false;
			}
		);


		// show museum pane on hover over museum dot
		$(".floating_panel").bind("mouseenter", function(event)
			{
				clearTimeout($(this).attr('timeout'));
				return false;
			}
		);
		$(".floating_panel").bind("mouseleave", function(event)
			{
				var panel_id = this.id;
				$(this).attr('timeout', setTimeout("$('#"+panel_id+"').fadeOut(200);",500));
				return false;
			}
		);
		$(".museum_dot").bind("mouseenter", function(event)
			{
				// hide all other panels
				$(".floating_panel").fadeOut(200);
				
				// show this panel
				clearTimeout($(this).parent().next().attr('timeout'));
				$(this).parent().next().fadeIn(200);
				return false;
			}
		);
		$(".museum_dot").bind("mouseleave", function(event)
			{
				var panel_id = $(this).parent().next().get(0).id;
				$(this).parent().next().attr('timeout', setTimeout("$('#"+panel_id+"').fadeOut(200);",500));
				return false;
			}
		);

		// highlight two rows of a table at once
		$(".double_next").hover(function(){ $(this).next().addClass("hover");},function(){ $(this).next().removeClass("hover");});
		$(".double_previous").hover(function(){ $(this).prev().addClass("hover");},function(){ $(this).prev().removeClass("hover");});
		
		// load ajax as overlay for classes .ajax
		$(".ajax").click(
			function(event)
			{
				event.stopPropagation();

				// callback function to set title and show overlay
				function setOverlay()
				{
					// find button which was clicked
					if (event.target)
						targ = event.target;
					else if (event.srcElement)
						targ = event.srcElement;
					
					// get title for ajax dialog
					if (jQuery(targ).parent().attr("ajaxtitle"))
						title = jQuery(targ).parent().attr("ajaxtitle");
					else if (jQuery(targ).attr("ajaxtitle"))
						title = jQuery(targ).attr("ajaxtitle");
					
					if (title)
						$("div#dialog>div#dialog_content").prepend('<div class="dialog_title">'+ title +'</div>');

				}

				// show spinner
				$("div#dialog>div#dialog_content").html('<div class="dialog_title">'+ lang_pleasewait +'</div><div class="spinner"><img src="'+webapp_path_to_root+'images/spinner.gif" alt="'+lang_pleasewait+'" title="'+lang_pleasewait+'"></div>');

				// need to specify all relatively positioned elements because of IE
				$("div#centerdiv, #sidebar, #rightbar, #content, #site_name, #site_slogan").fadeTo("medium",0.33);
				$("div#overlay").show("medium");

				// get content, and fill on callback
				$("div#dialog>div#dialog_content")
							.load( $(this).attr("uri"),	null, setOverlay );
				return false;
			}
		);

  		// tabs
		$.jtabber({
			mainLinkTag: "#tab_nav a", 				// much like a css selector, you must have a "title" attribute that links to the div id name
			activeLinkClass: "selected_tab",		// class that is applied to the tab once it\'s clicked
			hiddenContentClass: "hidden_tab",		// the class of the content you are hiding until the tab is clicked
			showDefaultTab: 1, 						// 1 will open the first tab, 2 will open the second etc.  null will open nothing by default
			showErrors: false, 						// true/false - if you want errors to be alerted to you
			effect: null, 							// null, "slide" or "fade" - do you want your content to fade in or slide in?
			effectSpeed: 'fast', 					// "slow", "medium" or "fast" - the speed of the effect
			savestate: true							// save tabstate in cookie store_tab_state
		});
		
		// change state of this div, when contained link is hovering
		$(".containsclickable > a").hover(function(){ $(this).parent().addClass("hover"); }, function(){ $(this).parent().removeClass("hover")});
		
		// fix failure of internet explorer to implement hover
		$(".clickable").hover(function(){ $(this).addClass("hover"); }, function(){ $(this).removeClass("hover"); });
		
		// fix IE6 transparent PNG bug
		//if (( $.browser.msie ) && ( $.browser.version < 7 ))
		//	$('img[@src$=.png], li').ifixpng();
				
	});			

