$(window).load(function()
{
	$('.linkTodayHappyHoursDetail').live('click', function()
	{
		var id = $(this).attr('href').replace('#','');
		var div = $('#divTodayHappyhours_' + id);
		
		//$('#moreLink_'+id).hide(200, function() {  });
		
		if(div.is(':hidden'))
		{
			div.fadeIn();
		}
		else
		{	
			div.fadeOut();
		}
		
		return false;
	});
	
	/*
	 * TABS - LOCATIONS
	 */
	$('div.locations a, a#startLocationsOffset').live('click', function()
	{
		var elem = $(this).text();
		var ajaxReq, offset;
		
		if($('a#startLocationsOffset').length > 0)
		{
			offset = $('a#startLocationsOffset').attr('rel');
		}
		if(offset == null) offset = 0;		
		
		$(this).parent().children('a').removeClass('active');
		$(this).addClass('active');
		
		switch(elem)
		{
			case "mehr":	
			case "Nahe": 
				// Default zwischenspeichern
				if($('div#startLocationsDefault').html().length == 0)
					$('div#startLocationsDefault').html($('#startLocationsContent').html());
				
				ajaxReq = "/user/ajaxgetnearlocations/";
				break;
			
			case "Top":
				// Default zwischenspeichern
				if($('div#startLocationsDefault').html().length == 0)
					$('div#startLocationsDefault').html($('#startLocationsContent').html());
				
				ajaxReq = "/locations/ajaxtoplocations/";
				break;
			
			default:
			case "Neue":
				if($('div#startLocationsDefault').html().length > 0)
				{
					$('#startLocationsContent').fadeTo(300,0.3, function() {
						$('div#startLocationsContent').html($('#startLocationsDefault').html());
						$('#startLocationsContent').fadeTo(300,1);
					});	
				}
				return false;
				break;
		}
		
		$('#startLocationsContent').fadeTo(300,0.3);
		$.post(ajaxReq, { 'offset' : offset, 'home' : 1 }, 
				function(data)
				{
					$('#startLocationsContent').html(data.html);
					$('#startLocationsContent').fadeTo(300,1);
				},'json');
	});
	
	/*
	 * TABS - HAPPY HOURS
	 */
	$('div.happyhours a, a#startHappyHoursOffset').live('click', function()
	{
		var elem = $(this).text();
		var ajaxReq, offset;
		
		if($('a#startHappyHoursOffset').length > 0)
		{
			offset = $('a#startHappyHoursOffset').attr('rel');
		}
		if(offset == null) offset = 0;	
		
		$(this).parent().children('a').removeClass('active');
		$(this).addClass('active');
		
		switch(elem)
		{
			case "mehr":	
			case "Nahe": 
				// Default zwischenspeichern
				if($('div#startHappyHoursDefault').html().length == 0)
					$('div#startHappyHoursDefault').html($('#startHappyHoursContent').html());
				
				ajaxReq = "/user/ajaxgetnearhappyhours/";
				break;
			
			case "Neue":
				// Default zwischenspeichern
				if($('div#startHappyHoursDefault').html().length == 0)
					$('div#startHappyHoursDefault').html($('#startHappyHoursContent').html());
				
				
				ajaxReq = "/happyhours/ajaxgetnewesthappyhours/";
				break;
				
			default:
			case "Heute":
				if($('div#startHappyHoursDefault').html().length > 0)
				{
					$('#startHappyHoursContent').fadeTo(300,0.3, function() {
						$('div#startHappyHoursContent').html($('#startHappyHoursDefault').html());
						$('#startHappyHoursContent').fadeTo(300,1);
					});	
				}
				return false;
				break;
		}
		
		$('#startHappyHoursContent').fadeTo(300,0.3);
		$.post(ajaxReq, { 'offset' : offset, 'home' : 1 }, 
				function(data)
				{
					$('#startHappyHoursContent').html(data.html);
					$('#startHappyHoursContent').fadeTo(300,1);
					//$('input.star').rating();
				},'json');
	});
	
	$('div.routen a').live('click', function()
	{
		var $this = $(this);
		var href = $this.attr('href');
		
		$(this).parent().children('a').removeClass('active');
		$(this).addClass('active');
		
		with(PowerHour.HappyHour)
		{
			//Locations loeschen
			Find.Current.clearHappyHours();
		}
		$.post(	href, 
					PowerHour.User.GetGeolocationJSON(),
					function(locations)
					{
						with(PowerHour.HappyHour)
						{
							if($this.hasClass('fastest'))
								routeMode = RouteMode.Fastest;
							else
								Find.Current.routeMode = RouteMode.Personal;
							
							Find.Current.addHappyHours(locations,true);
							Find.Current.calculateRoute();
						}
					});
		
		return false;
	});
	
	//Route of the day laden
	/*
	$.post(	"/userroute/routeoftheday", PowerHour.User.GetGeolocationJSON(), function(locations)
	{
		if(locations.length > 0)
		{
			new PowerHour.HappyHour.Find(locations, "divGoogleMapStart");
		
			if(locations.length > 0)
			{
				with(PowerHour.HappyHour)
				{
					Find.Current.routeMode = RouteMode.Fastest;
					Find.Current.calculateRoute();
				}
			}
		}
		else
		{
			new PowerHour.HappyHour.Find(null, "divGoogleMapStart");
			$('#startRouteOfTheDay').hide();
			$('#startRouteRandom').click();
		}
	});
	*/
});
