﻿$(function(){

//広告
$(".related-articles ul").prepend('<li><a href="http://waucland.jp/?ac=hach01" target="_blank">【半額】VITAとPS3が半額で売ってる！</a></li>');



$("#go_top, #go_comme, #go_bottom").click(function(){
	$('html,body').animate({scrollTop:$($(this).attr("href")).offset().top}, 'slow', 'swing');
	return false;
});

var article_limit = 10,
    url = 'http://blog.esuteru.com/';
$.getJSON(url + 'archives/popular_articles.json?rangetype=custom&from=&range=13&offset=&limit=' + article_limit, function(data){
	var items = [];
	$.each(data["articles"], function(key, val){
		items.push('<li>' + (key+1) + '.<a href="' + val["url"] + '">' + val["title"] + '</a></li>');
	});
	$('<ul/>', {html:items.join('')}).appendTo('.popular_articles');
});



$('.tweet_rank li img').hover(
function(){
	var twcm = $(this).parent().parent().find('.twcm');
	twcm.animate({'opacity':0}, 160);
	$(this).animate({'opacity':0}, 160);
},function(){
	var twcm = $(this).parent().parent().find('.twcm');
	twcm.animate({'opacity':1}, 160);
	$(this).animate({'opacity':1}, 160);
}
);
$('.comme_rank li img').hover(
function(){
	var twcm = $(this).parent().parent().find('.twcm');
	twcm.animate({'opacity':0}, 160);
	$(this).animate({'opacity':0}, 160);
},function(){
	var twcm = $(this).parent().parent().find('.twcm');
	twcm.animate({'opacity':1}, 160);
	$(this).animate({'opacity':1}, 160);
}
);


window.animate_flag = 1;
$('.amazon .left, .amazon .right, .amazon_hot_item_entry .left, .amazon_hot_item_entry .right').click(function(){
	var parent = $(this).parent();
	var dir = ($(this).hasClass('left'))?4:-4;
	var item_len = parent.find('li, .azlink-widget-item').size();
	var pos = parent.find('.hot_item, .azlink-widget').css('left');
	pos = pos.replace(/px$/, '');
	if(pos === 'auto') pos = 0;
	if(pos >= 0 && dir === 4) return false;
	if(pos <= -576 * (Math.ceil(item_len/4)-1) && dir === -4) return false;
	if(animate_flag){
		animate_flag = 0;
		parent.find('.hot_item, .azlink-widget').animate(
			{'left':(dir*144) + (pos-0) + 'px'},
			500,
			function(){
				animate_flag = 1;
			}
		);
	}
});
$('.amazon .left, .amazon .right, .amazon_hot_item_entry .left, .amazon_hot_item_entry .right').mouseover(function(){$(this).css('backgroundPosition', '0 -50px');});
$('.amazon .left, .amazon .right, .amazon_hot_item_entry .left, .amazon_hot_item_entry .right').mouseout(function(){$(this).css('backgroundPosition', '0 0');});
$('.amazon .left, .amazon .right, .amazon_hot_item_entry .left, .amazon_hot_item_entry .right').mousedown(function(){$(this).css('backgroundPosition', '0 -100px');});
$('.amazon .left, .amazon .right, .amazon_hot_item_entry .left, .amazon_hot_item_entry .right').mouseup(function(){$(this).css('backgroundPosition', '0 -50px');});



setTimeout(function(){
if($('#main_col').height() > $('#right_col').height()){
	$('#right_col').css('height', $('#main_col').height()+'px');
}else{
	$('#main_col').css('height', $('#right_col').height()+'px');
}
}, 1000);







$('#comment_list .body').each(function(key, value){
	$(value).html($(value).html().replace(/((?:&gt;)?&gt;)(\d{1,5})/g, '<a href="#comme$2" class="anchor">$1$2</a>'));
	$(value).html($(value).html().replace(/(※|コメ|ｺﾒ)(\d{1,5})/g, '<a href="#comme$2" class="anchor">$1$2</a>'));
});

$('#comment_list .anchor').hover(function(){
	var targ_anc = $(this).attr("href").match(/#comme(\d{1,5})/);
	var targ_html = $('#comme'+targ_anc[1]).html();
	if(!targ_html) return false;
	var top = $(this).offset().top;
	var left = $(this).offset().left;
	$('body').append('<div class="popup">'+targ_html+'</div>');
	$('.popup').css({
		'position':'absolute',
		'top':top+'px',
		'left':left+48+'px',
		'zIndex':1000
	});
},function(){
	$('.popup').remove();
});

$('.comme_res').click(function(){
	$('html,body').animate({scrollTop:$($(this).attr("href")).offset().top}, 'slow', 'swing');
	$('#text2').val('>>'+$(this).attr('id').replace(/comme_num/,''));
	return false;
});



});
