var mainPreload;

function mainInit() {
    if (window.parent && window.parent != window) {
        window.parent.location.href = window.location.href;
    }
    var links = $('.main_img_link').add('.main_login_link');
    mainPreload = [];
    var img;
    links.each(function() {
        this.rel = $('img', $(this)).attr('src').match(/\/([^\/]+)\.png$/)[1];
        img = document.createElement('img');
        img.src = '/images/main/'+this.rel+'_over.png';
        mainPreload.push(img);
    }).mouseover(mainImgLinkOver).mouseout(mainImgLinkOut);
    var shadowboxOptions = {
        width: '944',
        player: 'iframe'
    }
    Shadowbox.setup('a.main_img_link', shadowboxOptions);
    Shadowbox.setup('#main_footer a.main_footer_link', shadowboxOptions);
    Shadowbox.setup('#m_fejlec area', shadowboxOptions);
    if (window.location.hash.match(/\bpage=([^&]+)/)) {
        setTimeout(function() {
            var target = window.location.hash.match(/\bpage=([^&]+)/)[1];
            Shadowbox.open({
                content: '/hu/'+target,
                player: 'iframe',
                width: '944'
            });
        }, 500);
    } else if (window.location.hash.match(/\bvideo=([\d]+)/)) {
        setTimeout(function() {
            var videoNum = parseInt(window.location.hash.match(/\bvideo=([^&]+)/)[1]);
            var videoList = {1: 'http://static.generalitozsdejatek.hu/flv/capital.flv'}
            if (videoList[videoNum]) {
                Shadowbox.open({
                    content: videoList[videoNum],
                    player: 'flv',
                    width: '352',
                    height: '288'
                });
            }
        }, 500);
    }

}

function mainImgLinkOver() {
    $('img', this).attr('src', '/images/main/'+this.rel+'_over.png');
}

function mainImgLinkOut() {
    $('img', this).attr('src', '/images/main/'+this.rel+'.png');
}

Shadowbox.init({
//    skipSetup: true,
    players: ['iframe', 'flv']
})

$(document).ready(mainInit);