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


	$(document).ready(function() {
	
		actions();
		replaceSubmitButtons();
		slideshows();
		
	});
	
	$(window).load(function() {

		alerts();
		$('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: REPLACE SUBMIT BUTTONS
----------------------------------------------------------------------------- */


	function replaceSubmitButtons() {
	
	
/* Replace Buttons */

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

		});
		

/* Button Click */

	
		$('a.submit').click(function() {

			$(this).parents('form').submit();
			return false;
			
		});
		
		
/* Form Submit */


		$('form').submit(function() {
			
			if ($(this).attr('action').match('actions')) {
			
				var action = window.location.href.replace(window.location.protocol + "//" + window.location.hostname, '');
				$(this).attr('action', action);
				
			}
			
		});
		
	
	}
	
	
/* FUNCTION: ALERT
----------------------------------------------------------------------------- */


	function alerts() {
	
		$('div.alert').each(function() {
		
			$(this).prependTo('body').slideDown('fast');
		
		});
		
		$('div.alert').click(function() {
		
			$(this).slideUp('fast');
		
		});
			
	}
	
	
/* FUNCTION: SLIDESHOWS
----------------------------------------------------------------------------- */


	function slideshows() {
	
		$('#header > .links > .content').cycle({
		
			speed: 500,
			timeout: 5000
			
		});
	
	}