var portalDefault = '';
var portal = new Portal();

function Portal()
{
	this.activeHotels 			= new Array();    
	this.nextPreviewIndex 		= 0;	       		//For the slide show, which activehotel to show next
	this.currentPreviewId     	= false;	   		//The dom Id of the current slide
	this.nextPreviewId     		= false;	   		//The dom Id of the next slide	
	
	this.locationSelect         = false;            //Location Select for the hotel search mask
	
	this.init = function()
	{
		this.getActiveHotels();
		this.startSlideShow();
		this.locationSelect = document.getElementById('locationSelect');
	}
	
	this.getActiveHotels = function()
	{
		var hotels = $(".hotelPreview");
		
		for(var i = 0; i < hotels.length; i++)
		{
			this.activeHotels.push(hotels[i].id);
		}
	}
	
	this.startSlideShow = function()
	{
		var rand = Math.floor(Math.random() *  this.activeHotels.length);
		this.nextPreviewId = this.activeHotels[rand];
		this.nextSlide();
	}
	
	this.nextSlide = function()
	{
		if(this.nextPreviewId != this.currentPreviewId)
		{
			if(this.currentPreviewId !== false)
			{
				this.slideOut(this.currentPreviewId);
			}
			
			this.slideIn(this.nextPreviewId);
		}
		
		this.nextPreviewIndex++;
		this.currentPreviewId = this.nextPreviewId;
		this.setNextSlide();
		
		setTimeout('portal.nextSlide()',6000);
	}
	
	this.setNextSlide = function()
	{
		if(this.nextPreviewIndex >= this.activeHotels.length)
		{
			this.nextPreviewIndex = 0;
		}
		
		this.nextPreviewId = this.activeHotels[this.nextPreviewIndex];
	}
	
	this.slideIn = function(id)
	{
		$("#" + id).hide().css('left', '380px').fadeIn("slow");
	}
	
	this.slideOut = function(id)
	{
		$("#" + id).fadeOut("slow");
	}
	
	this.orderBy = function(orderBy)
	{
		$(".orderBy").css('color', '#444');
		
		$(".orderByImage").each(function (i) {
			if(this.src.indexOf('_mid') == -1)
			{
				this.src = this.src.replace('.png', '_mid.png');
			}
		});
		
		switch(orderBy)
		{
			case 'hotel' : 
				$("#orderByHotel").css("color", "#CF6018");
				$(".hotelContainer").tsort(".hotelName",{order:"asc"});
				break;
			case 'city' : 
				$("#orderByCity").css("color", "#CF6018");
				$(".hotelContainer").tsort(".sortByCity",{order:"asc"});
				break;
			case 'price' : 
				$("#orderByPrice").css("color", "#CF6018");
				$(".hotelContainer").tsort(".sortByPrice",{order:"asc"});
				break;
			case 'train' : 
				$("#iconTrainSort").attr('src', $("#iconTrainSort").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortByTrain",{order:"asc"});
				break;
			case 'highway' :
				$("#iconRoadSort").attr('src', $("#iconRoadSort").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortByHighway",{order:"asc"});
				break;
			case 'airport' : 
				$("#iconAirportSort").attr('src', $("#iconAirportSort").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortByAirport",{order:"asc"});
				break;
			case 'parking' : 
				$("#iconParkingSort").attr('src', $("#iconParkingSort").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortByParking",{order:"desc"});
				break;
			case 'centre' : 
				$("#iconCentreSort").attr('src', $("#iconCentreSort").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortByCentre",{order:"desc"});
				break;
			case 'safe' : 
				$("#iconSafeSort").attr('src', $("#iconSafeSort").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortBySafe",{order:"desc"});
				break;
			case 'fitness' : 
				$("#iconFitnessSort").attr('src', $("#iconFitnessSort").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortByFitness",{order:"desc"});
				break;
			case 'internet' : 
				$("#iconInternetSort").attr('src', $("#iconInternetSort").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortByInternet",{order:"desc"});
				break;
			case 'food' : 
				$("#iconRestaurantSort").attr('src', $("#iconRestaurantSort").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortByFood",{order:"desc"});
				break;
			case 'pool' : 
				$("#iconPoolSort").attr('src', $("#iconPoolSort").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortByPool",{order:"desc"});
				break;
			case 'sauna' : 
				$("#iconSaunaSort").attr('src', $("#iconSaunaSort").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortBySauna",{order:"desc"});
				break;
			case 'numberRooms' : 
				$("#iconNumberRooms").attr('src', $("#iconNumberRooms").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortByRooms",{order:"desc"});
				break;
			case 'confCapacity' : 
				$("#iconConfCapacity").attr('src', $("#iconConfCapacity").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortByConfCapacity",{order:"desc"});
				break;
			case 'air' : 
				$("#iconAir").attr('src', $("#iconAir").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortByAir",{order:"desc"});
				break;
			case 'techSupport' : 
				$("#iconTechSupport").attr('src', $("#iconTechSupport").attr('src').replace('_mid.png', '.png'));
				$(".hotelContainer").tsort(".sortByTechSupport",{order:"desc"});
				break;
		}
	}
}



