/**
 * Tennis Club Lausanne
 * Javascript main file
 *
 * Copyright 2009-2010 Antistatique.net Sàrl
 * Author: gde@antistatique.net
 */
var agendaSlider = null;
jQuery(function($){
   
   /** GENERAL ***************************************************************/
   
   // hide/show weather
   $("#weather h2").click(function(evt) {
      var $parent = $(this).parent();
      if( $("#weather_content").is(':visible') )
      {
         // close
         $("#weather_content").slideUp(400, function(){
            $parent.removeClass("weather_opened").addClass("weather_closed");
         });
      } else {
         // open
         $("#weather_content").slideDown(200, function(){
            $parent.removeClass("weather_closed").addClass("weather_opened");
         });
      }
   });
   
   
   $("input[placeholder]").each(function(i, el){
      // if placeholder isn't supported:
      if (!Modernizr.input.placeholder){
         // use a input hint script
         var hint = $(this).attr('placeholder');
         $(this).val(hint).addClass("placeholder")
            .focus(function(e){
               if($(this).val() == hint) $(this).removeClass("placeholder").val('');
            }).blur(function(e){
               if($(this).val() == '') $(this).addClass("placeholder").val(hint);
            });
      }
   });
   
   // Update today infos by Twitter statues
   $(".info_today").hide();
   $.getJSON('http://search.twitter.com/search.json?callback=?', { q: 'from:tennislausanne #tennis' }, function(data){
      var tweets = data.results || [];
      if(tweets.length > 0) {
         $(".info_today").text(tweets[0].text).fadeIn('slow');
      } else {
         $(".info_today").fadeIn('slow');
      }
   });
   
   /** HOME ******************************************************************/
   
	if($.fn.scrollable)
	{
	   // Agenda slider
	   agendaSlider = $("#agenda_slider").scrollable({
	      size: 1,
	      vertical: true,
	      clickable: false,
	      items: "ul",
	      next: "#next_slider",
	      prev: "#back_slider",
	      api: true,
	      onSeek: function(evt, index){
	         $("#agenda_slider_list.with_slider ul li").removeClass("active").eq(index).addClass("active");
	      }
	   });/*.circular({
	      api: true
	   })*/;
   
	   // init agenda list
	   $("#agenda_slider_list.with_slider ul li").each(function(i, el){
	      $('a', this).hoverIntent({
	         sensitivity: 7,
	         interval: 100,
	         timeout: 0,
	         over: function(evt){
	            // move to index
	            agendaSlider.seekTo(i);
	            // set active class
	            $(this).parents("ul").find("li").removeClass("active");
	            $(this).parent().addClass("active");
	         },
	         out: function(evt){}
	      });
	   });
   }
   
   /** AGENDA ***********************************************************************/
   // Ouverture détail agenda item
   $('.event_intro').click(function(e){
      $(this).next().slideToggle('fast');
	  e.preventDefault();
   });   
   
});
 