var packageScroller = new Class({
		options: {
			packages: [],
			counter: 0
		},
		initialize: function(options){
				this.setOptions(options);
				this.counter = this.options.counter;
				this.packages = [];
				this.effects  = [];
				this.effectsa  = [];
				this.running  = 0;
				this.addPackages(this.options.packages);
				var start = this.start();
		},
		addPackages: function(packages){
				$(packages).getChildren().each(function(package){
						this.packages.include($(package));
						this.effects[this.packages.indexOf(package)] = new Fx.Styles(package,{duration : 2000});
				}, this);
		},
		scrollLeft: function(){
			this.running = this.counter;
			cout = this.counter;
			this.start = this.effects[this.counter].start({'width':0,'margin-right':0,'margin-left':0}).chain(function(){$('pk'+cout).setStyles({'width':165,'margin-right':5,'margin-left':5}).injectInside($('paks'))})
			this.counter++;
			if(this.counter == this.packages.length)this.counter = 0;
		},
		scrollRight: function(){
			this.counter--;
			if(this.counter == -1)this.counter = this.packages.length-1;
			this.running = this.counter;;
			$('pk'+this.running).setStyles({'width':0,'margin-right':0,'margin-left':0}).injectTop($('paks'))
			this.effects[this.running].start({'width':165,'margin-right':5,'margin-left':5});

		},
		periodr: function(){
			$clear(this.per);
			if(this.effects[this.running].timer)
			{
				this.effects[this.running].stop();
				this.start.clearChain();
				this.effects[this.running].start({'width':165,'margin-right':5,'margin-left':5});
				this.counter--;
			}
			this.scrollRight();
			this.per = this.scrollRight.periodical(5000,this);
		},
		periodl: function(){
			$clear(this.per);
			if(this.effects[this.running].timer)
			{
				this.effects[this.running].stop();
				this.start.clearChain();
				var cout = this.running;
				this.effects[this.running].start({'width':0,'margin-right':0,'margin-left':0}).chain(function(){$('pk'+cout).setStyles({'width':165,'margin-right':5,'margin-left':5}).injectInside($('paks'))});
			}
			this.scrollLeft();
			this.per = this.scrollLeft.periodical(5000,this);
		},
		start: function(){
			this.scrollLeft();
			this.per = this.scrollLeft.periodical(5000,this);
		},
		Sleep: function (naptime){
	  naptime = naptime * 2000;
	  var sleeping = true;
	  var now = new Date();
	  var alarm;
	  var startingMSeconds = now.getTime();
	  while(sleeping){
		 alarm = new Date();
		 alarmMSeconds = alarm.getTime();
		 if(alarmMSeconds - startingMSeconds > naptime){ sleeping = false; }
		 sleeping = false;
	  }

   }

});
packageScroller.implement(new Options, new Events);

window.addEvent('domready',function(){
		if($defined($('paks')))
		{
			var scr = new packageScroller({
				packages : 'paks',counter:0
			})
			$('prev').addEvent('click', function(event) {
						event = new Event(event).stop();
						scr.periodr();
					});
			$('next').addEvent('click', function(event) {
						event = new Event(event).stop();
						scr.periodl();
					});

		}


})

//////////////////// stuff for the linked lists
function loadTypes()
{
	var url = "public/js/grabTypes.html";
	var country = $('country').options[$('country').selectedIndex].value
	/**
	 * The simple way for an Ajax request, use onRequest/onComplete/onFailure
	 * to do add your own Ajax depended code.
	 */
	new Ajax(url, {
		method: 'get',
		update: $('otherBox'),
		data: 'country='+country
	}).request();

}

function goToType(box)
{
	var location = $(box.id).options[$(box.id).selectedIndex].value;
	this.location.href = location;
}

