var ESYN;
if(ESYN == undefined) {
    ESYN = {} ;
}
if (!ESYN.initialized) {
    	
    ESYN.gId = function (id) {
	return document.getElementById(id);
    }

    ESYN.css = function (content) {
    	var head = document.getElementsByTagName('head')[0];
    	var style = document.createElement('style');
    	style.type = 'text/css';
    	
    	regexp = new RegExp("##PATH##" ,"g");
    	translated = content.replace(regexp, this.path);
    	
    	if (style.styleSheet) {
    		style.styleSheet.cssText = translated;
    	} else {
    		rules = document.createTextNode(translated);
    		style.appendChild(rules);
    	}
    	head.appendChild(style);
    }
    
    ESYN.ent_widget = function () {
	this.path = "http://donate.lafermeadede.com";

    this.raw_css = "#d4f_button { \n position: absolute; \n	z-index: 99999; \n top: 125px; \n left: 0px; \n } \n " +
    			   "#d4f_button img { \n border: none; \n } \n " +
    			   "#esGreybox { \n position: absolute; \n z-index: 99999; \n width: 100%; \n height: auto; \n top: 0; \n left: 0; \n } \n " +
    			   "#esGreyboxBg { \n position: fixed !important; \n background: #000; \n opacity: 0.6; \n filter : alpha(opacity=60); \n height: 100%; \n "+
    			   		"left: 0; \n top: 0 !important; \n width: 100%; \n z-index: 99998; \n } \n " +
    			   "#esGreybox #top { \n position: relative; \n width: 641px; \n height: 17px; \n margin: 5px auto 0; \n " +
    			   		"background: url(##PATH##/images/border_top.png) no-repeat top left; \n } \n " +
    			   "#esGreybox #middle { \n position: relative; \n width: 601px; \n height: auto; \n margin: 0 auto; \n padding: 5px 20px; \n " +
    			   		"background: url(##PATH##/images/border_middle.png) repeat-y top left; \n } \n " +
    			   "#esGreybox #bottom { \n position: relative; \n width: 641px; \n height: 17px; \n margin: 0 auto; \n " +
    			   		"background: url(##PATH##/images/border_bottom.png) no-repeat bottom left; \n } \n " +
    			   "#esGreybox #top #ent_close_button { \n position: absolute; \n z-index: 99999; \n margin-left: 615px; \n } \n " +
    			   "#esGreybox #top #ent_close_button img { \n border: none; \n } \n ";
	this.iframe_url = "/iframe";
	this.html_tab = '<div id="d4f_button"><a href="#" id="ent_pay_tab"><img src="'+ this.path +'/images/d4f_button.png" alt="Financez la prochaine nouveauté du jeu"/></a></div>';
	this.html_iframe = '<iframe id="ent_pay_iframe" allowTransparency="true" scrolling="no" frameborder="0" class="loading"' + 
	'src="" '+
	'width="595px" '+ 
	'height="830px" '+
	'style="width:595px; height:830px;"> '+
	'</iframe>';
	this.html_overlay = '<div id="ent_pay_overlay" style="display:none">' +
	'<div id="esGreyboxBg"></div>' +
	'<div id="esGreybox">' +
    '  <div id="top"><a href="#" id="ent_close_button"><img src="'+ this.path +'/images/close_button.png" alt="Fermer"/></a></div>' +
    '  <div id="middle">' +
	this.html_iframe + 
    '  </div>' +
    '  <div id="bottom"></div>' +
	'</div></div>';
	
	ESYN.css(this.raw_css);
	document.write(this.html_tab);
	document.write(this.html_overlay);
	
	var widget = this;
	ESYN.gId("ent_pay_tab").onclick = function () { widget.show(); return false; };
	ESYN.gId("ent_close_button").onclick = function () { widget.hide(); return false; };
    }
}

ESYN.ent_widget.prototype = {
    show : function () {
	ESYN.gId("ent_pay_iframe").setAttribute("src", this.path + this.iframe_url);
	if (ESYN.gId("ent_pay_iframe").addEventListener) {
	    ESYN.gId("ent_pay_iframe").addEventListener("load", this.loaded, false);
	} else if (ESYN.gId("ent_pay_iframe").attachEvent) {
	    ESYN.gId("ent_pay_iframe").attachEvent("onload", this.loaded); 
	}
	ESYN.gId("ent_pay_overlay").style.display = "block";
    },

    hide : function () {
	ESYN.gId("ent_pay_overlay").style.display = "none";
    },
    
    loaded : function () {
	// do something maybe after loading
    }
}