﻿////------------------------------------------------------ preload images

function LoadImages()
{
    image_url = new Array();
    image_url[0] = "Images/Master/RadioMusic_ItalyLogoOver.jpg";
    image_url[1] = "Images/Master/RadioMusic_ItalyLogoSelected.jpg";
    image_url[2] = "Images/Master/RadioMusic_DanceLogoOver.jpg";
    image_url[3] = "Images/Master/RadioMusic_DanceLogoSelected.jpg";
    image_url[4] = "Images/Master/RadioMusic_Salsa4teLogoOver.jpg";
    image_url[5] = "Images/Master/RadioMusic_Salsa4teLogoSelected.jpg";
    image_url[6] = "Images/Master/RadioMusic_Rock4teLogoOver.jpg";
    image_url[7] = "Images/Master/RadioMusic_Rock4teLogoSelected.jpg";
    image_url[8] = "Images/Master/RadioMusic_DanceOnAir.jpg";
    image_url[9] = "Images/Master/RadioMusic_ItalyOnAir.jpg";
    image_url[10] = "Images/Master/RadioMusic_Salsa4teOnAir.jpg";
    image_url[11] = "Images/Master/RadioMusic_Rock4teOnAir.jpg";
    image_url[12] = "Images/Channels/SnapDanceOver.png";
    image_url[13] = "Images/Channels/SnapEasyOver.png";
    image_url[14] = "Images/Channels/SnapRockOver.png";
    image_url[15] = "Images/Channels/SnapSalsaOver.png";

    // load images
    var i = 0;
    for (i = 0; i <= 15; i++)
        $("<img src='" + image_url[i] + "' />")
}

function PreLoadImages()
{
    LoadImages();
    setInterval(LoadImages, 30000);
}

////------------------------------------------------------ flash embedding

var params = {}
var flashvars = {}
var attributes = {};

params.allowfullscreen = "false";
params.autostart = "true";

flashvars.usefullscreen = "false";
flashvars.autostart = "true";

swfobject.embedSWF("Flash/XBarRM.swf", "XBarPlaceHolder", "940", "60", "9.0.0", "Flash/ExpressInstall.swf", flashvars, params, attributes);
//swfobject.embedSWF("Flash/RadioMusicLogo.swf", "RadioMusicPlaceHolder", "700", "158", "9.0.0", "Flash/ExpressInstall.swf", flashvars, params, attributes);
//swfobject.embedSWF("Flash/SlideShowArtists.swf", "SlideShowPlaceHolder", "234", "158", "9.0.0", "Flash/ExpressInstall.swf", flashvars, params, attributes);
swfobject.embedSWF("Flash/digclock.swf", "clockPlaceHolder", "80", "30", "9.0.0", "Flash/ExpressInstall.swf", flashvars, params, attributes);

params.wmode = "transparent";

swfobject.embedSWF("Flash/Marker.swf", "MarkerPlaceHolder1", "19", "19", "9.0.0", "Flash/ExpressInstall.swf", flashvars, params, attributes);
swfobject.embedSWF("Flash/Marker.swf", "MarkerPlaceHolder2", "19", "19", "9.0.0", "Flash/ExpressInstall.swf", flashvars, params, attributes);
swfobject.embedSWF("Flash/Marker.swf", "MarkerPlaceHolder3", "19", "19", "9.0.0", "Flash/ExpressInstall.swf", flashvars, params, attributes);

////------------------------------------------------------

