$(document).ready(function() {

	cleanOtrou();
	 
});

function cleanOtrou(){
	for (i in oTrou){
		delete oTrou[i];
	}
}



function splashHome(flag){
	var PoisHome = new Array();
	
	
	
	oTrou(17,3,'');
	
	oTrou(26,0,'B');
	oTrou(27,0,'O');
	oTrou(28,0,'N');
	oTrou(29,0,'N');
	oTrou(30,0,'I');
	oTrou(31,0,'E');
	
	oTrou(32,0,'');
	
	oTrou(33,0,'C');
	oTrou(34,0,'O');
	oTrou(35,0,'L');
	oTrou(36,0,'I');
	oTrou(37,0,'N');
	
	
	oTrou(39,0,'');
	
	oTrou(45,7,'');
	oTrou(48,5,'');
	oTrou(54,2,'');
	oTrou(59,3,'');
	oTrou(65,4,'');
	oTrou(68,0,'');
	
	 
	 populate(0,0,15,25,PoisHome,flag,'splashHome');
	 
	 
}

function splashHead(flag){
	var PoisIn = new Array();
	
	
	/*for (i in oTrou){
		oTrou[i].type=0;
		oTrou[i].lettre='';
	}*/
	
	oTrou(0,0,'');
	oTrou(1,1,'');
	oTrou(8,0,'');
	oTrou(9,0,'');
	oTrou(11,0,'');
	oTrou(12,2,'');
	oTrou(15,6,'');
	oTrou(17,7,'');
	
	oTrou(25,1,'');
	
	oTrou(26,0,'B');
	oTrou(27,0,'O');
	oTrou(28,0,'N');
	oTrou(29,0,'N');
	oTrou(30,0,'I');
	oTrou(31,0,'E');
	
	oTrou(32,0,'');
	
	oTrou(33,0,'C');
	oTrou(34,0,'O');
	oTrou(35,0,'L');
	oTrou(36,0,'I');
	oTrou(37,0,'N');
	
	oTrou(51,4,'');
	
	oTrou(75,3,'');
	 
	 populate(0,0,3,25,PoisIn,flag,'banner');
		
}



//
function populate(x0,y0,lignes,colonnes,aObjet,flag,nomcible){
	var n=1;
	
	for(i=0;i<colonnes;i++){
		if(i==1 || i==(colonnes-1)){
			type=1;
		} else {
			type=0;
		}
		for(j=0;j<lignes;j++){
			
				nom='poi_'+i+'_'+j;
				
				//
				
				if(j==1 || j==(lignes-1)){
					type=1;
				} else {
					type=0;
				}
				
				probTrou=Math.random()*100;
				if(probTrou>90){
					type=Math.floor(Math.random()*8);
				}else if(probTrou>12){
					type=1;
				}
				
				lettre='';//''
				if(oTrou[n]){type=oTrou[n].type;}
				if(oTrou[n]){lettre=oTrou[n].lettre;}
			aObjet[n] = new dot(nom,type,lettre,nomcible);
			/*	aObjet[n] = new dot(nom,type,n,nomcible);*/
				if(flag=='yes'){
					setTimeout('$("#'+aObjet[n].name+' div").fadeTo(Math.random()*300,1)', Math.random()*60*n);
	
				} else {
					$("#"+aObjet[n].name+" div").fadeTo(0,1);
					
				}
				

				
			n+=1;
		}
					
	}
	
	/*if(nomcible=='splashHome'){
		initEnter();
	}*/
	
	
}




function changeType(newType){
	this.type=newType;
	this.elem.css({
		// ------------------------------------------------------------------------------------------------------------------------------------------------------------------- url à modifier
			'background':'url(http://www.bonniecolin.com/wp-content/themes/starkers-html5-bc/style/images/poi'+this.type+'.png) no-repeat'
	});
}



//obj

function dot(name,type,num,nomcible){
	//vars
	this.name=name;
	this.type=type;
	
	
	
	//meths
	this.changeType=changeType;
	
	
	//constr.

	
	$('#'+nomcible).append(
		'<div id="'+this.name+'">'+
		'<div>'+num+
		'</div>'+
		'</div>'
	);
	
	toto=$("#"+this.name);
	totoin=$("#"+this.name+" div");
	
	zecss={
		'float' : 'left',
		'margin':'7px 7px 0px 8px',
		'width':'25px',
		'height':'25px'
	};
	zecssin={
		"font-family": "'Josefin Sans', serif",
		'margin':'0px',
		'padding':'5px 0px 0px 7px',
		'font-weight':'regular',
		'font-size':'13px',
		'width':'25px',
		'height':'25px',
		'display':'none'
	};
	
	if(this.type==0){
		zecssin.background='none';
	} else {
		zecssin.background='url(http://www.bonniecolin.com/wp-content/themes/starkers-html5-bc/style/images/poi'+this.type+'.png) no-repeat';
	}
	
	toto.css(zecss);
	totoin.css(zecssin);
	
}

function oTrou(id, type, lettre) {
	return oTrou[id] = {
	id: id,
	type: type,
	lettre: lettre
	}
}
