/**
 * @author Peter
 * 
 * JS-Compresser that works fine with these Script: http://www.creativyst.com/Prod/3/
 * 
 */
 


// init main object for moevenpick
var mp = new Object();

mp.HotelPictures = new Class({
	options: {
		onChange: Class.empty,
		images:new Array(),
		fadedurration:600,
		fps:50,
		useScoller:false,
		thumbStartOpacity:0.5,
		scrollArea:50,
		scrollVelocity:0.3,
		automaticdelay:6000
	},
	initialize: function(el,options){
		this.setOptions(options);
		this.el = $(el);
		this.selected = 0;
		this.imgCount = this.options.images.length;

		// get DOM Elements
		this.pictureEls = this.el.getElementsBySelector('a.picture');
		this.largeEl = this.el.getElement('div.imglargecont').getFirst();
		
		// run init function
		this.initEls();
		
		if(this.options.automaticdelay){
			this.periodic = this.next.delay(this.options.automaticdelay,this);
		}

	},
	initEls: function(){
		
		// adding Events to the small picturesb
		for(var i = 0; i < this.pictureEls.length; i++){
			if(i > 0)this.pictureEls[i].getFirst().setStyle('opacity',this.options.thumbStartOpacity);
			this.pictureEls[i].onclick = this.changeImage.bindAsEventListener(this,i);
		}
		// adding events to next and prev. button
		this.el.getElement('a.next').onclick = this.next.bindAsEventListener(this);
		this.el.getElement('a.prev').onclick = this.prev.bindAsEventListener(this);
		
		// adding scroller to thumb list
		if(this.options.useScoller){
			this.scroller = new Scroller(this.el.getElement('div.scoller'), {onlyX:true,area: this.options.scrollArea, velocity: this.options.scrollVelocity});
			this.el.getElement('div.scoller').addEvent('mouseover', this.scroller.start.bind(this.scroller));
			this.el.getElement('div.scoller').addEvent('mouseout', this.scroller.stop.bind(this.scroller));
		}
		
		$('StageToolTipText').innerHTML = this.options.images[0].imagealt;
		
		// init scrolling function
		this.scroll = new Fx.Scroll(this.el.getElement('div.scoller'), {
			wait: false,
			duration: 800,
			transition: Fx.Transitions.Quad.easeInOut
		});
	},
	changeImage:function(event,idx){
		// if not the active image is clicked change it
		
		if(idx != this.selected){
			
			this.fireEvent('onChange', this.step);
			
			// init Elements
			var oImgData = this.options.images[idx];
			var elLarge = this.largeEl;
			var fxFade = new Fx.Style(elLarge, 'opacity',{fps:this.options.fps, duration: (this.options.fadedurration/2).toInt()});
			
			// run animation for thumb
			this.pictureEls[this.selected].getFirst().effect('opacity', {transition: Fx.Transitions.Quint.easeIn,fps:this.options.fps, duration: this.options.fadedurration}).start(this.options.thumbStartOpacity);
			this.pictureEls[idx].getFirst().effect('opacity', {transition: Fx.Transitions.Quint.easeIn,fps:this.options.fps, duration: this.options.fadedurration}).start(1);
			
			// scroll to the new thumb
			this.scroll.scrollTo(64*idx-198,0);
			
			// run animation of big image
			fxFade.stop();
			fxFade.start(0.4).chain(function(){
				fxFade.stop();
				elLarge.setProperties({
					'src':oImgData.big,
					'width':oImgData.bigX,
					'height':oImgData.bigY
				});
				fxFade.start(1);
			});

			// Show headline only on first image
			if (idx == 0) {
				$('StageTitle').setStyle('display', 'block');
			} else {
				$('StageTitle').setStyle('display', 'none');
			}
			// Set Tooltip Text above slider

			$('StageToolTipText').innerHTML = this.options.images[idx].imagealt;			
			
			Cufon.replace('#StageToolTipText',{
						  hover:true
						  });
			// change the seleched item
			this.selected = idx;
		}
	},
	next:function(event){
		$clear(this.periodic);
		// get the next thumb and change the big image
		if(this.selected+1 >= this.imgCount){
			this.changeImage(new Object(),0);
		}else{
			this.changeImage(new Object(),this.selected+1);
		}
		if(this.options.automaticdelay){
			this.periodic = this.next.delay(this.options.automaticdelay,this);
		}
	},
	prev:function(event){
		$clear(this.periodic);
		// get the previous thumb and change the big image
		if(this.selected-1 < 0){
			this.changeImage(new Object(),this.imgCount-1);
		}else{
			this.changeImage(new Object(),this.selected-1);
		}
		if(this.options.automaticdelay){
			this.periodic = this.next.delay(this.options.automaticdelay,this);
		}
	}
});
mp.HotelPictures.implement(new Options, new Events);


// Reservation Funktions 
mp.reservation = new Object();

mp.reservation.getCalendarDate = function(cDate){
   var dateString = mp.reservation.months[cDate[0].toInt()] + ' ' + cDate[2];
   return dateString;
}
mp.reservation.addMonth = function(cDate,number){
	var newMonth = cDate[0].toInt() + number;
	var number2 = number;
	if(number2 < 0)number2= number2*-1;
	var iYearAdd = (number2/12).toInt()+1;
	
	if(newMonth <= 0){
		cDate[0] = 12;
		cDate[2] = cDate[2].toInt()-iYearAdd;
	}else if(newMonth > 12){
		cDate[0] = 1;
		cDate[2] = cDate[2].toInt()+iYearAdd;
	}else{
		cDate[0] = newMonth;
	}
	return cDate;
}
/*
Class: AvailabilityCalender
	Creates a Picture Rondel for Moevenpick
	
Note:

Arguments:
	element - the content container
	options - see Options below

Options:

Events:

*/



