

function ImageManage()
{
	this.Units = new Array();
	this.Position = 0;
	this.IndexView;
	this.ImageContainer;
	this.SubTheme;
	this.MainTheme;
	this.ImageTitle;
	this.bigTitle;
	this.LO;
	this.loader = 0;
	this.imc = 0;
	this.NoteStat = true;
	this.VideoScreen;
	this.Video;
	this.tmpname;
	this.blendStatus = true;

	this.prIndex = 0;
	this.prSize = 0;

	this.nextSkip;
	this.prevSkip;

	this.DR;
	this.FX;

	this.init = function(l,k)
	{
		this.Units 			= l;
		this.Position 		= !k ? this.getFirst() : k;
		this.ImageContainer = document.getElementById("ImageContainer");
		this.ImageTitle 	= document.getElementById("ImageTitle");
		this.IndexView 		= document.getElementById("IndexPos");
		this.SubTheme		= document.getElementById("SubTheme");
		this.MainTheme		= document.getElementById("MainTheme");
		this.VideoScreen	= document.getElementById("VideoContainer");
		this.Video			= new VideoHandel();

		this.nextSkip		= document.getElementById("skip-next");
		this.prevSkip 		= document.getElementById("skip-prev");

		this.nextSkip.parent = this;
		this.prevSkip.parent = this;

		this.nextSkip.onmouseup = this.skip_next;
		this.prevSkip.onmouseup = this.skip_prev;

		this.DR = new DireFlag();

		this.Position > 0 ? this.getPRSize(this.Units[this.Position][12]) : null ;

		for(var i=0; this.Units[i]; i++)
		{
			this.Units[i]["position"] = i;
			if(this.Units[i][3]=="fotos")
			{
				this.Units[i]["parent"]= this;
			}else if(this.Units[i][3]=="subTitle" || this.Units[i][3]=="bigTitle" || this.Units[i][3]=="video")
			{
				this.Units[i]["parent"]= this;
				this.Units[i]["image"] = "";
			}
		}

		document.getElementById("TitelContainer").style.display = "none";
		document.getElementById("DescrContainer").style.display = "none";
		document.getElementById("VideoContainer").style.display = "none";

		if (this.Units[this.Position][3] != "fotos")
		{
			this.initDomObjects()
			this.blendOut();
		}else{
			this.initDomObjects()
			this.blendOut();
			this.skip();
		}

		this.DR.startTracking();

	}

	this.reBuilt = function(d)
	{
		this.Units = new Array();
		this.Units = d;

		for(var i=0; this.Units[i]; i++)
		{
			this.Units[i]["position"] = i;
			if(this.Units[i][3]=="fotos")
			{

				this.Units[i]["parent"]= this;

			}else if(this.Units[i][3]=="subTitle" || this.Units[i][3]=="bigTitle" || this.Units[i][3]=="video")
			{
				this.Units[i]["parent"]= this;
				this.Units[i]["image"] = "";
			}
		}

	}

	this.getPRSize = function(pr)
	{
		k = 0;
		this.prIndex = 0;
		for(var i = 0; this.Units[i]; i++)
		{

			this.Units[i][12] == pr && ( this.Units[i][3]=="fotos" || this.Units[i][3]=="video" )? k++ : null ;
			this.prIndex = this.Units[this.Position][0] == this.Units[i][0] ? k : this.prIndex ;

		}

		this.prSize = k;
	}

	this.risePRIndex = function()
	{
		this.prIndex++;
	}

	this.getFirst = function()
	{
		var k = 0;
		for(var i=0; this.Units[i]; i++){k = this.Units[i][11]=="active" ? i : k ;}
		return k;
	}

	this.getBlockPosition = function()
	{
		var k = new Array();
		for(var i=0; this.Units[i]; i++){ this.Units[i][3]=="subTitle" || this.Units[i][3]=="bigTitle" ? k.push(i):null;}
		return k;
	}

	this.skip_next = function()
	{
		if (this.parent.blendStatus && this.parent.Position< this.parent.Units.length-1) {
			try{this.parent.prIndex = this.parent.Units[this.parent.Position+1][3]== "video" || this.parent.Units[this.parent.Position+1][3]== "fotos" ? this.parent.prIndex+1 : 0 ;} catch(e){}
			this.parent.Position = this.parent.Position >= (this.parent.Units.length - 1) ? this.parent.goToIndex() : this.parent.Position + 1;
			this.parent.skip();

		}else{
			this.parent.Position >= this.parent.Units.length-1 ? this.parent.goToIndex() : null;
		}
	}

	this.goToIndex = function()
	{
		new Fx.Style(this.ImageContainer, 'opacity',{duration:450, onComplete: function(){
			window.location.href="http://www.anjaweber.com/index/";
			}}).start(0);

		new Fx.Style(document.getElementById("ImageTitle"), 'opacity',{ duration:450 }).start(0);

		return 0;
	}

	this.skip_prev = function()
	{
		if (this.parent.blendStatus && this.parent.Position>0) {
			try {this.parent.prIndex = this.parent.Units[this.parent.Position-1][3]== "video" || this.parent.Units[this.parent.Position-1][3]== "fotos" ? this.parent.prIndex-1 : 0 ;} catch(e){}
			this.parent.Position = this.parent.Position <= 0 ? 0 : this.parent.Position - 1;
			this.parent.skip();
		}
	}

	this.skip = function()
	{
		if (this.NoteStat) {
			this.HideNote();
		}else{
			this.blendOut();
		}
	}

	this.ImageOnLoad = function(i)
	{
		this.loader++;
		document.getElementById("thumb").innerHTML = "&nbsp;"+Math.round((this.loader/this.imc)*100)+"&nbsp;";

		if(this.loader==this.imc)
		{
			this.DR.startTracking();
		}
	}

	this.initDomObjects = function()
	{
		document.getElementById("TitelContainer").style.display = "block";
		document.getElementById("DescrContainer").style.display = "block";
		document.getElementById("VideoContainer").style.display = "none";

		new Fx.Style(document.getElementById("TitelContainer"), 'opacity', {
			duration: 1
		}).start(0);

		new Fx.Style(document.getElementById("DescrContainer"), 'opacity', {
			duration: 1
		}).start(0);

		/*new Fx.Style(document.getElementById("VideoContainer"), 'opacity', {
			duration: 1
		}).start(0);*/
	}

	this.HideNote = function()
	{
		try {
				new Fx.Style(document.getElementById("note"), 'opacity', {duration: 450}).start(0);
				this.NoteStat = false;
			} catch(e){
				this.NoteStat = false;
				this.blendOut();
			}
	}


	this.blendOut = function()
	{
		this.blendStatus = false;
		try{
			this.FX2.stop();
		} catch(e){
			//no FX running;
			//new TG8_ERROR(e);
		}

		try{
			this.ImageTitle.innerHTML			= "";
		} catch(e){

		}

		p = this;

		try{
			this.Video.stop();
			this.Video.unloadVideo();
		} catch(e){
			//no alternative
		}

		if(this.ImageContainer.id=="VideoContainer")
		{
			this.ImageContainer.display="none";
			p.blendStatus = true;
			p.blendIn();

		}else{

			this.FX2 = new Fx.Style(this.ImageContainer, 'opacity',{duration:450, _tg8_parent:this, onComplete: function(){
			p.blendStatus = true;
			p.blendIn();
			}});

			this.FX2._tg8_parent = this;
			this.FX2.start(0);
		}



		if(p.Units[p.Position][3]=="fotos")
		{
			this.ImageContainer = document.getElementById("ImageContainer");
		}else if(p.Units[p.Position][3]=="subTitle" || p.Units[p.Position][3]=="bigTitle"){
			this.ImageContainer = document.getElementById("TitelContainer");
			//this.ImageContainer.innerHTML = p.Units[p.Position][1];
		}else if(p.Units[p.Position][3]=="text"){
			this.ImageContainer = document.getElementById("DescrContainer");
			/*this.ImageContainer.innerHTML = p.Units[p.Position][2];*/
		}else if(p.Units[p.Position][3]=="video"){
			this.ImageContainer = document.getElementById("VideoContainer");
		}

		p.getPRSize(p.Units[p.Position][12]);
		p.SubTheme.innerHTML  = p.Units[p.Position][12];
		p.MainTheme.innerHTML = "<b>"+p.Units[p.Position][11]+"</b>";
		p.IndexView.innerHTML = (p.prIndex)+"/"+p.prSize;


	}

	this.blendIn = function()
	{
		try{
			i++;
		} catch(e){
			i = 0;
		}

		try{p = this._tg8_parent;} catch(e){alert("alternate"); p = this;}

		p = this;

		try{p.FX.stop(); delete p.FX;} catch(e){ }

		try{ p.ImageContainer.style.backgroundImage = "none";} catch(e){}


		if(p.Units[p.Position][3]=="fotos")
		{
			p.blendStatus = false;
			/*p.risePRIndex();*/
			p.ImageContainer = document.getElementById("ImageContainer");
			p.ImageContainer.style.backgroundImage = "none";
			p.ImageTitle.innerHTML			= "";

		try {
			p.FX = new Fx.Style(p.ImageContainer, 'opacity', {
				duration: 450,
				onComplete: function(){
					tpp = p.Units[p.Position][1];
					tpp = tpp.replace(/&dpp/g, ":");
					p.ImageTitle.innerHTML = tpp;
					p.blendStatus=true;
				}
			});
		} catch (e) {
			p.blendStatus = false;
			p.FX = new Fx.Style(p.ImageContainer, 'opacity', {
				duration: 450,
				onComplete: function(){
					p.blendStatus=true;
				}
			}).start(1);

		}
			try{
				p.ImageContainer.onload			= function(){ p.FX.start(1); p.IndexView.innerHTML = (p.prIndex)+"/"+p.prSize;};
				p.ImageContainer.src 			= p.Units[p.Position].image.src;



				p.ImageContainer.style.width 	= p.Units[p.Position].image.width+"px";
				p.ImageContainer.style.height   = p.Units[p.Position].image.height+"px";
				p.ImageContainer.width 			= p.Units[p.Position].image.width;
				p.ImageContainer.height   		= p.Units[p.Position].image.height;
			} catch(e){

			}

		}else if(p.Units[p.Position][3]=="subTitle" || p.Units[p.Position][3]=="bigTitle" )
		{
			p.prIndex = p.prSize = 0;
			p.ImageContainer = document.getElementById("TitelContainer");
			p.ImageContainer.innerHTML = p.Units[p.Position][1];
			/*alert(p.Units[p.Position][3]);*/
			if(p.Units[p.Position][3]=="subTitle")
			{
				p.ImageContainer.innerHTML = p.ImageContainer.innerHTML+'<p style="margin-top: 15px; padding-top: 0px; font-weight: normal;" >'+p.Units[p.Position][2]+'</p>';
			}else if(p.Units[p.Position][3]=="bigTitle")
			{
				p.ImageContainer.innerHTML = '<span style=" display: block; font-size: 44px; padding-left: 25px; padding-top: 25px; width: 600px; height: 450px; color: #ffffff; background-color: #000000;" >'+p.Units[p.Position][1]+'</span>';
			}
			
			p.Units[p.Position][3]=="subTitle" ? p.getPRSize(p.Units[p.Position][1]) : null;
			p.blendStatus = false;
			new Fx.Style(p.ImageContainer, 'opacity', {
				duration: 450,
				onComplete: function(){
					p.blendStatus=true;
				}
			}).start(1);
		}else if(p.Units[p.Position][3]=="text")
		{
			p.ImageContainer = document.getElementById("DescrContainer");
			p.ImageContainer.innerHTML = p.Units[p.Position][2];
			p.blendStatus = false;
			new Fx.Style(p.ImageContainer, 'opacity', {
				duration: 450,
				onComplete: function(){
					p.blendStatus=true;
				}
			}).start(1);
		}else if(p.Units[p.Position][3]=="video")
		{
			p.ImageContainer = document.getElementById("VideoContainer");
			//p.ImageContainer.innerHTML = p.Units[p.Position][2];
			p.Video.loadVideo(p.Units[p.Position][10]);
			p.Video.start();
			/*p.risePRIndex();*/

			tpp = p.Units[p.Position][1];
					tpp = tpp.replace(/&dpp/g, ":");
					p.ImageTitle.innerHTML = tpp;
					p.blendStatus = true;

			p.ImageContainer.display="block";

			/*new Fx.Style(p.ImageContainer, 'opacity', {
				duration: 450,
				onComplete: function(){p.Video.loadVideo(p.Units[p.Position][10]); p.Video.start();tpp = p.Units[p.Position][1];
					tpp = tpp.replace(/&dpp/g, ":");
					p.ImageTitle.innerHTML = tpp;
					p.blendStatus = true;}
			}).start(1);*/
		}

		/*if(p.tmpname!=p.Units[p.Position][p.Units[p.Position].length-1]&&p.Units[p.Position][p.Units[p.Position].length-1]!="Buch")
		{
			p.tmpname = p.Units[p.Position][11];
			this.SubTheme.innerHTML = p.tmpname;
		}*/
		p.IndexView.innerHTML = (p.prIndex)+"/"+p.prSize;
	}
}

