/*------------------------------------------------------------------------------------------------
creation date 2009.7.14
Copyright (C) IkedaMasako.com All Rights Reserved.
------------------------------------------------------------------------------------------------*/
$(function()  {  
/*------------------------------
roll over
------------------------------*/
    $.fn.rollover = function(postfix) {
        postfix = postfix || '_on';
        return this.not('[src*="'+ postfix +'."]').each(function() {
            var img = $(this);
            var src = img.attr('src');
            var src_on = [
                src.substr(0, src.lastIndexOf('.')),
                src.substring(src.lastIndexOf('.'))
            ].join(postfix);
            $('<img>').attr('src', src_on);
            img.hover(
                function() {
                    img.attr('src', src_on);
                },
                function() {
                    img.attr('src', src);
					$('body#book li.book img').attr('src' ,  'http://www.ikeda-masako.com/image/base/nav_book_d_on.gif');
					$('body#parts li.parts img').attr('src' ,  'http://www.ikeda-masako.com/image/base/nav_parts_d_on.gif');
					$('body#unpublished li.unpublished img').attr('src' ,  'http://www.ikeda-masako.com/image/base/nav_unpublished_d_on.gif');
					$('body#others li.others img').attr('src' ,  'http://www.ikeda-masako.com/image/base/nav_others_d_on.gif');
                }
            );
        });
    };
	$('a img.on').rollover();


/*------------------------------
scrollto
------------------------------*/
	$('a[href*=#contact]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var target = $(this.hash);
			target = target.length && target;
			if (target.length) {
				var sclpos = 500;
				var scldurat = 1200;
				var targetOffset = target.offset().top - sclpos;
				$('html,body')
					.animate({scrollTop: targetOffset}, {duration: scldurat, easing: "easeOutExpo"});
				return false;
			}
		}
	});


/*------------------------------
fade
------------------------------*/
	$('div#wrapper dl#gNav dd ul').children().hover(function() {
		$(this).siblings().stop().fadeTo(800,0.4);
	}, function() {
		$(this).siblings().stop().fadeTo(800,1);
	});


/*------------------------------
current
------------------------------*/
	$('body#book li.book img').attr('src' ,  'http://www.ikeda-masako.com/image/base/nav_book_d_on.gif');
	$('body#parts li.parts img').attr('src' ,  'http://www.ikeda-masako.com/image/base/nav_parts_d_on.gif');
	$('body#unpublished li.unpublished img').attr('src' ,  'http://www.ikeda-masako.com/image/base/nav_unpublished_d_on.gif');
	$('body#others li.others img').attr('src' ,  'http://www.ikeda-masako.com/image/base/nav_others_d_on.gif');


});


/*------------------------------
protect
------------------------------*/
/*
	Class:    	dwIMageProtector
	Author:   	David Walsh
	Website:    http://davidwalsh.name
	Version:  	1.0.0
	Date:     	08/09/2008
	Built For:  jQuery 1.2.6
*/

jQuery.fn.protectImage = function(settings) {
	settings = jQuery.extend({
		image: 'http://www.ikeda-masako.com/image/base/blank.gif',
		zIndex: 10
	}, settings);
	return this.each(function() {
		var position = $(this).position();
		var height = $(this).height();
		var width = $(this).width();
		$('<img />').attr({
			width: width,
			height: height,
			src: settings.image
		}).css({
			top: position.top,
			left: position.left,
			position: 'absolute',
			zIndex: settings.zIndex
		}).appendTo('body')
	});
};


$(window).bind('load', function() {
	$('img.protect').protectImage();
});


/*------------------------------
random
------------------------------*/
var ranimg = new Array();

ranimg[0]="http://www.ikeda-masako.com/image/bg_all01.gif";
ranimg[1]="http://www.ikeda-masako.com/image/bg_all02.gif";
ranimg[2]="http://www.ikeda-masako.com/image/bg_all03.gif";
ranimg[3]="http://www.ikeda-masako.com/image/bg_all04.gif";
ranimg[4]="http://www.ikeda-masako.com/image/bg_all05.gif";
ranimg[5]="http://www.ikeda-masako.com/image/bg_all06.gif";

xx = Math.floor(ranimg.length*Math.random());
ranimg = ranimg[Math.floor(xx)];

$(function() {
	$('body#all div#wrapper').css('background' , 'url('+ ranimg +') no-repeat center top');
});
