$(document).ready(function(){
	if( $('#header-image div.anim-item').length > 1 ){
		$('#header-image').cycle({
			timeout:6500,
			speed:1800,
			after:function(currSlideElement, nextSlideElement, options, forwardFlag){
				moveArrow($(nextSlideElement).children('img.arrow'), $(nextSlideElement).children('img.arrow').attr('x_coord'), $(nextSlideElement).children('img.arrow').attr('y_coord') );
			
			},
			before:function(currSlideElement, nextSlideElement, options, forwardFlag){
				if( $($(nextSlideElement).children('img.arrow')).hasClass('left') ){
					$($(nextSlideElement).children('img.arrow')).css('left', '-300px');
				} else {
					$($(nextSlideElement).children('img.arrow')).css('left', '875px');
				}
			}
		})
	} else {
		moveArrow( $('#header-image div img.arrow'), $('#header-image div img.arrow').attr('x_coord'), $('#header-image div img.arrow').attr('y_coord') );
	}
	
	function moveArrow(oItem, x, y){
		
		$(oItem).animate({
			left: x			 
		}, {
			duration: 2500,
			easing: 'easeOutBounce'
		})
	}
	
	
	
	
	$('a[rel="lightbox"]').lightBox({
		imageLoading : '../../images/loading.gif',
		imageBtnClose : '../../images/closelabel.gif',
		imageBtnPrev : '../../images/prevlabel.gif',
		imageBtnNext : '../../images/nextlabel.gif',
		overlayOpacity : 0.6,
		strings : {
			prevLinkTitle: 'previous image',
			nextLinkTitle: 'next image',
			prevLinkText:  '&laquo; Previous',
			nextLinkText:  'Next &raquo;',
			closeTitle: 'Schliessen',
			image: 'Bild ',
			of: ' von '
		}
	});
})


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

animation = function() {}

animation.prototype = {
	iFadeSpeed : 0,

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

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

	initAnimation : function() {

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

		$("#header-images").append('<div id="headerImgAnim"></div>')
		$("#header").append('<div id="headerMaps"></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].src + '" width="' + this.aPreloadImages[i].width + '" heigth="' + this.aPreloadImages[i].height + '" />');


			}

			$("#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){
		oActiveImg.fadeOut(anim.iFadeSpeed, function(){ anim.playAnim(); $(this).removeClass('active') })
	}
}

function toggleContainer(iContainerID, sType, sBlockList) {
	if (sBlockList != null && sBlockList != '') {
		var aBlockList = sBlockList.split(',');
		if (aBlockList != null && aBlockList.length > 0) {
			for (var i in aBlockList) {
				$('#'+aBlockList[i]).css('display','none');
				
			}
		}
	}
	$('#' + iContainerID).css('display', sType);
}

function checkMandatory(aArray) {
	if (aArray.length > 0) {
		for (var i = 0; i < aArray.length; i++) {
			checkFormElement(aArray[i]);
		}
	}
}

function checkFormElement(sName) {
	var bFilled = true;
	var aNames = sName.split(',');

	if (aNames.length > 1) {
		for (i=0; i < aNames.length; i++) {
			var sName = aNames[i].replace(/ /, '');
			if (i==0) {
				var sTarget = document.getElementById('mand_' + sName);
			}
			var sElement = document.getElementsByName(sName)[0];
			if (sElement.value == '') {
				bFilled = false;
				break;
			}
		}
	} else {
		var sElement = document.getElementsByName(sName)[0];
		var sTarget = document.getElementById('mand_' + sName);
		if (sElement.value == '') {
			bFilled = false;
		}
	}
	if (bFilled) {
		sTarget.innerHTML = '';
		sTarget.className = '';
	} else {
		sTarget.innerHTML = '<img src="../images/form_error.gif" />';
		sTarget.className = 'formerror';

	}
}

function toggleHeader() {
	$('#headerimg').css('display', 'none');
	$('#headervid').css('display', 'block');
}


