// JavaScript Document


/////////////////////////////////////////////////////////////////////////////////////////////
NL = '\n';
/////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////
PROTO_SliderNews = function( xObj, W, N ){
	//////////////////////////////////// 
	this.Step = 1;
	this.Delay = 25
	this.Obj = xObj;
	this.W = W;
	this.N = N;
	this.NW = Math.ceil(W/N);
	this.scrollLeft = 0;
	//////////////////////////////////// 
	this.Main = {tag:document.getElementById(this.Obj), style:getDivStyle(this.Obj)};
	this.Main.style = (this.NW*N)+'px';
	this.Container = {tag:document.getElementById(this.Obj+'Container'), style:getDivStyle(this.Obj+'Container')};
	this.Items = new Array();
	//////////////////////////////////// 
	AJAXconn( this, '../App_Ajax/dynamic.php?limit=10', 'POST' );
	//////////////////////////////////// 
}
/////////////////////////////////////////////////////////////////////////////////////////////
PROTO_SliderNews.prototype.RequestStep = function(){
	///////////////////////////////
	if( this.XMLHTTP.readyState==4 ){
		///////////////////////////////
		var errorMsg = '';
		///////////////////////////////
		try {
			///////////////////////////////
			var StrItems = this.XMLHTTP.responseText.split(NL);
			//////////////////////////////////// 
			for( var i=0; i<(StrItems.length-1); i+=3 ){
				//////////////////////////////////// 
				var xItem = '<a href="home.php?s=0,1,51&dfa=do6529&diditem='+StrItems[i]+'" class="SliderNewsRollOver" onmouseover="javscript:SN_'+this.Obj+'.RollOver('+i+');" onmouseout="javscript:SN_'+this.Obj+'.RollOut('+i+');">' + NL + 
									  '	<div id="SliderItem'+i+'" class="SliderNewsItem" style="width:'+this.NW+'px;">' + NL +
									  '		<div class="SliderNewsItemContent">' + NL +
										'			<div class="grey10_0 padB5">' + StrItems[i+2] + '</div>' + NL +
										'			<div class="nero10">' + StrItems[i+1] + '</div>' + NL +
										'		</div>' + NL +
									  '	</div>' + NL + 
									  '</a>' + NL;
				this.Items.push( xItem );
				//////////////////////////////////// 
			}
			//////////////////////////////////// 
			this.SlideW = this.NW*this.Items.length;
			this.Container.style.width = (this.SlideW*2+50)+'px';
			//////////////////////////////////// 
			if( this.Items.length-this.N>0 ){
				this.Container.tag.innerHTML = this.Items.join(NL) + this.Items.join(NL);
				this.Move();
			} else {
				this.Container.tag.innerHTML = this.Items.join(NL);
			}
			///////////////////////////////
		} catch (e){	
			errorMsg = e;
		}
		///////////////////////////////
		if( errorMsg!='' ){
			alert( 'AJAX ERROR [PROTO_SliderNews]!' + NL + this.XMLHTTP.responseText );
		}
		///////////////////////////////
	}
	//////////////////////////////////// 
}
/////////////////////////////////////////////////////////////////////////////////////////////
PROTO_SliderNews.prototype.Move = function(){
	//////////////////////////////////// 
	this.scrollLeft += this.Step;		
	if(this.scrollLeft >= this.SlideW ){
		this.scrollLeft = 0;
	}
	this.Main.tag.scrollLeft = this.scrollLeft;
	////////////////////////////////////
	this.Timer = setTimeout( 'SN_'+this.Obj+'.Move();', this.Delay);
	//////////////////////////////////// 
}
/////////////////////////////////////////////////////////////////////////////////////////////
PROTO_SliderNews.prototype.RollOver = function( n ){
	//////////////////////////////////// 
	clearTimeout( this.Timer );
	//////////////////////////////////// 
}
/////////////////////////////////////////////////////////////////////////////////////////////
PROTO_SliderNews.prototype.RollOut = function( n ){
	//////////////////////////////////// 
	this.Timer = setTimeout( 'SN_'+this.Obj+'.Move();', this.Delay*5);
	//////////////////////////////////// 
}
/////////////////////////////////////////////////////////////////////////////////////////////






///////////////////////////////////////////////////////////////////////////////////////////// AJAX CONNECTION
AJAXconn = function( _Self, URL, FormAction, Dati ){ 
	//////////////////////////////////// 
	try{
		///////////////////////////////
		var Agent = navigator.userAgent.toLowerCase();	
		///////////////////////////////
		if( Agent.indexOf("msie")>=0){
			///////////////////////////////
			var Class = "Msxml2.XMLHTTP";
			if( navigator.appVersion.indexOf("MSIE 5.5")>=0 ){
				Class = "Microsoft.XMLHTTP";
			} 
			try	{
				_Self.XMLHTTP = new ActiveXObject(Class);
				_Self.XMLHTTP.onreadystatechange = function(){		_Self.RequestStep();		}
			} catch(e) {
				alert("Errore: l'ActiveX non verrà eseguito!");
				return false;
			}
			///////////////////////////////
		} else if( Agent.indexOf("mozilla")>=0 ){
			///////////////////////////////
			_Self.XMLHTTP = new XMLHttpRequest();
			_Self.XMLHTTP.onload = 	function(){		_Self.RequestStep();		}
			_Self.XMLHTTP.onerror = function(){		_Self.RequestStep();		}
			///////////////////////////////
		} else {
			///////////////////////////////
			alert("ERRORE! Browser!");
			return false;
			///////////////////////////////
		}
		///////////////////////////////
		var ArrURL = new Array();
		if( !Dati ){
			ArrURL = URL.split("?");
		} else {
			ArrURL = new Array(URL, Dati);
		}
		if( !FormAction || FormAction=='GET' ){
			_Self.XMLHTTP.open("GET", ArrURL[0]+"?"+ArrURL[1], true);
			_Self.XMLHTTP.send( null );
		} else {
			_Self.XMLHTTP.open("POST", ArrURL[0], true);
			//Send the proper header information along with the request
			_Self.XMLHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			_Self.XMLHTTP.setRequestHeader("Content-length", ArrURL[1].length);
			_Self.XMLHTTP.setRequestHeader("Connection", "close");
			_Self.XMLHTTP.send( ArrURL[1] );
		}
		///////////////////////////////
	} catch(e) {
		///////////////////////////////
		alert('AJAX ERROR [NTCommon.AJAXconn]!' + NL + e);
		return false;
		///////////////////////////////
	}
	///////////////////////////////
}
/////////////////////////////////////////////////////////////////////////////////////////////
