$(document).ready(function(){

	rotate = function(){
		$active.slideToggle('slow').removeClass('active');
		$next.slideToggle('slow').addClass('active');
	};

	rotateSwitch = function(){
		  play = setInterval(function(){ 
		      $active = $('#news_rollover div.active');
					$next = $active.next();
		      if ( $next.length === 0) { 
		          $next = $('#news_rollover div:first');
		      }
		      rotate();
		  }, 10000);
	};

	create = function(){
		i = 0;
		count = m.length;
		while(i < m.length){
			j = 0;
			var contenedor = $('<div class="wrap-new" >');
			while(j < 2){
				if(i >= m.length)
					break;

				var noticia = $('<div>');

				if(m[i].img_url == "")
					noticia.append('<img src="imagesn2/logo_uco_XS.jpg" alt="picture"/>');
				else
					noticia.append('<img src="http://www.uco.es/' + m[i].img_url + '" alt="picture"/>');

				noticia.append('<a href="' + m[i].url + '">' + m[i].title + ' <b>(' + (i+1) + '/' + count + ')</b></a>');						
				noticia.append('<div class="clearfix"></div>');
				contenedor.append(noticia);				
				
				j++;
				i++;
			}
			
			contenedor.appendTo('#news_rollover');
		}

		$('#news_rollover div').eq(0).removeClass('hidden').addClass('active');

		rotateSwitch();
	}

	create();

});


