/**************************************************
 * radio.blog.js
 * 03.04.2006
 * www.radioblogclub.com
 **************************************************/

// ======= RADIO.BLOG =========================================================================================================================
var RadioBlog = {
    basepath: 'http://stat.radioblogclub.com/radio.blog',
    playlist: '',
    id: 0,
    width: '300px',
    height: '300px',
    file: '',
    cover : 1,
    skin: 'default',
    background:'',
    debug: '0',
    shuffle: 0,
    crossfader: 1,
    replay: 1,
    color: {
        body: '#FFFFFF',
        border: '#CCCCCC',
        button: '#CCCCCC',
        player_text: '#BDC3C7',
        playlist_text: '#999999'
    },
    autoplay: {
        tracknum: '',
        title: '',
        playlistnum: '',
        playlist: '',
        trackmod: ''
    },

    // CREATE RADIO.BLOG
    createPlayer: function() {
        // SET COLORS
        var val;
        var colors = '&colors=';
        for (val in this.color) {
            colors += val+':'+this.color[val]+';';
        }

        // SET PATH
        var paths;
        if (this.playlist != '') paths = '&playlistPath='+this.playlist; 
        if (this.file != '') paths = '&filepath='+this.file; 
		if (this.cover != '') paths += '&cover=' + this.cover; 
		if (this.shuffle != '') paths += '&shuffle=' + this.shuffle; 
		if (this.crossfader != '') paths += '&crossfader=' + this.crossfader; 
		if (this.replay != '') paths += '&replay=' + this.replay; 
		if (this.background != '') paths += '&background=' + this.background; 

        // SET AUTOPLAYS (autoplay is executed only if at least one of this parameters is send : trackmod, title, tracknum) 
        var val;
        var autoplays = '';
        for (val in this.autoplay) {
            if(this.autoplay[val] != '') autoplays += '&'+val+'='+this.autoplay[val]+'';
        }

        var content = '<embed style="-moz-opacity:0.70; filter:alpha(opacity=70), finishopacity=80, startx=30, style=0" wmode="transparent" type="application/x-shockwave-flash" '
        +' src="'+RadioBlog.basepath+'/skins/'+RadioBlog.skin+'/player.swf" allowScriptAccess="always"'
        +' width="'+this.width+'" height="'+this.height+'" '
        +' bgcolor="'+this.color.body+'" '
        +' id="radioblog_player_'+this.id+'" '
        +' FlashVars="'
        +'id='+this.id
        +paths
        +colors
        +autoplays
        +'"'
        +'></embed>';

        if (this.debug == '1') alert(content);
        
        return content;
    },

    start: function(where) {
        RadioBlog.id++;
        if (typeof where == 'undefined') {
            document.write('<div id="radioblog_'+this.id+'" style="width:'+this.width+'; height:'+this.height+';"></div>');
            var where = document.getElementById('radioblog_'+this.id);
        }
        where.innerHTML =  this.createPlayer();
    },

    info: function(id,info) {
        var rbObj = document.getElementById('radioblog_player_'+id);
        rbObj.title = info;
    },
    
    searchLyrics: function(trackName) {
        if (RadioBlog.debug == '1') alert(trackName);
        window.open('http://www.google.com/search?q=lyrics%20'+escape(trackName)+'&client=pub-9107944072945632&channel=7588634332');
    },
    
    searchArtist: function(artist) {
        if (RadioBlog.debug == '1') alert(artist);
        window.open('http://www.google.com/search?q='+escape(artist)+'&client=pub-9107944072945632&channel=2414323561');
    },
    
    buyThisTrack: function(trackName) {
        if (RadioBlog.debug == '1') alert(trackName);
        window.open('http://www1.radioblogclub.com/buy_this_track/'+escape(trackName));
    },
    
    isPlaying: function(trackName) {
        if (RadioBlog.debug == '1') alert(trackName);
        for (val in this.isPlaying) {
            var isFunction = this.isPlaying[val];
            if(typeof isFunction == 'function') eval(isFunction(trackName));
        }
    }
}


// ======= UTILS =========================================================================================================================
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function setCookie(name, value, expires, path, domain, secure)
{   
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function isStrict() {
    var isStrict = document.compatMode=='CSS1Compat';
    return isStrict;
}