// Searchoptions object
var Searchoptions = Class.create({
	initialize: function(id) {
		this.id= id;
		this.switched = true;
	},
	swap: function() {
		if(searchoptions.switched == true) {
			Effect.BlindDown('searchOptions', {duration:.3});
			searchoptions.switched = false;
			$('searchOptionsText').innerHTML = 'Minder zoekopties';
			$('searchOptionsText').blur();
		}
		else {
			Effect.BlindUp('searchOptions', {duration:.3});
			searchoptions.switched = true;
			$('searchOptionsText').innerHTML = 'Meer zoekopties';
			$('searchOptionsText').blur();
		}
	}
});
var searchoptions = new Searchoptions("vliegtickets");

// Retour object
var Retour = Class.create({
	initialize: function(id) {
		this.open = true;
	},
	swap: function(method, detailpage) {
		if(method == true) {
			if(!this.open) {
				Effect.BlindDown('retour-box', {duration:.2});
				if(!detailpage) {
					$('vertrek2').disabled = false;
					$('bestemming2').disabled = false;
					$('retour_datum1').disabled = false;
				}
				this.open = true;
			}
		}
		else {
			Effect.BlindUp('retour-box', {duration:.2});
			if(!detailpage) {
				$('vertrek2').disabled = true;
				$('bestemming2').disabled = true;
				$('retour_datum1').disabled = true;
			}
			this.open = false;
		}
	}
});
var retour = new Retour();

var allOffers = [];
var Offer = Class.create({
	initialize: function(id, airline, price, conditions) {
		this.id= id;
		this.airline = airline;
		this.price = price;
		this.conditions = conditions;
		allOffers.push(this);
	},
	showOffer: function() {
		$('offerPrice').innerHTML = '&euro; '+this.price;
		$('offerAirline').innerHTML = '<img src="http://www.vliegtickets.nl/logo/'+this.airline+'" alt="'+this.airline+'" />';
		for(x=0;x < allOffers.length; x++) {
			Element.hide($(allOffers[x].conditions));
		}
		//Element.show($(this.conditions));
		$(this.conditions).style.display = 'block';
		this.showAllSideOffers();
	},
	showAllSideOffers: function() {
		for(x=0;x < allOffers.length; x++) {
			if(allOffers[x].id != this.id) {
				//$('offerListItem'+allOffers[x].id).style.display = 'block';
				Element.show($('offerListItem'+allOffers[x].id));
				//$('offerListItem'+allOffers[x].id).style.display = 'block';
			}
			else {
				Element.hide($('offerListItem'+allOffers[x].id));
				//$('offerListItem'+allOffers[x].id).style.display = 'none';
			}
		}
	}
});

var OfferColumn = Class.create({
	initialize: function(id,continent) {
		this.id= id;
		this.opened = false;

		this.regionNumbers = $w("startarray afrika azie midden-zuid-amerika europa noord-amerika midden-oosten oceanie");
		this.regionImageNumbers = $w("startarray afrika azie midden_zuid_amerika europa noord_amerika midden_oosten oceanie");

		this.image_world = new Image();
		this.image_world.src = "/images/maps/world/world.gif"
		this.image_afrika = new Image();
		this.image_afrika.src = "/images/maps/world/afrika.gif"
		this.image_azie = new Image();
		this.image_azie.src = "/images/maps/world/azie.gif"
		this.image_europa = new Image();
		this.image_europa.src = "/images/maps/world/europa.gif"
		this.image_midden_oosten = new Image();
		this.image_midden_oosten.src = "/images/maps/world/midden_oosten.gif"
		this.image_midden_zuid_amerika = new Image();
		this.image_midden_zuid_amerika.src = "/images/maps/world/zuid_amerika.gif"
		this.image_noord_amerika = new Image();
		this.image_noord_amerika.src = "/images/maps/world/noord_amerika.gif"
		this.image_oceanie = new Image();
		this.image_oceanie.src = "/images/maps/world/oceanie.gif"
		
		if(continent) {
			this.switchRegion(continent, 1);
			$("offer-map").src = eval("this.image_"+this.regionImageNumbers[continent]+".src");
		}
	},
	switchRegion: function(region, init) {
		this.activeRegion = region;
		//this.activeRegion = region;
		if(!this.opened) new Effect.Move ($('sliding-offers'),{ x: 0, y: 0, mode: 'absolute', duration: 0.3});
		this.opened = true;
		$("offer-map").blur();
		this.loadOffers(init);
	},
	loadOffers: function(init) {
		new Ajax.Request('/includes/ajax/offers.php',
		{
			method:'get',
			parameters: {continent: this.activeRegion},
			onSuccess: function(transport){
				var response = transport.responseText || "<div style=\"padding:10px;text-align:center;margin:0 auto;\">Er zijn momenteel geen aanbiedingen voor dit continent.<br /><br />Klik <a href=\"/aanbiedingen.php\">hier</a> voor een overzicht van alle aanbiedingen</div>";
				$("offers-list").innerHTML = response;
			},
			onFailure: function(){
				$("offers-list").innerHTML = 'error loading xml';
			},
			onLoading: function(){
				if(!init) $("offers-list").innerHTML = '<div style="text-align:center;margin:0 auto;"><img src="/images/spinner.gif" alt=""></div>';
			}
		});	
	},
	regionOver: function(region) {
		$("offer-map").src = eval("this.image_"+offercolumn.regionImageNumbers[region]+".src");
	},
	regionOut: function(region) {
		if(this.activeRegion != region) {
			if(this.activeRegion) $("offer-map").src = eval("this.image_"+offercolumn.regionImageNumbers[this.activeRegion]+".src");
			else $("offer-map").src = this.image_world.src;
		}
	},
	showContinentOffers: function() {
		if(this.activeRegion) location.href='/aanbiedingen/vliegtickets-'+offercolumn.regionNumbers[this.activeRegion];
		else location.href='/aanbiedingen.php';
	},
	closeOffers: function() {
		if(this.opened) new Effect.Move ($('sliding-offers'),{ x: 0, y: 242, mode: 'absolute', duration: 0.3});
		$("offer-map").src = this.image_world.src;
		this.opened = false;
	}
});


Array.prototype.getIndex = function(data) {
	for (i=0; i<this.length; ++i) {
		if (this[i] == data) {
			return i;
		}
	}
	return -1;
};

function update_inf() {
	var adults = parseInt($('nr_adults').options[$('nr_adults').selectedIndex].value,10);
	var inf = parseInt($('nr_infants').options[$('nr_infants').selectedIndex].value,10);
	
	
	if(adults == 10) {
		location.href = '/groepen.php';	
	}
	while (adults < $('nr_infants').options.length) {
		$('nr_infants').options[($('nr_infants').options.length - 1)] = null;
	}
	for (var i=0; i <= adults; i++) {
		if(i == 1)
			$('nr_infants').options[i] = new Option(i+' baby',i);
		else {
			$('nr_infants').options[i] = new Option(i+' baby\'s',i);
		}
	}
	if (inf <= $('nr_infants').options.length) {
		$('nr_infants').selectedIndex = inf;
	}
}

function checkNewsletter(){
	if($('email').value == 'typ hier uw mailadres'){
		$('email').value = '';
		$('email').style.color = '#000';
	}
}

