function change_img(me){
	var src = me.attr("src");
	if( src.indexOf('_on.') > -1 ){
		src = src.replace('_on.','_off.');
	}else{
		src = src.replace('_off.','_on.');
	}
	me.attr('src',src);
}

var timer;
var img_size;

$(document).ready(function(){
	// hover画像のセット
	$(".onOff_img").mouseover(function(){ change_img($(this)); });
	$(".onOff_img").mouseout(function(){ change_img($(this)); });
	
	// necoの初期化
	init_neco();
	timer = setInterval("neco.say()", 30000);
	
	// other album menu
	$("#nav-one li").hover(
        function(){ $("ul", this).fadeIn("fast"); }, 
        function() { } 
    );
    if (document.all) {
        $("#nav-one li").hoverClass ("sfHover");
    }
    
    // image size change
    if(!$.cookie('imgSize')){
    	$.cookie('imgSize',200);
    	img_size = 200;
    }else{
    	img_size = $.cookie('imgSize');
    }
	change_img_size(img_size);
	//$(".photoBox").click(function(){change_mode_view($(this).attr('id'))});
	$(".photoBox").each( function(){
		var id = $(this).attr('id');
		$(this).children('a').attr('href',
			'javascript:change_mode_view("'+id+'")'
		);
	});
	
	$(".photo_LR").mouseover(function(){$(this).css('background-color','#F88B0A');});
	$(".photo_LR").mouseout(function(){$(this).css('background-color','#C6B58D');});
	
});

// other album menu
$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
}; 

// image size change
function change_img_size(size, save_no){
	$(".photoBox").css("width",size+'px');
	$(".photoBox").css("height",size+'px');
	//$(".photoBox").css("cursor",'pointer');
	$(".photoBox img").each( function(){
		$(this).attr('src', $(this).attr('src').replace(/thumb.../,'thumb'+size));
	});
	if(!save_no){
	    $.cookie('imgSize',size);
    }
    var size_list = [100,200,300];
    $.each(size_list, function(){
		if(this == size){
		    $(".img_size a.size"+this).css({background:'#92BAE3',cursor:'default'});
    		$(".img_size a.size"+this).mouseover(function(){ $(this).css('background','#92BAE3');});
    		$(".img_size a.size"+this).mouseout(function(){ $(this).css('background','#92BAE3');});
		}else{
		    $(".img_size a.size"+this).css({'background':'#C6B58D','cursor':'pointer'});
    		$(".img_size a.size"+this).mouseover(function(){ $(this).css('background','#F88B0A');});
    		$(".img_size a.size"+this).mouseout(function(){ $(this).css('background','#C6B58D');});
		}
    });
    
}

//var photo_id;

// mode change view
function change_mode_view(target_id,change){
    target = $('#'+target_id);
    $(".list").animate({width:"122px"}, 'fast', 'swing',
		       function(){ $(this).scrollTo('#'+target_id,1000, {'offset':-200}); }
		       );
	
    var image = $('#'+target_id+' img').attr('src').replace(/thumb.../,'thumb500');
    
    $(".photo_main img").fadeOut(500,function(){
	    $(this).attr('src', image);
	    $(this).load( function(){$(this).fadeIn(500) });
	});
    change_img_size(100, true);
    $(".photoView").animate(
			    {"width":"650px" },
			    '3000',
			    'swing'
			    );
    $('.photoBox').css('border-color','#C6B58D');
    target.css('border-color','#92BAE3');
    
	var prev, next;
    //next_id = $(target).next().attr('id');
    if(target.prev().length){
		prev = target.prev().attr('id');
    }else{
		prev = $('.photoBox:last').attr('id');
    }
    if(target.next().length){
		next = target.next().attr('id');
    }else{
		next = $('.photoBox:first').attr('id');
    }	
    $('#photo_next, #photo_prev').unbind('click');
    $('#photo_prev').click(function(){change_mode_view(prev,true);});
    $('#photo_next').click(function(){change_mode_view(next,true);});
    
    
    $(".img_size").hide();
    $(".return_list").show();

}


// mode change list
function change_mode_list(){
	$(".photoView").animate({"width":"0px","margin-right":"0px"},'fast');	
	$(".list").queue( function() {
		$(this).scrollTop(0);
		$(this).animate({width:"775px"},'fast');
		change_img_size($.cookie('imgSize'),true);
		$(this).dequeue();
	});
	$('.photoBox').css('border-color','#C6B58D');
	$(".return_list").hide();
	$(".img_size").show();
}
