function log (msg) {
	if (window.console) console.log(msg);
}

Deferred.define();

Global = (function () { return this })();

function isLoggedIn () {
//	alert($('#mypageBox03 .logout').size());
	return $('#mypageBox03 .logout').size() != 0;
}

function absolute (p,q) {q=new Image;q.src=p;p=q.src;q.src='#';return p}

function showLoginBox () {
	$.get("/voice/loginFail", {}, function (data) {
		var boxes  = $('.displayBox');
		var whole  = $(data);
		ApplyRollover(whole.get(0));

		whole.css({
			position : 'absolute',
			width    : '700px',
			top      : '0',
			left     : '0'
		})
		.append(
			$("<a href='javascript:void(0)' title='close'>閉じる</a>").css({
				position: "absolute",
				top: "10px",
				right: "20px"
			})
		)
		.find('a:has(img[src*="close"]), a[title="close"]')
			.click(function () {
				$.blockUI.impl.boxCallback = null;
				$.blockUI.impl.boxRemove();
				Comment.update();
				return false;
			})
		.end()
		.find("a")
			.each(function () {
				this.href = String(this.href).replace("backurl=", "backurl=" + encodeURIComponent(location.href));
			})
		.end()
		.appendTo('#container').displayBox({}, function () {
			return confirm('閉じてもよろしいですか?');
		});

		boxes.remove();
	});
	return false;
}

CookieManager = {
	add : function (uid) {
		var stars = this.load();
		stars.unshift(uid);
		stars = stars.slice(0, 30);
		$.cookie('c', stars.join('.'), { expires: 365 });
	},

	remove : function (uid) {
		var n = [];
		$.each(this.load(), function () {
			if (this != uid) n.push(this);
		});
		$.cookie('c', n.join('.'), { expires: 365 } );
	},

	ok : function (uid) {
		var stars = this.load();
		return ('.' + stars.join('.') + '.').indexOf(uid) == -1;
	},

	load : function () {
		return ($.cookie('c') || '').split('.');
	}
};

function popup (url, name, w, h) {
	if (!name) name = "newwindow";
	w = w || screen.availWidth - 10;
	h = h || screen.availHeight;
	window.open(url, name, "width=" + w + ",height=" + h + ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,left=0,top=0");
}



$(function () {
	var tabs   = $("ul.mypageTabs01");
	var lists  = tabs.find("+ div.boxPara01").find(".eventList02");
	var links  = tabs.find("+ div.boxPara01").find(".link01");

	$(tabs.find("li").each(function (n) {
		var $t = $(this);
		this.text = $t.text();
		$t.click(function () {
			tabs.find("li").each(function (i) {
				var e = (i == n) ? "<strong />" : "<a href='javascript:void(0)'/>";
				$(e).append(this.text).appendTo($(this).removeClass("active").empty());
			});

			$(this).addClass("active");

			lists.hide();
			links.hide();
			$(lists[n]).show();
			$(links[n]).show();
		});

	})[0]).click();

	$("a.event_cancel").click(function () {
		if (confirm("本当に取り消しますか？")) {
			var t = $(this);
			$.getJSON(this.href, {}, function (data) {
				t.parent().parent().hide("fast");
			});
		}
		return false;
	});

	$("a[rel='external'], area[rel='external']").each(function () {
		this.target = "_blank";
	});

});
