<!--

function submitLogin(field,event) {
 var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
 if (keyCode == 13) {
	Scarabe.Form.submit('login_login','_qf_login_login_login');
	return false;
 }
 return true;
}

// Hier Select
function _hs_findOptions(ary, keys)
{
    var key = keys.shift();
    if (!key in ary) {
        return {};
    } else if (0 == keys.length) {
        return ary[key];
    } else {
        return _hs_findOptions(ary[key], keys);
    }
}

function _hs_findSelect(form, groupName, selectIndex)
{
    if (groupName+'['+ selectIndex +']' in form) {
        return form[groupName+'['+ selectIndex +']']; 
    } else {
        return form[groupName+'['+ selectIndex +'][]']; 
    }
}

function _hs_unescapeEntities(str)
{
    var div = document.createElement('div');
    div.innerHTML = str;
    return div.childNodes[0] ? div.childNodes[0].nodeValue : '';
}

function _hs_replaceOptions(ctl, optionList)
{
    var j = 0;
    ctl.options.length = 0;
    for (i in optionList) {
        var optionText = (-1 == optionList[i].indexOf('&'))? optionList[i]: _hs_unescapeEntities(optionList[i]);
        ctl.options[j++] = new Option(optionText, i, false, false);
    }
}

function _hs_setValue(ctl, value)
{
    var testValue = {};
    if (value instanceof Array) {
        for (var i = 0; i < value.length; i++) {
            testValue[value[i]] = true;
        }
    } else {
        testValue[value] = true;
    }
    for (var i = 0; i < ctl.options.length; i++) {
        if (ctl.options[i].value in testValue) {
            ctl.options[i].selected = true;
        }
    }
}

function _hs_swapOptions(form, groupName, selectIndex)
{
    var hsValue = [];
    for (var i = 0; i <= selectIndex; i++) {
        hsValue[i] = _hs_findSelect(form, groupName, i).value;
    }

    _hs_replaceOptions(_hs_findSelect(form, groupName, selectIndex + 1), 
                       _hs_findOptions(_hs_options[groupName][selectIndex], hsValue));
    if (selectIndex + 1 < _hs_options[groupName].length) {
        _hs_swapOptions(form, groupName, selectIndex + 1);
    }
}

function _hs_onReset(form, groupNames)
{
    for (var i = 0; i < groupNames.length; i++) {
        try {
            for (var j = 0; j <= _hs_options[groupNames[i]].length; j++) {
                _hs_setValue(_hs_findSelect(form, groupNames[i], j), _hs_defaults[groupNames[i]][j]);
                if (j < _hs_options[groupNames[i]].length) {
                    _hs_replaceOptions(_hs_findSelect(form, groupNames[i], j + 1), 
                                       _hs_findOptions(_hs_options[groupNames[i]][j], _hs_defaults[groupNames[i]].slice(0, j + 1)));
                }
            }
        } catch (e) {
            if (!(e instanceof TypeError)) {
                throw e;
            }
        }
    }
}

function _hs_setupOnReset(form, groupNames)
{
    setTimeout(function() { _hs_onReset(form, groupNames); }, 25);
}

function _hs_onReload()
{/*
    var ctl;
    for (var i = 0; i < document.forms.length; i++) {
        for (var j in _hs_defaults) {
            if (ctl = _hs_findSelect(document.forms[i], j, 0)) {
                for (var k = 0; k < _hs_defaults[j].length; k++) {
                    _hs_setValue(_hs_findSelect(document.forms[i], j, k), _hs_defaults[j][k]);
                }
            }
        }
    }

    if (_hs_prevOnload) {
        _hs_prevOnload();
    }*/
}

var _hs_prevOnload = null;
if (window.onload) {
    _hs_prevOnload = window.onload;
}
window.onload = _hs_onReload;

var _hs_options = {};
var _hs_defaults = {};




var Scarabe = {
	progress: function(id){
		$(id).innerHTML = '<div id="boxLoad"><img src="images/loading.gif"/><span>loading</span></div>';
	}
}

var SWindow = Class.create();
Object.extend(SWindow.prototype, Window.prototype);

