$(document).ready(function() {
    $('.page-link').each(function(n, el) {
        $(el).mouseover(function(event) {
            var menu = $('#'+$(el).attr('id')+'-menu');
            if (menu[0]) {
                $('.submenu-container').hide();
                menu.show();
            }
            else
            {
                $('.submenu-container').hide();
                $('.submenu-container.shown').show();
            }
        })
    });
    $('.submenu-container').mouseout(function(event) {
        $('.submenu-container').hide();
        $('.submenu-container.shown').show();
    });
    $('#content').mouseover(function(event) {
        $('.submenu-container').hide();
        $('.submenu-container.shown').show();
    });
    // $(document).pngFix(); 

    $('#selection-list div div').each(function(n, el) {
        el = $(el);
        el.mouseover(function(event) {
            $('#selection-list div div').removeClass('active');
            el.addClass('active');
            // $('#map-address').show();
            $('#selection-detail').html($('#detail-'+el.attr('id')).html());
        });
        el.mouseout(function(event) {
            //el.removeClass('active');
            // $('#map-address').hide();
        });
        if (n == 0) el.mouseover();
            //alert($(el).attr('id'));
    });
    $('a').each(function(n, el) {
        el = $(el);
        var link = el.attr('href');
        var server = document.location.hostname; // for IE
        if (link && link.search(/^http:\/\//) != -1 && link.indexOf(server) == -1) {
            el.attr('class', 'external');
            el.attr('target', '_blank');
        }
        if (link && link.search(/\.pdf$/) != -1) {
            el.attr('class', 'external');
            el.attr('target', '_blank');
        }
    });

    $('#team img').each(function() {
        var src = $(this).attr('src');
        if (src.match(/_hell.jpg$/))
        {
            var name = src.match("team\/\(.*\)_hell.jpg")[1];
            var xname = $(this).attr('id').match(/^team-img-(.*)$/)[1];
            //alert(name);
            $(this).mouseover(function() {
                    $(this).attr('src', src.replace(/_hell.jpg$/, ".jpg"));
                    $('#team-'+xname).addClass('active');
            });
            $(this).mouseout(function() {
                    $(this).attr('src', src);
                    $('#team-'+xname).removeClass('active');
            });
        }
    });

    $('#team-content div').each(function() {
        var id = $(this).attr('id');
        if (id.match(/^team-/))
        {
            var name = id.match(/^team-(.*)$/)[1];
            var src = $('#team-img-'+name).attr('src');
            var el = $(this);
            el.find('span').mouseover(function() {
                    $('#team-img-'+name).attr('src', src.replace(/_hell.jpg$/, ".jpg"));
                    el.addClass('active');
            });
            el.find('span').mouseout(function() {
                    $('#team-img-'+name).attr('src', src);
                    el.removeClass('active');
            });
        }
    });

});

function popup(link, w, h)
{
    var url = link.getAttribute('href') + '?popup=true';
    var x = screen.availWidth/2-w/2;
    var y = screen.availHeight/2-h/2;
    window.open(url, 'popup', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+w+',height='+h+',top='+y+',screenX='+x+',screenY='+y);
    return false;
}


