/**
 * Home view javascript for carousel
 * @version:  $Id$
 * @todo:     clean up this file and perhaps split it into separate files
 */
 
var public_car;
var carousel_started = false;

/* If document is loaded (domready) */
$(document).ready(function(){
  
  var pids = [];
  var outside_counter = 0;
  
  var navHtml = "";

  // Cycle through the images and build a LI for each of them
  $("#cycle_holder img").each(function(){
    var pid = $(this).attr("rel");
    var title = $(this).attr("title");
    var thumb_src = $(this).attr("src").replace(".jpg","_thumb.jpg");

    if(outside_counter==0)
      navHtml+="<li class='active_slide' id='cycle_item_"+outside_counter+"'>";
    else
      navHtml+="<li id='cycle_item_"+outside_counter+"'>";
  
    navHtml+="<img border='0' src='"+thumb_src+"' width='100' height='60' />";
    navHtml+="<span>"+title+"</span>";
    navHtml+="</li>";

    outside_counter++;    
  });

  // Set the generated HTML into the nav div
  $("#nav").html(navHtml);

  // Wrap the builded list with a UL
  var html = $("#nav").html();
  $("#nav").html("<ul  class='nav_cycler'>"+html+"</ul>");

  // Cycle the images on click
  $("#nav ul li").each(function(){
    $(this).click(function(){
      var me = parseInt($(this).attr("id").replace("cycle_item_",""));
      $("#cycle_holder").cycle(me);
    });
  });    

  // Activate agenda ticker
  $('#agenda_ticker ul').list_ticker();

});



function onBefore() { 
	
  $("#nav ul li").each(function(){$(this).removeClass("active_slide")});
 
  var current_id = parseInt($(this).attr("id").replace("cycle_wrap_element_",""));
  
  
  $("#cycle_item_"+current_id).addClass("active_slide");  
/*
  if(carousel_started) {
    if(current_id%3 == 0)
  		//public_car.scroll((current_id/3) + 1);
      }
*/
}

function onAfter() { 
  $(".cycle_text").each(function(){$(this).css("bottom","0px");});
//  $(this).children(".cycle_text").animate({bottom:"0"},800);  
}


function mycarousel_initCallback(carousel) {
  public_car = carousel;	
  carousel_started = true;
}

