$(document).ready(function() {
//	=========================================================================================================
//	FIXED SIDEBAR
/*
	function staticNav() { 
		var sidenavHeight = $("#sidenav").height();
		var winHeight = $(window).height();
		var browserIE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;

		if (browserIE6) {
			$("#sidenav").css({'position' : 'absolute'});
		} else {
			$("#sidenav").css({'position' : 'fixed'});
		}
	
		if (sidenavHeight > winHeight) {
			$("#sidenav").css({'position' : 'static'});
		}
	}
		
*/

	$(function() {
		$(window).scroll(function() {
			var top = $('#sidenav');
			if($(this).scrollTop() > 275) {
				top.css({'position': 'fixed', 'top': '-275px'});
			} 
			else {
				top.css({'position': 'absolute', 'top': '0px'});
			}
		});
	});


//	=========================================================================================================
//	PAGE NAVIGATION

	var arrsections = new Array();
	
	arrsections[0] = new Array('top');
	arrsections[1] = new Array('pricing');
	arrsections[2] = new Array('book');
	arrsections[3] = new Array('timetable');
	arrsections[4] = new Array('maps');
	arrsections[5] = new Array('faqs');
	
	function animateMenu(menu) {
		var scrollposition = $(window).scrollTop();
		var top = $("a[name='"+ menu +"']").offset().top;
		var sectionheight = $("a[name='"+ menu +"']").next().outerHeight();
		
		if (((top-100) < scrollposition) && ((top+sectionheight-140) > scrollposition)) {
			$("a[href='#"+ menu +"']").parent().addClass("current");
		} else {
			$("a[href='#"+ menu +"']").parent().removeClass("current");
		}		
	}


    $(window).scroll(
    	function() {
			
            for (var i = 0; i < arrsections.length; i++) {
            	animateMenu(arrsections[i][0],arrsections[i][1]);
            } 
            
    	}
   	);  
        

	$("#homePage #nav ul a").click(
		function(event) {
			event.preventDefault();
			var loc = $(this).attr("href");    
			var loc = loc.substring(1);
			var dest = 0;
			if (loc == "") {
				dest = 0;
			} else {
				dest = $("a[name='"+loc+"']").offset().top -20;	
			}
			$("body, html").stop().animate({scrollTop: dest}, {duration:1000});
		}
	);
	
	$("#footer a#top").click(
		function(event) {
			event.preventDefault();
			var loc = $(this).attr("href");    
			var loc = loc.substring(1);
			var dest = 0;
			if (loc == "") {
				dest = 0;
			} else {
				dest = $("a[name='"+loc+"']").offset().top -20;	
			}
			$("body, html").stop().animate({scrollTop: dest}, {duration:1000});
		}
	);
	
	$("#accordion h3 a").click(
		function(event) {
			event.preventDefault();
		}
	);
	
	$("#bus a").click(
		function(event) {
			event.preventDefault();
			var loc = $(this).attr("href");    
			var loc = loc.substring(1);
			var dest = 0;
			if (loc == "") {
				dest = 0;
			} else {
				dest = $("a[name='"+loc+"']").offset().top -20;	
			}
			$("body, html").stop().animate({scrollTop: dest}, {duration:1000});
		}
	);

// 	===========================================================
// 	POPUP WINDOW

/*	*/$("#subMenu li a").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'overlayOpacity'	: '0.7',
		'overlayColor'		: '#000',
		'speedIn'			: 500,	
		'speedOut'			: 800,
		'showNavArrows'		: false
	});
	

	$("a.footerlink").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'overlayOpacity'	: '0.7',
		'overlayColor'		: '#000',
		'speedIn'			: 500,	
		'speedOut'			: 800,
		'showNavArrows'		: false
	});


// 	===========================================================
// 	ZEBRA STRIPE

	$("#priceTable").each(function(){
		$("tr:odd", this).not(".even").addClass("odd");
		$("tr:even", this).not(".odd").addClass("even");
	});


// 	===========================================================
// 	JQUERY UI

	$("#datepicker").datepicker({ showAnim: 'slideDown' });
	$("#submit").button();
	$("#accordion").accordion({ icons: false, collapsible: false, active:1, event: 'mouseover' });
	
	
	$('#end').keypress(function() {
	  if($("#end").val().length >= 0) {
	    $("#start").val('');
	  }
	});
	
	$('#start').keypress(function() {
	  if($("#start").val().length > 0) {
	    $("#end").val('');
	  }
	});
	
	
	//$("#accordion").accordion({ icons: { 'header': 'ui-icon-plus', 'headerSelected': 'ui-icon-minus' }, collapsible: false, active:1, event: 'mouseover' });

// 	===========================================================
// 	FORM DEFAULTS

	//$("#start").DefaultValue("Enter your destination address...");
	//$("#end").DefaultValue("Enter your departure address...");

});


