/*--
init reading.
--*/
//var url = "/gatten/";

//


if($.cookie("style") && !$.cookie("style").match(new RegExp(cookie_url+'common/css/size_[nb]\.css$'))){
	$.cookie("style", cookie_url+"common/css/size_n.css", { path: '/' });
}

$(function(){
    var e = location.pathname;
    var f = e.split(cookie_url);
    var g = f[0] + cookie_url + "common/";
    var h = ($.cookie('style')) ? $.cookie('style') : g + "css/size_n.css";
    $("#fonts").attr({
        href: h
    });
    if (h.match(/size_b\.css/)) {
        $("#size_b").attr({
            src:"./common/images/resize_big_on.gif"
        });
        $("#size_n").attr({
            src:"./common/images/resize_normal_off.gif"
        })
    }
    else {
        $("#size_b").attr({
            src:"./common/images/resize_big_off.gif"
        });
        $("#size_n").attr({
            src:"./common/images/resize_normal_on.gif"
        })
    }
    if ($("#option_btn").length) {
        $("#option_btn").click(function(){
            $(this).toggleClass("ico_plus").toggleClass("ico_minus");
            $("#options").slideToggle()
        })
    }
    $("#size_n").hover(function(){
        var a = $(this).attr("src");
        var b = a.split("/");
        if (b[4] == "resize_normal_off.gif") 
            $(this).attr("src", b[0] + "/" + b[1] + "/" + b[2] + "/" + b[3] + "/resize_normal_off_over.gif")
    }, function(){
        var a = $(this).attr("src");
        var b = a.split("/");
        if (b[4] == "resize_normal_off_over.gif") 
            $(this).attr("src", b[0] + "/" + b[1] + "/" + b[2] + "/" + b[3] + "/resize_normal_off.gif")
    });
    $("#size_b").hover(function(){
        var a = $(this).attr("src");
        var b = a.split("/");
        if (b[4] == "resize_big_off.gif") 
            $(this).attr("src", b[0] + "/" + b[1] + "/" + b[2] + "/" + b[3] + "/resize_big_off_over.gif")
    }, function(){
        var a = $(this).attr("src");
        var b = a.split("/");
        if (b[4] == "resize_big_off_over.gif") 
            $(this).attr("src", b[0] + "/" + b[1] + "/" + b[2] + "/" + b[3] + "/resize_big_off.gif")
    });
    if ($("#option_btns #option1")) {
		$('#option_btns #option1').click(function(){
			$('#option_btns #option1').addClass("recipe-selected");
			$('#option_btns #option2').removeClass("recipe-selected");
		});
		$('#option_btns #option2').click(function(){
			$('#option_btns #option2').addClass("recipe-selected");
			$('#option_btns #option1').removeClass("recipe-selected");
		});
		/*
        $("#option1").hover(function(){
            var a = $(this).attr("src");
            var b = a.split("/");
            if (b[1] == "option_btn1.gif") 
                $(this).attr("src", "images/option_btn1_over.gif")
        }, function(){
            var a = $(this).attr("src");
            var b = a.split("/");
            if (b[1] == "option_btn1_over.gif") 
                $(this).attr("src", "images/option_btn1.gif")
        });
        $("#option2").hover(function(){
            var a = $(this).attr("src");
            var b = a.split("/");
            if (b[1] == "option_btn2.gif") 
                $(this).attr("src", "images/option_btn2_over.gif")
        }, function(){
            var a = $(this).attr("src");
            var b = a.split("/");
            if (b[1] == "option_btn2_over.gif") 
                $(this).attr("src", "images/option_btn2.gif")
        })*/
    }
    $("#search_input").focus(function(){
        $(this).css({
            "background-position": "0 -26px"
        })
    });
    $("#search_input").blur(function(){
        $(this).css({
            "background-position": "0 0"
        })
    });
    $("#recipe_search .s_input").focus(function(){
        $(this).css({
            "background-position": "0 -24px"
        })
    });
    $("#recipe_search .s_input").blur(function(){
        $(this).css({
            "background-position": "0 0"
        })
    });
    $("#search_btn").hover(function(){
        $(this).css({
            "background-position": "0 -26px"
        })
    }, function(){
        $(this).css({
            "background-position": "0 0"
        })
    });
    if ($("#latest_recipes").length) {
        $("#slider").jcarousel({
            auto: 8,
            acroll: 4,
            wrap: 'circular',
            animation: 'slow',
            itemVisibleInCallback: {
                onBeforeAnimation: mycarousel_itemVisibleInCallback
            },
            itemVisibleOutCallback: {
                onAfterAnimation: mycarousel_itemVisibleOutCallback
            },
            initCallback: mycarousel_initCallback
        })
    }
    if ($("#center_contents_main").length) {
        $("#option1").click(function(){
            $(this).parent().addClass("recipe-selected");
            $("#option2").parent().removeClass("recipe-selected")
        });
        $("#option2").click(function(){
            $("#option1").parent().removeClass("recipe-selected")
            $(this).parent().addClass("recipe-selected");
        });
    }

    $("#mobile_btn").click(function(){
        $("#mobile_detail").toggle();
    })
	
    $.easing.quart = function(x, t, b, c, d){
        return -c * ((t = t / d - 1) * t * t * t - 1) + b
    };
    $('a[href*=#]').click(function(){
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
            var a = $(this.hash);
            a = a.length && a || $('[name=' + this.hash.slice(1) + ']');
            if (a.length) {
                var b = a.offset().top;
                $('html,body').animate({
                    scrollTop: b
                }, 1200, 'quart');
                return false
            }
        }
    });
	$("#shorten_url_btn").click(function(){
		$("#shorten_url_area").toggle();
		if (is_archive_detail != undefined && is_archive_detail) {
			OpenNowGattenPoint();
		}
	});
	$("#shorten_url_close_area").click(function(){
		$("#shorten_url_area").hide();
		if (is_archive_detail != undefined && is_archive_detail) {
			OpenNowGattenPoint();
		}
	});
	$("#shorten_url_text").click(function(){$(this).select();return false;});
	
    $("#size_b,#size_n").click(function(){
        if ($(this).attr("id") == "size_b") {
            var a = g + "css/size_b.css";
            $(this).attr({
                src: g + "images/resize_big_on.gif"
            });
            $("#size_n").attr({
                src: g + "images/resize_normal_off.gif"
            })
        }
        else {
            var a = g + "css/size_n.css";
            $(this).attr({
                src: g + "images/resize_normal_on.gif"
            });
            $("#size_b").attr({
                src: g + "images/resize_big_off.gif"
            })
        }
        $("#fonts").attr({
            href: a
        });
        $.cookie("style", a, {
            expires: 30,
            path: "/"
        });
        $.tID = setInterval(setHeight, 200)
    });
    $("#navi li").hover(function(){
        $(this).find('ul:first').css({
            visibility: "visible",
            display: "none"
        }).show()
    }, function(){
        $(this).find('ul:first').hide()
    });
    if ($('.over').length) {
        $('.over').rollover('_over')
    }
    $.tID = setInterval(setHeight, 1000)
});
function setHeight(){
    $('#1k, #rightmat_contents, #rightmat_contents0').removeAttr("style");
    $(".tlink").removeAttr("style");
    $("#left_contents_main,#center_contents_main,#right_contents_main").removeAttr("style");
    if ($("#main_2mat").length) 
        $('#1k, #rightmat_contents, #rightmat_contents0').flatHeights();
 /*   if ($("#contents_area").length) 
        $("#left_contents_main,#center_contents_main,#right_contents_main").flatHeights();*/
    if ($(".tlink").length) 
        $(".tlink").flatHeights();
    clearInterval($.tID)
}

function mycarousel_initCallback(a){
    a.clip.hover(function(){
        a.stopAuto()
    }, function(){
        a.startAuto()
    });
    $("#prevBtn,#nextBtn").hover(function(){
        a.stopAuto()
    }, function(){
        a.startAuto()
    });
    $('#nextBtn').bind('click', function(){
        a.next();
        return false
    });
    $('#prevBtn').bind('click', function(){
        a.prev();
        return false
    })
}

function mycarousel_itemVisibleInCallback(a, b, i, c, d){
    var e = a.index(i, itemList.length);
    a.add(i, mycarousel_getItemHTML(itemList[e - 1]))
}

function mycarousel_itemVisibleOutCallback(a, b, i, c, d){
    a.remove(i)
}

function mycarousel_getItemHTML(a){
    return '<a href="' + a.link + '"><img src="' + a.url + '" alt="' + a.title + '" /></a><br /><a href="' + a.link + '">' + a.title + '</a>'
};

