/* RESEN */
/* Javascript Functions
----------------------------------------------------------------------------- */


	$(document).ready(function() {
	
		language();
		lightbox();
		actions();
		
	});
	
	$(window).load(function() {

		tabs();
		replaceSubmitButtons();
		$('body').removeClass('loading');

	});
		

/* FUNCTION: LINK BEHAVIORS
----------------------------------------------------------------------------- */

	
	function actions() {

		
/* Back Link */


		$('a[href=#back]').click(function() {
		
			history.go(-1);
			return false;
		
		});
		
		
/* Social Bookmarks */
			

		if ($('ul.share').length > 0) {
		
			var itemTitle = $('ul.share').parent().children('h4').text();
		
			$('ul.share .facebook a').attr('href', 'http://www.facebook.com/sharer.php?u=' + location.href);
			$('ul.share .delicious a').attr('href', 'http://del.icio.us/post?v=4&noui&jump=close&url=' + location.href + '&title=' + itemTitle);
			$('ul.share .stumbleupon a').attr('href', 'http://www.stumbleupon.com/submit?url=' + location.href + '&title=' + itemTitle);
			$('ul.share .digg a').attr('href', 'http://digg.com/submit?phase=2&url=' + location.href + '&title=' + itemTitle);

		}
		
	}
	
	
/* FUNCTION: TABS
----------------------------------------------------------------------------- */


	function tabs() {
	
	
/* Remove Empty Tabs */


		$('.tabbed > ul.tabs').children('li').each(function() {
		
			var pane = $(this).find('a').attr('href');
			if ($(this).parent().siblings(pane).children().length == 0) { 
			
				$(this).parent().siblings(pane).remove();
				$(this).remove();
				
			}
	
		});
		
	
/* Initiate Tabs */


		$('.tabbed > ul.tabs').tabs({
			
			fxSlide: false
	
		});
		
		
/* Fix Tabbed Paging */

		
		$('.tabbed .pane ul.paging a, .tabbed .pane ul.pages a').each(function() { 
		
			var pane = $(this).closest('.pane').attr('id');
			$(this).attr('href', $(this).attr('href') + '#' + pane); 
	
		});
		
		
	}
	
	
/* FUNCTION: REPLACE SUBMIT BUTTONS
----------------------------------------------------------------------------- */


	function replaceSubmitButtons() {
	
	
/* Replace Buttons */

	
		$('input[type=submit]').each(function() {
					
			var language = $(this).attr('value');
			$(this).parent().addClass('submit');
			$(this).replaceWith('<a class="action submit" href="#submit">' + language + '</a>');

		});
		

/* Submit Form */

	
		$('a[href=#submit]').click(function() {

			$(this).parents('form').submit();
			$('a.action.submit').unbind('click');
			return false;
			
		});
	
	}