$(document).ready( function() {
    peps.rollover.init();
    $().ajaxSuccess(function(){	
    	$('.roll').unbind('mouseenter mouseleave')
		peps.rollover.init();
	});
});
peps = {};
peps.rollover = {
   init: function() {
      this.preload();
      $(".roll").hover(
         function () { $(this).attr( 'src', peps.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', peps.rollover.oldimage($(this).attr('src')) ); }
      );
   },
preload: function(){
      $(window).bind('load', function() {
         $('.roll').each( function( key, elm ) { $('<img>').attr( 'src', peps.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   newimage: function( src ) {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_rol' + src.match(/(\.[a-z]+)$/)[0];
   },
   oldimage: function( src ){
      return src.replace(/_rol\./, '.');
   }
};

function CambiarFrame(frame){
	videoVar = document.getElementById('sonidooo');
	
	if(videoVar == undefined){
		videoVar = document.getElementById('swf_sonido');
	}
	if(frame == undefined){
		videoVar.GotoFrame(1);
	}else{
		videoVar.GotoFrame(frame);
	}
	
}

function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

	function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	function MM_findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}

	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

	function levantarVirtual(url){
		$.get(url,{},function(responseText){
			
			$('#blockUIContent').html(responseText);
			$('#blockUIContent').pngFix();
			
			$.blockUI({ 
		        message: $('#blockUIContent'), 
		        css: { 
		            top:  1 + 'px', 
		            left: ($(window).width() - 822) /2 + 'px', 
		            width: '822px',
		            border: 'none',
		            background: 'transparent',
		            cursor: 'default'
		        },
		        overlayCSS: { backgroundColor: '#fff' }
		    }); 
		    
		   
		})
	}

	function levantarPopURL(url,w,h,showOver){
		$.get(url,{},function(responseText){
			
			$('#blockUIContent').html(responseText);
			$('#blockUIContent').pngFix();
			
			$.blockUI({ 
		        message: $('#blockUIContent'), 
		        css: { 
		            top:  $(window).scrollTop()+(($(window).height() - h)/2) + 'px',  
		            left: ($(window).width() - w) /2 + 'px', 
		            width: w+'px',
		            border: 'none',
		            background: 'transparent',
		            cursor: 'default'
		        },
		        overlayCSS: { backgroundColor: '#fff' },
		        showOverlay: showOver
		    }); 	    
		   
		})
	}

	function levantarPop(element,w,h,showOver){
				
		$.blockUI({ 
	        message: element, 
	        css: { 
	            top:  $(window).scrollTop()+(($(window).height() - h)/2) + 'px', 
	            left: ($(window).width() - w) /2 + 'px', 
	            width: w+'px',
	            border: 'none',
	            background: 'transparent',
	            cursor: 'default'
	        },
	        overlayCSS: { backgroundColor: '#fff' },
	        showOverlay: showOver
	    }); 	    

	}

	function levantarPopScroll(url,w,h, callback){
		$.get(url,{},function(responseText){		
			$('#blockUIContent').html(responseText);	
			htop = $(window).scrollTop()+(($(window).height() - h)/2);
			if(htop<0)htop=0;				
			$.blockUI({ 
		        message: $('#blockUIContent'), 
		        css: { 
		            top:  htop + 'px', 
		            left: ($(window).width() - w) /2 + 'px', 
		            width: w+'px',
		            border: 'none',
		            background: 'transparent',
		            cursor: 'default'
		        },
		        overlayCSS: { backgroundColor: '#fff' }
		    });
		    //Hago una pausa de medio segundo para que ponga el contenido como popup
		    //Asi puedo comprobar el alto del scroll, sino no lo detecta
		    setTimeout(callback,500);
		})
	}

	function ShowScroll(height){	

		$('.scroll_botones').css('height',$('#scroller').css('height'));	
		if($('#scroller')[0].scrollHeight > height){
			$('.scroll_botones').css('display','block');
		}	    	
	}

	function ShowScrollTournament(height){
		$('.scroll_botones').css('height',$('#scroller_tournament').css('height'));

		if($('#scroller_tournament')[0].scrollHeight > height){
			$('.scroll_botones').css('display','block');
		}
	}

	function ShowScrollLatest(height){
		$('.scroll_botones').css('height',$('#scroller_latest').css('height'));

		if($('#scroller_latest')[0].scrollHeight > height){
			$('.scroll_botones').css('display','block');
		}
	}

	function ShowScrollPackages(height){
		$('.scroll_botones').css('height',$('#scroller_pack').css('height'));

		if($('#scroller_pack')[0].scrollHeight > height){
			$('.scroll_botones').css('display','block');
		}
	}


	function scrollMas(id,monto){
		$(id).scrollTo('+='+monto+'px', 300);
	}

	function scrollMenos(id,monto){
		$(id).scrollTo('-='+monto+'px', 300);
	}
