var tempX = 0
var tempY = 0

function infobull(id_info,text_info,titre_info,link_info) {
	document.write('<a ');
	if(link_info)document.write(' href="'+link_info+'" ');
	document.write('onMouseOver = "javascript:showTip(\''+id_info+'\');" onMouseOut = "javascript:hideTip(\''+id_info+'\');">'+titre_info+'</a>');
	
	document.write('<div style="box-shadow: 0 0 10px #888;width:400px;padding:10px;border-radius:10px;border:1px solid;position: absolute;background-color:#'+c09+';visibility: hidden;z-index:9999'+id_info+';" id="'+id_info+'">');
	document.write(text_info);
	document.write('</div>');
	
	
}
function showTip(id){
	obj = document.getElementById(id);
	XX=((tempX+400)>document.body.offsetWidth)?document.body.offsetWidth-420:tempX;
	XX=((tempX+400)>document.body.offsetWidth)?document.body.offsetWidth-420:tempX;
	obj.style.left = XX;
	obj.style.top = tempY+15;
	obj.style.zIndex = 1500;
	obj.style.display = "none";
	obj.style.visibility = "visible";
	$('#'+id).fadeIn('fast');

}
function hideTip(id){
	document.getElementById(id).style.visibility = "hidden";
}
function hid(form){var i=0;
while(document[form].elements[i]){document[form].elements[i].style.visibility='hidden';i++;}
}

function style(theme_bgcolor,theme_textcolor,theme_bordercolor,theme_linkcolor,theme_textbtcolor,theme_bgbtcolor,theme_c1color,theme_c2color,theme_c1textcolor,theme_c2textcolor){
document.write('<style type="text/css">');
document.write('body{background-color:#'+theme_bgcolor+';font-family:"Arial", sans-serif;color:#'+theme_textcolor+';margin:0px;border:0px none;padding:0px;font-size:4mm;}');
document.write('table{border-collapse:collapse;font-size:4mm;border-color:#'+theme_bordercolor+';}');
document.write('td{border-color:#'+theme_bordercolor+';text-align:center;padding:5px;}a{text-decoration:none;}a:link{color:#'+theme_linkcolor+'; text-decoration:none;}a:active{color:#'+theme_linkcolor+'; text-decoration:none;}a:visited{color:#'+theme_linkcolor+'; text-decoration:none;}a:hover{color:#'+theme_textbtcolor+';}input{color:#'+theme_textbtcolor+';font-family:"Arial", sans-serif;border-style:solid;background-color:#'+theme_bgbtcolor+';border-width:1px;}');
document.write('.tr1{background-color:#'+theme_c2color+';color:#'+theme_c1textcolor+';}.tr2{background-color:#'+theme_c1color+';color:#'+theme_c2textcolor+';}');
document.write('select,textarea{color:#'+theme_textbtcolor+';border-style:solid;border-width:1px;font-family:Arial;background-color :#'+theme_bgbtcolor+';}');
document.write('.quote,.code{text-align:left;font-size:12px;color:#'+theme_c2textcolor+';line-height:125%;background-color:#'+theme_c2color+';border-style:solid;border-left-width:1px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px}');
document.write('.infobulle_div{position:absolute;visibility:hidden;z-index:1001;}.infobulle_table{border:1px solid #'+theme_bordercolor+';background-color :#'+theme_bgbtcolor+';width:400px;}');
document.write('.checkbox{background-color:transparent;border-style:none;}');
document.write('.cl1{background-color:'+theme_c2color+';margin-top:10px;}');
document.write('p{margin:0px;}');
 
document.write('</style>');
}

function light_on(id){
	topic_row_style=document.getElementById(id);
	topic_row_style.style.background="#"+c03;
	topic_row_style.style.cursor='pointer';
}

function light_off(id){
	topic_row_style=document.getElementById(id);
	topic_row_style.style.background='transparent';
	topic_row_style.style.cursor='default';
}

function checkAllBoxes(id){var i=0;while(document[id].elements[i]){if (document[id].elements[i].name!="action_type"){document[id].elements[i].checked=1;}i++;}}
function uncheckAllBoxes(id){var j=0;while(document[id].elements[j]){if (document[id].elements[j].name!="action_type"){document[id].elements[j].checked=0;}j++;}}
function negateChoice(id){var k=0;while(document[id].elements[k]){if (document[id].elements[k].name!="action_type"){if(document[id].elements[k].checked == 1){document[id].elements[k].checked=0;}else{document[id].elements[k].checked=1;}}k++;}}

