var pnews;
var lastNews = 0;
var lastCaptures = 0;
var CPosC;
var infoBulle;


function nextCaptures(){
	if(lastCaptures != pcaptures.length -1){
		lastCaptures++;
		displayItem(lastCaptures, pcaptures, document.getElementById('menu_captures').firstChild.getElementsByTagName('span'));
	}
}

function prevCaptures(){
	if(lastCaptures != 0){
		lastCaptures--;
		displayItem(lastCaptures, pcaptures, document.getElementById('menu_captures').firstChild.getElementsByTagName('span'));
	}
}

/*var velem;

function opacity_anim(elem, sens){
	velem = elem;
	opacity_anim_def((sens ? 0 : 10), sens);
}

function opacity_anim_def(n, sens){
	//alert(n / 10);
	velem.style.opacity = (n / 10);

	if(sens){
		if(n < 10){
			setTimeout('opacity_anim_def('+(++n)+', '+sens+')', 41);
		}
	}else{
		if(n > 0){
			setTimeout('opacity_anim_def('+(--n)+', '+sens+')', 41);
		}
	}
}*/

function displayItem(f, item, span){
	if(span.length == 2){
		if(f == 0){
			span[0].className = 'inactiv';
		}else{
			span[0].className = 'activ';
		}

		if(f == item.length -1){
			span[1].className = 'inactiv';
		}else{
			span[1].className = 'activ';
		}
	}

	for(n = 0; item.length > n; n++){
		if(n == f){
			//opacity_anim(item[n], 1);
			item[n].style.display = 'block';
		}else{
			//opacity_anim(item[n], 0);
			item[n].style.display = 'none';
		}
	}
}


function PosCursor(){
	this.target = document.getElementById('menu').getElementsByTagName('dl')[0];
}

PosCursor.prototype.setTime = function(){
	if(this.startPos < this.endPos){
		this.time = 1200 / (this.endPos - this.startPos);
		//this.time = 1000 / 30;
		this.dir = true;
	}else{
		this.time = 1200 / (this.startPos - this.endPos);
		//this.time = 1000 / 30;
		this.dir = false;
	}
}

PosCursor.prototype.move = function(){
	var glo = this;

	npix = 5;

	if(this.dir){
		if(this.startPos < this.endPos){
			if(this.startPos + npix > this.endPos){
				this.set(this.endPos);
			}else{
				this.set(this.startPos+=npix);
			}
		}
	}else{
		if(this.startPos > this.endPos){
			if(this.startPos - npix < this.endPos){
				this.set(this.endPos);
			}else{
				this.set(this.startPos-=npix);
			}
		}
	}

	this.timeout = setTimeout(function(){glo.move();}, this.time);
}

PosCursor.prototype.moveTo = function(new_pos){
	clearTimeout(this.timeout);
	this.startPos = this.curPos;
	this.endPos = parseInt(new_pos);
	this.setTime();
	this.move();
}

PosCursor.prototype.set = function(pos){
	this.target.style.backgroundPosition = pos+"px 20px";
	this.curPos = pos;
}

function menu_note_on(e){
	target = e ? e.target : event.srcElement;

	//alert(target.parentNode.offsetLeft);
	endPos = target.parentNode.offsetLeft + 40;
	CPosC.moveTo(endPos);

	target.parentNode.nextSibling.style.display = 'block';
}

function menu_note_off(e){
	target = e ? e.target : event.srcElement;
	target.parentNode.nextSibling.style.display = 'none';
}

function hasParent(node, nclass){
	while(1){
		if(!node.parentNode){
			return false;
		}

		node = node.parentNode;

		if(node == nclass){
			return true;
		}
	}
}

if(window.innerWidth)
	width = window.innerWidth;
else
	width = document.documentElement.clientWidth;

if(width > 995 && !_resize){
	document.write('<style type="text/css">body, .body{width: 920px; margin: auto;}</style>');
}

