function ItemLoader(d,p)
{
	this.Items 			= d;
	this.Pos			= p;
	this.phold			= p;

	this.firstLoaded	= false;

	this.Image;
	this.Images 		= new Array();
	this.ItemIndex		= new Array();

	this.L 				= 0;
	this.I 				= 0;

	this.tS;
	this.tF;

	this.tCheck			= new Array();
	this.tCheckSum		= 0;
	this.tCheckCount	= 0;

	this.acPort			= "";
	this.acRef			= "";
	this.flip			= 1;

	this.loadItems = function()
	{

		this.tS = new Date().getTime();

		var i = -1;
		var to= "";
		try{
			while(this.Items[(i < 0 ? i+=1 : i++)])
			{
				try {
					this.Items[i]["position"] = i;
					this.ItemIndex[this.Items[i][0]]=this.Items[i];

					if(this.Items[i][3].toLowerCase()=="subtitle")
					{
						/*out.innerHTML+="<br/>Referenz: "+this.Items[i][1]+" | ID:"+this.Items[i][0];*/
					}else if(this.Items[i][3].toLowerCase()=="bigtitle")
					{
						/*out.innerHTML+="<br/>Portfolio: "+this.Items[i][1]+" | ID:"+this.Items[i][0];*/
					}

				} catch(e){}
			}

		} catch(e){}

		this.I = this.ItemIndex[this.Pos].position;
		this.loadStep();
	}

	this.getItems = function()
	{
		return this.Items;
	}

	this.setImage = function()
	{
		var d = new Image();
		d.parent = this;
		d.onload = function()
		{
			this.si != false ? clearInterval(this.si) : null ;

			if(!this.parent.firstLoaded){this.parent.firstLoaded = true; this.parent.onLoadFirst();}
			this.parent.SequentOnLoad();

			this.parent.I =  this.parent.getNextItemIndex(this.parent.I);

			if(this.parent.Items[this.parent.I]["image"])
			{
				this.parent.onload();
			}else{
				this.parent.Items[this.parent.I]["image"] = this.parent.setImage();
				this.parent.Items[this.parent.I]["image"].index = this.parent.I;
				this.parent.Items[this.parent.I]["image"].ts = new Date().getTime();
				this.parent.Items[this.parent.I]["image"].src = "../img/big/"+this.parent.Items[this.parent.I][10];
			}
		};

		try {
			d.si = navigator.userAgent.toLowerCase().indexOf("applewebkit/3") >=0 ? window.setInterval(function(){d.complete==true ? d.onload() : null ;}, 500) : false ;
		} catch(e){
			alert(e);
		}

		return d;
	}

	this.singleLoad = function()
	{

	}

	this.loadStep = function()
	{
		try{
			trace("loaded image # "+this.I);
			//this.SequentOnLoad();
			this.I =  this.getNextItemIndex(this.I-1);

			this.Items[this.I]["image"] = this.Items[this.I]["image"] ? this.Items[this.I]["image"] : this.setImage();
			this.Items[this.I]["image"].src = "../img/big/"+this.Items[this.I][10];

		} catch(e){
			try{
				this.parent.onload();
			} catch(e){
				this.onload();
			}
		}
	}

	this.getNextItemIndex = function(f)
	{
		trace("IN: "+f);
		/*alert("IN: "+f);*/
		
		/*if(f>0)
		{
			i=f*-1;
			alert("IN1: "+i);
			for(i = i-1 < 0 ? (this.Items.length) : i ; this.Items[i][3]!="fotos"; i--){}
		}else{
			i=Math.abs(f)+1;
			alert("IN2: "+i);
			for(i = i+1 >= (this.Items.length) ? 0 : i+1; this.Items[i][3]!="fotos"; i++){}
		}
		
		if(this.flip==1)
		{
			this.flip=-1;
			for(i = i-1 < 0 ? (this.Items.length) : i ; this.Items[i][3]!="fotos"; i--){}
		}else{
			this.flip=1;
			for(i = i+1 >= (this.Items.length) ? 0 : i+1; this.Items[i][3]!="fotos"; i++){}
		}*/
		
		/*alert("OUT: "+i);*/
		/*f = f>0 ? f*-1 : Math.abs(f)+1;*/
		
		for(i= f+1 >= (this.Items.length) ? 0 : f+1; this.Items[i][3]!="fotos"; i++){}
		
		trace("OUT: "+i);
		return i;
	}

	this.onload = function()
	{

	}

	this.SequentOnLoad = function()
	{

	}

	this.onLoadFirst = function()
	{

	}
}
