var dentro;
var pos;
var inc;
var time;
var num;
var actual;
var temp;
var item=new Array();

$(document).ready(function(){
	dentro=false;
	inc=120;
	pos=0;
	time=1000;
	num=16;
	
	$("a.video_thumbnail").css("height","120px");
	
  $("a[@rel^=\'thumb-\']").mouseover(function(){
    num=$(this).attr("rev");
		temp=($(this).attr("rel")).toString();
		item=temp.split("-");
		actual=(item[1]).toString();
		if(!dentro) dentro=true; setTimeout("next("+actual+","+num+");",time);
	});
	
	$("a[@rel^=\'thumb-\']").mouseout(function(){
		dentro=false;
		pos=0;
		$(this).children("img").css("top",pos+"px");
	});
	
	$("a[@rel^='button-']").toggle(
    function(){
      dentro = true;
      $(this).css("background", "transparent url(/css/img/bt_pause.gif) no-repeat scroll 0 0");
      id = $(this).attr("rel").split("-");
		  play(id[1], $(this).attr("rev"));
    },
    function () {
      dentro = false;
      $(this).css("background", "transparent url(/css/img/bt_play.gif) no-repeat scroll 0 0");
    }
  );

});

function next(item, num){
	if(dentro && actual==item){
		pos-=inc;
		pos%=-(inc*num);
		//$("a[@rel=\'thumb-"+item+"\']").css("height","120px");
		$("a[@rel=\'thumb-"+item+"\'] img").css("top",pos+"px");
		setTimeout("next('"+item+"\',\'"+num+"\');",time);
	}
}

function play(item, num){
	if(dentro){
		pos-=inc;
		pos%=-(inc*num);
		// play the rollover
		$("a[@rel=\'thumbphone-"+item+"\'] img").css("top",pos+"px");
		setTimeout("play(\'"+item+"\',\'"+num+"\');", time);
	}
}