fd.video.container = ".gallery-image";
fd.video.autoplay  = true;

var image_position, image_count;

function icon_selected(){
  image_position = $("#thumbnail-gallery .thumbnail").index(this);
  image_show();
}

function image_show(){
  $("#thumbnail-gallery .thumbnail").removeClass("active");
  $("#thumbnail-gallery .thumbnail:eq("+ image_position +")").addClass("active");
  $("#gallery-image-container .gallery-image").hide();
  $("#gallery-image-container .gallery-image:eq("+image_position+")").fadeIn().trigger(fd.video.eventShow);
}

function image_next(){
  image_position += 1;
  if(image_position > image_count -1) image_position = 0;
  image_show();
}

function image_previous(){
  image_position -= 1;
  if(image_position < 0)  image_position  = image_count -1;
  image_show(); 
}

$(document).ready(function(){
   if($("#gallery-image-container").length > 0){
     image_count = $("#gallery-image-container .gallery-image").length;
     image_position = 0;
     image_show();
     $("#gallery-image-container .gallery-image").click(image_next);
     $("#thumbnail-gallery .thumbnail").click(icon_selected);
     $("#thumbnail-gallery #gallery-navigation .forward").click(image_next);
     $("#thumbnail-gallery #gallery-navigation .back").click(image_previous);
  };
});

function init_music(){
  $("object param").each(function(){
    var url = $(this).attr("value");
    $.getScript("http://soundcloud.com/oembed?url="+encodeURIComponent(url)+"&format=js&callback=load_music");
  })
}
    
function load_music(d){
   $(".collection").html(d.html);
}
  
$(document).ready(function()
{
   init_music(); 
  //toggle the componenet with class msg_body
  $("div.msg_list").click(function(){
    if($(this).find(".msg_body.selected").length > 0) return true;
    $(".msg_body.selected").slideUp().removeClass("selected");
    $(this).find(".msg_body").slideDown(400).addClass("selected");
  });
});