function DireFlag()
{
	this.nextSkip;
	this.prevSkip;
	this.Control;

	this.Status;
	this.Flag;

	this.main = function()
	{
		this.nextSkip		= document.getElementById("skip-next");
		this.prevSkip 		= document.getElementById("skip-prev");
		this.Flag			= document.getElementById("thumb");
		this.Control		= document.getElementById("Controls");

		p = this;
		this.Flag.parent = this;
		this.nextSkip.Flag = this.Flag;
		this.prevSkip.Flag = this.Flag;

		this.nextSkip.Control = this.Control;
		this.prevSkip.Control = this.Control;

		this.Control.Flag  = this.Flag;
		this.Control.yM = 0;
		this.Control.xM = 0;



		this.Control.onmousemove = this.FlagFollow;
		this.Control.onmouseout  = function(){this.Flag.style.display = 'none';};

		this.startTrackingClear();

	}

	this.FlagFollow = function(e)
	{
		this.Flag.style.display = 'block';
		e = e ? e : window.event;
		this.Flag.style.left = this.Flag.parent.Status == "NEXT" ? (document.body.clientWidth-e.clientX < 75 ? (e.clientX-35)+"px" : (e.clientX+25)+"px"):(e.clientX-35 <= 0 ? (e.clientX+25)+"px" : (e.clientX-35)+"px");
		this.Flag.style.top  = ((e.clientY+this.Flag.parent.getScrollDiff())-40)+"px";
	}

	this.getScrollDiff = function()
	{
		return window.pageYOffset ? window.pageYOffset : (document.documentElement.scrollTop ? document.documentElement.scrollTop: document.body.scrollTop);
	}

	this.startTrackingClear = function()
	{
		this.nextSkip.onmouseover = function(){ this.Flag.parent.Status = "NEXT";};
		this.prevSkip.onmouseover = function(){ this.Flag.parent.Status = "PREV";};
	}

	this.startTracking = function()
	{
		var p = this;
		this.Flag.innerHTML = "&nbsp;Move and click mouse&nbsp;<br/>&nbsp;to control the page.&nbsp;"
		window.setTimeout(function()
		{
			p.Flag.innerHTML = p.Status == "NEXT" ? "&nbsp;next&nbsp;" : "&nbsp;previous&nbsp;";
			p.nextSkip.onmouseover = function(){ this.Flag.innerHTML = "&nbsp;next&nbsp;"; 		this.Flag.parent.Status = "NEXT";};
			p.prevSkip.onmouseover = function(){ this.Flag.innerHTML = "&nbsp;previous&nbsp;"; 	this.Flag.parent.Status = "PREV";};
		},  3000);
	}

	this.main();
}

