var default_fade = .75;
$('document').ready( function() {
	
	/* LAYER SCRIPTS
	======================================================================================
	*//* ------------------------------------------------------------------------------ */
	// LAYER SCRIPTS
	$('#body_layer-fog').click( function(event) {
		$('#body_layer-fog, #body_layer').fadeOut(default_fade, function() {
			
		});
	});
	
	/* ANCHOR TAGS - Backup if the stylesheet doesn't work
	======================================================================================
	*//* ------------------------------------------------------------------------------ */
	/*
	$('.content p a').each(function(index) {
		if( $(this).attr("name") != undefined &&  $(this).attr("name") != 'undefined' ) {
			$(this).addClass('name');
			$(this).click( function(event) {
				event.preventDefaults();
			});
		}
	});
	*/
	
	/* SEARCH FORM
	======================================================================================
	*//* ------------------------------------------------------------------------------ */
	$('.form-SEARCH').submit(function(event) {
		event.preventDefault();
		var s_action = $(this).attr('action');
		var s_value	 = $(this).children('input').val();
		var s_submit = s_action+'/'+s_value;
			document.location.href = s_submit;
		
	});
	// Header Action
	$("a.SEARCH").click(function(event) {
		event.preventDefault();
		if(!$(this).hasClass('active')) {
			$(this).addClass('active').parent('li').addClass('active');
			$('li.SEARCH, div.INPUT').animate({
				width: '+=169'
				}, 200, function() {
					// Animation complete.
					
				});
		} else {
			var s_action = $('#form-SEARCH').attr('action');
			var s_value	 = $('#form-SEARCH').children('input').val();
			var s_submit = s_action+'/'+s_value;
				document.location.href = s_submit;
		}
	});
	// Sidebar Action
	$("a.SEARCH-sidebar").click(function(event) {
		var s_action = $('#form-SEARCH-sidebar').attr('action');
		var s_value	 = $('#form-SEARCH-sidebar').children('input').val();
		var s_submit = s_action+'/'+s_value;
			document.location.href = s_submit;
	});
	
	/* JOIN FORM
	======================================================================================
	*//* ------------------------------------------------------------------------------ */
	var join_val = $('#JOIN input.input-text').val();
	$('#JOIN input.input-text:not(.focus)').focus(function() {
		if( $(this).val() == join_val ) {
			$(this).val('').addClass('focus');
		}
	}).blur(function() {
		if( $(this).val() == '' ) {
			$(this).val( join_val ).removeClass('focus');
		}
	});
	
	
	/* SLIDESHOW - Pages, inline
	======================================================================================
	*//* ------------------------------------------------------------------------------ */
	$('.content-slideshow').hover(
		function() {
			$(this).children('.content-slideshow-controls').show();
		},
		function() {
			$(this).children('.content-slideshow-controls').hide();
		}
	);
	
	
	/* SIDEBAR - Filters, dropdown ul elements
	======================================================================================
	*//* ------------------------------------------------------------------------------ */
	$('ul.filters li.header a').click( function(event) {
		var obj = $(this).parents('ul.filters').find('ul');
		if( $(obj).hasClass('showing') ) {
			$(obj).removeClass('showing').fadeOut('fast');
		} else {
			$(obj).addClass('showing').fadeIn('fast');
		}
	});
	$('ul.filters > ul.filters li a').click( function(event) {
		var obj = $(this).parents('ul.filters.CHILDREN');
		if( $(obj).hasClass('showing') ) {
			$(obj).parents('ul.filters').find('li.header a').text( $(this).text() );
			$(obj).removeClass('showing').fadeOut('fast');
		} else {
			$(obj).addClass('showing').fadeIn('fast');
		}
	});
	
	/* SIDEBAR - Auth Component
	======================================================================================
	*//* ------------------------------------------------------------------------------ */
	var auth_user_val = $('input#AUTH-user').val();
	var auth_pass_val = $('input#AUTH-pass').val();
	$('input#AUTH-user:not(.focus)').focus(function() {
		if( $(this).val() == auth_user_val ) {
			$(this).val('').addClass('focus');
		}
	}).blur(function() {
		if( $(this).val() == '' ) {
			$(this).val( auth_user_val ).removeClass('focus');
		}
	});
	$('#AUTH-pass:not(.focus)').focus(function() {
		if( $(this).val() == auth_pass_val ) {
			$(this).val('').addClass('focus');
		}
	}).blur(function() {
		if( $(this).val() == '' ) {
			$(this).val( auth_pass_val ).removeClass('focus');
		}
	});


});
