/* <![CDATA[ */
function Webcam(Data) {
	this.Data					= Data;
	
	this.NumImg 			= this.Data.Img.length;
	
	this.ThumbPage		= this.ThumbPage 			|| 0;
	this.DetailPage		= this.DetailPage			|| (this.Data.Img.length -1);
	this.PerSite			= this.Data.PerSite 	|| 6;
	this.IVWTag				= this.Data.IVWTag		|| 'http://nwz.ivwbox.de/cgi-bin/ivw/CP/260spezial';
	this.Interval			= this.Data.Interval	|| 60;
	this.ItvUnit			= this.Data.ItvUnit		|| ['Minute', 'Minuten', 'Seite', 'Seiten'];
	this.Jumps				= this.Data.Jumps			|| this.Interval;
	this.Path					= this.Data.Path;
	this.Thumbnails		= this.Data.Thumbnails|| false;
	
	this.NumPages 		= Math.ceil(this.NumImg / this.PerSite);	
	
	// Initialisiert den Bildbrowser
	this.init = function() {

		this.isPI = false;

		if(parseInt(this.DetailPage) != 0 && parseInt(this.DetailPage) < this.NumImg)
			this.picDetail(this.DetailPage);
		else if(this.ThumbPage != 0)
			this.picList();
		else
			this.Start();
			
		document.onkeyup = this.keyPager.bindAsEventListener(this);
	
		this.isPI = true;
	}
	
	// Blättert bei Druck von Pfeiltasten
	this.keyPager = function(e) {
		if(e.keyCode == Event.KEY_RIGHT)
			this.Pager(true, 1);
		if(e.keyCode == Event.KEY_LEFT) 
			this.Pager(false, 1);
	}
	
	// setzt ThumbPage entsprechend Detail oder Slideshow
	this.setThumbPage = function() {
		this.ThumbPage = Math.floor((this.DetailPage + 0) / this.PerSite);
	}
	
	// ruft Blätterfunktion auf. Abhängig von momentaner Bildgröße
	this.Pager = function(bool, inc) {
		switch(this.size) {
			case 'big' 			: this.dPager(bool, inc); break;
			default					: this.tPager(bool, inc); break;
		}
	}
	
	// blättert Detailansicht
	this.dPager = function(bool, inc) {			
		if(bool) {
			this.DetailPage = (this.DetailPage + inc > this.NumImg - 1) 
								? 0 
								: this.DetailPage + inc;
		} else {
			this.DetailPage = (this.DetailPage - inc < 0) 
								? this.NumImg - 1
								: this.DetailPage - inc;
		}
		this.picDetail(this.DetailPage);		
	}
	
	// blättert Thumbnails
	this.tPager = function(bool, inc) {
		if(bool) {
			this.ThumbPage = ((this.ThumbPage + inc) * this.PerSite >= this.NumImg)
								? 0
								: this.ThumbPage + inc;
		} else {
			this.ThumbPage = ((this.ThumbPage - inc) * this.PerSite < 0)
								?	this.NumPages - 1
								: this.ThumbPage - inc;
		}
		this.picList(this.ThumbPage);
	}
	
	// IVW / Werbung
	this.PI = function() {
		if(this.isPI == true) {
			// Banner nachladen
			IVW = $('ivw').getElementsByTagName('img')[0];
			IVW.src = this.IVWTag +"?r="+escape(document.referrer)+"&d="+(Math.random()*100000);
		}
	}
	
	this.getUnit = function(Unit) {
		ret = (Unit == 1)
			? ((this.size == 'big') ? this.ItvUnit[0] : this.ItvUnit[2])
			: ((this.size == 'big') ? this.ItvUnit[1] : this.ItvUnit[3])
		return ' '+ret;
	}
	
	
		
/* THUMBANSICHT ************************************/	
	
	
	// Thumbnailseite
	this.picList = function(par) {
		this.PI();
		this.ThumbPage = par;
		this.size = 'thumb';
		
		start = this.ThumbPage * this.PerSite;
		end 	= (this.ThumbPage + 1) * this.PerSite
		end 	= (end > this.NumImg) ? this.NumImg : end;
		text 	= '';

		for(var i = start; i < end; i++) {
			text += '<a href="#" onclick="WC.size=\'big\';WC.picDetail('+i+');return false;"><img src="'+this.Path + this.Data.Img[this.DetailPage].File+'" alt="" width="100" /></a>';
			this.DetailPage = i;
		}
		$('WC_Images').innerHTML = text;
		$('WC_Navigation').innerHTML = this.getPicListNavigation();
	}
	
	this.getPicListNavigation = function() {
		text = '<a href="#" onclick="WC.Start(0);return false;" class="start">Start</a><span></span>';

					for(j = this.Jumps.length; j >= 0; j--) {
						Span = this.Jumps[j]/this.Interval;
						Unit = this.getUnit(Span);
						laquo = '';
						for(Arrow = 0; Arrow < j; Arrow++)
							laquo += '&laquo;';
						if(Span < this.NumPages)
							text += '<a href="#" onclick="WC.Pager(false, '+Span+');return false;" class="zurueck" title="&laquo; '+Span+Unit+'">'+laquo+'</a>';
					}
		
		aktPage = this.ThumbPage + 1;
		
		text+= '<a href="#" onclick="WC.Pager(true, 1);return false;" class="XOfY">'+ aktPage +' von '+ this.NumPages +'</a>';
		
					for(j = 0; j < this.Jumps.length; j++) {
						Span = this.Jumps[j]/this.Interval;
						Unit = this.getUnit(Span);
						raquo = '';
						for(Arrow = 0; Arrow < j; Arrow++)
							raquo += '&raquo;';
						if(Span < this.NumPages)
							text += '<a href="#" onclick="WC.Pager(true, '+Span+');return false;" class="weiter" title="'+Span+Unit+' &raquo;">'+raquo+'</a>';
					}
											
		return text +'<br />';
	}
	

	
	
	
	/* DETAILANSICHT ************************************/	
	
	// Detailseite
	this.picDetail = function(par) {
		this.PI();
		this.DetailPage = par;
		this.size = 'big';
		
		this.setThumbPage();
		
		RecDate = this.Data.Img[this.DetailPage].File.substr(0, 10).split('-');
		RecTime = this.Data.Img[this.DetailPage].File.substr(11, 5).split('_');
		Recorded = 'Aufgenommen am '+RecDate[2]+'.'+RecDate[1]+'.'+RecDate[0]+' um '+RecTime[0]+':'+RecTime[1]+' Uhr';
		
		$('WC_Images').innerHTML = '<strong>'+Recorded+'</strong><br /><div onclick="WC.Pager(true, 1);" style="background:URL('+this.Path + this.Data.Img[this.DetailPage].File+') 80% 50% no-repeat;width:472px;height:352px"></div>';
		$('WC_Navigation').innerHTML = this.getDetailNavigation();
	}
	
	this.getDetailNavigation = function() {
		text = '<a href="#" onclick="WC.Start(0);return false;" class="start">Start</a><span></span>';
		if(this.Thumbnails != false)
		text+= '<a href="#" onclick="WC.picList('+ this.ThumbPage +');return false;" class="thumbs">&Uuml;bersicht</a>';
						
					for(j = this.Jumps.length; j >= 0; j--) {
						Span = this.Jumps[j]/this.Interval;
						Unit = this.getUnit(Span);
						laquo = '';
						for(Arrow = 0; Arrow <= j; Arrow++)
							laquo += '&laquo;';
						if(Span < this.NumImg)
							text += '<a href="#" onclick="WC.Pager(false, '+Span+');return false;" class="zurueck" title="&laquo; '+Span+Unit+'">'+laquo+'</a>';
					}
		
		aktPic = this.DetailPage + 1;
		
		text+= '<a href="#" onclick="WC.Pager(true, 1);return false;" class="XOfY">'+ aktPic +' von '+ this.NumImg +'</a>';
		
					for(j = 0; j < this.Jumps.length; j++) {
						Span = this.Jumps[j]/this.Interval;
						Unit = this.getUnit(Span);
						raquo = '';
						for(Arrow = 0; Arrow <= j; Arrow++)
							raquo += '&raquo;';
						if(Span < this.NumImg)
							text += '<a href="#" onclick="WC.Pager(true, '+Span+');return false;" class="weiter" title="'+Span+Unit+' &raquo;">'+raquo+'</a>';
					}
								
		return text +'<br />';
	}
	

	
	// Startseite
	this.Start = function() {
		this.ThumbPage = this.DetailPage = 0;
		this.picDetail(0);
	}
}
/* ]]> */