SWindow.prototype.initialize = function(id) {

		this.hasEffectLib = String.prototype.parseColor != null;
		this.options = Object.extend({
		  className:         "dialog",
      minWidth:          100,
      minHeight:         20,
      resizable:         true,
      closable:          true,
      minimizable:       true,
      maximizable:       true,
      draggable:         true,
      userData:          null,
      showEffect:        (this.hasEffectLib ? Effect.Appear : Element.show),
      hideEffect:        (this.hasEffectLib ? Effect.Fade : Element.hide),
      showEffectOptions: {},
      hideEffectOptions: {},
      effectOptions:     null,
      parent:            document.getElementsByTagName("body").item(0),
      title:             "&nbsp;",
      url:               null,
      onload:            Prototype.emptyFunction,
      width:             200,
      height:            300,
      opacity:           1
    }, arguments[1] || {});

	  if (this.options.effectOptions) {
	    Object.extend(this.options.hideEffectOptions, this.options.effectOptions);
	    Object.extend(this.options.showEffectOptions, this.options.effectOptions);
	  }
		if (this.options.hideEffect == Element.hide)
		  this.options.hideEffect = function(){ Element.hide(this.element); if (this.destroyOnClose) this.destroy(); }.bind(this)

		this.element = $(id);

		// Bind event listener
    this.eventMouseDown = this._initDrag.bindAsEventListener(this);
  	this.eventMouseUp   = this._endDrag.bindAsEventListener(this);
  	this.eventMouseMove = this._updateDrag.bindAsEventListener(this);
  	this.eventKeyPress  = this._keyPress.bindAsEventListener(this);
  	this.eventOnLoad    = this._getWindowBorderSize.bindAsEventListener(this);
    this.eventMouseDownContent = this.toFront.bindAsEventListener(this);
    this.eventResize = this._recenter.bindAsEventListener(this);

		this.topbar = $(this.element.id + "_top");
		this.bottombar = $(this.element.id + "_bottom");
    this.content = $(this.element.id + "_content");

		Event.observe(this.topbar, "mousedown", this.eventMouseDown);
		Event.observe(this.bottombar, "mousedown", this.eventMouseDown);
		Event.observe(this.content, "mousedown", this.eventMouseDownContent);
		Event.observe(window, "load", this.eventOnLoad);
		Event.observe(window, "resize", this.eventResize);
  	Event.observe(window, "scroll", this.eventResize);

		if (this.options.draggable)  {
			this.bottombar.addClassName("bottom_draggable");
			this.topbar.addClassName("top_draggable");
    }

		if (this.options.resizable) {
			this.sizer = $(this.element.id + "_sizer");
    	Event.observe(this.sizer, "mousedown", this.eventMouseDown);
    }

    this.useLeft = null;
    this.useTop = null;
		if (arguments[1].left != null) {
			this.element.setStyle({left: parseFloat(arguments[1].left) + 'px'});
			this.useLeft = true;
		}
		if (arguments[1].right != null) {
			this.element.setStyle({right: parseFloat(arguments[1].right) + 'px'});
			this.useLeft = false;
		}
    if (this.useLeft == null) {
	    this.element.setStyle({left: "0px"});
			this.useLeft = true;
    }

		if (arguments[1].top != null) {
			this.element.setStyle({top: parseFloat(arguments[1].top) + 'px'});
			this.useTop = true;
		}
		if (arguments[1].bottom != null) {
			this.element.setStyle({bottom: parseFloat(arguments[1].bottom) + 'px'});
			this.useTop = false;
		}
    if (this.useTop == null) {
			this.element.setStyle({top: "0px"});
			this.useTop = true;
    }

    this.storedLocation = null;

		this.setOpacity(this.options.opacity);
		if (this.options.zIndex)
			this.setZIndex(this.options.zIndex)

		this.destroyOnClose = false;

    this._getWindowBorderSize();
    this.width = this.options.width;
    this.height = this.options.height;

    if (this.width && this.height)
		  this.setSize(this.options.width, this.options.height);
		this.setTitle(this.options.title)
		Windows.register(this);	    
  };


