jQuery.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('');
		return true;
    }
	else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.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;
    }
};

function install_pop(id){
	var btn = $('#' + id + '_btn');
	var pop = $('#' + id);
	var btn_close_cls = "pop_button pop_button_down";
	var btn_open_cls = "pop_button pop_button_up";
	var pop_close_cls = "body pop_close";
	var pop_open_cls = "body";
	var state = 'closed';
	btn.click ( function (){
		if(state=='closed'){
			btn.removeClass().addClass(btn_open_cls);
			pop.removeClass().addClass(pop_open_cls); 
			state = 'open';
		}
		else {
			btn.removeClass().addClass(btn_close_cls);
			pop.removeClass().addClass(pop_close_cls); 
			state = 'closed';
		}
	});
	btn.parent('h1:first').find('a:first').click(function (event){
		event.preventDefault();
		btn.click();
	})
	if(btn.hasClass('expanded'))btn.click();
	//pop.find('.menu-link').click(function (){
	//	jQuery.cookie('last_item_click',this.id);
	//	jQuery.cookie('last_item_section',btn.attr('id'));
	//});
	//var last_item_click = jQuery.cookie('last_item_click');
	//var last_item_section = jQuery.cookie('last_item_section');
	//if(last_item_section==btn.attr('id')) btn.click();
}
$(function (){
	$('a.target_blank').click(function (event){
		event.preventDefault();
		window.open(this.href);
	});
	$('.cat').each(function (){
		var first_old = $(this).find('li.old:first');
		if(!first_old.length) return ;
		var sep = $('<li class="clear sep"/>').insertBefore(first_old);
	})
})
