 $(document).ready(function()
{
    $('#menu > a').mouseover(updateMenuPos).mouseout(function(){updateMenuPos()}).click(clicked);
    //alert($('#active').length?100:0);
    $('<div>').attr('id', 'menuSlider').prependTo('#wrapper').css('opacity', $('#active').length?100:0);
    updateMenuPos();

    $('.lb').lightBox();

    $('#nextRow').click(nextRow);
    $('#prevRow').click(prevRow);
    calcRows();
});

function clicked()
{
    if(!$('#flash').length) return true;
    
    $('#active').removeAttr('id');
    $(this).attr('id', 'active');

    $('#flash')[0].changeCategorie(String($(this).attr('href')).replace(/^(.*\/)(.*)\/$/, '$2'));
    return false;
}

function updateMenuPos(e)
{
    //alert('ik benhier');
    var item = e?$(this):$('#active');
    //  alert(':'+item);
    var o = item.length?{'left':item.offset().left-$('#wrapper').offset().left, opacity:100, 'width':item.width()}:{'opacity':0}
    $('#menuSlider').stop().animate(o, 500);
}

function headerChange(title, categorie, description)
{
    $('#videoHeader').html(title);
    $('#active').removeAttr('id');
    $('.'+categorie).attr('id', 'active');
    $('#videoDescription').html(description);
    updateMenuPos();
}

function ajaxStuff(e)
{
    url = $(this).attr('href')
    if(url.substr(0, 1)!='/') return false;
    
    e.stopPropagation();
    e.stopImmediatePropagation();
    window.location += '#'+url;
    $.getJSON(url, {'json':1}, function(o){
        
    });
    return false;
}

var currentRow = 0;
function nextRow()
{
    currentRow++;
    calcRows();
}

function prevRow()
{
    currentRow--;
    calcRows();
}

function calcRows()
{
     $('#prevRow, #nextRow').show();
    if(currentRow<=0){
        currentRow = 0;
        $('#prevRow').hide();
    }
    
    if(currentRow>=$('.backstageRow').length-1){
        currentRow = $('.backstageRow').length-1;
        $('#nextRow').hide();
    }

    $('.backstageRow').animate({'margin-left':635*-currentRow});
}
