/**
 *  Formats the playlist and sends it to the printer
 *
 *  Copyright: (c)2007 CK Web Technologies
 *  Author:    Chris Knowles <chris.knowles@ckweb.com.au>
 *  Version:   $Id: Printer.js 22 2007-11-13 04:31:39Z Chris $
 */

var Printer = function(app)
{
    this.app = app;
}

Printer.prototype = 
{
    format: function()
    {       
        // get html from server
        var playlist = $D.getContent('playlist-table');
        
        // clear the printable list if it exists
        $D.setContent($D.id('print'), "");
        
        // insert the html into the doc
        var div = $D.create('div', {id:'print'});
        $D.setContent(div, "<table>" + playlist + "</table>");
        $D.tags('body')[0].appendChild(div);
        
        // call print
        window.print();
        
        /*
        var http = new $H;
        var self = this;
        http.get('print/' + this.app.Playlist.list + "/", false, function(){self.insert(http)});
        */
        
        
    },
    
    insert: function(http)
    {
        // clear the printable list if it exists
        $D.setContent($D.id('print'), "");
        
        // insert the html into the doc
        var div = $D.create('div', {id:'print'});
        $D.setContent(div, http.text);
        $D.tags('body')[0].appendChild(div);
        
        // call print
        window.print();
        
    },
    
    print: function()
    {
        // need to check if saved
        // if so, print saved or visible?
    
        if (this.app.Playlist.list && this.app.Playlist.list.length > 0) {
            this.format();
            //window.print();
        }
    }

};

