/*----------------------------------------
	Hover
----------------------------------------*/
(function($){

$(function(){
	$('div.topicsInfoBlock').hover(
	function(){ $(this).addClass('hover'); },
	function(){ $(this).removeClass('hover'); }).each(function(){
		var _this = $(this);
		var _anchor = _this.find('div.infoTableHeadline a');
		_anchor.click(function(e){ this.blur(); });
		_this.click(function(e){
			//location.href = _anchor.attr('href');
		});
	});
});

/*----------------------------------------
	Modal
----------------------------------------*/

// FRIEND POST
$(function()
{
	$(".mobileInfoOuter").hide()
	$("body").append("<div id='glayLayer'></div><div id='overLayer'></div>");
	
	$("#glayLayer").click(function()
	{
		$(this).hide();
		$("#overLayer").hide();
	});
	
	$(".mobileInfoBtn").click(function()
	{
		$("#glayLayer").show();
		$("#overLayer").fadeIn(700).html("<img src='/common/images/icon_close.gif' class='close' />"+$("+.mobileInfoOuter",this).html()).css(
		{
			marginTop:"-"+$("#overLayer").height() / 2 + "px", 
			marginLeft:"-"+$("#overLayer").width() / 2 + "px" 
		});
		
		$("#overLayer img.close,#overLayer .itemFriendBtn").click(function()
		{
			$("#glayLayer").hide();
			$("#overLayer").hide();
		});
		return false;
	});
	
	if($.browser.msie && $.browser.version < 7)
	{
		$(window).scroll(function()
		{
			$("#glayLayer").get(0).style.setExpression("top", "$(document).scrollTop() + 'px'");
			$("#overLayer").get(0).style.setExpression("top", "($(document).scrollTop() + $(window).height() / 2) + 'px'");
		});
	}
});


/*----------------------------------------
	Tab Interface with History
----------------------------------------*/
var _container,_blocks,_tabs;

function pageload(_hash) {
	var _block = '';
	var _tab = '';
	if(_hash) {
		_block = _hash.replace(/^/, 'cat');
		_tab = _hash;
	}
	activateBlock(_block);
	activateTab(_tab);
	_container.jScrollPane(ist.scrollSettings);
}
function activateBlock(_block){
	_blocks.hide();
	var _targetBlock;
	if(_block == "catAll"){
		_targetBlock = _blocks.show();
	} else {
		_targetBlock = _blocks.filter('.' + _block).show();
	}
	if(_targetBlock.length == 0){
		_notFound.show();
	} else {
		_notFound.hide();
	}
}
function activateTab(_tab){
	_tabs.removeClass('stay');
	_tabs.each(function(){
		var _this = $(this);
		if(_this.find('a').attr('href') == '#' + _tab){
			_this.addClass('stay');
		}
	});
}
$(function(){
	_notFound = $('<p id="notFoundBlock">現在トピックスはございません。</p>').hide();
	_container =  $('#topicsContainer').append(_notFound);
	_blocks = $('div.topicsInfoBlock');
	_tabs = $("#topicsTab li");

	if(_blocks.length == 0){
		_notFound.show();
	}

	$.historyInit(pageload);
	// set onlick event for buttons
	var _anchors = $("#topicsTab a").click(function(e){
		this.blur();
		var _hash = this.href;
		_hash = _hash.replace(/^.*#/, '');
		$.historyLoad(_hash);
		e.preventDefault();
	});
	if(location.hash == '') {
		_anchors.eq(0).click();
	}
});

})(jQuery);
