// JavaScript Document
////
//初期設定、カテゴリーの開閉
$(function(){
    $('#content').css('display', 'none');
	$('#content').fadeIn('slow');
    
    $('#category > div > h2 , #history > h2').click(function(){
        // 引数には開閉する速度を指定します
        $(this).next().slideToggle('fast');
        //$(this).next().toggle('normal');
    });
});

////
//カテゴリーの開閉状態を保存＆復元

//変数定義
category = new Array();
category = ["school", "library", "publick", "welfare", "hausing", "temple", "office", ];
r_status = new Array();
w_status = new Array();

//onload時の処理
$(function(){
    //クッキーから状態を配列（status）に保存
    //例外処理
    try {
        r_status = $.cookie('category_status').split(",");
    } 
    //初めてアクセスしたときや期限切れ時の開閉状態＝デフォルトの状態
    catch (e) {
        for (i = 0; i < category.length + 1; i++) {
            r_status.push("none");
        }
    }
    //カテゴリーの開閉状態を復元
    for (i = 0; i < category.length; i++) {
        $("#" + category[i] + "> ul").css("display", r_status[i]);
    }
    //ヒストリーの開閉状態を復元
    $("#history ul").css("display", r_status.pop())
});

//onunload時の処理
function write_status(){
    //idのリスト（category）をたよりに、カテゴリーの開閉状態を配列（status）に保存
    for (i = 0; i < category.length; i++) {
        w_status[i] = $("#" + category[i] + "> ul").css("display");
    }
    //ヒストリーの開閉状態を配列に追加
    w_status.push($("#history ul").css("display"));
    //開閉状態の配列をクッキーに保存
    $.cookie("category_status", w_status, {
        expires: 30,
        path: '/'
    });
}




//Image preview script （改）

/*
 * Image preview script
 * powered by jQuery (http://www.jquery.com)
 *
 * written by Alen Grakalic (http://cssglobe.com)
 *
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
this.imagePreview = function(){
    /* CONFIG */
    
    xOffset = 100;
    yOffset = 100;
    
    // these 2 variable determine popup's distance from the cursor
    // you might want to adjust to get the right result
    
    /* END CONFIG */
    $(".preview").hover(function(e){
        this.t = this.title;
        this.title = "";
        
        /* 撮影者ありの場合、タグの追加 */
        var x = this.t.indexOf("撮");
        var y = this.t.length;
        if (x != -1) {
            var z = this.t.slice(0, x) + "<span>" + this.t.slice(x, y) + "</span>";
        }
        else {
            var z = this.t;
        }
        
        var c = (z != "") ? z + "<br/>" : "";
        $("body").append("<div id='preview'><p>" + c + "</p><img src='images/" + this.id + "' alt='Image preview' /></div>");
        $("#preview").css("top", (e.pageY - xOffset) + "px").css("left", (e.pageX + yOffset) + "px").fadeIn("fast");
    }, function(){
        this.title = this.t;
        $("#preview").remove();
    });
    $(".preview").mousemove(function(e){
        $("#preview").css("top", (e.pageY - xOffset) + "px").css("left", (e.pageX + yOffset) + "px");
    });
};


// starting the script on page load
$(document).ready(function(){
    imagePreview();
});

//-->
