﻿var filterReg = RegExp("\"(http:.*?)\"");

function button_enter(el) {
    if (el.src.indexOf("blank") <= 0) {
        var slash_idx = el.src.lastIndexOf("/") + 1;
        el.src = el.src.substr(0, slash_idx) + "over-" + el.src.substr(slash_idx);
    }
    else {
        var src = el.getAttribute('oSrc');
        var slash_idx = src.lastIndexOf("/") + 1;
        var src = '"' + src.substr(0, slash_idx) + "over-" + src.substr(slash_idx) + '"';
        el.style.filter = el.style.filter.replace(filterReg, src);
    }
}

function button_leave(el) {
    if (el.src.indexOf("blank") <= 0) {
        el.src = el.src.replace("over-", "");
    }
    else {
        var src = '"' + el.getAttribute('oSrc') + '"';
        el.style.filter = el.style.filter.replace(filterReg, src);
    }
}

function popup(href, name, width, height, scrollbar) {
    var larghezza = width;
    var altezza = height;
    var windowLeft = (screen.width - larghezza) / 2;
    var windowTop = (screen.height - altezza) / 2;
    window.open(href, name, 'height=' + altezza + ', width=' + larghezza + ', top=' + windowTop + ',left=' + windowLeft + ', resizable=0, menubar=0, toolbar=0, location=0, scrollbars=' + scrollbar)
}

$(document).ready(function() {
    $("a[rel='credits']").click(function() {
        targetPopup = $(this).attr('href');
        popup(targetPopup, 'credits', 300, 300, "no");
        return false;
    });

    $("a[rel='popup']").click(function() {
        targetPopup = $(this).attr('href');
        popup(targetPopup, 'popup', 500, 500, "yes");
        return false;
    });

    $(".button").bind('mouseenter', function() {
        button_enter(this);
    });

    $(".button").bind('mouseleave', function() {
        button_leave(this);
    });

});
