/*
* Author: C. Imperiale
* Functions added to supplement some of ext.util.CSS
* They can be used to change the CSS sheet on a frame based page.
* The modules used to create the ext.js are:
* 1. choose the 'Yahoo UI' adapter
* 2. Ext Core
* 3. Core - Utilities
* 4. Core - State Management
*/

dyncss = function()
{
    // Private
    // data
    var cp = new Ext.state.CookieProvider();
    Ext.state.Manager.setProvider(cp);
    
    // members
    
    // Public data & Members
    return {
        init : function(id, css_file)
	{
            var css = cp.get("css",css_file);	         
            Ext.util.CSS.swapStyleSheet( id, css);
        },
        /**
	 * Removes a style or link tag by id
	 * Exists in util class	 
	 * @param {String} id The id of the tag
	 * @param {Object} mydoc The document to work on.
	 */        
	removeStyleSheet : function(mydoc, id)
	{
	       var existing = mydoc.getElementById(id);
	       if(existing)
	       {
	           existing.parentNode.removeChild(existing);
	       }
	},
	
	/**
	 * Dynamically swaps an existing stylesheet reference for a new one
	 * Exists in util class	 
	 * @param {String} id The id of an existing link tag to remove
	 * @param {String} url The href of the new stylesheet to include
	 * @param {Object} mydoc The document to work on.	
	 */
	swapStyleSheet : function(mydoc, id, url)
	{
	       this.removeStyleSheet(mydoc, id);
	       var ss = mydoc.createElement("link");
	       ss.setAttribute("rel", "stylesheet");
	       ss.setAttribute("type", "text/css");
	       ss.setAttribute("id", id);
	       ss.setAttribute("href", url);
	       mydoc.getElementsByTagName("head")[0].appendChild(ss);
       },
       
       change_size : function(id, css_file)
       {
           Ext.util.CSS.swapStyleSheet(id, css_file);
       	   this.swapStyleSheet(window.parent.MAIN.document, id, css_file);
       		
       	   cp.set("css",css_file);
       }
    };
}();


// Load tradcca3 by default.
Ext.onReady(function() { dyncss.init("ss","tradcca3.css"), dyncss, true });