$(document).ready(function() {
	var root = $('#header h1 a').attr('href');
	
/*----------------------------------------------------------------------------
	Fix IE hover:
----------------------------------------------------------------------------*/

	if ($.browser.msie) {
		$('li, input[type=submit]').hover(
			function() {
				$(this).addClass('hover');
			},
			function() {
				$(this).removeClass('hover');
			}
		);
		$('li, input[type=submit]').focus(
			function() {
				$(this).addClass('hover');
			},
			function() {
				$(this).removeClass('hover');
			}
		);
	}
	
/*----------------------------------------------------------------------------
	Insert presentational \ on items:
----------------------------------------------------------------------------*/

	$('#nav ul ul li:not(:last-child), #textNav li:not(:last-child)').after("<li>\\</li>");
	$("ul.related li:not(:last-child), div.breadcrumbs li:not(:last-child)").after("<li class='highlight'>\\</li>");
	
/*----------------------------------------------------------------------------
	Placeholder
----------------------------------------------------------------------------*/
	/*!
	* HTML5 Placeholder jQuery Plugin
	* @link http://github.com/mathiasbynens/Placeholder-jQuery-Plugin
	* @author Mathias Bynens <http://mathiasbynens.be/>
	*/
//	;(function($){$.fn.placeholder=function(){$(this).prev('label').hide();if(this[0]&&'placeholder'in document.createElement('input')){return this;};function setPlaceholder($elem){if($elem.val()===''||$elem.val()===$elem.attr('placeholder')){$elem.addClass('placeholder').val($elem.attr('placeholder'));}else{$elem.removeClass('placeholder');};};$('form:has([placeholder]) :submit').click(function(){if($(this.form).find('.placeholder').length){$(this.form).find('.placeholder:first').val('').focus().removeClass('placeholder');return false;};});return $(this).each(function(){var $input=$(this);if($input.is(':password')||!$input.is(':input')){return;};setPlaceholder($input);$input.focusin(function(){if($input.val()===$input.attr('placeholder')){$input.val('').removeClass('placeholder');};}).focusout(function(){setPlaceholder($input);});});};})(jQuery);
//
//	$('#site-search input').placeholder();
	
	
/*----------------------------------------------------------------------------
	Use scrollTo for Top Links:
----------------------------------------------------------------------------*/

	$('a[href=#top]').click(function() {
		$(document).scrollTo($('#header'), 700);

		return false;
	});
	
/*----------------------------------------------------------------------------
	For login, hide link until client logs in.
----------------------------------------------------------------------------*/

	$('li.hidden').hide();
	
/*----------------------------------------------------------------------------
	Open external links in a new tab/window
----------------------------------------------------------------------------*/
	
	$(document).ready(function() {
		$('a.external, a[rel=external]').click(function() {
			window.open($(this).attr('href'));			
			return false;
		})
	});
	
/*----------------------------------------------------------------------------
	Tabbed content:
	@modified 	2009-04-17
	@why		allowed multiple tabs per page
	@modified 	2009-06-11
	@why		max width!
----------------------------------------------------------------------------*/
	
	$('.tabbed').each(function() {
		var container = $(this);
		var tabContainer = container.find('.tabs');
		
		tabContainer.each(function() {		
			var tabs = $(this).find('li');			
			
			var niceWidth = Math.floor((((tabs.parent().width() - tabs.length)  / tabs.length) - tabs.length));			

			tabs.each(function(){
				var tab = $(this);	
							
				/* If the width is bigger, let it fly */
				if(tab.width() <= niceWidth) {
					tab.width(niceWidth);
				} else {
					var trim = Math.ceil((tab.width() - niceWidth) / tabs.length);				
					niceWidth = niceWidth - trim;
				}

				tab.click(function() {
					var position = tab.prevAll().length;

					container.find('.tabs a.active').removeClass('active');
					tab.find('a').addClass('active');
					
					/* 
					** If there are more then one lot of tabs on the page
					** we'll need to set the active tab class on the right
					** tab in that as well
					*/
					if(tabContainer.length > 1){
						tabContainer.each(function() {						
							$(this).find('li a:eq(' + position + ')').addClass('active');
						});
					}

					container.children('.tab').hide();
					container.children('.tab:eq(' + position + ')').show();

					return false;
				});
			});
		});		
	});

	
/*----------------------------------------------------------------------------
	Lightbox:
----------------------------------------------------------------------------*/
	
	$('.imageRiver a').lightBox({
		imageLoading: root + '/workspace/images/lightbox-ico-loading.gif',
		imageBtnClose: root + '/workspace/images/lightbox-btn-close.gif',
		imageBtnPrev: root + '/workspace/images/lightbox-btn-prev.gif',
		imageBtnNext: root + '/workspace/images/lightbox-btn-next.gif'
	});
	
/*----------------------------------------------------------------------------
	Clock:
----------------------------------------------------------------------------*/

	$("#clock").clock(10);
});
