function onLoadUpdater(updaterInterval, playlistInterval)
{
    // if div present, start update event
    if($('tracksView') != null)
    {
        viewTracks();
        playlistInt = window.setInterval('viewTracks()',playlistInterval); 
    }
    /*
    else
    {
        updateTracks();
        updaterInt = window.setInterval('updateTracks()', updaterInterval);
    }
    */
    
    Alert.checkAir();
    alertInt = window.setInterval('Alert.checkAir()', 5000);
};


function openPlayer(url, width, height, playlistId, streamId)
{
    window.open(url, 'radiomixPlayer', 'width=' + width + ',height=' + height + ',resizable=no,scrollbars=no,top=100,left=300');
    Ajax.updater(undefined ,''+ baseUrl +'?_event_=ajaxListeningsUpdate&playlistId='+ playlistId +'&streamId='+ streamId +'','get');
}

function openPlayerAndCloseWindow(url, width, height, playlistId, streamId)
{
    window.opener.open(url, 'radiomixPlayer', 'width=' + width + ',height=' + height + ',resizable=no,scrollbars=no,top=100,left=300');
    
    ajax = Ajax.getXmlHttpObject();
    ajax.onreadystatechange = function (){ _openPlayerAndCloseWindow() };
    ajax.open('GET',''+ baseUrl +'?_event_=ajaxListeningsUpdate&playlistId='+ playlistId +'&streamId='+ streamId +'',true);
    ajax.send(null);
}

// callback function
function _openPlayerAndCloseWindow()
{
    if (ajax.readyState==4)
    { 
        window.close();
               
    }
}




function getRandomNumber()
{
    return Math.ceil(1000000000000*Math.random());
}

function updateTracks()
{
    Ajax.updater(undefined ,''+ baseUrl +'?_event_=ajaxTracksUpdate','get');
}

function viewTracks()
{
    Ajax.updater('tracksView',''+ baseUrl +'?_event_=ajaxTracksView','get');
}

function addToFavourites(id)
{
    Ajax.updater('station_' + id,''+ baseUrl +'?_event_=ajaxFavourites&_subevent_=add&id=' + id,'get');
}

function removeFromFavourites(id)
{
    Ajax.updater('station_' + id,''+ baseUrl +'?_event_=ajaxFavourites&_subevent_=remove&id=' + id,'get');
}

Alert = {};
Alert.onBlink = "Hraje sledovaná skladba!";
Alert.offBlink = "RadioMix.cz - Rádia Online";
Alert.interval;


Alert.checkAir = function ()
{
    
   
    
    // run once
    if($('aircheckAlert') != null && Alert.interval == null)
    {
         Alert.interval = window.setInterval('Alert.blink()', 900);
    }
    
    // disable all blinking interval
    if($('aircheckAlert') == null)
    {
        clearInterval(Alert.interval);
        Alert.interval = null;
        document.title = Alert.offBlink;
    }
    
    
    // lunch popup where flag is on
    if($('aircheckAlert') != null && $('aircheckAlert').className == "runPopup")
    {
        
        popupAlert = window.open('?_event_=popupAlert', 'popupAlert', 'width=500,height=190,resizable=no,scrollbars=yes,top=100,left=300');
        
        if(popupAlert != null)
        {
            popupAlert.focus();
        }
        
        
        $('aircheckAlert').className = "";
        
        
    }
    
    
         
    
}

Alert.blink = function ()
{
    if(document.title == Alert.offBlink)
        document.title = Alert.onBlink;
    else
        document.title = Alert.offBlink;    
}

function copyAndEnableNews(id, timestamp)
{
    $('newId').value= id;
    $('f-timestamp').value= timestamp;
    $('f-title').value= $('title_'+ id).innerHTML;
    $('f-text').value=$('text_' + id).innerHTML;
    enable('delete');
    show('newsForm');
}