function GetStreamLink(player, kbps)
{
    var currentChannel = document.getElementById('SelectedChannel').value;
    
    var sourceBase;
    var sourceName;

    if ((currentChannel == "Dance") && (kbps == 128))
    {
        sourceBase = "http://server1.visiotec.it";
        sourceName = "radiomusicdance";
    }
    else if ((currentChannel == "Dance") && (kbps == 32))
    {
        sourceBase = "http://server1.visiotec.it";
        sourceName = "radiomusicdanceaacp";
    }        
    else if ((currentChannel == "Italy") && (kbps == 128))
    {
        sourceBase = "http://server1.visiotec.it";
        sourceName = "easyanditaly";
    }        
    else if ((currentChannel == "Italy") && (kbps == 32))
    {
        sourceBase = "http://server1.visiotec.it";
        sourceName = "easyanditalyaacp";
    }        
    else if ((currentChannel == "Salsa4te") && (kbps == 128))
    {
        sourceBase = "http://server1.visiotec.it";
        sourceName = "radiosalsa4te";
    }        
    else if ((currentChannel == "Salsa4te") && (kbps == 32))
    {
        sourceBase = "http://server1.visiotec.it";
        sourceName = "radiosalsa4teaacp";
    }
    else if ((currentChannel == "Rock4te") && (kbps == 128))
    {
        sourceBase = "http://server1.visiotec.it";
        sourceName = "larockaforte";
    }
    else if ((currentChannel == "Rock4te") && (kbps == 32))
    {
        sourceBase = "http://server1.visiotec.it";
        sourceName = "larockaforteaacp";
    }
        
    if (player == "WinAmp")
        return sourceBase + "/Centova/tunein.php/" + sourceName + "/playlist.pls";
    else if (player == "WMPlayer")
        return sourceBase + "/Centova/tunein.php/" + sourceName + "/playlist.asx";
    else if (player == "QuickTime")
        return sourceBase + "/Centova/tunein.php/" + sourceName + "/playlist.qtl";
    else if (player == "RealPlayer")
        return sourceBase + "/Centova/tunein.php/" + sourceName + "/playlist.ram";
    else if (player == "WinAmp80")
        return sourceBase + "/Centova/proxy.php?stream=" + sourceName;
}

////------------------------------------------------------

function ChannelClick(newChannel)
{
    var currentChannelHidden = document.getElementById('SelectedChannel');
    var currentChannel = currentChannelHidden.value;

    if (newChannel == currentChannel)
        return;

    // scroll to channel box
    
    var api = $("#VisitCannels").data("scrollable");    

    if (newChannel == "Dance")
        api.seekTo(0);
    else if (newChannel == "Italy")
        api.seekTo(1);
    else if (newChannel == "Salsa4te")
        api.seekTo(2);
    else if (newChannel == "Rock4te")
        api.seekTo(3);

    // change channel box

    var currentChannelBox = document.getElementById(currentChannel + "Box")
    setBackground(currentChannelBox, "Images/Master/RadioMusic_" + currentChannel + "Logo.jpg");

    var newChannelBox = document.getElementById(newChannel + "Box")
    setBackground(newChannelBox, "Images/Master/RadioMusic_" + newChannel + "LogoSelected.jpg");

    // change onair box background

    var OnAirBox = document.getElementById("PlaylistWrapper");
    setBackground(OnAirBox, "Images/Master/RadioMusic_" + newChannel + "OnAir.jpg");    

    // change onair channel name
    
    var channelTextName;
    if (newChannel == "Dance")
        channelTextName = "Dance Radio";
    else if (newChannel == "Italy")
        channelTextName = "Easy & Italy";
    else if (newChannel == "Salsa4te")
        channelTextName = "Radio Salsa4te";
    else if (newChannel == "Rock4te")
        channelTextName = "La Rockaforte";

    var channelNowPlaying = document.getElementById("channelNowPlaying");
    setInnerText(channelNowPlaying, channelTextName);    

    // change onair go-to link

    var channelUrl;
    if (newChannel == "Dance")
        channelUrl = "www.radiodancemusic.com";
    else if (newChannel == "Italy")
        channelUrl = "www.easyanditaly.com";
    else if (newChannel == "Salsa4te")
        channelUrl = "www.radiosalsa4te.it";
    else if (newChannel == "Rock4te")
        channelUrl = "www.larockaforte.com";

    var channelAnchor = document.getElementById("channelGoToLink");
    setInnerText(channelAnchor, channelUrl);    
    channelAnchor.href = "http://" + channelUrl;

    // change channel up arrow

    

    // show channel on air e coming up

    $('.OnAirWrapper').hide()
    $('.ComingUpWrapper').hide();

    $('#OnAirWrapper_' + newChannel).show();
    $('.ComingUpWrapper.' + newChannel).show();

    /*
    $('#OnAirWrapper_' + newChannel).show(
        350,
        function() 
        {
            $('.ComingUpWrapper.' + newChannel).show();
        } 
    );
    */
    
    // remember current selected channel
    
    currentChannelHidden.value = newChannel;
}