function select_switch(status){for(i=0;i<document.privmsg_list.length;i++){document.privmsg_list.elements[i].checked=status;}}

function zlitons(z){document.getElementById('user_zlitons').innerHTML=z;}

function show_hide_all(prefix,id){
	var i=0;
	var obj;
	while(obj=document.getElementById(prefix+"_"+i)){
		if(i==id){
			show_hide(prefix,id);
		}else{
			obj.style.visibility='hidden';
			obj.style.display='none';
		}
		i++;
	}
}

function show_hide(prefix,id){
	var obj=document.getElementById(prefix+"_"+id);
	if(obj.style.visibility=='hidden'){
		obj.style.visibility='visible';
		obj.style.display='';
	} else {
		obj.style.visibility='hidden';
		obj.style.display='none';
	}
	return true;
}

function flash_object(value,width,height){
	document.write('<OBJECT classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" WIDTH="'+width+'" HEIGHT="'+height+'">');
	document.write('<PARAM NAME=movie VALUE="includes/object/'+value+'">');
	document.write('<PARAM name=menu value=false>');
	document.write('<PARAM NAME=quality VALUE=high>');
	document.write('<PARAM NAME=wmode VALUE=transparent>');
	document.write('<PARAM NAME=bgcolor VALUE=#FFFFFF>');
	document.write('<EMBED src="includes/object/'+value+'" quality=high wmode=transparent bgcolor=#FFFFFF WIDTH="'+width+'" HEIGHT="'+height+'" NAME="martien" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>');
}

function flash_object1(value,width,height){
	document.write('<OBJECT classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" WIDTH="'+width+'" HEIGHT="'+height+'">');
	document.write('<PARAM NAME=movie VALUE="'+value+'">');
	document.write('<PARAM name=menu value=false>');
	document.write('<PARAM NAME=quality VALUE=high>');
	document.write('<PARAM NAME=wmode VALUE=transparent>');
	document.write('<PARAM NAME=bgcolor VALUE=#FFFFFF>');
	document.write('<EMBED src="'+value+'" quality=high wmode=transparent bgcolor=#FFFFFF WIDTH="'+width+'" HEIGHT="'+height+'" NAME="martien" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>');
}

function remplace(var1, var2, id) {
	reg0 = new RegExp( "([^0-9a-zA-Z]{1})"+var1+"([^0-9a-zA-Z]{1})" , "gi");
	reg1 = new RegExp( '<a id="?' + id + '"? [^>]+>' + var1 + '</a>', "gi");
	var message = '.'+parent.document.post.message.value+'.';
	var message2 = parent.document.getElementById('correction').innerHTML;
	message = message.replace(reg0, '$1'+var2+"$2" );
	message = message.replace(reg0, '$1'+var2+"$2" );
	message2 = message2.replace(reg1, var2 );
	parent.document.post.message.value = message.substring(1,message.length-1);
	parent.document.getElementById("correction").innerHTML = message2;
	document.getElementById("resultats").innerHTML = '<p align="center">Cliquez sur un mot mal orthographié</p>';
}

function footer(l_online_users,registered_users){
	document.write('<br><br><div style="box-shadow: 0 0 10px #666;position:fixed;bottom:0px;width:100%;text-align:center;border-top:1px solid #'+c13+';background-color:#'+c04+';"><table align="center" width="975" cellpadding="0" cellspacing="0" border="0" style="border:0px;"><tr><td style="font-size:11px;text-align:left;padding:3px;"> <b>'+l_online_users+'</b>: ');
	for(var i = 0; i < online_userlist.length; i++) {
		document.write('<div style="box-shadow: 0 0 10px #888;text-align:center;padding:10px;border:1px solid;border-radius:10px;position: fixed;background-color:#'+c09+';bottom:30px;visibility: hidden;z-index:9999'+online_userlist[i][0]+';" id="u'+online_userlist[i][0]+'">');
	
		document.write('<b>'+online_userlist[i][1]+'</b><br><font style="font-size:12px;">'+online_userlist[i][3]+'</font>');
		if (online_userlist[i][2]) document.write('<br><img src="images/avatars/'+online_userlist[i][2]+'">');

		document.write('</div><a href="membres.php?id='+online_userlist[i][0]+'" onMouseOver = "javascript:showTipu(\'u'+online_userlist[i][0]+'\');" onMouseOut = "javascript:hideTip(\'u'+online_userlist[i][0]+'\');">'+online_userlist[i][1]+'</a>, ');
	}

	document.write( registered_users+'</td></tr></table></div>');
}
function showTipu(id){

	obj = document.getElementById(id);
	XX=((tempX+160)>document.body.offsetWidth)?document.body.offsetWidth-180:tempX;
	obj.style.left = XX;
	obj.style.top = tempY-220;
	obj.style.display = "none";
	obj.style.visibility = "visible";
	$('#'+id).fadeIn('fast');
}

	function open_popup(purl,pname,pwidth,pheight){
		testwindow = window.open(purl, pname, 'HEIGHT='+pheight+',resizable=yes,WIDTH='+pwidth+',scrollbars=yes');
	}
	
