$(function() {

	var path = location.pathname.match(/\w+\.html$/),
		filePath = path ? location.pathname.replace(path,'') : location.pathname;
	
	$.LiVE.body.opening.activate = function() {
		
		var repeat = $.LiVE.body.opening.repeat,
			date = new Date(),
			now = {
				year: date.getFullYear(),
				month: date.getMonth()+1,
				date: date.getDate()
			},
			cookie = {//「0_2012/2/14」
				name: "LiVEopeningcookie",
				set: function() {
					var val = repeat + "_" + now.year + "/" + now.month + "/" + now.date;
					$.cookie(this.name, val, {path: filePath});
				}
			},
			set = true;
		
		if ($.cookie(cookie.name)) {
			var val = $.cookie(cookie.name).split("_")[0];
			if (val!=repeat) {
				$.cookie(this.name, "", { expires:-1, path: filePath });
			}
		}
		
		switch(repeat) {
			case 1:
				if ($.cookie(cookie.name, {path: filePath})) set = false;
				else cookie.set();
				break;
			case 2:
				set = false;
				if ($.cookie(cookie.name, {path: filePath})) {
					var date = $.cookie(cookie.name, {path: filePath}).split("_")[1].split("/");
					if (now.year > date[0]) set = true;
					else if (now.month > date[1]) set = true;
					else if (now.date > date[2]) set = true;
				}
				else {
					cookie.set();
					set = true;
				}
				break;
		}
		
		return set;
	};
	
});