$.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.replace("selected", "").split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
/*
$.cookie('the_cookie'); // get cookie
$.cookie('the_cookie', 'the_value'); // set cookie
$.cookie('the_cookie', 'the_value', { expires: 7 }); // set cookie with an expiration date seven days in the future
$.cookie('the_cookie', '', { expires: -1 }); // delete cookie
*/

function startFlash(){
	if ($.cookie('banner') =='closed'){
		alert($.cookie('banner'));
	} else {
		$('#main').append('<div id="mask"></div>');
		var maskHeight = $('#main').height();
		var maskWidth = $('#main').width();
	
		//var maskHeight = $(document).height();
		//var maskWidth = $(window).width();
	
		$('#mask').css({'width':maskWidth,'height':maskHeight, 'opacity':0});
	
		$('#mask').fadeIn("fast").fadeTo('slow', 0.8, function(){
			$('#main').append('<div id="banner-box"></div>');
			$('#banner-box-in').prependTo($('#banner-box')).css({'display':'block'})
			
			$('#banner-box').animate({'height':'550px'}, 500).animate({'height':'530px'}, 100, function(){
				//$('#banner-box-in').animate({'opacity': 1});
				$('#main').append('<div id="banner-button"><a title="quit banner">quit</a></div>')
				$('#banner-button').css({'top':'700px'});
				$('#banner-button').click( function() {exitFlash()});
				$('#mask').click(function() {exitFlash()});
			});
		});	
		//return false;
	}
}

function exitFlash(){
	$('#banner-button').remove();
	$('#banner-box').animate({'height':'550px'}, 100).animate({'height':'0px'}, 500, function(){
		$(this).remove();
		$('#mask').fadeOut(500, function(){
			$(this).remove();
			$.cookie('banner', 'closed', { expires: 7 });
		})
	})
}


$(document).ready(function() {
	/*if ($.cookie('banner') =='closed'){
	} else {
		startFlash();
	}*/
});
