$(function (){
    // PNGFIX
    if($.browser.msie && $.browser.version <=6){// ～IE6
        var oldFixPng = DD_belatedPNG.fixPng;
        DD_belatedPNG.fixPng = function (el) {
            oldFixPng(el);
            if (el.vml && el.vml.image.fill.getAttribute("src").match(/_off\./)) {
                el.vml.image.shape.attachEvent('onmouseenter', function() {
                    var image = el.vml.image.fill;
                    image.setAttribute("src", image.getAttribute("src").replace("_off.", "_on."));
                });
                el.vml.image.shape.attachEvent('onmouseleave', function() {
                    var image = el.vml.image.fill;
                    image.setAttribute("src", image.getAttribute("src").replace("_on.", "_off."));
                });
            }
        };
        DD_belatedPNG.fix('.title a img, .sub_navigation li a img');
    }
});

// RollOver
$(function () {
    $.rollover = {
        init: function () {
            // <img>
            $('a img,input[type="image"]')
                .filter('[src*="_off."]')
                .bind('mouseover', this.over)
                .bind('mouseout',  this.out)
                .each(this.preload);
            // <a> with <img>, <shape> with <img> (for DD_belatedPNG.js)
            if ($.browser.msie && $.browser.version <= 6 )    // ie6
            $('shape')
                .filter(function(){return this.firstChild && this.firstChild.src})
                .bind('mouseover', this.overx)
                .bind('mouseout',  this.outx)
                .each(this.preloadx);
        },

        // <img>
        over : function () {
            this.setAttribute('src', this.getAttribute('src').replace('_off.', '_on.'));
        },
        out : function () {
            this.setAttribute('src', this.getAttribute('src').replace('_on.', '_off.'));
        },
        preload : function () {
            new Image().src = this.getAttribute('src').replace('_off.', '_on.');
        },
        // <a> with <img>, <shape> with <img> (for DD_belatedPNG.js)
        overx : function () {
            var img = this.firstChild;
            img.setAttribute('src', img.getAttribute('src').replace('_off.', '_on.'));
        },
        outx : function () {
            var img = this.firstChild;
            img.setAttribute('src', img.getAttribute('src').replace('_on.', '_off.'));
        },
        preloadx : function () {
            var img = this.firstChild;
            new Image().src = img.getAttribute('src').replace('_off.', '_on.');
        }
    };
    $.rollover.init();
});

// fancybox
$(function(){
    $(' a[href$=jpg],  a[href$=gif],  a[href$=png]').fancybox();
});



// shop
$(window).bind('load',function(){
    var sets = [], temp = [];
    $('div.other_shop dl').each(function(i) {
        temp.push(this);
        if (i % 4 == 3) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);
    $.each(sets, function() {
        $(this).flatHeights();
    });
});
$(function(){
    $("div.other_shop > dl:nth-child(5n)").addClass("last");
});



//Restaurant
$(function(){
    /* div要素を3つずつの組に分ける */
    var sets = [], temp = [];
    $('div.restaurant_list dl.food').each(function(i) {
        temp.push(this);
        if (i % 3 == 2) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);

    /* 各組ごとに高さ揃え */
    $.each(sets, function() {
        $(this).flatHeights();
    });
    $("div.restaurant_list dl.food:nth-child(3n)").addClass("last");
})


$(function() {
	$("ul li:last-child").addClass("last");
});



//fancybox
$(function () {
	$('a[href*=jpg],a[href*=JPG],a[href*=gif],a[href*=GIF]').fancybox({
		'overlayOpacity' : 0.7, 
		'overlayColor' : "#000",
		'titlePosition' : "inside"
	});
})

//fancybox
$(function () {
	$('a[href^=http]')
	.not('[href*=http://www.caoca.net], [href*=https://www.caoca.net]')
	.not('a:has(img)')
	.addClass("external")
	.attr({ target: "_blank" });
})
