(function($) {
  $.fn.GestYoutube = function(option) {
    var defaults = {
      array_video_big: new Array(),
      array_video_small: new Array(),
			colore: 'eeeeee',       
			coloredue: 'eeeeee',   
      position_big: 'up'
    };

    $(this)[0].VariabiliObject = $.extend(defaults, option);

    if ($(this)[0].VariabiliObject.array_video_big.length <= 1)
      return;

    $(this)[0].array_percorso_video = new Array();

    for ($(this)[0].i = 0; $(this)[0].i < $(this)[0].VariabiliObject.array_video_big.length; $(this)[0].i++) {
      $(this)[0].array_percorso_video[$(this)[0].i] = $(this)[0].VariabiliObject.array_video_big[$(this)[0].i].substring($(this)[0].VariabiliObject.array_video_big[$(this)[0].i].indexOf('?v=') + 3);
    }

    $("#" + $(this)[0].id).append("<div id='contenitore_video_" + $(this)[0].id + "'><object width=\"340\" height=\"270\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + $(this)[0].array_percorso_video[0] + "&hl=jp&fs=1&color1=0x" + $(this)[0].VariabiliObject.colore + "&color2=0x" + $(this)[0].VariabiliObject.coloredue + "\"></param><param name=\"allowFullScreen\" value=\"true\"></param><embed src=\"http://www.youtube.com/v/" + $(this)[0].array_percorso_video[0] + "&hl=jp&fs=1&color1=0x" + $(this)[0].VariabiliObject.colore + "&color2=0x" + $(this)[0].VariabiliObject.coloredue + "\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"340\" height=\"270\"></embed></object></div>");

    if ($(this)[0].VariabiliObject.position_big == 'up') {
      $("#" + $(this)[0].id).append("<ul id='small_" + $(this)[0].id + "' ></ul>");
    }


    for ($(this)[0].i = 0; $(this)[0].i < $(this)[0].VariabiliObject.array_video_small.length; $(this)[0].i++) {
      $("#small_" + $(this)[0].id).append("<li id='img_" + $(this)[0].i + "_" + $(this)[0].id + "'><a href=''><img src='" + $(this)[0].VariabiliObject.array_video_small[$(this)[0].i] + "' /><span>&#21205;&#30011;&#12434;&#20877;&#29983;</span></a></li>");
      $("#img_" + $(this)[0].i + "_" + $(this)[0].id)[0].onclick = function() {
        var temp = $(this)[0].id.substring(4);
        var numero = temp.substring(0, temp.indexOf("_"));
        $("#contenitore_video_" + this.parentNode.parentNode.id).html("<object width=\"340\" height=\"270\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + $("#" + this.parentNode.parentNode.id)[0].array_percorso_video[numero] + "&hl=jp&fs=1&color1=0x" + $("#" + this.parentNode.parentNode.id)[0].VariabiliObject.colore + "&color2=0x" + $("#" + this.parentNode.parentNode.id)[0].VariabiliObject.coloredue + "\"></param><param name=\"allowFullScreen\" value=\"true\"></param><embed src=\"http://www.youtube.com/v/" + $("#" + this.parentNode.parentNode.id)[0].array_percorso_video[numero] + "&hl=jp&fs=1&color1=0x" + $("#" + this.parentNode.parentNode.id)[0].VariabiliObject.colore + "&color2=0x" + $("#" + this.parentNode.parentNode.id)[0].VariabiliObject.coloredue + "\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"340\" height=\"270\"></embed></object>");
      }

    } 
  } 
})
(jQuery);


$(function() {

  var array_videoBig = new Array();
  array_videoBig[0] = 'http://jp.youtube.com/watch?v=08anoQHL85s?fs=1&amp;hl=ja_JP';
  array_videoBig[1] = 'http://jp.youtube.com/watch?v=Zr0JkHZaQu4?fs=1&amp;hl=ja_JP';
  array_videoBig[2] = 'http://jp.youtube.com/watch?v=01k9Dw8yeLw?fs=1&amp;hl=ja_JP';

  var array_video_small = new Array();
  array_video_small[0] = 'img/top/thumb01.png';
  array_video_small[1] = 'img/top/thumb02.png';
  array_video_small[2] = 'img/top/thumb03.png';

  $("#video").GestYoutube({
    array_video_big: array_videoBig,
    array_video_small: array_video_small,
    position_big: 'up' 
  });

  $("ul#small_video > li:first").addClass("current");
  
	$("ul#small_video > li").click(function() {
	  $("ul#small_video > li").removeClass("current");
	  $(this).addClass("current");
		return false;
  });
	
});
