$(document).ready(function() {
//Index links

	$("a.indexLink img")
	.mouseover(function() { 
            var src = $(this).attr("src").match(/[^\.]+/) + "_2.jpg";
            $(this).attr("src", src);
        })
        .mouseout(function() {
            var src = $(this).attr("src").replace("_2", "");
            $(this).attr("src", src);
        });
	
//Photo Slide

	$("div.slide_menu a").mouseover(function () {
		var num =$(this).attr("id");
		var newSrc="<img src='images/fotos/"+num+".jpg' alt='' />";
		var newText=$("div.slide_menu a#"+num+" span").html();
		
		$("div.slide_menu a#"+num+" img").css({opacity:1});
		$("div#slide_main img").replaceWith(newSrc); //New main image to be replaced
		$("div#slide_main span").html(newText);//New captition to be replaced
			
			$("div#slide_main").css({opacity:0});
			$("div#slide_main span").css({opacity:0, bottom:"-30px"});
			$("div#slide_main").stop();
			$("div#slide_main").animate({opacity:1}, 1000);
			$("div#slide_main span").stop();
			$("div#slide_main span").animate({opacity:0.8, bottom:"27px"},"slow");
	});
	$("div.slide_menu a").mouseout(function () {
		var num =$(this).attr("id");
		$("div.slide_menu a#"+num+" img").css({opacity:0.5});
	});

//End of Photo Slide

//Start Arte Photo mesh
		function random (valMin, valMax) {
			var randWidth=valMin+Math.floor(Math.random()*valMax);
			return randWidth;
		}
	//Sets random css attributes
		$("div.imga img").each(function() {
			$(this).animate({	width:random(80,100),
									height:150,			
									left:random(10,160),
									top:random(10,120)
									}).
									css({'z-index':random(100,400)
									});
		});
		$("div.imga img").hover(function () {
			$(this).css({'border-color':'#990099'}) }, function () {
			$(this).css({'border-color':'#fff'});
		});
			//Centers the selected image
		$("div.imga img").click(function () {
		if($(this).css('z-index')<999) {
			$(this).animate({
			
				width:'85%',
				height:'85%',
				top:'10px',
				left:'10px'
		},600).css({'z-index':999,'border-color':'#ffffff'});
		}
		else {
			$(this).animate({	
									width:random(80,100), 
									height:random(100,160),
									left:random(10,180),
									top:random(10,120),
									padding:0
									}).css({'z-index':random(1,100)});
		}
		});

//End of Arte Photo Mesh

});