window.onload = function(){
	form = document.getElementById('form_capture');
	browser = document.getElementById('browser');
	resolution = document.getElementById('resolution');
	foot = document.getElementById('foot');
	privat = document.getElementById('privat');
	email = document.getElementById('form_email');
	hmenu = document.getElementById('menu');
	hcaptures = document.getElementById('captures');
	hanalyse = document.getElementById('analyse');

	if(hmenu){
		CPosC = new PosCursor();

		var dl = hmenu.getElementsByTagName('dl')[0];
		if(dl){
			dl.onmouseover = function(){
				dl.className = 'mouseover';
			}
	
			s_sel = document.getElementById('sel');
	
			if(s_sel){
				//var posLeft = (s_sel.offsetLeft - s_sel.parentNode.offsetLeft + 40);
				//alert(s_sel.offsetLeft+' '+s_sel.parentNode.offsetLeft);
				var posLeft = s_sel.offsetLeft + 40;
				//alert(posLeft);
	
				CPosC.set(posLeft);
	
				dl.onmouseout = function(e){
					relatedTarget = e ? e.relatedTarget : event.toElement;
					if(relatedTarget != dl && !hasParent(relatedTarget, dl)){
						CPosC.moveTo(posLeft);
					}
	
					dl.className = '';
				}
		
				alinks = dl.getElementsByTagName('a');
				for(n = 0; alinks.length > n; n++){
					alinks[n].onmouseover = menu_note_on;
					alinks[n].onmouseout = menu_note_off;
				}
			}
		}
	}

	if(hcaptures){
		pcaptures = hcaptures.getElementsByTagName('div');
		if(pcaptures.length > 1){
			div = document.createElement('h3', 'ok');
			div.id = 'menu_captures';
			div.className = 'menu_nav';
			span = document.createElement('span');
			span1 = document.createElement('span');
			span1.appendChild(document.createTextNode("\u25C4"));
			span1.onclick= prevCaptures;
			span2 = document.createElement('span');
			span2.appendChild(document.createTextNode("\u25BA"));
			span2.onclick= nextCaptures;
			span.appendChild(span1);
			span.appendChild(document.createTextNode(' | '));
			span.appendChild(span2);
			div.appendChild(span);

			hcaptures.appendChild(div);

			displayItem(lastCaptures, pcaptures, document.getElementById('menu_captures').firstChild.getElementsByTagName('span'));
		}
		
		for(n = 0; pcaptures.length > n; n++){
			lnk = document.createElement('a');
			if(pcaptures[n].id && pcaptures[n].getElementsByTagName('a').length){
				lnk.setAttribute('href', pcaptures[n].getElementsByTagName('a')[0].href);

				capture_id = /\d+$/.exec(pcaptures[n].id);
	
				img = document.createElement('img');
				img.setAttribute('src', _host+'data/'+capture_id+'-thumbnail.png');
				lnk.appendChild(img);
	
				ul = pcaptures[n].getElementsByTagName('ul')[0];
				pcaptures[n].insertBefore(lnk, ul);
			}
		}
	}
	
	if(hanalyse){
		onload_analyse();
	}


	if(form){
		form.onsubmit = function(){
			document.getElementsByName('ok')[0].value = "Patientez s.v.p.";
		}
 	}


 	if(privat){
		privat.onclick = function(event){
			if(privat.checked){
				email.style.display = '';
			}else{
				email.style.display = 'none';
			}
		}
		if(!privat.checked)
			email.style.display = 'none';
	}

	if(browser){
		browser.onchange = function(){
			name = browser.options[browser.selectedIndex].value;
			if(name == 'lx' || name == 'lk'){
				if(!resolution.disabled) resolution.disabled = true;
				if(!foot.disabled)       foot.disabled = true;
			}else{
				if(resolution.disabled)  resolution.disabled = false;
				if(foot.disabled)        foot.disabled = false;
			}
		}
	}
}

function display_http_info(plus, id_name){
	td = document.getElementById(id_name);
	if(td){
		if(td.style.display == '' || td.style.display == 'none'){
			plus.innerHTML = '&mdash;';
			plus.style.color = "#666";
			if(!document.all)
				td.style.display = 'table-row';
			else
				td.style.display = 'block';
		}else{
			plus.innerHTML = '+';
			plus.style.color = "#098A00";
			td.style.display = 'none';
		}
	}
}

function cap_zoom(div_img){
	if(div_img.className == 'zoom'){
		div_img.className = '';
		div_img.getElementsByTagName('div')[0].style.display = 'none';
		div_img.getElementsByTagName('img')[0].style.width = '250px';
		div_img.style.height = '';
	}else{
		div_img.className = 'zoom';
		div_img.getElementsByTagName('div')[0].style.display = 'block';
		div_img.getElementsByTagName('img')[0].style.width = 'auto';
		div_img.style.height = document.body.scrollHeight+'px';
	}
}

function display_p(espan){
	http_info = espan.parentNode.getElementsByTagName('p')[0];
	if(!http_info) return;
	if(http_info.style.display != 'block'){
		espan.firstChild.nodeValue = "\u2014";
		espan.style.color = "#666";
		http_info.style.display = 'block';
	}else{
		espan.firstChild.nodeValue = '+';
		espan.style.color = "#098A00";
		http_info.style.display = 'none';
	}
}











