jQuery.noConflict();
(function($) { 
	$(function() {
   $(document).ready(function(){
   
		$('.resizeme').resize({ maxWidth:180,height:180})
		
		
		var ancho=parseInt($('#foto0 a img').css("width"))+20;
		
		var totalelem=parseInt($(".elements-images").size())-1;
		$(".resizeme").each(function(i,val){
		  var ancho2=$(val).css("width")
		  var alto2=$(val).css("height")
	
		 
		$('#foto'+i+',#foto'+i+' h3').css({"width":ancho2,"height":alto2})
		
			
		if(i>0){
	
			
			
			$('#foto'+i+'').css({"left":ancho})
		
		ancho +=parseInt($('#foto'+i).css("width"))+5
		
		}
		if(i==0)
		{
	
			//$('#foto'+(i+1)+'').css({"left":(parseInt($('.elements-images:first').css("width"))+5)})
		}
	
		
	
		
		
		})
		var positions=new Object();
		positions.elements=new Array()
		var I2=0;
		
		$(".elements-images").each(function(i,val){
	
		var I=i;
	
		$(".elements-images").each(function(i2,val2){
		
		var heightmitad=parseInt($('#foto'+I).css("height"))+parseInt($('#foto'+i2).css("height"))
	
	
		divsion=Math.round((((heightmitad-250))+heightmitad)/13);
		heightmitad=(((heightmitad-250))+heightmitad)+divsion;
		
		
		//chekeamos el alto
		
		if(heightmitad == 250)
		{
		
		
		
		
		positions.elements[I2]=new Object()
		//columm
		positions.elements[I2].parent1=I;
		positions.elements[I2].index=I2;
		//file
		positions.elements[I2].parent2=i2;
		/*other elements*/
		positions.elements[I2].prev=i2-1;
		positions.elements[I2].next=i2+1;
		/*get positions*/
		positions.elements[I2].toppos=(parseInt($('#foto'+I).css("height"))+15)
		positions.elements[I2].leftpos=parseInt($('#foto'+I).css('left'))
		
		
		
	
		I2++;
			
		
		}
		
		
	
		})
		
		})
		var i=0;
	
		var positionsnew=new Object();
		positionsnew.elements=new Array()
		$.each(positions.elements,function(i,val){
		var elems=val
		var I2=0;
		$.each(positions.elements,function(i2,val2){
		
		if(val2.parent1==elems.parent2 && elems.index==1){
		
		positionsnew.elements[I2]=val2
		I2++;
		}
		
		})
		})
		positions=null;
	
		
		
		
		var intervalo=setInterval(function(){
	
		
		if(i<=(positionsnew.elements.length-1)){
		
		ancho3=positionsnew.elements[i].leftpos;
		alto3= positionsnew.elements[i].toppos;
	
		if(ancho3!='undefined' && alto3!='undefined')
		{
		$('#foto'+positionsnew.elements[i].parent2).css({"left":ancho3,'top':alto3})
		var nextss=parseInt(positionsnew.elements[i].next);
		
		
		
			var ancho=parseInt($('#foto'+(nextss)).prev().prev().css("left"));
			var anchoelem=parseInt($('#foto'+(nextss)).prev().css("width"));
			ancho = ancho + anchoelem+5
			
		for(var i2=nextss;i2<=(totalelem);i2++){
		
		
	
		
		$('#foto'+(i2)).css({"left":ancho})
		ancho += anchoelem+5
		}
		
	
		}
		
		}
		
		
		if(i==totalelem-1)
		{
			clearInterval(intervalo);
			
		}
		i++;
		},1000)
	
	$('.elements-images').fadeIn('fast')
			$(".elements-images").hover(function(){
		
		
			$(".elements-text").animate({"scrollTop":(parseInt($(".thetexts:eq("+$(this).index()+")").attr("scrollHeight"))*$(this).index())},'fast')
			//console.log("aaa",$(".thetexts:eq("+$(this).index()+")").scrollTop())
			},function(){
			//$(".elements-text").animate({"scrollTop":"-="+$(".thetexts:eq("+$(this).index()+")").attr("scrollHeight")},'fast')
			})
			});
	
	$('.elements-images.slidedown').hover(function(){  
        $(".cover", this).stop().animate({top:'-50%'},{queue:false,duration:300});  
    }, function() {  
        $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});  
    });  
  
    $('.elements-images.slideright').hover(function(){  
        $(".cover", this).stop().animate({left:'100%'},{queue:false,duration:300});  
    }, function() {  
        $(".cover", this).stop().animate({left:'0px'},{queue:false,duration:300});  
    });  

    $('.elements-images.thecombo').hover(function(){  
        $(".cover", this).stop().animate({top:'100%', left:'100%'},{queue:false,duration:300});  
    }, function() {  
        $(".cover", this).stop().animate({top:'0px', left:'0px'},{queue:false,duration:300});  
    });  
    //Partial Sliding (Only show some of background)  
    $('.elements-images.peek').hover(function(){  
        $(".cover", this).stop().animate({top:'30%'},{queue:false,duration:160});  
    }, function() {  
        $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});  
    });  
    //Full Caption Sliding (Hidden to Visible)  
    $('.elements-images.captionfull').hover(function(){  
        $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});  
    }, function() {  
        $(".cover", this).stop().animate({top:'100%'},{queue:false,duration:160});  
    });  
    //Caption Sliding (Partially Hidden to Visible)  
    $('.elements-images.caption').hover(function(){  
        $(".cover", this).stop().animate({top:'30%'},{queue:false,duration:160});  
    }, function() {  
        $(".cover", this).stop().animate({top:'100%'},{queue:false,duration:160});  
    });  

	
		
		})
		})(jQuery);
	
	
