(function($) {
// definición de la función   
$.fn.ReproductorVideo = function(options){   
              
         var opts = $.extend({}, $.fn.ReproductorVideo.defaults, options);   
              
         this.each(function(){
          		  		  		
			var Aca = $(this).attr("Id")+ "_Reproductor" ;
			var Cabecera = $(document.createElement('div')).attr('id', 'Cabecera').addClass("Cabecera_video");
			var Cabecera2 = $(document.createElement('div')).attr('id', 'Cabecera2').css({"margin-left":"10px","margin-top":"10px"}).html("VIDEOS");
            var Contenedor = $(document.createElement('div')).attr('id', 'Contenedor').addClass("Contenedor_video");
            var Reproductor = $(document.createElement('div')).addClass("Reproductor_video").attr('id',Aca);
            var Lista = $(document.createElement('div')).attr('id', 'Lista').addClass("Lista_video");
			var Desc = $(document.createElement('div')).attr('id', 'Desc').addClass("Desc_video");
		    var Desc_Titulo = $(document.createElement('span')).attr('id', 'Desc_tit').addClass("Desc_tit");
			var Desc_Desc = $(document.createElement('span')).attr('id', 'Desc_Desc').addClass("Desc_Desc");
						
         	Contenedor.append(Reproductor);							            				
			var str="";				
			if(opts.lista!=null)
			{		
				if( opts.lista.length > 0)
				{
					str+= " <div id=\"Contenedor_lista\">    "+
								 "     <div class=\"lista\">"+
								 " 		<table class=\"vc\">";															
					for (var i = 0; i < opts.lista.length; i++) {
						
						var path=opts.lista[i].path;
						var img=opts.lista[i].img;
						var Tit = "Video "+ eval(i+1)+" de "+opts.lista.length;
						
						str+=" <tr class=\"li_it\" onclick=\"Reproducir('"+path+"','"+img+"','"+Aca+"','"+Tit+"','"+opts.lista[i].nombre+"');\" >"+	
								"<td class=\"vc\">"+
									"     <img   class=\"thumbnail\"  height=\"67px\" width=\"84px\" src=\""+img+"\">"+								
									"   </td>"+
									"<td class=\"vc\">"+
									"<div class=\"info\">"+									
										"<span class=\"titulo\">Video "+ eval(i+1)+" de "+opts.lista.length+"</span>"+
										"<span class=\"item\">"+opts.lista[i].nombre+"</span>"+								
									" </div>"+
									"<div class=\"clear\"></div>"+
									"</td>"+									
									"</tr>";																										
					}				
					str+="      </table>"+
								 "    </div>"+
								 " </div>";
								 str+=(opts.lista.length > 3)?"<br><div class=\"botones_scroll\"><img class=\"prev\"  src=\"../images/reproductor_video/prev.png\">&nbsp;<img  class=\"next\" src=\"../images/reproductor_video/next.png\"></div>":"";			
							  
				  Lista.append(str);
				  Contenedor.append(Lista);
				  
				   Desc.append(Desc_Titulo);		
				   Desc.append(Desc_Desc);
				  
				  Contenedor.append(Desc);
				  
				 
				}
			}
			else	
			{
				Contenedor.css({"height":"228"});
//				Cabecera.css("width","308");
			}
		//	Cabecera.append(Cabecera2);
		//	$(this).append(Cabecera);		
            $(this).append(Contenedor);			
													
			Reproducir(opts.videoDefault.path,opts.videoDefault.img,Aca,((opts.lista!=null)?"Video 1 de "+ opts.lista.length:""),opts.videoDefault.nombre);
			
			 if(opts.lista!=null)
			 {
				 Scroll(".lista")						
				*$(".li_it").hover(function() {$(this).find("img").stop().animate({filter: 'alpha(opacity=100)', opacity: 1}, 300);
											$(this).find("span.titulo").addClass("titulo_hover");	
											//$(this).find("span.item").addClass("item_hover");	
											   } 
									, 
									 function() {$(this).find("img").stop().animate({filter: 'alpha(opacity=70)', opacity: .7}, 300);
											$(this).find("span.titulo").removeClass("titulo_hover").addClass("titulo");	
											//$(this).find("span.titulo").removeClass("item_hover").addClass("item");	
				});
			 }
			
         });   	
		  }; 
// definimos los parámetros junto con los valores por defecto de la función   
/*$.fn.ReproductorVideo.defaults = {
								videoDefault:{'nombre':'video 1','path':'149128','img':'149128_2'},
								lista:[{'nombre':'video 1','path':'149128','img':'149128_2'},
									   {'nombre':'video 2','path':'149056','img':'149056_2'},
									   {'nombre':'video 3','path':'149048','img':'149048_2'}]};	*/							 
								 						 								 	  	  	  	  
 

})(jQuery);


function Reproducir(vPath,vImg,vContenedor,vTitulo,vDesc)
{
	$("#Desc_tit").html(vTitulo);
	$("#Desc_Desc").html(vDesc).fadeIn(500);
 $("#"+vContenedor).html("");
  $("#"+vContenedor).html(
  "<object type=\"application/x-shockwave-flash\" "+
  " data=\"http://www.26noticias.com.ar/images/flash/videos26_final.swf?img_video="+vImg+"&video="+vPath+"\" "+
  " width=\"308\" height=\"228\"> "+
  " <param name=\"movie\" "+
 "value=\"http://www.26noticias.com.ar/images/flash/videos26_final.swf?img_video="+vImg+"&video="+vPath+"\"/>"+
			"    <param name=\"quality\" value=\"High\" />"+
			"    <param name=\"wmode\" value=\"transparent\" />"+
			"    <param name=\"scale\" value=\"ExactFit\" />"+
			"    <param name=\"allowFullScreen\" value=\"true\"/>"+
			"    </object>");
}


function Scroll(vElemento)
{
	    var running = false, animCss="top", sizeCss="height";
        var div = $(vElemento);
		var ul = $("table", div);
		var tLi = $("li_it", ul);
		var tl = tLi.size();
		var v = 3;

	

      
        var li = $("tr", ul), itemLength = li.size(), curr = 0;
        div.css("visibility", "visible");

        li.css({overflow: "hidden", float:"none"});
        ul.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"});
        div.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"});

		
	


        var liSize =  height(li);   
        var ulSize = liSize * itemLength;                  
        var divSize = liSize * v;                          

        li.css({width: li.width(), height: li.height()});
        ul.css(sizeCss, ulSize+"px").css(animCss, -(curr*liSize));

        div.css(sizeCss, divSize+"px");                    

        
            $(".prev").click(function() {
                return go(curr-1);
            });
   
    
            $(".next").click(function() {
                return go(curr+1);
            });           
       
		        function go(to) {
            if(!running) {

           
                    if(to<0 || to>itemLength-v) return;
                    else curr = to;
                                          

                running = true;

                ul.animate(
                    animCss == "left" ? { left: -(curr*liSize) } : { top: -(curr*liSize) } , 200, null,
                    function() {                       
                        running = false;
                    }
                );
				
				
				
                // Disable buttons when the carousel reaches the last/first, and enable when not
               
                    $(".prev",".next").removeClass("disabled");
                    $( (curr-1<0 &&  $(".prev"))
                        ||
                       (curr+1 > itemLength-v && $(".next"))
                        ||
                       []
                     ).addClass("disabled");
               

            }
            return false;
        };


function css(el, prop) {
    return parseInt($.css(el[0], prop)) || 0;
};
function width(el) {
    return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
};
function height(el) {
    return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
};
}




