function shoddyPager() {
  $('.shoddyPagerNext').click(function() {
    var page = $(this).attr('href');
    $.ajax({
      async: false,
      url: page,
      beforeSend: function() {
        $('.shoddyPagerNextWrap').append('<p style="padding: 0 1em; color: #666; font-size: 12px;" class="nowLoading"><img src="/images/ajax-loader-16x16-fff-trans.gif" style="vertical-align: middle" /> Loading...</p>');
      },
      success: function(data) {
				$('li.lastChild').removeClass('lastChild');
				$('table.lastChild').removeClass('lastChild');
        $('.nowLoading').remove();
        $('.shoddyPagerContent').append($(data).find('.shoddyPagerContent').children().get());
				var next = $(data).find('.shoddyPagerNext').attr('href');
				if (next) {
					$('.shoddyPagerNext').attr('href', next);
				} else {
					$('.shoddyPagerNextWrap').remove();
				}
      },
      error: function() {
        $('.nowLoading').remove();
        $('.shoddyPagerNextWrap').append('<p style="padding: 0 1em; color: #666; font-size: 12px;" class="shoddyPagerError">ページ取得に失敗しました</p>');
        $('.shoddyPagerError').hide('slow');
      }
    });
    return false;
  });
}

var $j = jQuery;
$j(function(){
	var overSuffix = "_o";
	$j("img[imgrollover='true']").each(function(){
		var ext = this.src.substring(this.src.lastIndexOf('.'), this.src.length);
		var $img = $j(this);
		$img
			.preload({
				find:ext,
				replace:overSuffix + ext,
				threshold:1
			})
			.hover(
				function(){
					this.src = this.src.replace(ext, overSuffix + ext);
				},
				function(){
					this.src = this.src.replace(overSuffix, "");
				}
			)
			.parent().each(function(){
				if(String(document.location).indexOf($j(this).attr("href")) != -1){
					//$j(this).click(function(){return false;})
					//		.css("cursor", "default");
					$img.unbind("mouseover")
						.unbind("mouseout")
						.attr("src", $img.attr("src").replace(ext, overSuffix + ext))
						;

				}
			});
	});
});

$(document).ready(function() {
  $('.alphafilter').pngfix();
  shoddyPager();

	$('form input[type=image]').click(function() {
		$(this.form).submit();
		return false;
	});

  $('.PostImageThumb').each(function() {
		var src = $(this).attr('postImage');
    var hasImg = $(this).parent('h3').children('.PostHasImg');

    var pos = hasImg.position();
    var w = hasImg.width();
    var h = hasImg.height();
		var tag = $.tag('div').addClass('ImgWindow')
      .css({zIndex: 5000, position: 'absolute',
        top: pos.top - 4, left: pos.left + 4})
			.tag('img').attr('src', src).css({border: 'solid 2px #FFF'})
      .gat();
		tag.animate({opacity:'0', width:'0', height:'0'}, {'duration': 0});
    $(this).parent('h3').after(tag);
  });

	$('.PostImageThumb').hover(function(e) {
    $(this).parent('h3').parent('.listTitle')
			.children('.ImgWindow').animate(
				{opacity:'100', width:'92px', height:'92px'},
				{duration: 'fast', easing: 'swing'}
			);
  }, function() {
    $(this).parent('h3').parent('.listTitle')
			.children('.ImgWindow').animate(
				{opacity:'0', width:'0', height:'0'},
				{duration: 'normal', easing: 'swing'}
			);
  });

  $('.explain a img').click(function() {
    var url = $(this).parent('a').attr('href');
    var tag = $.tag('div').addClass('ImgWindow')
      .tag('img').attr('src', url).addClass('close')
        .css('border', 'solid 10px #FFF')
      .gat();
    $.modal(tag, {
      position: ['200px', '0%'],
      overlayId: 'profileOverlay',
      overlayCss: {backgroundColor: '#666666'},
      containerId: 'profileContainer',
      containerCss: {
        backgroundColor: 'transparent',
        xIndex: 5000, width: '100%', textAlign: 'center'
      },
      closeClass: 'close',
      close: false
    });
    return false;
  });

  // サイドメニュー用
	var links = $('#selectBtn a');
	var imgs = $('#selectBtn a img');
	imgs.mouseover(function() {
		if (!$(this).hasClass('current')) {
			$(this).attr('src', $(this).attr('src').replace('.gif', '_o.gif'));
		}
	});
	imgs.mouseout(function() {
		if (!$(this).hasClass('current')) {
			$(this).attr('src', $(this).attr('src').replace('_o.gif', '.gif'));
		}
	});

	links.click(function() {
		var img = $(this).children('img');
    if (img.hasClass('current')) {
      return false;
    }

		imgs.each(function() {
			$(this).attr('src', $(this).attr('src').replace('_on.gif', '.gif'))
				.removeClass('current');
		});
		img.attr(
      'src',
      img.attr('src').replace('_o.gif', '.gif').replace('.gif', '_on.gif')
    ).addClass('current');

		var c = $(this).attr('class');
		$('#searchBoxContentsMiddle .setsuyakuIdeaSearchBox').each(function() {
			if ($(this).hasClass(c)) {
				$(this).show();
			} else {
				$(this).hide();
			}
		});

		var target = '#searchBoxContentsMiddle';
		if (!$(target).children().is('.' + c)) {
			$(target).append('<div class="nowLoading" style="text-align:center;padding:12px;"><p><img src="/images/ajax-loader-16x16-fff-trans.gif" /> Loading...</p></div>');
			$.get($(this).attr('href'), function(data) {
					$(data).find(target + ' .' + c).appendTo(target);
					$(target + ' .nowLoading').remove();
			});
		}

		return false;
	});
	//$('#selectBtn a.searchBoxIdeaStyles').click();

	$('div#debugMsg').mouseover(function() {
			$(this).css('background-color', 'transparent').css('color', '#CC3333');
	});

	$('div#debugMsg').mouseout(function() {
			$(this).css('background-color', '#CC3333').css('color', '#FFFFFF');
	});
});

