

(function($) {
// definición de la función   
$.fn.futbol_online = function(options){   
              
         var opts = $.extend({}, $.fn.futbol_online.defaults, options);   
              
         this.each(function(){
          		  		
						
		
						 
						  				
			var carousel = $(document.createElement('div')).attr('id', 'carousel_futbol');
            var cabecera = $(document.createElement('div')).attr('id', 'cabecera')/*.addClass("cabecera")*/;
			var img_cab =  $(document.createElement('img')).attr({'id':'cabecera_img','src':'../css/img/cabecera.jpg'});
			
            var buttons = $(document.createElement('div')).attr('id','buttons');			
            var prev = $(document.createElement('a')).attr({'id':'prev','href':'#'});
			var next = $(document.createElement('a')).attr({'id':'next','href':'#'}); 

			var clear = $(document.createElement('div')).addClass("clear");
			
			var slides = $(document.createElement('div')).attr('id','slides_futbol');	
			var ul = $(document.createElement('ul'));
			var info = $(document.createElement('div')).attr('id','info').addClass("info");	
			var fin_control = $(document.createElement('div')).attr('id','fin_control');						
			
						
			
			
			cabecera.append(img_cab);
			carousel.append(cabecera);
			cabecera.append(buttons);
		
			//buttons.append(prev);
			buttons.append(next);
			buttons.append(clear);
						
			carousel.append(slides);
			//carousel.append(info);		
			//carousel.append(fin_control);
			
			slides.append(ul);
																							
				if( opts.partido.length > 0)
				{																	
					for (var i = 0; i < opts.partido.length; i++) {
																							
						var li = $(document.createElement('li'));
								 var marq= "<table>"+
								  " <tr>"+
								  " <td class=\'Torneo\'>"+opts.partido[i].torneo +"</td>"+
								  " <td class=\'"+((opts.partido[i].torneo_desc!="finalizado")?"Torneo_desc":"Torneo_desc_fin")+"\' align=\'right\' >"+opts.partido[i].torneo_desc +"</td>"+
								  " </tr>"+
								  "</table>"+
								  "<table>"+
								  " <tr>"+
								  "   <td class=\'escudo\'><img   src=\'"+opts.partido[i].local_img+"\'></td>"+
								  "   <td class=\'equipo\'>"+opts.partido[i].local_desc+"</td>"+
								  "   <td class=\'goles\'>"+opts.partido[i].local_gol+"</td>"+
								  " </tr>"+
								  " <tr>"+
								  "   <td class=\'escudo\'><img   src=\'"+opts.partido[i].visitante_img+"\'></td>"+
								  "   <td class=\'equipo\'>"+opts.partido[i].visitante_desc+"</td>"+
								  "   <td class=\'goles\'>"+opts.partido[i].visitante_gol+"</td>"+
								  " </tr>"+
								  "</table>";
								  
								  var piso="";								 								  
								  if(opts.partido[i].eventos !=null)
								  {
								  piso+="<marquee  class=\'slide_futbol_marque\'   behavior='scroll' scrollamount='3'  direction='left'  "+
								  				" onmouseover=\"this.setAttribute(\'scrollamount\', 1, 0);\" onmouseout=\"this.setAttribute(\'scrollamount\', 3, 0);\">";																		 
									for (var e = 0; e < opts.partido[i].eventos.length; e++) {										
										var pat_ico="";										
										switch( opts.partido[i].eventos[e].eventos_tipo)
										{
											case "1":
											{
												//ROJA
												pat_ico="ico_Roja";
												break;
											}
											case "2":
											{
												//AMARILLA
												pat_ico="ico_Amarilla";
												break;
											}
											case "3":
											{
												//GOL
												pat_ico="ico_Gol";
												break;
											}
											case "4":
											{
												//LESION
												pat_ico="ico_Lesion";
												break;
											}
											case "5":
											{
												//PENAL
												pat_ico="ico_Penal";
												break;
											}
											case "6":
											{
												//CAMBIO
												pat_ico="ico_Cambio";
												break;
											}
											default:
											{
												break;
											}
										}																				
										piso+="<span class=\'"+pat_ico+"\'>"+  opts.partido[i].eventos[e].eventos_Desc+"</span>";							
									}	
									piso+= "</marquee>";		
								  }
								  else
								  {
									  piso+="<div class=\'slide_futbol_marque\'></div>";
								}
								  
						li.append(marq + piso);																					 											
						ul.append(li);																																																						
					}								
				}	
													
			carousel.append(clear);
			carousel.append(fin_control);
			$(this).append(carousel);		           																					
    });   	
}; 							 								 						 								 	  	  	  	   
})(jQuery);


/*FUNCION CARROUSEL*********************************************************************************************************************************************************************************************/
$(document).ready(function() {	

	
			
		var item_width = $('#slides_futbol li').outerWidth(); 			
		var ancho_ul = $('#slides_futbol ul li').size() * item_width;									 		
		$("#slides_futbol ul").css("width",ancho_ul);		
		var left_value = item_width * (-1); 
			
			
		if( $('#slides_futbol ul li').size() > 1)
		{			
			$('#slides_futbol ul').css({'left' : left_value+'px','margin-left':item_width+'px'});			
		//$('#slides_futbol li:first').before($('#slides_futbol li:last'));				
		//$('#slides_futbol ul').css({' margin-left':'290px'});		
		var speed = 59000;  // 1000 1 seg   60000 1 min    600000  milisegundos = 1 hora
			
		var run = setInterval('rotate()', speed);		
		}
		else
		{
			$("#buttons").css("display","none");
		}
//EVENTO DE LOS BOTONES/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //if user clicked on prev button
	$('#prev').click(function() {		
		//get the right position            
		var left_indent = parseInt($('#slides_futbol ul').css('left')) + item_width;	
		            
		$('#slides_futbol ul:not(:animated)').animate({'left' : left_indent}, 200,function(){    

            //move the last item and put it as first item            	
			$('#slides_futbol li:first').before($('#slides_futbol li:last'));           

			//set the default item to correct position
			$('#slides_futbol ul').css({'left' : left_value});
		
		});

		//cancel the link behavior            
		return false;
            
	});

 
    //if user clicked on next button
	$('#next').click(function() {								
		var left_indent = parseInt($('#slides_futbol ul').css('left')) - item_width;											
		$('#slides_futbol ul:not(:animated)').animate({'left' : left_indent}, 200, function () {                       
			$('#slides_futbol li:last').after($('#slides_futbol li:first'));                 							
			$('#slides_futbol ul').css({'left' : left_value});				
		});
		         
		//cancel the link behavior
		return false;
		
	});        
//EVENTO DE LOS BOTONES/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


	
	//if mouse hover, pause the auto rotation, otherwise rotate it
	/*$('#slides_futbol').hover(
		
		function() {
			clearInterval(run);
		}, 
		function() {
			run = setInterval('rotate()', speed);	
		}
	); */
        
});
function rotate() {
	$('#next').click();
}  
/*FUNCION CARROUSEL*********************************************************************************************************************************************************************************************/





