// JavaScript Document
var fakeIE = false;
try{var ipt = document.createElement('<input>'); ipt.outerHTML && (fakeIE=ipt.outerHTML.substr(0,2)=='<<');}catch(e){fakeIE=false}
var isIE=navigator.appName.indexOf("Microsoft Internet Explorer")!=-1 && !fakeIE?true:false;

var url = ''+window.top.location;
url = url.substr(url.indexOf('://')+3);
if (!window.GLOBALS)GLOBALS={};
GLOBALS.HOST = url.substr(0, url.indexOf('/'));
var CURRENT = url.substr(url.indexOf('/'));

function	dc(n){return(document.createElement(n))};
function	dt(t){return(document.createTextNode(t))};
function	GetKeyCode(e){if(!e)e=window.event;return(e.keyCode?e.keyCode:(e.which?e.which:0));};

var ieexpr = "(document.documentElement.scrollTop || document.body.scrollTop)" + 
			"+Math.round((document.documentElement.offsetHeight || document.body.clientHeight) - 20) + 'px'";
launchApp.basePath = '/';
jQuery.createCss(
//!	Fixed positioning emulation for IE6
(jQuery.browser.msie && jQuery.browser.version <= 6.0?
	'div#foot		 		{position:absolute; top:expression('+ieexpr+')}': '') +
'');

function	MakeInput(obj){
	var input=false;
	if(isIE){
		var t='';
		for(i in obj)
			if(typeof(obj[i])=='boolean')t+=' '+i+'="'+(obj[i]? 'true': 'false')+'"';
			else if(typeof(obj[i])!='object'&&typeof(obj[i])!='function'){
				try{
					t+=' '+i+'="'+obj[i].replace('\\', '\\\\').replace('"', '\\"')+'"';
				}catch(e){
					t+=' '+i+'="undefined"';
				}
			}
		try {
			input=dc('<input'+t+'>');
			for(i in obj)
				if(typeof(obj[i])=='object'||typeof(obj[i])=='function')
					input[i]=obj[i];
		}
		catch(e) {input=false;}
	}
	if (!input) {
		var input=dc('input');
		for(i in obj)
			input[i]=obj[i];
	}
	return input;
};

function	Help(text){
	jQuery('#tabhelp').html(text || '');
};
function	AltToHelp(n){
	for(;n;n=n.nextSibling){
		AltToHelp(n.firstChild);
		if(n.alt)
			n._help = n.alt;
		else if (n.title)
			n._help = n.title;
		else
			continue ;		
		n.alt = '';
		n.title = '';
		n.onmouseover=function(){Help(this._help);}
		n.onmouseout=function(){Help();}
	}
	return false;
};
function	ValidateEmail(email) {var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;if(filter.test(email))return(true);else return(false);};
function	ChangeLang(lang){jQuery.cookie('lang',lang);window.top.location=window.top.location;};
jQuery.deleteCookie('lang');

function	debug(t) {var n=jQuery('#debug')[0];if(n)n.innerHTMLt+=t;else if (window.opener)window.opener.debug(t);};
var Calendars = [];