function submitenter(myform,e){
	var keycode;
	if(window.event) {
		keycode=window.event.keyCode;
	} else if(e) {
		keycode=e.which;
	} else {
		return true;
	}

	if(keycode==13) {
		document[myform].submit();
		return false;
	} else {
		return true;
	}
}




var sun=0;
var thisnextsun=1;
function nextsun() {
	sun+=thisnextsun;
	if ( sun == 14 ) thisnextsun = -1;
	if ( sun == 0 ) thisnextsun = 1;
	$('#sun').css('background-position', "-"+(sun*90)+"px 0px");

}


function startnuage1() {
	$('#nuage1').css('top', (Math.floor(Math.random()*100))+"px");
	$('#nuage1').animate({
		left: '+='+$(document).width()
	  }, 17000, 'linear', function() {
		$('#nuage1').css('left', "-100px");
		startnuage1();
	});
}

function startnuage2() {
	$('#nuage2').css('top', (Math.floor(Math.random()*80))+"px");
	$('#nuage2').animate({
		left: '+='+$(document).width()
	  }, 13000, 'linear', function() {
		$('#nuage2').css('left', "-100px");
		startnuage1();
	});
}


function downmenus() {
	$('.menuu1items')
	.stop()
	.css('margin-top','-5px')
	.css('opacity','0')
	.animate({marginTop: '+=10px', opacity:1}, 100, 'linear');
}

function zloeuf(ident, key) {

	$.ajax({
	  url: 'eggtrophy.php',
	  type: "POST",
      data: {"id":ident, "k":key},
	  dataType: "json",
	  success: function(data){
		alert(data.message);
		$('#zloeuf'+ident).css('display', 'none');
	  }
	});

	
	
}

function killzlimoucham(key) {
	$('#zlimouchamimg').attr('src', "http://games.zliton.com/images/trophies/1/zlimoucham-dead.png");
	$('#zlimoucham').stop();
	$.ajax({
	  url: 'zlimoucham.php',
	  type: "POST",
      data: {"k":key},
	  dataType: "json",
	  success: function(data){
		
	  }
	});
}

function zlimouchamove() {

	var size = Math.round(Math.random()*32)+32;
	
	$('#zlimoucham').animate({
		top: Math.round(Math.random()*250)+50+'px',
		marginLeft: Math.round(Math.random()*600)-300+'px',
		width: size+'px',
		height: size+'px',
	}, 1000+Math.round(Math.random()*400), function() {
		zlimouchamove();
	});

}

$(document).ready(function() {
	$('#nuage2').css('left', Math.floor(Math.random()*$(document).width())+"px");
	startnuage2();
	$('#nuage1').css('left', Math.floor(Math.random()*$(document).width())+"px");
	startnuage1();
	setInterval("nextsun()", 100);
	$(document).mousemove(function(e){
		tempX = e.pageX;
		tempY = e.pageY;
		if (tempX < 0){tempX = 0}
		if (tempY < 0){tempY = 0}  
	}); 
	
	$('.menuu1items').mouseenter(function() {
		$(this).css('background-color', '#'+c04);
	});
	
	$('.menuu1items').mouseleave(function() {
		$(this).css('background-color', '#'+c03);
	});
	
	$('#startmenu').mouseenter(function() {
		$('#menuu1').css('display','');
		$('#menuu2').css('display','none');
		downmenus();
	});
	
	$('#startmenu2').mouseenter(function() {
		$('#menuu2').css('display','');
		$('#menuu1').css('display','none');
		downmenus();
	});
	
	$('#menuu1').mouseleave(function() {
		$('#menuu1').css('display','none');
	});
	
	$('#menuu2').mouseleave(function() {
		$('#menuu2').css('display','none');
	});
	zlimouchamove();
});
