var musilineOptions = {
    pathInLine: "/srv/www/content/sk/youradio/prehravac.shtml",
    pathPopUp: "/srv/www/content/sk/youradio/youradio-pop-up.html",
    playNormalizedName: "/srv/yr/musiline-connect/playArtist.x?normalizedName=",
    playPublicToken: "/srv/yr/musiline-connect/playMood.x?publicToken=",
    playByGenres: "/srv/yr/musiline-connect/playMood.x",
    targetWindowName: "player",
    width: 940,
    height: 520
};
function getCenterW(width) {
    return parseInt(eval((screen.availWidth - parseInt(width)) / 2));
}

function getCenterH(height) {
    return parseInt(eval((screen.availHeight - parseInt(height)) / 2));
}
function openWin(path) {
    var name = musilineOptions.targetWindowName;
    var width = musilineOptions.width;
    var height = musilineOptions.height;
    window.open(path, name, 'scrollbars=no,resizable=no,resize=no,width=' + width + ',height=' + height + ',screenX=' + getCenterW(width) + ',screenY=' + getCenterH(height) + ',top=' + getCenterH(height) + ',left=' + getCenterW(width));
    return false;
}

function playToken(token) {
    token = (token!=null ? token : '');
    openWin(musilineOptions.pathPopUp + "?token=" + token);
    return false;
}
function playPublicToken(token) {
    token = (token!=null ? token : '');
    openWin(musilineOptions.playPublicToken + token + "&popUp=true");
    return false;
}
function playArtist(normalizedName){
    openWin(musilineOptions.playNormalizedName + normalizedName + "&popUp=true");
    return false;
}

function playGenres(genresArray){
    var idGenres = genresArray.join('&genreIds=');
    if(idGenres.length > 0){
        openWin(musilineOptions.playByGenres + '?genreIds=' + idGenres + "&popUp=true");
    }
    else{
        openWin(musilineOptions.pathPopUp + '?token=newMood');
    }
    return false;
}
function tuneGenres(genresArray){
    var idGenres = genresArray.join(',');
    if(idGenres.length > 0){
        openWin(musilineOptions.pathPopUp + '?idGenre=' + idGenres);
    }
    else{
        openWin(musilineOptions.pathPopUp + '?token=newMood');
    }
    return false;
}
/*funkce pouite pouze ve widgetu YouRadia*/
function checkSelectedGenres(){
    if (jQuery("#genresBox .checkbox:checked").length == 0) {
        jQuery("#play-mood-button").removeClass("play-disabled");
        jQuery("#play-mood-button").removeAttr("title");
    } else {
        jQuery("#play-mood-button").addClass("play-disabled");
        jQuery("#play-mood-button").attr("title", "Pre prehrávanie je nutné vybrať aspoň jeden žáner");
    }
}
function playMood() {
    if (jQuery("#genresBox .checkbox:checked").length == 0) {
        alert("Pre prehrávanie je nutné vybrať aspoň jeden žáner.");
        return false;
    }
    playGenres(jQuery('#genresBox .checkbox:checked').map(function(){return jQuery(this).val()}).get())
    return false;
}

jQuery(document).ready(function(){
    jQuery("#interpretName").example("Vyhľadaj rádio interpreta");
    jQuery(".js-hover-red").hover(
            function () {
                $(this).addClass("hovered");
            },
            function () {
                $(this).removeClass("hovered");
            }
    );
});