function ChannelOver(newChannel) {
    var currentChannel = document.getElementById('SelectedChannel').value;

    if (newChannel == currentChannel)
        return;

    var newChannelBox = document.getElementById(newChannel + "Box")
    setBackground(newChannelBox, "Images/Master/RadioMusic_" + newChannel + "LogoOver.jpg");
}

function ChannelOut(newChannel) {
    var currentChannel = document.getElementById('SelectedChannel').value;

    if (newChannel == currentChannel)
        return;

    var newChannelBox = document.getElementById(newChannel + "Box")
    setBackground(newChannelBox, "Images/Master/RadioMusic_" + newChannel + "Logo.jpg");
}

////------------------------------------------------------ menu

function menuItemOver(elem)
{
    document.getElementById(elem).style.color = "#3fabda";
}

function menuItemOut(elem)
{
    document.getElementById(elem).style.color = "White";
}

////------------------------------------------------------ pop up

var popupMultPlayerRef = null;

function popupMultiPlayer()
{
    if (popupMultPlayerRef != null && !popupMultPlayerRef.closed)
        popupMultPlayerRef.focus();
    else {
        popupMultPlayerRef = window.open('MultiPlayer.aspx', '',
                                         'width=410px,height=263px,left=450,top=200,resizable=no,scrollbars=no,status=no');
        if (popupMultPlayerRef == null)
            alert("Disabilita il blocco Pop Up");
        else
            popupMultPlayerRef.focus();
    }
}

var popupcontactsRef = null;

function PopUpContacts()
{   
    if (popupcontactsRef!=null && !popupcontactsRef.closed)
        popupcontactsRef.focus();
    else
    {
        popupcontactsRef = window.open("Contacts.aspx","","left=350,top=100,width=540,height=490,status=no,titlebar=no,menubar=no");
        if (popupcontactsRef == null)
            alert("Disabilita il blocco Pop Up");
        else
            popupcontactsRef.focus();
    }
}

var popupcreditsRef = null;

function PopUpCredits()
{   
    if (popupcreditsRef!=null && !popupcreditsRef.closed)
        popupcreditsRef.focus();
    else
    {
        popupcreditsRef = window.open("Credits.aspx","","left=380,top=120,width=280,height=250,status=no,titlebar=no,menubar=no");
        if (popupcreditsRef == null)
            alert("Disabilita il blocco Pop Up");
        else
            popupcreditsRef.focus();
    }
}

$(document).ready(function()
{        
    $("#VisitCannels").scrollable({});

    $("#VisitCannels .PopUpMultiPlayerAnchor").open({
        left: 380, top: 200,
        width: 830, height: 470
    });
    
    jPLogic.channelNames = [ 'Dance', 'Salsa4te', 'Rock4te', 'Italy' ];
    jPLogic.ajaxRequestURL = 'localhost';
    jPLogic.useProxy = true;
    jPLogic.proxyDomainURL = 'http://www.radiomusic.net';
    jPLogic.pictureHOST = 'http://www.radiomusic.net';
    jPLogic.maxQueue = 4;
    //jPLogic.sourceDelay = 16;

    StartRegiaUpdate();
    
    
    $("#facebox").overlay(
    {
        // custom top position
        top: 25,
        fixed: false,

        // some mask tweaks suitable for facebox-looking dialogs
        mask: {

	        // you might also consider a "transparent" color for the mask
	        color: '#fff',

	        // load mask a little faster
	        loadSpeed: 200,

	        // very transparent
	        opacity: 0.4
        }
    });    


    PreLoadImages();
});

