var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}(); 



$(document).ready(function() {
	
	
	
	$('.addButton').click(function(e){
          $(this).next('div').show(); 
    });
	  	$('.CloseButton').click(function(e){
          var box = $(this).parent();  
               box.hide(); 
    });
	       
	
	
	
	
	
	
	$('.go').click(function(e){
	   
	   var  saddr = $('#from').val() + " Lexington, KY ";
	   var  daddr = $('#to').val()  + " Lexington, KY ";
	   var  date  = $('#date').val();
	   var  hours = $('#hours').val();
		var min  = $('#min').val();
		var am   = $('#ampm').val(); 
		var time = + hours +":"+ min +" "+ am;
		var leave_now = $('#leave_now').val();
		
		if (leave_now) {time = "";};
		
		var string  = "?saddr="+ saddr +"&daddr="+ daddr + "&date=" + date + "&time=" + time;
		
		//alert(leave_now + string);
		 location.href='http://google.com/transit' + string;
	});
	
	$('.loopedSlider').loopedSlider();                                                 
   	$("#RouteTabs").tabs();
 	
	$('.mapbtns .flt_Rt').click(function(e){
	$('.favoritetxt').slideToggle('slow');
	})

	newsCount =0;
	timedelay = 5000;   
	timer = window.setInterval(news, timedelay);

	$(".alert0").show(1000).addClass('currentNews');   

	function news(e){

		newsCount++;    
		if(newsCount == $(".service_alerts").length) { newsCount = 0 };  
		$('.service_alerts').removeClass('currentNews').hide(1000);
		$(".alert"+newsCount).show(1000).addClass('currentNews');  
	}

	$('.schedule li').each(function(e){ if(e % 2) $(this).addClass('diffbg');});

	$('.menu ul').each(function(e){ $('li:last-child a', this).addClass('lastsubnav'); });
     



 $.easing.elasout = function(x, t, b, c, d) {
        var s=1.70158;var p=0;var a=c;
        if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
        if (a < Math.abs(c)) { a=c; var s=p/4; }
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
    };
$('#route_button').click(function(){
	
	$('#routemap_menu').toggle();
	
	
});


    // This one is important, many browsers don't reset scroll on refreshes
    // Reset all scrollable panes to (0,0)
  $('#routes').scrollTo( 0 );
    // Reset the screen to (0,0)
    $.scrollTo( 0 );
    
    
    // Target examples bindings
    // THIS DEMO IS NOT INTENDED TO SHOW HOW TO CODE IT
    // JUST THE MULTIPLE OPTIONS. THIS CODE IS UGLY.
    var $paneTarget = $('#routes');
    
  
 $('.routelinks').click(function(){
	
	   var route = $(this).attr('rel');  
	    var target = $(this).attr('alt');
	   $("#current_route_text").attr('href','/routes/view/'+ route);  
  
	$("#current_route_text").text($(this).text()); 
        $('#routes').scrollTo( target, 800 );
         $('#routemap_menu').toggle(); 
                       
      initialize(route);
    });



    
    // Options examples bindings, they will all scroll to the same place, with different options
    function reset_o(){//before each animation, reset to (0,0), skip this.
        $paneOptions.stop(true).attr({scrollLeft:0, scrollTop:0});
    };
   

    // onAfterFirst exists only when queuing
    $('#options-onAfterFirst').click(function(){
        reset_o(); $paneOptions.scrollTo( 'li:eq(15)', 1600, { 
            queue:true,
            onAfterFirst:function(){
                $('#options-message').text('Got there horizontally!');
            },
            onAfter:function(){
                $('#options-message').text('Got there vertically!');
            }
        });
    });


});    
	

