﻿function centerPage() {
    try {
        var left = (($(window).width() - 960) / 2);
        $('div#background').css('margin-left', (left - 320) + 'px');
        if (left < 0) left = 0;
        $('div#center').css('left', left + 'px');
    }
    catch(ex) {}
}

function setBackground() {
    centerPage();
    
    try {
        var left = (($(window).width() - 960) / 2);
        var pos = $('div#main').position();
        $('div#topnavPopup').css('left', left + 'px');
        $('div#topnavPopup').css('top', (pos.top - 50) + 'px');
    }
    catch(ex) {}
}

function setMargins(left, right, offset) {
    if (!offset) offset = 0;
    try {
        var height_l = $(left).height() + offset;
        var height_r = $(right).height() + offset;
        if (height_r < height_l) $(right).height(height_l);
        if (height_l < height_r) $(left).height(height_r);
    }
    catch(ex) {}
}

function setNavigation() {
    var url = location.pathname.substring(_vpath.length).toLowerCase();
        
    var sections = {'season':'1', 'subscriptions':'1', 'support':'2', 'music':'3', 'community':'4', 'projects':'5', 'about':'6'};
    var section = '';
    var match = url.match(/^\/([^\/]+)\//);
    if (match) section = match[1];
        
    $('a.menuFirst').bind('mouseover', function(){var img=this.getElementsByTagName('img')[0]; if (img.src.indexOf('menu_on') == -1) img.src=img.src.replace('menu_','menu_on_');});
    $('a.menu').bind('mouseover', function(){var img=this.getElementsByTagName('img')[0]; if (img.src.indexOf('menu_on') == -1) img.src=img.src.replace('menu_','menu_on_');});
    $('a.menuFirst').bind('mouseout', function(){var img=this.getElementsByTagName('img')[0]; if (img.id != 'imgMenu_' + sections[section]) img.src=img.src.replace('menu_on_','menu_');});
    $('a.menu').bind('mouseout', function(){var img=this.getElementsByTagName('img')[0]; if (img.id != 'imgMenu_' + sections[section]) img.src=img.src.replace('menu_on_','menu_');});

    // highlight current section menu
    if (section) $('#imgMenu_' + sections[section]).attr('src', _vpath + '/App_Themes/SFSMain/i/menu_on_0' +  + sections[section] + '.gif');
}

$(window).bind('resize', setBackground);
$(document).ready(setBackground);
$(document).ready(function(){setMargins('div#mainLeft','div#mainRight');});
$(document).ready(setNavigation);
setTimeout(function(){setMargins('div#mainLeft','div#mainRight');}, 5000);

function search(txtSearch) {
   location.href = _vpath + '/Search.aspx?q=' + document.getElementById(txtSearch).value;
}

function playVideo(file, width, height) {
    if (!width) width = 248;
    if (!height) height = 96;
    
    var win = window.open(_vpath + '/media/player.aspx?mediapath=&amp;mediaid=' + escape(file) + '&width=' + width + '&height=' + height, 'video', 'width=' + width + ',height=' + (height + 64));
    if (win.focus) win.focus();
}

function deframe(loc) {
    if (self.parent.frames.length > 0) self.parent.location=loc;
}


// For promo boxes to trigger the enter button instead of searching.
$(function() {
    $(".infosummary input[type='text']").keyup(function(e) {
        if (e.keyCode == 13) {
            $(".infosummary input[type='submit']").trigger("click");
        }
    });
});