Scarabe.Uploader = {
	messages: {
		aucun_chargement:"No upload.",
		chargement_en_cours:"Uploading...",
		chargement_termine:"Upload complete.",
		info_transfere:'Transfered: ',
		info_poids:'Total transfered: ',
		info_poids_total:'Total size: ',
		veuillez_patienter:"Uploading. Please wait until upload is complete."
	},
	field: '',
	cgi: false,
	ul: {},
	in_progress: 0,
	updater: {},
	sid: false,
	onDone: function(hid){},
	url_uploader: "/index.php",
	winid:'window_id_upload',
	cpt:1,
	win:{},
	options:{},
	open: function(options){
		if (options.onDone){
			this.onDone = options.onDone
		}
		this.options = options;
		this.field = options.field;
		var pars = '_l_=upload/form&name='+options.field;
		var myAjax = new Ajax.Request( this.url_uploader, { method: 'post', parameters: pars,
			onComplete: function(request){Scarabe.Uploader.showForm(options.title,request)} });
	},
	showForm: function(title, originalRequest){
		this.win = new Window(this.winid, {title: title, minimizable:false, maximizable: false,
                                              top:70, left:70, width:350, height:200,
                                              resizable: false, closable:false, hideEffect:Element.hide, showEffect:Element.show})
		this.win.getContent().innerHTML= originalRequest.responseText;
		this.win.setDestroyOnClose(false);
		this.win.setStatusBar(this.messages.aucun_chargement);
		this.win.showCenter(true);
	},
	beginUpload: function(ul,sid) {
		if ( this.in_progress == 0 ){
			this.sid = sid + this.cpt;
			this.cpt++;
			if (!this.cgi){
				this.cgi = ul.form.action;
			}
			ul.form.action = this.cgi+'?sid='+this.sid;
			ul.form.submit();
			this.ul = ul;
			this.in_progress = 1;
			var pb = $(ul.name + "_progress");
			Element.show(pb.parentNode);
			this.win.setStatusBar(this.messages.chargement_en_cours);
			Scarabe.Uploader.updater = new Ajax.PeriodicalUpdater({update:Prototype.emptyFunction},Scarabe.Uploader.url_uploader,{'decay': 2,'frequency' : 0.5,'method': 'post','parameters': '_l_=upload/progress&sid=' + this.sid,'onComplete':Prototype.emptyFunction,'onSuccess' : function(request){Scarabe.Uploader.updateProgress(ul,request)},'onFailure':function(request){Scarabe.Uploader.updateFailure(pb,request)}})
		}
	},
	updateProgress: function(ul,req) {
		var pb = $(ul.name + "_progress");
		var info = req.responseText.split(',');
		var percent = parseInt(info[0]);
		var done_size = info[1];
		var total_size = info[2];
		
//		if ( this.sid != info[3] ){
//			alert('mismatch sid');
//		}
		if (this.in_progress == 0){
				Scarabe.Uploader.updater.stop();
				this.updater.stop();
		}

		if (this.in_progress == 1 && this.sid == info[3]) {
			if(!percent) percent = 0;
			pb.style.width = percent + "%";
			$('file2upload_info').innerHTML = this.messages.info_transfere+percent+'%<br>'+this.messages.info_poids+done_size+'<br>'+this.messages.info_poids_total+total_size;//+'<br>sid='+this.sid+'<br>serversid='+info[3];
			if(percent >= 100) {
				Scarabe.Uploader.updater.stop();
				Scarabe.Uploader.updater.onTimerEvent=Prototype.emptyFunction;
				this.win.setStatusBar(this.messages.chargement_termine);
				var inp_id = pb.id.replace("_progress","");
				if(this.sid) {
					var inp = $(inp_id+'_sid');
					if(inp) {
						inp.value = this.sid;
					}
					if (this.options.preview){

						var html = '<div><span></span><img src="/index.php?_l_=upload/preview&sid='+this.sid+'"/></div>';
						if (this.ul.value.lastIndexOf(".swf")!=-1){
							html = '<object type="application/x-shockwave-flash" data="/index.php?_l_=upload/preview&sid='+this.sid+'" width="100" height="100"><param name="movie" value="/index.php?_l_=upload/preview&sid='+this.sid+'" /><param name="wmode" value="transparent" /></object>';
						}
						Element.update('file2upload_preview', html);
//						this.HTMLPreview('file2upload_preview', this.sid);
					}
				}
				Element.hide(pb.parentNode);
				this.in_progress = 0;
			}
		}
	},
	HTMLPreview: function(elt, sid){
		Element.update(elt, '<div><span></span><img src="/index.php?_l_=upload/preview&sid='+sid+'"/></div>');
	},
	endProgress: function(val, flash){
		this.sid = false;
		var field = $(this.field);
		if (field){
			field.value = val;
		}
		if (this.onDone){
			this.onDone(val, flash);
		}
		this.win.hide();
	},
	updateFailure: function(pb,req) {
		var mes = req.responseText;
		pb.style.width=0;
		alert(mes);
		this.in_progress = 0;
	},
	cancelUpload: function(){
		this.in_progress = 0;
		this.win.hide();
	},
	submitUpload: function(hidid) {
		if(this.in_progress > 0) {
			alert(this.messages.veuillez_patienter);
		} else {
			var flash = false;
			if (this.ul.value.lastIndexOf(".swf")!=-1){
				flash = true;
			}
			var val = $F(hidid);
			this.endProgress(val, flash);
		}
	}
};
		
