var maps_timetables = {
	init: function() {
		$('#destination_route_box h4').css('cursor', 'pointer');
		
		$.each($('#destination_route_box h4'), function() {
			$(this).nextUntil('h4').wrap('<div class="section_content" />');
		});
		
		$('.section_content').hide();
		
		$('#destination_route_box h4').toggle(function() {
			$(this).next().slideDown();
			$(this).css('background-image', 'url(http://getbus.marcomhosting.com/wp-content/themes/GET/images/up_arrow.png)');
			$(this).css('background-position', '98% 4px');
		}, function() {
			$(this).next().slideUp();
			$(this).css('background-image', 'url(http://getbus.marcomhosting.com/wp-content/themes/GET/images/down_arrow.png)');
			$(this).css('background-position', '98% 5px');
		});
		
		$('#destinations_link').addClass('current');
		$('#destinations_link').click(function() {
			$('#destinations').show();
			$('#route_details').hide();
			
			$('#route_details_link').removeClass('current');
			$(this).addClass('current');
			
			return false;
		});
		
		$('#route_details_link').click(function() {
			$('#destinations').hide();
			$('#route_details').show();
			
			$('#destinations_link').removeClass('current');
			$(this).addClass('current');
			
			return false;
		});
	}
}

var alerts = {
	init: function() {
		if ($('#alerts_container .service_alert').length < 3) {
			$('#more_alerts').hide();
			return;
		}

		var alerts = $('#alerts_container .service_alert');

		alerts.hide();

		$('#alerts_container .service_alert:eq(0)').show();
		$('#alerts_container .service_alert:eq(1)').show();

		var first = 2;
		var second = 3;

		$('#more_alerts a').click(function() {
			if ($('#alerts_container .service_alert').length < 3) return false;

			alerts.hide();

			$('#alerts_container .service_alert:eq('+first+')').fadeIn();
			$('#alerts_container .service_alert:eq('+second+')').fadeIn();

			if (first >= alerts.length-1) {
				first = 0;
				second = 1;
			} else {
				first += 2;
				second += 2;
			}

			return false
		});
	}
}

var search = {
	init: function() {
		$('#s').focus(function() {
			$(this).val('');
		});
		
		$('#s').blur(function() {
			if ($(this).val() == '') {
				$(this).val('Search');
			}
		});
	}
}

var text_size = {
	init: function() {
		$('#textsize1').click(function() {
			$('#main_content, #footer').css('font-size', '80%');
			$('body.home .news, body.home .service_alert').css('font-size', '80%');
			
			return false;
		});
		
		$('#textsize2').click(function() {
			$('#main_content, #footer').css('font-size', '');
			$('body.home .news, body.home .service_alert').css('font-size', '');
			
			return false;
		});
		
		$('#textsize3').click(function() {
			$('#main_content, #footer').css('font-size', '120%');
			$('body.home .news, body.home .service_alert').css('font-size', '120%');
			
			return false;
		});
	}
}

$(function() {
	
	maps_timetables.init();
	alerts.init();
	search.init();
	text_size.init();
	
});
