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

// ======= RADIO.BLOG =========================================================================================================================
var RadioBlog = {
    basepath: 'http://stat.radioblogclub.com/radio.blog',
    playlist: '',
    id: 0,
    width: '200px',
    height: '400px',
    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 != '1') paths += '&cover=' + this.cover; 
		if (this.shuffle != '0') paths += '&shuffle=' + this.shuffle; 
		if (this.crossfader != '1') paths += '&crossfader=' + this.crossfader; 
		if (this.replay != '1') 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 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();
        
        // START TOOLS
        for (key in this.start) {
            var isFunction = this.start[key];
            if(typeof isFunction == 'function') eval(isFunction(where));
        }
    },
 
    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.radioblogclub.com/search/0/'+escape(artist.toLowerCase()));
    },
    
    buyThisTrack: function(trackName) {
        if (RadioBlog.debug == '1') alert(trackName);
    },
    
    onPlay: function(title,url) {
        if (RadioBlog.debug == '1') alert(title+' : '+url);
        for (key in RadioBlog.onPlay) {
            var isFunction = RadioBlog.onPlay[key];
            if(typeof isFunction == 'function') eval(isFunction(title,url));
        }
    }
}