Scarabe.Form = {
	clearfield: function(id, defval){
		if ($(id) && $F(id) == defval){
			$(id).value = '';
		}
	},
	submit: function(frm,action) {
		frm = $(frm);
		if ( $(frm.name+'_qf_default') ){
			$(frm.name+'_qf_default').value = frm.name+':'+action;
		}
		else {
			new Insertion.Top(frm, '<input id="'+frm.name+'_qf_default" type="hidden" name="'+action+'" value="1"/>');
		}
		frm.submit();
	},
	submit_: function (){
		tinyMCE.triggerSave(true,true);
//		document.forms["editarticleform"].submit();
	},
	edithtml: function (id, w, h){
		if (typeof(w) == "undefined"){
			w = 600;
		}
		if (typeof(h) == "undefined"){
			h = 480;
		}
		win = Windows.getWindow('IDWIN');
		
		var editor = tinyMCE.getInstanceById('mce_editor_0');
		editor.execCommand('mceSetContent', false, $(id).innerHTML);
		
		if (!win){
			win = new SWindow('IDWIN', {title: '&nbsp;', minimizable:false, maximizable: false,
	                                              top:70, left:70, width:w, height:h,
	                                              resizable: true, closable:true, showEffect: Element.show, hideEffect: Element.hide})

			TinyMCE_AdvancedTheme._resizeTo(editor, w-2, h -100, true);
			myObserver = { 
				onEndResize: function(eventName, swin) { 
					if (swin == win) {
						TinyMCE_AdvancedTheme._resizeTo(editor, win.width-2, win.height -100, true);
					} 
				} 
			};
			Windows.addObserver(myObserver); 
			
		}
		
		$('frm_editor').onsubmit = function (){
			tinyMCE.triggerSave();
			$(id).innerHTML = $F('editeur_html');
			var hidfile = $(id+'_hidfield');
			if (hidfile){
				hidfile.value = $F('editeur_html');
			}
			win.hide();
			return false;
		}
		
		win.showCenter(true);
	}
};


