$(document).ready(function(){
	/*
	 *	Top Alert 
	 */
	var $alert = $('#alert');
	
	var $toggle = $('#alert .toggle');
	var layout = {
		'on':new Array(),
		'off':new Array()
	}
		
	layout.on['#alert'] = $alert.css('margin-top');
	layout.on['#alert .toggle'] = $toggle.css('top');
	
	$alert.addClass('hidden');
	$('a',$alert).attr('href','').click(function(){return false;});
	
	layout.off['#alert'] = $alert.css('margin-top');
	layout.off['#alert .toggle'] = $toggle.css('top');
	
	$('#alert .toggle').click(function(){
		var speed = ($(this).data('init') != true) ? 500 : 100;
		$(this).data('hidden',!$(this).data('hidden'));
		$(this).data('init',true);
		$.cookie('hide-alert', $(this).data('hidden'));
		var dest = ($(this).data('hidden'))
			? layout.off
			: layout.on;
		$('#alert').stop().animate({marginTop:dest['#alert']},speed,function(){
			$(this).attr('class',$('#alert .toggle').data('hidden') ? 'hidden' : '' );
		});
		$(this).stop().animate({top:dest['#alert .toggle']},speed);
		return false;
	});
	
	//Show unless cookie states otherwise
	if($.cookie('hide-alert') == null || $.cookie('hide-alert') == 'false'){
		$alert.removeClass('hidden');
		
		if($.cookie('init') == null){
			$alert.css('margin-top',layout.off['#alert']);
			$toggle.data('hidden',true).delay(200).queue(function(){
				$(this).click();
				$(this).dequeue();
			});
			$.cookie('init',true);
		}else{
			$toggle.data('init',true);
		}
	}else{
		$toggle.data('init',true).data('hidden',true);
	}
});
