window.animation = window.animation || {};

animation = function() {}

animation.prototype = {
	iFadeSpeed : 1500,

	iShowMS : 2500,
	iCurrentImg : 0,
	aImages : new Array(),
	aPreloadImages : new Array(),
	iImageCnt : 0,

	addImage : function(imagePath) {
		this.aImages[this.iImageCnt] = new Object();
		this.aImages[this.iImageCnt].src = imagePath;
		this.iImageCnt++;
	},

	initAnimation : function() {

		for( i=0; i<this.aImages.length; i++ ){
			this.aPreloadImages[i] = this.aImages[i].src;
		}

		$("#navi-main-images").append('<div id="headerImgAnim"></div>')
		$('#headerImgAnim').addClass('loading');

		$.preload( this.aPreloadImages, {
		base:'',
		ext:'',
		aPreloadImages : this.aPreloadImages,
		onFinish:function(){
			$("#headerImgAnim").hide();
			for( i=0 ; i < this.aPreloadImages.length ; i++){
				$("#headerImgAnim").append('<img src="' + this.aPreloadImages[i] + '" />');

			}

			$("#headerImgAnim").removeClass('loading');
			$("#headerImgAnim img:eq(0)").addClass('active');
			$("#headerImgAnim").fadeIn(anim.iFadeSpeed, function () {
				if (anim.aPreloadImages.length > 1)
					anim.playAnim();
			});
			
		}});
	},

	 playAnim : function(){
		var oActiveImg = $("#headerImgAnim img:eq(" + this.iCurrentImg + ")");
		oActiveImg.addClass('active');
		
		if(this.iCurrentImg == this.aPreloadImages.length - 1){
			this.iCurrentImg = 0;
		} else {
			this.iCurrentImg++;
		}
		var oNextImg = $("#headerImgAnim img:eq(" + this.iCurrentImg + ")");
		oNextImg.show();
		window.setTimeout(function(){ anim.resume(oActiveImg)},this.iShowMS);
		
	},
	resume : function(oActiveImg){
		$('#headerMaps [mapname="' + oActiveImg.attr('usemap') + '"]').hide();
		oActiveImg.fadeOut(anim.iFadeSpeed, function(){ anim.playAnim(); $(this).removeClass('active') })
	}
}



	function imageSlideShow() {
	  
		var $alt = $('#slideshow img.firstimage');
		var $neu = $alt.next().length ? $alt.next() : $('#slideshow img:first');
		$alt.addClass('image');
		$alt.removeClass('firstimage');
		$neu.css({opacity: 0.0});
		$neu.addClass('firstimage');
		$neu.animate({opacity: 1.0}, 2000, function() {
				$alt.removeClass('image');
		});	  
	}
	
	function switchGallery(iGalleryID) {
		var sHTML = '<div id="slider"><ul>';
		var iCnt;
		var aImages = aReferences[iGalleryID];
		
		if(aImages.length > 0) {
			for(iCnt = 0; iCnt < aImages.length; iCnt++) {
				sHTML += '<li style="background-image: url(' + aImages[iCnt] + ');" /></li>';
			}
		}
		
		sHTML += '</ul></div>';

		$("#headerimage").html(sHTML);
		$("#gallerybuttons").remove("#gallerybuttons");
		
		$("#slider").easySlider({ 
								controlsBefore:	'<div id="gallerybuttons">',
								controlsAfter:	'</div>',
								speed: 500,
								continuous: true
								});

	}
	