Scarabe.Service = {
	url: '/index.php',
	popup_cpt: 1,
	test: function(){
		var req = {
			type: 'mdb',
			source:'liste_produit',
			param: [{name:'capacity', value: 20},{name:'page', value: 1}, {name:'produit.info.langue_id', value: 1}]
		}
		this.ask(req, function(originalRequest){
			win = new Window(' ', {title: 'test', minimizable:false, maximizable: false,
	                                              top:70, left:70, width:350, height:200,
	                                              resizable: true, closable:true, showEffectOptions: {duration:0.3}})
			win.getContent().innerHTML= originalRequest.responseText;
			win.setDestroyOnClose(true);
			win.setStatusBar('xxx');
			win.showCenter(true);
			
		});
	},
	
	ask: function(req, onComplete){

		var params = 'type='+req.type+'&source='+req.source;
		for(var i=0; i<req.param.length; i++){
			var parm = req.param[i];
			params += '&param['+i+'][name]='+parm['name']+'&param['+i+'][value]='+parm['value']+'&';
		}
		var myAjax = new Ajax.Request( '/dump_req.php', { method: 'post', parameters: params,
		onComplete: onComplete});

	},
	submit: function(id, frm, action){
		frm = $(frm);
		if ( $(frm.name+'_qf_default') ){
			$(frm.name+'_qf_default').value = frm.name+':'+action;
		}
		else {
			new Insertion.Top(frm, '<input id="'+frm.name+'_qf_default" type="hidden" name="'+action+'" value="1"/>');
		}
		var pars = Form.serialize(frm);
		var myAjax = new Ajax.Updater(
			id, 
			this.url, 
			{
				method: 'post', 
				parameters: pars,
				evalScripts: true
			});
	},
	update: function(id, pars){
		$(id).startWaiting('bigWaiting');
		var myAjax = new Ajax.Updater(
			id, 
			this.url, 
			{
				method: 'get', 
				parameters: pars,
				evalScripts: true,
				onSuccess: function(){ $(id).stopWaiting();}
			});
	},/*
	setSWFAddress: function(val){
		SWFAddress.setValue(val);
		return false;
	},
	onUpdate: function(event){
		var elt = $('colonnecentrale');
		var x = $H(event.parameters);
		if (x.size() > 0){
//			alert($H(event.parameters).toQueryString());
			elt.startWaiting('bigWaiting');
			var myAjax = new Ajax.Updater(
				'colonnecentrale', 
				'/index.php', 
				{
					method: 'get', 
					parameters: $H(event.parameters).toQueryString(),
					evalScripts: true,
					onSuccess: function(){ elt.stopWaiting();},
					onException: function(r,e){ 
//						alert(e.toString()+' '+r.responseText);
						elt.stopWaiting();},
					onFailure: function(){ alert('fail');elt.stopWaiting();}
				});
		}
	},
	seo: function(swfaddress, base) {
    var hash = location.href.indexOf('#');
    if (swfaddress != '/' && (hash == -1 || hash == location.href.length - 1)) {
        var xhr;
        if (window.XMLHttpRequest) {
            xhr = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            try {
                xhr = new ActiveXObject('Msxml2.XMLHTTP');
            } catch(e) {
                xhr = new ActiveXObject('Microsoft.XMLHTTP');
            }
        }
        xhr.open('get', ((typeof base != 'undefined') ? base : '') + '/?' + swfaddress, false);                
        xhr.setRequestHeader('Content-Type', 'application/x-swfaddress');
        xhr.send('');
        eval(xhr.responseText);
    }
	},*/
	ajax_popup: function(query, options){
		var myAjax = new Ajax.Request( this.url, { method: 'post', parameters: query,
			onComplete: function(originalRequest){
				Scarabe.Service.open_popup(originalRequest.responseText, options)
			}
		});
	},
	open_popup: function(content, options){
		winid = 'win_popup_'+this.popup_cpt++;
		win = new Window(winid, options)
		win.getContent().innerHTML= content;
		win.setDestroyOnClose(true);
		win.setStatusBar('&nbsp;');
		win.showCenter();
	}
	
}
//Scarabe.Service.seo("/","/index.php");
//SWFAddress.addEventListener(SWFAddressEvent.CHANGE, Scarabe.Service.onUpdate);

	
Scarabe.Selecteur = {
	frm_id: '',
	ids: {},
	onfinish: Prototype.emptyFunction,
//		selecteurs:{},
	
//		function getSelecteur(id){
//			return this.selecteurs[id];
//		}
	display: function(originalRequest){
		if ($('selpdt')){
			win = Windows.getWindow('selpdt');
			originalRequest.responseText.evalScripts();
			win.getContent().innerHTML = originalRequest.responseText;
		}
		else {
			win = new Window('selpdt', {title: 'Sélectionner des produits', minimizable:false, maximizable: false,
	                                              top:40, left:40, width:580, height:450,
	                                              resizable: true, closable:true, showEffectOptions: {duration:0.1}, hideEffectOptions: {duration:0.1}});
			win.getContent().innerHTML= originalRequest.responseText;
			originalRequest.responseText.evalScripts();
			win.setDestroyOnClose(true);
			win.setStatusBar('&nbsp;');
			win.showCenter(true);
		}
	},
	open: function(onfinish,keepopen){
		if (keepopen){
			this.keepopen = keepopen;
		}
		this.onfinish = onfinish;
		this.update(false);
	},
	update: function(frmid){
		if (frmid){
			params = Form.serialize(frmid);
		}
		else {
			params = '';
		}
		params += '&_l_=osc/sel_produits';
		new Ajax.Request( '/index.php?_l_=osc/sel_produits', { method: 'post', parameters: params,onComplete: this.display});
	},
/*	add: function(id){
		this.ids[id] = 'ok';
	},
	remove: function(id){
		this.ids[id] = 'nok';
	},*/
	validate: function(frmid){
		var checkboxes = Form.getInputs(frmid, 'checkbox');
		var produits = [];
		checkboxes.each(function(checkbox){
			if (checkbox.checked){
				pdtid = checkbox.name.gsub('produits\\[','').gsub('\\]','');
				produits.push(pdtid.gsub('\\]',''));
			}
		});
		this.onfinish(produits);
		if (!this.keepopen){
			win = Windows.getWindow('selpdt');
			win.hide();
		}
	}
}
/*
Scarabe.Templates = {
	templates: [],
  getTemplate: function(id) {
	  return this.templates.detect(function(d) { return d.id ==id });
  },
  register: function(tpl) {
    this.templates.push(tpl);
  },
  unregister: function(tplid) {
    this.templates = this.windows.reject(function(d) { return d.id==tplid });
  }
}
*/

	var _extrainfo_cpt=1;
	function __add_extrainfo(){
		var tpl = new Template('<div id="extrainfo#{id}" class="extrainfo"><div class="checkbox"><span></span></div><div class="extrainfo_libelle">\
		<input name="extrainfo[new#{id}][libelle]" id="extrainfo_new#{id}__libelle" class="extrainfo_libelle" value="" type="text">\
	</div>\
	<div class="extrainfo_valeur">\
		<div class="edithtml_container"><input id="extrainfo_new#{id}__valeur_hidfield" name="extrainfo[new#{id}][valeur]" value="" type="hidden"><div name="extrainfo[new#{id}][valeur]" id="extrainfo_new#{id}__valeur" class="edithtml_preview"><br/></div><a class="edithtml_link" href="#" onclick="Scarabe.Form.edithtml(\'extrainfo_new#{id}__valeur\'); return false;">editer le texte</a></div>\
	</div>\
</div></div>');
		var data = {id: _extrainfo_cpt};
		new Insertion.Bottom('liste_produit_extrainfo', tpl.evaluate(data));
		_extrainfo_cpt++;
	}


	function tpl_render(idtpl, data){
//		if ($(idtpl)){
//			alert($(idtpl).innerHTML);
//			var tpl = new Template($(idtpl).innerHTML);
			
var tpl = new Template('<div class="fltr_elt">\
		<input class="fltr_elt" type="text" name="filter[n_#{id}][name]" value="#{field}"/>\
		<select name="filter[n_#{id}][op]">#{op}</select>\
		<input class="fltr_elt" type="text" name="filter[n_#{id}][value]" value=""/>\
	</div>');
//		<input class="fltr_elt" type="checkbox" name="filter[n_#{id}][options][ignoreIfEmpty]" value="1"/>ignore si nul\
//		<input class="fltr_elt" type="checkbox" name="filter[n_#{id}][options][notNull]" value="1"/>obligatoire\
			
//			alert(data.op);
//			alert(tpl.evaluate(data));
			return tpl.evaluate(data);
//		}
//		return "";
	}

	function tpl_fltr_elt(id, field, op){
		var ops = '';
		for(var i=0; i<op.length; i++){
			ops += '<option value="'+op[i]+'">'+op[i]+'</option>';
		}
		return tpl_render('tpl_fltr_elt', {id: id, field: field, op: ops});
	}

