var position = 0;
var selectedId = "pict_1";
function defilDiapo( diapoDivId, index, url, params, htmlId )
{
	linkId = "pict_" + index;
	if( linkId != selectedId )
	{
		to = 285 * ( index - 1 );
		if( url != undefined && params != undefined && htmlId != undefined )
			new Effect.ScrollHorizontal( diapoDivId, {from: position, to: to, duration:1, transition: Effect.Transitions.exponential, beforeStart: function(){/*$(htmlId).innerHTML = '';*/}, afterFinish: function(){ajaxUpdater(url, params, htmlId, 'get', false)} });
		else
			new Effect.ScrollHorizontal( diapoDivId, {from: position, to: to, duration:1, transition: Effect.Transitions.exponential });
		if( $( selectedId )!= undefined )
		{
			str = $( selectedId ).className;
			$( selectedId ).className = str.replace(/selected/i, "");
		}
		
		if( $( linkId ) != undefined )
			$( linkId ).className += ( $( linkId ).className == "" ) ? "selected": " selected";
			
		position = to;
		selectedId = linkId;
	}
}
function returnPictPos(way)
{
	c = 1;
	while($('pict_'+c) != undefined)
	{
		last = c;
		c++;
	}
	currentPic = ( Math.round( position / 285 ) + 1 );
	switch(way)
	{
		case "next" :
		default:
			if( currentPic < last )
				$('pict_'+(currentPic + 1)).onclick();
			break;
		case "previous" :
			if( currentPic > 1 )
				$('pict_'+(currentPic - 1)).onclick();
			break;
	}
}

var ResFormOpened = false;
var ResFormClickEnable = true;
function displayResForm()
{
	if(ResFormClickEnable == true)
	{
		switch(ResFormOpened)
		{
			case false :
				ResFormOpened = true; 
				Effect.SlideDown('formRes',{duration:1.0, beforeStart: function() {ResFormClickEnable=false}, afterFinish: function() {ResFormClickEnable=true} });
				break;
			case true : 
				ResFormOpened = false;
				Effect.SlideUp('formRes',{duration:1.0, beforeStart: function() {ResFormClickEnable=false}, afterFinish: function() {ResFormClickEnable=true}});
				break;
		}
	}
}

function defilNews( diapoDivId, index )
{
	linkId = "pict_" + index;
	to = 390 * ( index - 1 );
	new Effect.ScrollVertical( diapoDivId, {from: position, to: to, duration:1, transition: Effect.Transitions.exponential});
	if( $( selectedId )!= undefined )
	{
		str = $( selectedId ).className;
		$( selectedId ).className = str.replace(/selected/i, "");
	}
	
	if( $( linkId ) != undefined )
		$( linkId ).className += ( $( linkId ).className == "" ) ? "selected": " selected";
		
	position = to;
	selectedId = linkId;
}

function defilNewsArrows( way )
{
	c = 1;
	while( $( 'pict_' + c ) != undefined )
	{
		last = c;
		c++;
	}
	page = ( Math.round( position / 390 ) + 1 );
	switch( way )
	{
		case "next" :
		default:
			if( page < last )
				defilNews( 'newsDiapoHandle', page + 1 );
			break;
		case "previous" :
			if( page > 1 )
				defilNews( 'newsDiapoHandle', page - 1 );
			break;
	}
}

function ajaxUpdater(url, params, htmlId, method, reload)
{
	if( reload == true || reload == undefined )
	{
		position = 0;
		selectedId = "pict_1";
	}
	if( method == undefined ) method = "get";
	var request = new Ajax.Updater( htmlId, url, { method: method, parameters: params, evalScripts: true } ); 
}

var tooltipsLabels = new Array();
var mouse_x, mouse_y;
var timeout_tooltip;
var tooltip;
function initTooltip()
{
	if ( navigator.appName.substr(0,2) != "Mi" ) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = setMousePosition;
	tooltip = Builder.node('div', {'id': 'tooltip', 'style': 'display:none;'});
	$('pagecontener').appendChild(tooltip);
}
function addTooltip(e, text)
{
	if(navigator.appName.substr(0,2) == "Mi")
	{
		e.attachEvent("onmouseover", function(event){displayTooltip(event.toElement.parentNode.parentNode.getAttribute("id"));});
		e.attachEvent("onmouseout", function(event){hideTooltip();});
	}
	else
	{
		e.addEventListener("mouseover", function(event){displayTooltip(this.id)}, false);
		e.addEventListener("mouseout", hideTooltip, false);
	}
	tooltipsLabels[e.getAttribute("id")] = text;
}
function displayTooltip(id)
{
	timeout_tooltip = setInterval("changePosition()", 20);
	tooltip.style.display = "block";
	tooltip.innerHTML = tooltipsLabels[id];
}
function hideTooltip(e)
{
	clearInterval(timeout_tooltip);
	tooltip.style.display = "none";
	tooltip.innerHTML = "";
}
function changePosition () 
{
	tooltip.style.left = mouse_x - 10 + "px";
	tooltip.style.top = mouse_y + 25 + "px";
}
function setMousePosition(e)
{
	if ( navigator.appName.substr(0,2) == "Mi" ) 
	{
		mouse_x = event.clientX;
		mouse_y = event.clientY;
	}
	else
	{
		mouse_x = e.pageX;
		mouse_y = e.pageY;
	}
}