PLSatellite = function(conf){
    var PLS = this;
    PLS.config = {};
    
    PLS.iframe = document.createElement('iframe');
	PLS.ifDocument = false;

	PLS.getCDocument = function(){

		var doc = null;
		if(PLS.iframe.contentDocument)
		  // Firefox, Opera
		  doc = PLS.iframe.contentDocument;
		else if(PLS.iframe.contentWindow)
		  // Internet Explorer
		  doc = PLS.iframe.contentWindow.document;
		else if(PLS.iframe.document)
		  // Others?
		  doc = PLS.iframe.document;
		
		if(doc == null)
		  throw "Document not initialized";
		else
			return doc;
    }
	
    PLS.getParentNode = function(){
		
		var t = document.getElementsByTagName('script');
		for( node in t ){
			if(t[node].src == 'http://planetacommerce.it/widget.js')
				return t[node].parentNode;
		}
		return document.body;
			
    }

    PLS.addIFEventListener = function(type, expression, bubbling){
        bubbling = bubbling || false;
        
        if (window.addEventListener) { // Standard
            PLS.iframe.addEventListener(type, expression, bubbling);
            return true;
        }
        else 
            if (window.attachEvent) { // IE
                PLS.iframe.attachEvent('on' + type, expression);
                return true;
            }
            else 
                return false;
    }

    PLS.addCssFile = function(src){

        var fileref = PLS.ifDocument.createElement("link");
        PLS.ifDocument.setAttribute("rel", "stylesheet");
        PLS.ifDocument.setAttribute("type", "text/css");
        PLS.ifDocument.setAttribute("href", src);
    }

	PLS.init = function(){
    
        if (typeof conf.SID === "undefined") 
            return false;
        
        PLS.config.SID = conf.SID.toString();
        PLS.config.width = conf.width ? ((conf.width.toString().match(/px$/i) || conf.width.toString().match(/\%$/i)) ? conf.width.toString() : parseInt(conf.width) + 'px') : '100%';
        PLS.config.height = conf.height ? (conf.height.toString().match(/px$/i) || conf.height.toString().match(/\%$/i) ? conf.height.toString() : parseInt(conf.height) + 'px') : '100%';
        PLS.config.css = typeof conf.css == 'undefined' ? false : conf.css;
        
    }
    
	PLS.onRender = function(){
		/*
		 * quando l'iframe è caricato completamente eseguo questo
		 */
//		console.log('iframe loaded');
		// carico il document
		PLS.ifDocument = PLS.getCDocument();
		if( PLS.config.css != false ){
//			PLS.addCssFile(PLS.config.css);
		}
		
	}
	
    PLS.render = function(){
        PLS.iframe.src = 'http://www.planetacommerce.it/index.php?mk=' + Math.random() + '&SID=' + PLS.config.SID;
        //	document.write('<iframe id="PLSat" src="http://planetacommerce.it/index.php?mk='+Math.random()+'&SID=' + PLS.config.SID + '" frameborder="0" width="'+PLS.config.width+'" height="'+PLS.config.height+'"></iframe>');
        //	var PLSat = document.getElementById('PLSat');
        if (PLS.iframe.style) {
            PLS.iframe.style.width = PLS.config.width;
            PLS.iframe.style.height = PLS.config.height;
            PLS.iframe.style.border = 'none';
			
			//imposto
			PLS.iframe.style.minWidth = '640px';
			if (window.attachEvent)	{ //IE
			
				PLS.iframe.style.height = '600px';
			}
        }
	
        PLS.getParentNode().appendChild(PLS.iframe);
		
		//PLS.addIFEventListener('load', PLS.onRender);

    }
    
    PLS.init();
    PLS.render();
	 
    return true;
}