/*
<div id="extrainfo6" class="extrainfo">
	<div class="checkbox"><input name="extrainfo[6][selected]" value="1" id="extrainfo6__selected" type="checkbox"></div>
	<div class="extrainfo_libelle">
		<input name="extrainfo[6][libelle]" id="extrainfo6__libelle" class="extrainfo_libelle" value="test2" type="text">
	</div>
	<div class="extrainfo_valeur">
		<div class="edithtml_container"><input id="extrainfo6__valeur_hidfield" name="extrainfo[6][valeur]" value="blabla" type="hidden"><div name="extrainfo[6][valeur]" id="extrainfo6__valeur" class="edithtml_preview">blabla</div><a class="edithtml_link" href="#" onclick="Scarabe.Form.edithtml('extrainfo6__valeur'); return false;">editer le texte</a></div>

	</div>
*/
//-->

	
var DynTip = Class.create({
  initialize: function(element) {
    this.element = $(element);
    this.tipoptions = arguments[2] || {};
    this.options = Object.extend({
    	id: 'tip_'+element.id,
    	className: 'tip',
      location: '/index.php', 
      parameters: '',
      method: 'post'
    }, arguments[1] || {});

  	Event.observe(element, 'mouseover', this.onmouseover.bindAsEventListener(this), false);
  },
  onmouseover: function(event){
  	var content = '<div id="'+this.options.id+'" class="'+this.options.className+'"></div>';
    var tip = new Tip(this.element, content, this.tipoptions);
    tip.showDelayed(event);
  	Event.stopObserving(this.element, 'mouseover', this.onmouseover, false);
		new Ajax.Updater( 
			this.options.id, 
			this.options.location, 
			{ method: this.options.method, parameters: this.options.parameters,
					evalScripts: true,
					onSuccess: function(){ /*$('tip__'+event.currentTarget.id).stopWaiting();*/}
			}
		);
  }
});
