$(function(){
	$.lbs.setScrolls();
	$.lbs.rollOver();
	$.lbs.setClass();
	$.lbs.catBdrUtil();
	$.lbs.setHeightIframe();

	// iframme reload.
	/*
	$('#main_visual').find('iframe').each(function() {
		this.contentWindow.location.reload(true);
	});
	$('#side_banner_area').find('iframe').each(function() {
		this.contentWindow.location.reload(true);
	});
	*/
});

$.lbs = {
	setScrolls: function(){
		$('a[href^=#]').click(function(){
			var top = $(this.hash).offset().top;
   $($.browser.safari ? 'body' : 'html').animate({scrollTop:top}, 700, 'swing');
			return false;
		});
	}
	,rollOver: function(){
		$('img.btn').each(function(){
			this.oSrc = $(this).attr("src");
            if(this.oSrc.match(/_(stay|dis)(\.gif|\.jpg|\.png)$/))
            {
                this.hSrc = this.oSrc;
            } else {
                this.hSrc = this.oSrc.replace(/(\.gif|\.jpg|\.png)$/, "_o$1");
                this.cache = new Image();
                this.cache.src = this.hSrc;
            }
		}).hover(function(){
			$(this).attr('src',this.hSrc);
		},function(){
			$(this).attr('src',this.oSrc);
		});
		$('input.btn').each(function(){
			this.oSrc = $(this).attr("src");
            if(this.oSrc.match(/_(stay|dis)(\.gif|\.jpg|\.png)$/))
            {
                this.hSrc = this.oSrc;
            } else {
                this.hSrc = this.oSrc.replace(/(\.gif|\.jpg|\.png)$/, "_o$1");
                this.cache = new Image();
                this.cache.src = this.hSrc;
            }
		}).hover(function(){
			$(this).attr('src',this.hSrc);
		},function(){
			$(this).attr('src',this.oSrc);
		});
	}
	,setClass: function(){
		$('.booklist01 li:last-child').addClass('lc');
		$('#side_ranking li:last-child').addClass('lc');
		$('#footer li:last-child').addClass('lc');
		if($('body').hasClass('index')){
			$('#top_category tr:last-child').children().addClass('lc');
			$('#top_category li:first-child').addClass('fc');
			$('#top_newarrival .box01:last-child').addClass('lc');
		}
		$('.search_pakuzu>li').each(function(ind,e){
			$(e).css('margin-left',ind+'em');
		});
		$('#ranking_section .box01').find('.book_detail:eq(0)').addClass('fc');
/*
		if($('body').hasClass('second') && $('#main_visual').length > 0) {
			$('#global_nav').css('padding-bottom','10px');
		}
*/
	}
	,catBdrUtil: function(){
		if($('body').hasClass('index')){
			var num;
			$('#top_category td').each(function(){
				num = $(this).find('li').length;
				$(this).find('li').each(function(ind){
					if(ind+1 != num)$(this).append('|');
				});
			});
		}
	}
	,setHeightIframe: function(){

		//var ifr_top  = document.getElementById('iframe_top');
		var ifr_side = document.getElementById('iframe_side');

		ifr_side.onload = function(){

			setTimeout( function() {

				var HeightMainVisual = $("#main_visual iframe").contents().find('body').height();
				$("#main_visual iframe").css('height', HeightMainVisual);

				var HeightSideBanner = $("#side_banner_area iframe").contents().find('body').height();
				$("#side_banner_area iframe").css('height', HeightSideBanner);

			}, 100);

		};

	}
}










