$(window).load(function(){

	/* LOAD ITEMS CONTENT ***********************************
	****************************************************/
	$('#items_container').children().each(function(){  
		var contentURL = $(this).attr("ref");
		var contentDiv = $(this);
		$.ajax({
	        type: "GET",
	        url: contentURL, // Call the file with HTML in it (this page should have no <head> or <body> tags)
	        dataType: "html",
	        success: function(html) {
	           $(contentDiv).html($(html).filter('#header').children()); // Load the HTML snippet into a DIV with an id of myContent
	           registerClick(contentDiv);
	  
	        }
		});
    });
	
	
	/* SHOWCASE HOVER ***********************************
	****************************************************/

	 //for each showcase-item-title div...  
    $('div.showcase-item-image').each(function(){ 
     // set bisibility to true
        //$(this).css('visibility', 'visible'); 
        //set the opacity to 0...  
       	//$(this).css('opacity', '0'); 
    });  
  
    $('div.showcase-item-image').hover(function(){  
        //when mouse hover over the wrapper div  
        //get it's children elements with class showcase-item-title '  
        //and show it using fadeTo  
         //$(this).css('visibility', 'visible');
          
        $(this).stop().fadeTo(350, 0, "easeOutSine");  
    },function(){  
        //when mouse out of the wrapper div  
        //use fadeTo to hide the div  
        $(this).stop().fadeTo(350, 1, "easeOutSine");  
    });  
    
    
    /* SHOWCASE CLICKS ********************************
	****************************************************/
	$('div.showcase-item').click(function(e){
			var target = $(this).children('a').attr("href");
			$(window).scrollTo(target, 1600, {easing:'easeInOutQuad', offset:-103} ); 
			e.preventDefault();
	});
	
    
    /* ITEM CLICKS ********************************
	****************************************************/
	function registerClick(target){
		
		$(target).children('div.item-header').children('div.goback').click(function(e){
			$(window).scrollTo(0, 1600, {easing:'easeInOutQuad'} ); 
			e.preventDefault();
			$(target).children('div.more-info').fadeOut(1200, "easeOutCubic");
		});

 		$(target).children('div.item-header').children('div.goback').hover(function(){  
	        $(this).stop().fadeTo(350, 0.8, "easeOutSine");  
	    },function(){    
	        $(this).stop().fadeTo(350, 1, "easeOutSine");  
	    });
 		
 		
		$(target).children('div.more-info').hide();
		$(target).children('div.more-info-button').hover(function(){  
	        $(this).stop().fadeTo(350, 0.8, "easeOutSine");  
	    },function(){    
	        $(this).stop().fadeTo(350, 1, "easeOutSine");  
	    });  

		
	    $(target).children('div.more-info-button').click(function() {
	   	    if($(this).siblings('div.more-info').css("display") == "none"){
		    	var moreInfoButton = $(this);
		    	
		    	var moreInfoDiv = $(this).siblings('div.more-info');
		    	var contentURL = $(this).siblings('div.more-info').attr("ref");
		    	
		    	$(moreInfoButton).css("background-image", "url(images/loading-info.gif)");
		    	
		    	$.ajax({
			        type: "GET",
			        url: contentURL, // Call the file with HTML in it (this page should have no <head> or <body> tags)
			        dataType: "html",
			        success: function(html) {
			       		$(moreInfoButton).siblings('div.blog-intro').css('display', 'none');
			        	$(moreInfoDiv).html($(html).filter('#info').children()); // Load the HTML snippet into a DIV with an id of myContent
			      		$(moreInfoDiv).onImagesLoad({
			      			selectorCallback:showInfo
            			}); 
			        }
	     		});
	     		return false;
			    	
		    } else {
		    	var moreInfoButton = $(this);
				
		    	$(moreInfoButton).siblings('div.more-info').fadeOut({
					duration:1000,
					easing:"easeOutQuad",
					complete:function(){	
						var target = $(this).parent();
  						$(moreInfoButton).css("background-image", "url(images/more-info.png)");
  						$(moreInfoButton).siblings('div.blog-intro').css('display', 'block');
					}
				});
				
				$.scrollTo(target, 1200, {easing:'easeInOutCubic', offset:-103} );
		    	
		    }
		});
	}
	
	function showInfo($selector){
		$selector.fadeIn(1200, "easeInCubic");
		$selector.siblings('div.more-info-button').css("background-image", "url(images/less-info.png)");
	}
});
