$(function(){

	/*
	test
	
	var maxWidth = 640;
	$('.photo .image img').each(function(){
		alert($(this).width());
		if ( $(this).width() > maxWidth ) $(this).width(maxWidth);
	});
	*/

	// external link
	$('a[href^="http"]:not(a[href*="oops"])').click(function(){
		window.open(this.href, '');
		return false;
	});
	
	// search input
	$('form.search input').focus( function() {
		if (this.value=='サイト検索') { this.value=''; $(this).css('color', '#222'); }
	});
	$('form.search input').blur( function() {
		if (this.value=='') { this.value='サイト検索'; $(this).css('color', '#888'); }
	});

	// scroll
	$('#pageup a').click(function(){
			$.scrollTo($(this).attr('href'), 400, {axis:'y'});
			return false;
	});
	
	// hover fadeto
	$('.banner img, li a img, .movielistwrap a img').hover(function(){
		$(this).stop().fadeTo(50, 0.8);
	},function(){
		$(this).fadeTo(300, 1);
	});

	$('p.more a, .pagenav .next a').hover(function(){
		$(this).animate({ backgroundColor: "#91E0D7" }, 80 );
	},function(){
		$(this).animate({ backgroundColor: "#FF4B63" }, 300 );
	});

	$('ul.archive li a, #sidebar .archive ul.sidelist li a, .jacket a').hover(function(){
		$(this).stop().animate({ backgroundColor: "#C6EFEA" }, 80 );
	},function(){
		$(this).animate({ backgroundColor: "#fff" }, 300 );
	});

	$('ul.tag a, a.tag').hover(function(){
		$(this).stop().animate({ backgroundColor: "#C6EFEA" }, 80 );
	},function(){
		$(this).animate({ backgroundColor: "#f3f3f3" }, 300 );
	});

	// rollover
	$('#pageup img').rollover();

	// tooltips
	$('.search .box, .jacketlist img').tipsy({gravity: 's'});

	// colorbox (lightbox)
	$('.page-photolist a').colorbox({
		rel:'group',
		transition:"fade",
		initialWidth: "300",
		initialHeight: "200",
		maxWidth: "1000",
		maxHeight: "90%"
	});

	// page up
	var o = $('#footer').offset().top;
	var wh = $(window).height(); // window size
	var fh = $('#footer').height(); // footer size
	$(window).scroll(function(){
		var st = $(this).scrollTop();
		// $('#test').text(('offset:' + o + ' win height:' + wh + ' scroll top:' + st)).css('color','#fff');
		if ((st+wh-fh) > o ) $('#footer').css({ position: 'fixed', bottom: '0' });
		if ((st+wh-fh) <= o ) $('#footer').css({ position: 'relative', bottom: 'auto' });
	});
	
});
