novUtils.addEvent(window,'load',caracInit);

function caracInit() {
	initImprimer();
	initFavoris();
	initPanno();
	initDesc();
	initBlocRubrique();
}



/*******************/
/* initImprimer */
/*******************/
function initImprimer() {
	var ltie7 = navigator.appName;
	if(novUtils.$('impression'))
	{
		novUtils.$('impression').style['display'] = "block";
		novUtils.$('impression').onclick=function(){
				window.print();
			};
	}
	return false;
}

/***************/
/* initFavoris */
/***************/
function initFavoris() {
	if (window.ActiveXObject) {
		if(novUtils.$('ajoutFavoris')){
			novUtils.$('ajoutFavoris').style['display'] = "block";
			novUtils.$('ajoutFavoris').style['cursor'] = "pointer";
			novUtils.$('ajoutFavoris').onclick=function(){	
				window.external.AddFavorite(location.href,document.title);
			}
		}
	}
	return false;	
}

/***************/
/* initPanno */
/***************/
function initPanno() {
	var pannoViewer=novUtils.getElementsByClassName('viewPanno','div');
	var pannoViewerTmp=novUtils.getElementsByClassName('viewPanno','span');
	if(pannoViewerTmp.length>0)
		pannoViewer = pannoViewer.concat(pannoViewerTmp);
	
	var pannoViewerLength=pannoViewer.length;	
	for(var i=0; i<pannoViewerLength; i++){
		idDivPanno=pannoViewer[i].getAttribute('rel');
		novUtils.$(idDivPanno).style['display'] = "none";
		pannoViewer[i].onmouseover = function(e){ 
			this.style['textDecoration']='underline'; 
			this.style['color']='#4B7284';
			this.style['cursor']='pointer';

			//pointeur de fonction
			document.onmousemove = get_mouse;
			return false;
		}
		pannoViewer[i].onmouseout = function(){ 
			this.style['textDecoration']=''; 
			this.style['color']='';
			this.style['cursor']='pointer';
			novUtils.$(this.getAttribute('rel')).style['display'] = "none";
			document.onmousemove = null;
			return false;
		}			
	}
}
	
function get_mouse(e) {
	var idRef = novUtils.getEvtTarget(e).getAttribute('rel');	
	if (idRef!=null){
		
		var x = (window.ActiveXObject) ? (event.x)  : e.pageX ;
		var y = (window.ActiveXObject) ? (event.y)  : e.pageY ;
		if(!(window.ActiveXObject))
		{
			x=parseInt(x)-parseInt(novUtils.getLeft(novUtils.$("idFor_"+idRef)))+20;
			y=parseInt(y)-parseInt(novUtils.getTop(novUtils.$("idFor_"+idRef)))-40;
		}
		else
		{
			x=parseInt(x)+20;
			y=parseInt(y)-40;			
		}
		//redéfini le style du div à afficher
		novUtils.$(idRef).style['left'] = x+"px";
		novUtils.$(idRef).style['top'] = y+"px";
		novUtils.$(idRef).style['display'] = "block";
		novUtils.$(idRef).style['position'] = "absolute";
		novUtils.$(idRef).style['border'] = "1px solid #528EA5";
		novUtils.$(idRef).style['background'] = "#E7EBF7";
		novUtils.$(idRef).style['width'] = "200px";
		novUtils.$(idRef).style['padding'] = "5px";		
		novUtils.$(idRef).style['textDecoration'] = "none";	
		novUtils.$(idRef).style['zIndex'] = "10";	
		novUtils.$(idRef).style['zoom'] = "1";
	}
}

