/**
 * @author miguel
 */

$(function() {
	$("a[href^='http']").click(function(){window.open(this.href); return false;});
	$("a[href*=.pdf]").click(function(){window.open(this.href);	return false;});
	images.init({
	 imgsArray:['./img/ampliacion_aeropuerto_malaga.jpg',
	 './img/marques_de_riscal_la_rioja.jpg',
	 './img/plaza_de_toros_puertollano.jpg',
	 './img/plaza_de_toros_puertollano2.jpg',
	 './img/plaza_de_toros_puertollano3.jpg',
	 './img/arcomilenio2.jpg',
	 './img/termoarcilla.jpg']
	})
});

var images = {
	container: "slideShow",
	timeinterval: 5000,
	imgArray: [],
	init:function(ops){
		for(i=0;i<ops.imgsArray.length;i++){
		  var img = new Image();
		  $(img)
		    .load(function() {
				$(this).appendTo($("#"+images.container));
		    })
		    .error(function() {
				alert("No existe el archivo "+ops.imgsArray[i]);
		    })
		    .attr('src', ops.imgsArray[i]);
		}
		setInterval( "images.slideSwitch()", this.timeinterval );
		return;
	},
	slideSwitch: function(){
		var $active = $('#'+this.container+' img.active');
		
		if ($active.length == 0) 
			$active = $('#'+this.container+' img:last');
		
		var $next = $active.next().length ? $active.next() : $('#'+this.container+' img:first');
		
		$active.addClass('last-active');
		
		$next.addClass('active');
		$next.css({
			opacity: 0.0
		}).addClass('active').animate({
			opacity: 1.0
		}, 1000, function(){
			$active.removeClass('active last-active');
		});
		/*$('#'+images.slideDiv).css({'opacity':'0.0','background':'url('+$next.attr('src')+') no-repeat top left'}).animate({'opacity': '1.0'}, 1000, function(){
			$active.removeClass('active last-active');
		});*/
		return;
	}
}