jQuery(function() {
    //rss hover
    jQuery('#rss').hover(function() {
        jQuery(this).children('img').attr('src', TEMPLATE_URL + '/images/rss-hover.png');
    }, function() {
        jQuery(this).children('img').attr('src', TEMPLATE_URL + '/images/rss.png');
    });

    //search hover
    jQuery('#search-submit').hover(function() {
        jQuery(this).attr('src', TEMPLATE_URL + '/images/search-hover.png');
    }, function(){
        jQuery(this).attr('src', TEMPLATE_URL + '/images/search.png');
    });

    $('a[rel=lytebox], a.zoom').fancybox({
        overlayShow: true,
        zoomSpeedIn: 300,
        zoomSpeedOut: 300
    });
});

jQuery(window).load(function() {
    
    //image border adding
    jQuery('.post .entry img.size-thumbnail').each(function() {
        var img = jQuery(this);
        var imgOffset = img.offset();

        if (img.parent().attr('href') != null) {
            var border = $('<a class="border"></a>');
            border.attr('href', img.parent().attr('href'));
            border.attr('title', img.parent().attr('title'));

            var urlString = new RegExp(/\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/i);
            
            if (urlString.test(img.parent().attr('href'))) {
                border.append('<img src="' + img.attr('src') + '" style="width: ' + img.width() + 'px; height: ' + img.height() + 'px; visibility: hidden; margin: 14px 0px 0px 13px;" alt="" />')
                
                border.fancybox({
                    overlayShow: true,
                    zoomSpeedIn: 300,
                    zoomSpeedOut: 300
                });
            }
        } else {
            var border = jQuery('<div class="border"></div>');
        }

        border.css({
            left: (imgOffset.left - 13) + 'px',
            top: (imgOffset.top - 14) + 'px'
        });

        if (img.width() == 200 && img.height() == 150) {
            border.css({
                width: '230px',
                height: '180px',
                background: 'url(' + TEMPLATE_URL + '/images/border200x150.png)'
            });
        } else if (img.width() == 200 && img.height() == 200) {
            border.css({
                width: '230px',
                height: '230px',
                background: 'url(' + TEMPLATE_URL + '/images/border200x200.png)'
            });
        } else if (img.width() == 200 && img.height() == 113) {
            border.css({
                width: '230px',
                height: '143px',
                background: 'url(' + TEMPLATE_URL + '/images/border200x113.png)'
            });
        } else {
            img.removeClass('size-thumbnail');
        }

        border.appendTo(document.body);
    });
});