window.addEvent('domready', function()
{
	album_onload();
	//var ttip = new TipsX3($$('.user_name'), {});
	//var ttip = new TipsX3($$('.ttip'), {});
	var ttip1 = new TipsX3($$('.user_mail'), { className: 'ttip', offsets: {'x': 15, 'y': 10} });
	var ttip2 = new TipsX3($$('.min_menu_icon'), { className: 'ttip', offsets: {'x': 15, 'y': 10} });
	var ttip3 = new TipsX3($$('a'), { className: 'ttip', offsets: {'x': 15, 'y': 10} });
	var ttip4 = new TipsX3($$('img'), { className: 'ttip', offsets: {'x': 15, 'y': 10} });
	var ttip5 = new TipsX3($$('.menu_side_mini'), { className: 'ttip', offsets: {'x': 15, 'y': 10} });
	combobox();
	autocompleter_country();
});


function toggle_checkbox(chkbox)
{
	chkbox.checked = !chkbox.checked;
}

function toggle_div(div)
{
	var dv = $(div);
	if (dv)
	{
		var myFx = new Fx.Slide(dv);
		//myFx.cancel();
		myFx.toggle();
	}
}

function toggle_div_vis(div)
{
	var dv = $(div);
	if (dv)
	{
		if (dv.style.visibility == 'visible')
		{
			dv.style.visibility = 'hidden';
			dv.style.position = 'absolute';
		}
		else
		{
			dv.style.position = 'relative';
			dv.style.visibility = 'visible';
		}
	}
}

function popup_wait()
{
	var divw = $('popup_wait');
	if (divw)
	{
		var winSize = $(window).getSize();
		var winScroll = $(window).getScroll();
		var divSize = divw.getSize();
		var posx =  winScroll.x + winSize.x / 2 - divSize.x / 2;
		var posy =  winScroll.y + winSize.y / 2 - divSize.y / 2 - 100;
		divw.style.left = posx + "px";
		divw.style.top = posy + "px";
		divw.style.visibility = 'visible';
	}
}

function blink_hover(hover, id)
{
	var nam = $('blink_'+id);
	if (nam)
	{
		if (hover)
		{
			nam.set('morph', {duration: 'long', transition: 'elastic:out'});
			nam.morph('a.blink_hover');
		}
		else
		{
			nam.set('morph', {duration: 'long', transition: 'elastic:out'});	
			nam.morph('a.blink');
		}
	}
}

function blinkh_hover(hover, id)
{
	var nam = $('blinkh_'+id);
	if (nam)
	{
		if (hover)
		{
			//nam.set('morph', {duration: 'short', transition: 'bounce:out'});
			//nam.morph('div.blinkh_hover');
			nam.className = 'blinkh_hover';
		}
		else
		{
			//nam.set('morph', {duration: 'normal', transition: 'bounce:out'});	
			//nam.morph('div.blinkh');
			nam.className = 'blinkh';
		}
	}
}

function combobox()
{
    $$('.combobox').each(function(el)
			 {
			     new n2Select(el, {
				     onChange: function (value) {
					 var base = window.location.href.split('/')[3];
					 var aid = $('picture_add').options[$('picture_add').selectedIndex].value;
					 $('picture_add_link').href='/'+base+'/picture_add/id='+aid;
				     }
			     }); });
}

function bot_status(text)
{
	var dv = $('mnu_bot_status');
	if (dv) dv.set('html', text);
}

function cmt_bar(shown, text)
{
	var dv = $('cmt_bar');
	if (dv)
	{
		if (shown)
		{
			if (text == "")
				dv.set('html', 'Aucun Commentaire');
			else
				dv.set('html', text);
			dv.fade('hide'); dv.fade(0.92);
		}
 		else dv.fade(0);
	}
}