function goToItinerary()
{
	var location = $('itinerary').options[$('itinerary').selectedIndex].value;
	this.location.href = location;
}
function goToCruise()
{
	var location = $('cruise').options[$('cruise').selectedIndex].value;
	this.location.href = location;
}
function updateFields(picker)
{
	var country = $('hcountry').options[$('hcountry').selectedIndex].value;
	var destination = $('hdestination').options[$('hdestination').selectedIndex].value;
	var accomodation = $('htype').options[$('htype').selectedIndex].value;
	var interest = $('hinterest').options[$('hinterest').selectedIndex].value
	if($defined($('countrybox'))) $('countrybox').innerHTML = "<strong>Updating</strong>";
	$('destinationbox').innerHTML = "";
	$('accomdationbox').innerHTML = "";
	$('interestbox').innerHTML = "";
	/**
	 * The simple way for an Ajax request, use onRequest/onComplete/onFailure
	 * to do add your own Ajax depended code.
	 */
	 var url = "public/js/get_hotel_country.html";
	 new Ajax(url, {
		method: 'get',
		update: $('countrybox'),
		data: 'country='+country+'&destination='+destination+'&accomodation='+accomodation+'&interest='+interest
	}).request();

	 var url = "public/js/get_hotel_destination.html";
	 new Ajax(url, {
		method: 'get',
		update: $('destinationbox'),
		data: 'country='+country+'&destination='+destination+'&accomodation='+accomodation+'&interest='+interest
	}).request();
		 var url = "public/js/get_hotel_accomodation.html";
	new Ajax(url, {
		method: 'get',
		update: $('accomdationbox'),
		data: 'country='+country+'&destination='+destination+'&accomodation='+accomodation+'&interest='+interest
	}).request();
		 var url = "public/js/get_hotel_interest.html";
	new Ajax(url, {
		method: 'get',
		update: $('interestbox'),
		data: 'country='+country+'&destination='+destination+'&accomodation='+accomodation+'&interest='+interest
	}).request();

}function updatePackageFields(picker)
{
	var country = $(picker.id).options[$(picker.id).selectedIndex].value;
	$('pdestinations').innerHTML = "";
	$('pinterests').innerHTML = "";
	/**
	 * The simple way for an Ajax request, use onRequest/onComplete/onFailure
	 * to do add your own Ajax depended code.
	 */

	 var url = "public/js/get_package_destination.html";
	 new Ajax(url, {
		method: 'get',
		update: $('pdest'),
		data: 'country='+country
	}).request();
	 var url = "public/js/get_package_interests.html";
	 new Ajax(url, {
		method: 'get',
		update: $('pint'),
		data: 'country='+country
	}).request();
}
function clearHotel()
{
	 var url = "public/js/get_hotel_country.html";
	 new Ajax(url, {
		method: 'get',
		update: $('countrybox'),
		data: 'country=all&destination=all&accomodation=all&interest=all'
	}).request();

	 var url = "public/js/get_hotel_destination.html";
	 new Ajax(url, {
		method: 'get',
		update: $('destinationbox'),
		data: 'country=all&destination=all&accomodation=all&interest=all'
	}).request();
		 var url = "public/js/get_hotel_accomodation.html";
	new Ajax(url, {
		method: 'get',
		update: $('accomdationbox'),
		data: 'country=all&destination=all&accomodation=all&interest=all'
	}).request();
		 var url = "public/js/get_hotel_interest.html";
	new Ajax(url, {
		method: 'get',
		update: $('interestbox'),
		data: 'country=all&destination=all&accomodation=all&interest=all'
	}).request();

}
function searchHotel()
{
	var country = $('hcountry').options[$('hcountry').selectedIndex].value;
	var destination = $('hdestination').options[$('hdestination').selectedIndex].value;
	var accomodation = $('htype').options[$('htype').selectedIndex].value;
	var interest = $('hinterest').options[$('hinterest').selectedIndex].value;
	if(country == ''  && destination == '' && accomodation == '' && interest == '')
	{
		alert('Eliga un hotel')

	}
	else if(country == 'all'  && destination == 'all' && accomodation == 'all' && interest == 'all')
	{
		alert('Eliga un hotel')

	}
	else
	{
		var location = "/"+country+"/"+destination+"/"+accomodation+"/"+interest+"/hotel_search.html";
		this.location.href = location;
	}

}

function ssearchHotel()
{
	var country = $('country_name').value;
	var destination = $('hdestination').options[$('hdestination').selectedIndex].value;
	var accomodation = $('htype').options[$('htype').selectedIndex].value;
	var interest = $('hinterest').options[$('hinterest').selectedIndex].value;
	if(country == '' && destination == '' && accomodation == '' && interest == '')
	{
		alert('Please narrow you selection, you are trying to view all our hotels')
		exit;
	}
	var location = "/"+country+"/"+destination+"/"+accomodation+"/"+interest+"/hotel_search.html";
	this.location.href = location;
}


function sendMe(form)
{
	alert('sending');
	$('reservation_form').submit();
}

function clearMe(form)
{
	alert('sending');
	$('reservation_form').clear();
}