function MouseWheelControl()
{
	this.main = function()
	{
		try{
			window.addEventListener("DOMMouseScroll", function(){alert("1"); return false;}, false);
		} catch(e){
			window.onmousewheel = document.onmousewheel = function(){alert("2");};
		}
	}
}

function VideoHandel()
{
	this.VideoScreen;

	this.main = function()
	{
		this.VideoScreen = document.getElementById("VideoContainer");
	}

	this.loadVideo = function(v)
	{
			var v = v;
			new Fx.Style(document.getElementById("VideoContainer"), 'opacity',{duration:1}).start(1);
			try{document.getElementById("VideoContainer").innerHTML = '<object width="780" height="520"><param name="movie" value="http://www.anjaweber.com/media/video.swf?v='+v+'"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.anjaweber.com/media/video.swf?v='+v+'" type="application/x-shockwave-flash" allowfullscreen="true" width="780" height="520"></embed></object>';} catch(e){ alert("1\n"+e);}

			try{document.getElementById("VideoContainer").style.display = "block";} catch(e){ alert("2\n"+e);}
			try{document.getElementById("ImageContainer").style.display = "none"; } catch(e){ alert("3\n"+e);}
			try{document.getElementById("TitelContainer").style.display = "none"; } catch(e){ alert("4\n"+e);}
			try{document.getElementById("DescrContainer").style.display = "none"; } catch(e){ alert("5\n"+e);}


	}

	this.unloadVideo = function()
	{
		document.getElementById("VideoContainer").innerHTML= "";

		document.getElementById("VideoContainer").style.display = "none";
		document.getElementById("ImageContainer").style.display = "block";
		document.getElementById("TitelContainer").style.display = "block";
		document.getElementById("DescrContainer").style.display = "block";
	}

	this.start = function()
	{
		//alert("start Video");
	}

	this.stop = function()
	{
		//alert("stop Video");
	}

	this.main();
}