function star_rating(base, el, id, js)
{
	var myStyles = ['nostar', 'onestar', 'twostar', 'threestar', 'fourstar', 'fivestar', 'sixstar', 'sevenstar', 'eightstar', 'ninestar', 'tenstar'];
	myStyles.each(function(myStyle)
	{
		//if (el.getParent().hasClass(myStyle))
		//	el.getParent().removeClass(myStyle);
		//if ($(el.parent).hasClass(myStyle))
		//	$(el.parent).removeClass(myStyle);
	});
	myStyles.each(function(myStyle, index)
	{
		var val = el.id.substr(0, 1);
		var id = el.id.substr(2);
		if (index == val)
		{
			//el.getParent().toggleClass(myStyle);
			//$(el.parent).toggleClass(myStyle);
			var url = "/" + base + "/ajax/ajax=" + js + "&val=" + val + "&id=" + id;
			ajax_request($(js+"_"+id), url);
		}
	});
}

function ajax_request(dst, url)
{
	var req = new Request.HTML({
		method: 'get',
		url: url,
		data: { 'do' : '1' },
		update: dst,
		onRequest: function()
		{
			//alert('Request made. Please wait...');
			dst.set('html', "<img src='/img/ratings-loading.gif'/>");
		},
		onFailure: function()
		{
			dst.set('html', "Internal ERROR");
		},
		onComplete: function(txt)
		{
			//alert('Request completed successfully.');
			//dst.setStyle('background','#fffea1');
		}
	}).send();
}

function ajax_command(url)
{
	var req = new Request.HTML({
		method: 'get',
		url: url,
		data: { 'do' : '1' }
	}).send();
}

function form_clean(input)
{
	var inp = $(input);
	inp.value = inp.value.replace(/^\.+|\/|\\|\s|<|>|'|"|=|&|\$|\?|\%|{|}|\!|:|\*/g, '');
}

function div_hover_size(hover, id)
{
	var dv = $('divhs_'+id);
	if (dv)
	{
		if (dv.style.width == 0) dv.style.width = '225px';
		dv.set('tween', {duration: 'long', transition: 'elastic:out'});	
		if (hover)
		{
			dv.tween('width', dv.style.width, '240');
	
		}
		else
		{
			dv.tween('width', dv.style.width, '225');
		}
	}
}

function txtbox_focus(id, focused)
{
	var tb = $('txtbox_'+id);
	if (tb)
	{
		if (tb.style.width == 0) tb.style.width = '70px';
		tb.set('tween', {duration: 'normal', transition: 'expo:out'});	
		if (focused)
		{
			if (tb.value == ' ( email )') tb.value = '';
			tb.select();
			tb.tween('width', tb.style.width, '270');
		}
		else
		{
			if (tb.value == '') tb.value = ' ( email )';
			tb.tween('width', tb.style.width, '70');
		}
	}
}

function messenger(base, uid)
{
	Shadowbox.open({
		player:		'iframe',
		content:	'/'+base+'/messenger/uid='+uid,
		width:		530,
		height:		210
	});
}

function forum_reply(mid)
{
	
	var dv = $('forum_reply_'+mid);
	if (dv)
	{
		toggle_div_vis(dv);
		if (dv.style.visibility == 'visible')
		{
			var txt = $('forum_reply_txt_'+mid);
			if (txt) txt.focus();
		}
	}
}

function add_to_fav()
{
	if (navigator.appName != 'Microsoft Internet Explorer')
		window.sidebar.addPanel("WeeboW", "http://www.weebow.org", "");
	else
		window.external.AddFavorite("http://www.weebow.org", "WeeboW");
}

function menu_top_status_hide()
{
	var s = $('menu-top-status');
	if (s) s.style.visibility = 'hidden';
}

function popup_vote()
{
	var sizx=560;
	var sizy=300;
	var posx=(screen.width-sizx)/2;
	var posy=(screen.height-sizy)/2;
	//window.open('http://www.meilleurduweb.com/rubriques/votepour.php?ref=224198','Votez !','resizable=no, location=no, width='+sizx+', height='+sizy+', menubar=no, status=no, left='+posx+', top='+posy);
	window.open('http://www.meilleurduweb.com/rubriques/votepour.php?ref=224198','Votez !','resizable=no, directories=no, location=no, width='+sizx+', height='+sizy+', menubar=no, status=no, left='+posx+', top='+posy);
}

/*
function popup_vote()
{
	Shadowbox.open({
		player:		'iframe',
		content:	'http://www.meilleurduweb.com/rubriques/votepour.php?ref=224198',
		width:		560,
		height:		300
	});
}
*/
