/*
 * Contempo Alert Bar
 * http://contempographicdesign.com
 *
 * Copyright(c) 2011, Chris Robinson
 * All rights reserved.
 *
 * You may not redistribute this file, under any circumstances.
 */

jQuery(document).ready(function() {

	var alert = jQuery('#alert-wrapper'),
		alertClose = jQuery('#alert-close'),
		alertOpen = jQuery('#alert-open'),
		alertOpened = jQuery.cookie('alertOpened');
	
	if (alertOpened != 0) { 
		openAlert(alert, alertOpen);
	} else { alertOpen.show(); }
	
	alertClose.click(function(e){
		e.preventDefault();
		closeAlert(alert, alertOpen);
	});
	
	alertOpen.click(function(e) {
		e.preventDefault();
		openAlert(alert, alertOpen);
	});
});

function openAlert(alert, alertOpen) {
	alert.delay(250).slideDown({
		duration: 1000,
		easing: 'easeInOutBack',
	});
	alertOpen.slideUp({
		duration: 500,
	});
	jQuery.cookie('alertOpened', 1, { expires: 1 }); // Cookie expires in one day	
}

function closeAlert(alert, alertOpen) {
	alert.slideUp({
		duration: 500,
	});
	alertOpen.delay(500).slideDown({
		duration: 250,
		easing: 'easeInOutBack',
	});
	jQuery.cookie('alertOpened', 0, { expires: 1 }); // Cookie expires in one day
}