function	ShowCalendar(input) {
	if (!input.Calendar) {
		var parent = input.parentNode;
		var d = dc('div');
		with (d.style) {position='relative'}
		d.style.top=(input.clientHeight+4)+'px'
		var div = dc('div');
		div.id = 'div_'+input.name;
		with (div.style) {position='absolute';width='190px';height='210px';zIndex=99;border='solid 0px #000000';visibility='hidden';}
		d.appendChild(div);
		parent.insertBefore(d, input);
		try {input.Calendar = new GnooCalendar(input, 6, 6);}catch(e){alert('le calendrier n\'est pas chargé');}
		input.Calendar.init('div_'+input.name, input);
		input.Calendar.setFormat("us");
		Calendars.push(input.Calendar);
	}
	for (var i=0; i<Calendars.length; i++)
		Calendars[i].hide();
	try {
		input.Calendar.show();
	}catch(e) {alert(e.message);}
};
jQuery(function() {
	jQuery('input.date').click(function() {
		ShowCalendar(this);
	});
});
var Calendar = false;
var expdate = new Date();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
(function() {

//////////////////////////////////////////////
//                                          //
//     For the sidebar togglable lists      //
//                                          //
//////////////////////////////////////////////
function	MakeSidebarExpandable() {
	var sidebar = jQuery('#sidebar');
	if (!sidebar.length)
		return ;
	var main = sidebar.prevAll('td');
	
	sidebar.find('dl dd:has(> .expandable)').prepend('<div class="expand more before">Plus &raquo;</div>').append('<div class="expand more after">Plus &raquo;</div>');
	sidebar.find('.expand.more').click(function() {
		var dl = jQuery(this).parents('dl');
		var buttons = jQuery(this).parents('dd:first').find('> .expand');
		
		if (main.is(':visible')) {
			var animated = main.parent().find('> td > div, > td > dl');
			var i = 0;
			animated.fadeOut(function() {
				++i;
				if (i<animated.length)
					return ;
				main.hide();
				sidebar.removeClass('sidebar').addClass('centerbar');
				buttons.html('Revenir à la page &laquo;');
				dl.fadeIn();
			});
		}
		else {
			dl.fadeOut(function() {
				sidebar.removeClass('centerbar').addClass('sidebar');
				buttons.html('Plus &raquo;');
				main.css({display:''});
				main.parent().find('> td > div, > td > dl').fadeIn();
			});
		}
	});
};




/////////////////////////////////////////
//                                     //
//            For the Menu             //
//                                     //
/////////////////////////////////////////

var Expandable = [];
var ExpandTo = '';
var IsOut = true;
var fullrow = false;
function	TimeExpand(url) {
	if (url != ExpandTo)
		return;
	HighlightNow(ExpandTo);
	ExpandNow(ExpandTo);
	ExpandTo='';
};
function	HighlightNow(url){
	for (var i=0; i<Expandable.length; i++){
		try {
		var trs = Expandable[i].getElementsByTagName('tr');
		for(var j=0;j<trs.length; j++) {
			var chg = url.indexOf(trs[j].id)!=-1? 'hover': '';
			var td = trs[j].getElementsByTagName('td')[0];
//			alert('ca: '+td.className );
			if (td.className != chg)
				td.className = chg;
		}
		}catch(e){}
	}
};
function	ExpandNow(url){
	for (var i=0; i<Expandable.length; i++)
		if (url.indexOf(Expandable[i].id) === 0 && (!Expandable[i].parentNode || !Expandable[i].parentNode.parentNode))
			fullrow.appendChild(Expandable[i]);
		else if (url.indexOf(Expandable[i].id) !== 0 && Expandable[i].parentNode && Expandable[i].parentNode.parentNode)
			fullrow.removeChild(Expandable[i]);
	var width = 0;
	for (var i=0; i<Expandable.length; i++)
		if (Expandable[i].parentNode && Expandable[i].parentNode.parentNode)
			width += Expandable[i].clientWidth;
};
function	RewriteMenu() {
	var td = jQuery('#menu')[0];
	if (!td)
		return ;
	td.onmouseout = function() {
		IsOut=true;
		setTimeout(function() {
			if (!IsOut)
				return ;
			ExpandTo=CURRENT;
			setTimeout(function() {
				TimeExpand(CURRENT);
			}, 250);
		}, 40);
	};
	td.onmouseover = function() {IsOut=false;};
	
	fullrow = td.getElementsByTagName('tr')[0];
	var as = fullrow.getElementsByTagName('a');
	for (i=0;i<as.length;i++) {
		var href = as[i].href;
		var tdtext = as[i].parentNode;
		var row = jQuery(as[i]).parents('tr:first')[0];
		tdtext.insertBefore(dt('  '), tdtext.firstChild);
		href = href.substr(href.indexOf('://')+3);
		href = href.substr(href.indexOf('/'));
		row.onmouseover=function(){
			var url = this.id;
			HighlightNow(url);
			ExpandTo = url;
			setTimeout(function() {
				TimeExpand(url);
			},250);
		};
		row.id = href;
	}
	for (var td2 = fullrow.firstChild; td2; )
		if (td2.tagName && td2.tagName.toLowerCase() == 'td') {
			td2.style.display = '';
			//n = tds[i];
			n = td2;
			var id = '';
			//! recover td's id from sub a href
			var as = n.getElementsByTagName('a');
			for (j=0; j<as.length; j++) {
				var href = as[j].href;
				href = href.substr(href.indexOf('://')+3);
				href = href.substr(href.indexOf('/'));
				var tid = href;
				tid = tid.substr(0, (tid.charAt(tid.length-1)=='/'? tid.substr(0, tid.length-1): tid).lastIndexOf('/') + 1);
				id = (!id? tid: (id.length<tid.length? id: tid));
			}
			n.id = id;
			Expandable.push(n);
			if (CURRENT.indexOf(id) !== 0) {
				rem = td2;
				td2=td2.nextSibling;
	//			alert('removing: '+rem.outerHTML);
				fullrow.removeChild(rem);
			}
			else
				td2=td2.nextSibling;
		}
		else
			td2=td2.nextSibling;
	HighlightNow(CURRENT);
	var divs = td.getElementsByTagName('div');
	if (divs.length)
		divs[0].style.display = '';
};







/////////////////////////////////////////////////
//                                             //
//            The Login Popup                  //
//                                             //
/////////////////////////////////////////////////

function	PopupAdmin() {
	jQuery.loadComponent(jQuery.libroot+'jquery.nmodal.js', function() {
		var win = jQuery('#auth').alert({
			className: 'user login'
		});
		var error = win.find('.error');
		if (error.length)
			return ;
		jQuery('<h1>Connexion administrateur</h1>').prependTo(win);
		error = jQuery('<div class="error" />').appendTo(win.find('.data'));
		win.find('.button.Annuler').click(function() {
			win.close();
		});
		var user = win.find('[name=user]');
		var pass = win.find('[name=pass]');
		win.submit(function() {
			login();
			return false;
		});
		user.focus();
		function	login() {
			error.html('');
			jQuery.ajax({
				url: '/?json',
				dataType: 'json',
				type: 'post',
				data: {
					Action: 'login',
					user: user.val(),
					pass: pass.val()
				},
				success: function(json) {
					window.top.location = window.top.location;
				},
				error: function(json) {
					error.html(json.error);
					return false;
				}
			});
		};
	});
	
}
/////////////////////////////////////////////////
//                                             //
//               The Help Popup                //
//                                             //
/////////////////////////////////////////////////

var dom = false;
var msgtext = false;
var show = false;
var opened = false;

function	BuildHelpbox() {
	var help = document.body.appendChild(dc('span'));
	help.id = 'helpbox';
	jQuery(help).css({visibility:'hidden', top:'0px', left:'0px', position:'absolute', zIndex:100000});
	
	var table = help.appendChild(dc('table'));
	table.style.width = '170px';
	table.style.border = 'none';
	var tbody = table.appendChild(dc('tbody'));
	var tr = tbody.appendChild(dc('tr'));
	var td = tr.appendChild(dc('td'));
	td.style.height = '5px';
	td.style.width = '170px';
	td.colSpan = 5;
	td.style.background = 'url(/view/img/help_top.gif)';
	var tr = tbody.appendChild(dc('tr'));
	var td = tr.appendChild(dc('td'));
	td.style.width = '1px';
	td.style.backgroundColor = '#a44d00';
	var td = tr.appendChild(dc('td'));
	td.style.width = '4px';
	td.style.backgroundColor = '#f5ffe0';
	var td = tr.appendChild(dc('td'));
	td.style.width = '160px';
	td.style.backgroundColor = '#f5ffe0';
	td.id = "msgtext";
	msgtext = td;
	var td = tr.appendChild(dc('td'));
	td.style.width = '4px';
	td.style.backgroundColor = '#f5ffe0';
	var td = tr.appendChild(dc('td'));
	td.style.width = '1px';
	td.style.backgroundColor = '#a44d00';
	var tr = tbody.appendChild(dc('tr'));
	tr.style.height = '5px';
	var td = tr.appendChild(dc('td'));
	td.style.height = '5px';
	td.style.width = '170px';
	td.colSpan = 5;
	td.style.background = 'url(/view/img/help_bottom.gif)';
	dom = help;
};
function startPop() {
	if (!show)
		return;
	popUp(show,15,15);
	opened = true;
};
function helpBox(evt, msg) {
	if (!evt || !msg) {
		show = false;
		opened = false;
		window.status = '';
		HidePop();
		return ;
	}
	if (!dom || !msgtext)
		BuildHelpbox();
	msgtext.innerHTML = msg;
	while (msg.search('<b>') != -1)
		msg = msg.replace('<b>','');
	while (msg.search('<br />')!=-1)
		msg = msg.replace('<br />',' ');
	while (msg.search('</b>')!=-1)
		msg = msg.replace('</b>','');
	while (msg.search('<br>')!=-1)
		msg = msg.replace('<br>', '');
	window.status = msg? msg: '';
	if (show.type=='mousemove' && opened) {
		popUp(evt,15,15);
		return ;
	}
	show = jQuery.extend({}, evt);
	setTimeout(startPop, 1000);
};
function popUp(evt,offsetX,offsetY) {
	ShowPop(evt, offsetX, offsetY, -1, -1, 1);
};
function popUpAbsolute(evt,Xabs,Yabs) {
	ShowPop(evt, 0, 0, Xabs, Yabs, false);
};
function HidePop(){
	jQuery(dom).css({top:0, left:0, visibility:'hidden'});
};
var isNS4=(document.layers?true:false);
function ShowPop(evt,offsetX,offsetY,Xabs,Yabs,autom) {
	var topVal, leftVal;
	if (Xabs != -1 && Yabs != -1) {
		topVal=Yabs;
		leftVal=Xabs;
	}
	livePageWidth = window.innerWidth? window.innerWidth: document.body.clientWidth;
	scrollLeft = (evt.x&&!isNS4)? document.body.scrollLeft: 0;
	elemWidth = dom.offsetWidth? dom.offsetWidth: (dom.clip? dom.clip.width: 0);
	pageX = evt.pageX? evt.pageX: evt.x;
	if (Xabs != -1) {
		leftVal = Xabs;
	}
	else {
		leftVal = pageX + offsetX + scrollLeft;
		if (autom && leftVal+elemWidth-scrollLeft > livePageWidth) {
			leftVal2 = pageX + scrollLeft - elemWidth + 10 - offsetX;
			leftVal = leftVal2>=2? leftVal2: livePageWidth-elemWidth-2;
		}
		if (leftVal < 2)
			leftVal=2;
	}
	livePageHeight = window.innerHeight? window.innerHeight: document.body.clientHeight;
	scrollTop = evt.y&&!isNS4? document.body.scrollTop: 0;
	elemHeight = dom.offsetHeight? dom.offsetHeight: (dom.clip? dom.clip.height: 0);
	pageY = evt.pageY? evt.pageY: evt.y;
	if (Yabs != -1) {
		topVal=Yabs;
	}
	else {
		topVal = pageY + offsetY + scrollTop;
		if (autom && topVal+elemHeight-scrollTop > livePageHeight) {
			topVal2 = pageY - 5 + scrollTop - elemHeight - offsetY;
			topVal = topVal2>=2? topVal2: livePageHeight-elemHeight-2;
		}
		if (topVal<2)
			topVal=2;
	}
	jQuery(dom).css({top:parseInt(topVal)+'px', left:parseInt(leftVal)+'px', visibility:'visible'});
};

window.AddHelp = function	AddHelp(n, text) {
	if (!n.help && text) {
		n.setAttribute('help',text);
		n.alt = '';
		n.title = '';
		n.help = text;
	}
	n.onmouseout=function(){try{helpBox();}catch(e){}}
	n.onmouseover=n.onmousemove=function(e){helpBox(e, jQuery(this).attr('help'));}
};
/////////////////////////////////////////////////
//                                             //
//        The default text on inputs ...       //
//                                             //
/////////////////////////////////////////////////

window.MakeAutoText = function	MakeAutoText(input, text) {
	var bak = {color: input.style.color, text: text};
	
	if (input.value == "" || input.value == text)
		jQuery(input).css({color:'#CCCCCC'}).val(text);
	
	jQuery(input)
		.data('bak', bak)
		.focus(function() {
			if (this.value == bak.text)
				jQuery(input).val('');
			jQuery(input).css({color:bak.color});
		})
		.blur(function() {
			if (this.value != '' && this.value != bak.text)
				return ;
			jQuery(input).css({color:'#CCCCCC'}).val(bak.text);
		});
};

//jQuery.support.minHeight = function() {
//	//var id = "minheightsupport" + (new Date).getTime();
//	var el = $("<div />")
//		.css({height:'1px', minHeight:'2px', overflow:'hidden', border:'none', padding:'0', margin:'0'})
//		.appendTo("body");
//	var iscorrectheight = el[0].offsetHeight==2;
//	el.remove();
//	return iscorrectheight;
//};


/////////////////////////////////////////////////
//                                             //
//        Once everything Loaded ...           //
//                                             //
/////////////////////////////////////////////////

jQuery(function() {
	/** Redimensionne le contenu pour que le footer soit a la bonne hauteur */
	var jwindow = jQuery(window),
		foot = jQuery('#foot'),
		divcontent = jQuery('#divcontent'),
		content = jQuery('#MainTable');
	jwindow.resize(function() {
		function resizeNow() {
			content.css({height:''});
			var height = foot.offset().top-divcontent.offset().top;
			content.find('> *').each(function() {
				height = Math.max(height, this.clientHeight);
			});
			content.height(height);
		}
		if (jQuery.browser.msie)
			setTimeout(resizeNow, 10);
		else
			resizeNow();
	}).resize();
	
	RewriteMenu();
	
	MakeSidebarExpandable();
	
	var shares = jQuery('.share');
	if (shares.length)
		jQuery.loadComponent('http://s7.addthis.com/js/250/addthis_widget.js', function() {
			shares.append('<div class="addthis"><div class="floater"></div></div>');
			shares.find('.floater').each(function() {
				addthis.button(this, {}, {});
			});
		});
	
	// Replace Bullets
	jQuery('div.puce1, span.puce1, div.puce2, span.puce2').prepend('<span class="puce" />');
	jQuery('ul:not(.nopuce)').addClass('puce1').find('li').prepend('<span class="puce" />');
	
	// add _blank to external links
	var host = gethost();
	jQuery('a').each(function(){
		var href = this.href;
		if (href && gethost(href) != host || fileext(href) == 'pdf')
			this.target = '_blank';
		if (window._gaq && jQuery.inArray(fileext(href), ['pdf', 'doc', 'xls', 'avi', 'mov', 'flv']) != -1)
			jQuery(this).click(function() {
				console.info('clicked on '+this.href+' pageTracker: '+window.pageTracker);
				_gaq.push(['_trackPageview', this.href]);
			});
	});
	
	// add helpBox to tag with attribute title, help or alt
	jQuery('[title],[help],[alt]').each(function() {
		AddHelp(this, this.title || this.help || this.alt);
	});
	
	// add buttons to change lang
	jQuery('<div id="lang">' +
			'<span class="change-lang-FR" id="go-lang-FR">FRANÇAIS</span>'+
			'<span class="change-lang-EN" id="go-lang-EN">ENGLISH</span>' +
		'</div>').prependTo('#menu')
		.find('span').click(function(){ChangeLang(this.id.substr(8))});
	jQuery('#NewsLetter #go2lang-EN, #NewsLetter #go2lang-FR').click(function(){ChangeLang(this.id.substr(8)); return false});
	
	var text = jQuery('body.current-language-FR').length? 'Ce document est dans une autre langue': 'This document is in another language';
	jQuery('body.current-language-EN a.lang-FR, body.current-language-FR a.lang-EN').each(function() {
		AddHelp(this, text);
	});
	jQuery('#IddriNet img').click(function() {
		if (!window.TitleToFilename)
			PopupAdmin();
		else
			jQuery.ajax({
				url: '/?json',
				type: 'post',
				dataType: 'json',
				data: {Action: 'logout'},
				success: function() {
					window.location = window.location;
				}
			});
	});
	
	jQuery('.top a[href=#main]').attr({href:'javascript:'}).click(function() {
		if (document.documentElement.scrollTop)
			document.documentElement.scrollTop = jQuery('#main').offset().top;
		else if (document.body.scrollTop)
			document.body.scrollTop = jQuery('#main').offset().top;
	});
	
	jQuery('a.register').click(function() {
		var a = jQuery(this);
		var func;
		if (a.is('.register-session'))
			func = function() {ExpandRegister(a[0], 'Session');};
		else if (a.is('.register-evenement'))
			func = function() {ExpandRegister(a[0], 'Evenement');};
		else if (a.is('.register-newsletter'))
			func = function() {RegisterToLetter()};
	
		if (func)
			jQuery.loadComponent('/view/RegisterToLetter.js', func);
	});
});


/****************************
 ****************************
 ****************************
 ******* QUICK SEARCH *******
 ****************************
 ****************************
 ****************************/

function	DrawSearchPanel() {
	var dropdown = dc('div');
	dropdown.className = 'dropdown';
	
	var quick = dropdown.appendChild(dc('div'));
	quick.className = 'quick';
	
	var form = quick.appendChild(dc('form'));

	QuickSearch = quick;
	var prev = jQuery.cookie('q');
	var search_input = form.appendChild(MakeInput({name: 'search', value: prev? prev: ''}));
	
	MakeAutoText(search_input, GLOBALS.lang=='EN'? 'search ...': 'rechercher ...');
	search_input.ondblclick = function(e) {
		LaunchSearch(this.value);
	};
	jQuery(form).append('<input value="" class="submit" type="submit" />');
	form.onsubmit = function(e) {
		LaunchSearch(search_input.value);
		return false;
	};
	
	var advsearch = dropdown.appendChild(dc('a'));
	advsearch.className = 'advsearchbt';
	advsearch.href = '/?r';
	return dropdown;
};

var QuickSearchResults = null;
var QuickSearch = null;

function	DrawSearchResult(list, searchtext) {

	var ul = dc('ul');
	for (var i=0; i<list.length; i++) {
		var item = list[i];
		var li = ul.appendChild(dc('li'));
		var a = li.appendChild(dc('a'));
		a.className = 'highlight'
		a.href = item.link;
		var t = searchtext? list[i].title.replace(searchtext, '<b>'+searchtext+'</b>'): list[i].title;
		a.innerHTML += '<span></span>'+t;
	}
	return ul;
};

function	DrawSearchResponse(list, total, searchtext) {
	var old = 0;
	var res = DrawSearchResult(list, searchtext);
	if (!QuickSearchResults) {
		if (!QuickSearch) {
			console.warn('missing QuickSearch');
			return ;
		}
		
		QuickSearchResults = dc('div');
		QuickSearchResults.className = 'results';
		if (list.length)
			QuickSearchResults.appendChild(res);
		QuickSearch.appendChild(QuickSearchResults);
	}
	else {
		old = jQuery(QuickSearchResults).height();
		jQuery(QuickSearchResults).empty();
		if (list.length)
			QuickSearchResults.appendChild(res);
	}

	if (total > 10) {
		tdhelp = dc('div');
		tdhelp.className = 'more';
		tdhelp.innerHTML += 'Affichage de '+list.length+' éléments sur '+total+' trouvés, ';
		var a = tdhelp.appendChild(dc('a'));
		a.href = '/?r='+escape(jQuery.cookie('q'));
		a.innerHTML += 'plus de résultats';
		QuickSearchResults.insertBefore(tdhelp, QuickSearchResults.firstChild);
	}
	else if (total == 0) {
		tdhelp = dc('div');
		tdhelp.className = 'noresult';
		tdhelp.innerHTML += 'Aucun résultat pour votre recherche, essayez la ';
		var a = tdhelp.appendChild(dc('a'));
		a.href = '/?r='+escape(jQuery.cookie('q'));
		a.innerHTML += 'recherche avancée';
		QuickSearchResults.insertBefore(tdhelp, QuickSearchResults.firstChild);
	}
	var closeButton = dc('a');
	closeButton.href = 'javascript:';
	closeButton.className = 'close';
	closeButton.innerHTML = 'Fermer';
	closeButton.onclick = function() {
		jQuery(QuickSearchResults).slideUp(function() {
			jQuery(QuickSearchResults).remove();
			QuickSearchResults = null;
		});
		return false;
	};
	QuickSearchResults.appendChild(closeButton);
	QuickSearchResults.style.height = '';
	var height = jQuery(QuickSearchResults).height();
	QuickSearchResults.style.height = old+'px';
	console.info('current: '+old+' to '+height);
	jQuery(QuickSearchResults).animate({height:height+'px'}, function() {
		QuickSearchResults.style.height = '';
	});
};

function	LaunchSearch(searchtext) {
	jQuery.cookie('q', searchtext);
	jQuery.ajax({
		url: '/?json&search='+escape(searchtext),
		dataType: 'json',
		success: function(json) {
			DrawSearchResponse(json.items, json.total, searchtext);
		}
	});
};

jQuery(function() {
	var req = ''+window.top.location.search;
	if (req.indexOf('?r')===0)
		return ;
	var search = jQuery('<div id="search"></div>');
	var menutd = search[0];
	if (!menutd)
		return ;
	jQuery('#menu').after(search);
	menutd.appendChild(DrawSearchPanel());
});


})();
