var http_request = false;

function loadOffers(area) {
	switch (area) {
		case 1:
			ganz.src = '/styles/images/ausland/sa_active.gif';
			break;
		case 2:
			ganz.src = '/styles/images/ausland/na_active.gif';
			break;
		case 3:
			ganz.src = '/styles/images/ausland/af_active.gif';
			break;
		case 4:
			ganz.src = '/styles/images/ausland/eu_active.gif';
			break;
		case 5:
			ganz.src = '/styles/images/ausland/aus_active.gif';
			break;
		case 6:
			ganz.src = '/styles/images/ausland/as_active.gif';
			break;
	}
	
	http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) { }
		}
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	
	url = '/ausland/loadOffers/';
	parameters = 'area=' + area;
	
	http_request.onreadystatechange = changeOffers;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

function changeOffers() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			document.getElementById('carousel').innerHTML = http_request.responseText;

			window.addEvent('domready', function() {
				// Let's define some variables first
				wrapper = $('wrap'); // The outer wrapper
				carousel = $('carousel'); // The inner wrapper
				items = $$('#carousel li'); // The different elements, this is an array
				item_width = 152; // The full width of a single item (incl. borders, padding, etc ... if there is any)
				max_margin = ((items.length * item_width) - (item_width * 4));

				// Set up the animation
				var animation = new Fx.Tween(carousel, {duration: 500});
				animation.start('left', 0);

				if (items.length < 5) {
					$('next').addClass('inaktivr');
					$('previous').addClass('inaktivl');
				}
	
				// The function to browse forward
				/*function next_item(pos) {
					if (pos == -max_margin) {
						animation.start('left', 0);
					} else {
						var newposition = pos - item_width;
						animation.start('left', newposition);
					}
				}
				
				// The function to browse backward
				function previous_item(pos) {
					if (pos == 0) {
						animation.start('left', -max_margin);
					} else { 
						var newposition = pos + item_width;
						animation.start('left', newposition);
					}
				}
				
				// Set up the 'next' and 'previous' buttons
				$('next').addEvent('click', function() {
					if (items.length > 4) {
						var position = parseInt(carousel.getStyle('left'));
						next_item(position);
					}
				});
					
				$('previous').addEvent('click', function() {
					if (items.length > 4) {
						var position = parseInt(carousel.getStyle('left'));
						previous_item(position);
					}
				});*/
			});
		} else {
			alert('There was a problem with the request.');
		}
	}
}