/***************/
/* initDesc */
/***************/
function initDesc() {
	var descViewer=novUtils.getElementsByClassName('viewDesc','span');
	var descViewerLength=descViewer.length;	
	for(var i=0; i<descViewerLength; i++){
		idDivPanno=descViewer[i].getAttribute('rel');
		novUtils.$(idDivPanno).style['display'] = "none";
		descViewer[i].onmouseover = function(e){ 
			this.style['textDecoration']='underline'; 
			this.style['color']='#4B7284';
			this.style['cursor']='pointer';

			//pointeur de fonction
			document.onmousemove = get_mouseDesc;
			return false;
		}
		descViewer[i].onmouseout = function(){ 
			this.style['textDecoration']=''; 
			this.style['color']='';
			this.style['cursor']='pointer';
			novUtils.$(this.getAttribute('rel')).style['display'] = "none";
			document.onmousemove = null;
			return false;
		}			
	}
}
	
function get_mouseDesc(e) {
	var idRef = novUtils.getEvtTarget(e).getAttribute('rel');	
	if (idRef!=null){
		
		var x = (window.ActiveXObject) ? (event.x)  : e.pageX ;
		var y = (window.ActiveXObject) ? (event.y)  : e.pageY ;
		if(!(window.ActiveXObject))
		{
			x=parseInt(x)-parseInt(novUtils.getLeft(novUtils.$("idFor_"+idRef)))+20;
			y=parseInt(y)-parseInt(novUtils.getTop(novUtils.$("idFor_"+idRef)))+120;
		}
		else
		{
			x=parseInt(x)-120;
			y=parseInt(y)+20;			
		}
		//redéfini le style du div à afficher
		novUtils.$(idRef).style['left'] = x+"px";
		novUtils.$(idRef).style['top'] = y+"px";
		novUtils.$(idRef).style['display'] = "block";
		novUtils.$(idRef).style['position'] = "absolute";
		novUtils.$(idRef).style['border'] = "1px solid #528EA5";
		novUtils.$(idRef).style['background'] = "#E7EBF7";
		novUtils.$(idRef).style['width'] = "400px";
		novUtils.$(idRef).style['padding'] = "5px";		
		novUtils.$(idRef).style['textDecoration'] = "none";	
		novUtils.$(idRef).style['zIndex'] = "10";	
		novUtils.$(idRef).style['zoom'] = "1";
	}
}


/* doc : http://qualitew.novactive.com/index.php/Adjustheight */ 
function adjustheight(my_array, limit, offset) {
	if (!offset  || offset < 1) offset = 0;
	if (limit < 1) limit = my_array.length;
	if (!my_array[0] || offset > (limit-1))
		return;
	//nb de lignes
	var rows = Math.ceil(my_array.length/limit);
	
//	console.log(offset);
//	console.log(limit);
//	console.log(rows);
	
	for (var i=0; i<rows; i++)
	{
//		console.log('ligne');
		var index = (limit * i);
		var rowmaxheight=0;
		
		if (index+limit-offset < my_array.length) {var portee = index+limit-offset; }
		else var portee = my_array.length;
		
		if (i==0) var depart = 0;
		else var depart = index-offset;
		
//		console.log(depart)
//		console.log(portee);
		
//		console.log("premier for");
		for (var j=depart; j<portee; j++)
		{
			if (my_array[j].offsetHeight > rowmaxheight) rowmaxheight = my_array[j].offsetHeight;
			if (j%2 == 1)
			{
				navigator.appName == 'Microsoft Internet Explorer' ? my_array[j].style.height = my_array[j-1].style.height = rowmaxheight : my_array[j].style.minHeight  = my_array[j-1].style.height= rowmaxheight + 25 + "px";
				rowmaxheight = 0;
			}
		}
//		for (var j=depart; j<portee; j++)
//		{	
//			// 20 px de rajouter pour decaler l'image en savoir plus 
//			var temp = rowmaxheight +20 + "px";
//		
//			navigator.appName == 'Microsoft Internet Explorer' ? my_array[j].style.height = temp : my_array[j].style.minHeight = temp;
//		}
	}
}


/*********************/
/* initBlocRubrique */
/*********************/
function initBlocRubrique() {
	var arrayEpargne = novUtils.getElementsByClassName('autoheight','div');
	if (arrayEpargne[0]) {
		
		adjustheight(arrayEpargne,2);
	}
}