function pauseAll(){  $('.vtr-dmotion-video').each(function(index,oDom){      var url=$(this).attr('url');      $(this).replaceWith('<a href="'+url+'" class="ver-video" style="display:none;">Ver video</a>');      });  }function onready(e){    $("#"+e.id).css({marginLeft:"-27px"}).animate({marginLeft:"27px"},1000);}var currentCreating = 0;var slideHomeVtrCurrentIndex = 0; var slideHomeVtrCurrentTimeout = 0;      function   goSlideHomeVtrWithDmotion() {        var hasit = $('.slidewd').eq(slideHomeVtrCurrentIndex).find(".vtr-dmotion-video").length;    hasit += $('.slidewd').eq(slideHomeVtrCurrentIndex).find(".ver-video").length;            if(hasit==0)    {            $(".menu-right a").trigger('click');    }    clearTimeout(slideHomeVtrCurrentTimeout);    slideHomeVtrCurrentTimeout = setTimeout("goSlideHomeVtrWithDmotion()",10000);     } (function($) {  slideHomeVtrCurrentTimeout = setTimeout("goSlideHomeVtrWithDmotion()",10000);    $.fn.slideHomeVtrWithDmotion = function(options) {      var opts = $.extend({}, $.fn.slideHomeVtrWithDmotion.defaults, options);        return this.each(function() {                                        this.boxes = $(this).find('li');      $(this).find("#slidewdmotion").css("width",(this.boxes.length*$(this).find('li:first-child').width())+"px"  );                       //el menu      var t =$(this);        var tbox = $(this).find('#slidewdmotion li');      var tmenu = $(this).find(".slidewdmotion-menu");      var tul = $(this).find('#slidewdmotion');            $(tmenu.find(".menu-item").get(0)).addClass("current-item");      tmenu.find(".menu-item").click(function(){           var tItem = this;           pauseAll();           tmenu.find(".menu-item").each(function(index,obj){                                       if(tItem == obj){                        $.fn.slideHomeVtrWithDmotion.selectCurrent(index,t.find("#slidewdmotion"),tmenu);                        clearTimeout(slideHomeVtrCurrentTimeout);                        slideHomeVtrCurrentTimeout = setTimeout("goSlideHomeVtrWithDmotion()",10000);                   }                             });          return false;      });            $(".slidewdmotion-close").bind("click",function(){         pauseAll();                  $vitrina = $(this).parents("#vitrina");                            $vitrina.animate({height:24},500);         $vitrina.find("#slidewdmotion").animate({top:30});          $vitrina.find(".slidewdmotion-menu").animate({top:34});                 $(this).animate({top:34});         return false;                            });                  $(".slidewdmotion-expand").bind("click",function(){                  $vitrina = $(this).parents("#vitrina");                            $vitrina.animate({height:300},500);         $vitrina.find("#slidewdmotion").animate({top:0});          $vitrina.find(".slidewdmotion-menu").animate({top:10});                  $vitrina.find(".slidewdmotion-close").animate({top:10});                     //$.fn.slideHomeVtrWithDmotion.selectCurrent(slideHomeVtrCurrentIndex,$vitrina.find("#slidewdmotion"),$vitrina.find(".slidewdmotion-menu") );        $.fn.slideHomeVtrWithDmotion.showVideo(slideHomeVtrCurrentIndex, $vitrina.find("#slidewdmotion") );         return false;                          });            $(".menu-left a").bind("click",        function(){           pauseAll();           slideHomeVtrCurrentIndex--;           if(slideHomeVtrCurrentIndex<0){             slideHomeVtrCurrentIndex = tbox.length-1;                        }               $.fn.slideHomeVtrWithDmotion.showCurrentInMenu(tmenu);           $.fn.slideHomeVtrWithDmotion.showVideo(slideHomeVtrCurrentIndex, tul);                            t.find("#slidewdmotion").animate({left:-t.find('#slidewdmotion" li:first-child').width()*slideHomeVtrCurrentIndex },1000);          clearTimeout(slideHomeVtrCurrentTimeout);           slideHomeVtrCurrentTimeout = setTimeout("goSlideHomeVtrWithDmotion()",10000);                         return false;        } );      $(".menu-right a").bind("click",        function(){             pauseAll();            slideHomeVtrCurrentIndex++;            if(slideHomeVtrCurrentIndex> tbox.length-1){              slideHomeVtrCurrentIndex = 0;                         }            $.fn.slideHomeVtrWithDmotion.showCurrentInMenu(tmenu);            $.fn.slideHomeVtrWithDmotion.showVideo(slideHomeVtrCurrentIndex, tul);            t.find("#slidewdmotion").animate({left:(-t.find('#slidewdmotion" li:first-child').width()*slideHomeVtrCurrentIndex) },1000); return false;            clearTimeout(slideHomeVtrCurrentTimeout);            slideHomeVtrCurrentTimeout = setTimeout("goSlideHomeVtrWithDmotion()",10000);            return false;        } );            $(this).find(".ver-video").css("display","none");              tul.find("li:first-child .ver-video").each(function(index,oDOM){        var url = $(this).attr("href");            var id =  "vtr-dmotion-0";          $(this).replaceWith($('<div id="'+id+'" class="vtr-dmotion-video"></div>'));        swfobject.embedSWF(url, id , "489", "282", "10.0.0", null, {},  {	menu: "false",scale: "noScale", wmode: 'transparent',	allowFullscreen: "false",	allowScriptaccess: "always", bgcolor: "#FFFFFF" }, { id:id,'class':"vtr-dmotion-video",url:url },onready);                                    });                                                                    /**** DEFINAMOS EL INICIAL ALEATORIO ****/        pauseAll();                slideHomeVtrCurrentIndex = Math.floor(Math.random()*tbox.length);                        $.fn.slideHomeVtrWithDmotion.showCurrentInMenu(tmenu);        $.fn.slideHomeVtrWithDmotion.showVideo(slideHomeVtrCurrentIndex, tul);        t.find("#slidewdmotion").css({left:(-t.find('#slidewdmotion" li:first-child').width()*slideHomeVtrCurrentIndex) },1000);        clearTimeout(slideHomeVtrCurrentTimeout);        slideHomeVtrCurrentTimeout = setTimeout("goSlideHomeVtrWithDmotion()",10000);                 /***********************************/                  });           }  $.fn.slideHomeVtrWithDmotion.defaults = {     width : 490,     height: 360               };  $.fn.slideHomeVtrWithDmotion.showVideo=function(tindex, tul)  {             tul.find("li.slidewd").each(function(index,obj){                   if(index==tindex)        {                         if($(this).find('.ver-video').length >0)          {                 var url = $(this).find('.ver-video').attr("href");                            var id =  "vtr-dmotion-"+index;              $(this).find('.ver-video').css("display","").replaceWith($('<div id="'+id+'" class="vtr-dmotion-video"></div>'));           swfobject.embedSWF(url, id , "489", "282", "10.0.0", null, {},  {	menu: "false",scale: "noScale", wmode: 'transparent',	allowFullscreen: "false",	allowScriptaccess: "always", bgcolor: "#FFFFFF" }, { id:id,'class':"vtr-dmotion-video",url:url },onready);                        //setTimeout(' swfobject.embedSWF('+url+', '+id+' , "490", "360", "10.0.0", null, {},  {	menu: "false",scale: "noScale", wmode: "transparent",	allowFullscreen: "false",	allowScriptaccess: "always", bgcolor: "#FFFFFF" }, { id:'+id+',class:"vtr-dmotion-video",url:'+url+' },onready);',500);                    }                }                                       });            }      $.fn.slideHomeVtrWithDmotion.selectCurrent = function(tindex,tul,tmenu){    if(tindex>=0 && tindex!=slideHomeVtrCurrentIndex)    {       slideHomeVtrCurrentIndex = tindex;              $.fn.slideHomeVtrWithDmotion.showVideo(slideHomeVtrCurrentIndex, tul);                      tul.animate({left:-tul.find('li:first-child').width()*slideHomeVtrCurrentIndex },1000);        $.fn.slideHomeVtrWithDmotion.showCurrentInMenu(tmenu);                  }    return false;  };       $.fn.slideHomeVtrWithDmotion.showCurrentInMenu = function(tmenu){    tmenu.find(".current-item").removeClass("current-item");        if(tmenu.find("li").length-2<=1)          tmenu.css("display","none");    else      tmenu.css("display","");    $(tmenu.find(".menu-item")[slideHomeVtrCurrentIndex]).addClass("current-item");  };  })(jQuery);
