function initializePortfolio(hash){
	if($(hash)[0] && $(hash)[0].initialize) $(hash)[0].initialize();
	else  $(hash+" .slider").easySlider();
}
function showPortafolioItem(hash){
	if($(hash).length > 0)
	{
		$(hash).fadeIn(500, function(){initializePortfolio(hash);});
		$(hash).addClass("selected");
		$('#portfolio_items .blocker').hide();
	}
	else
	{
		var hashId = hash.substring(1);
		$('#portfolio_items .portafolio_container').append("<article id='"+hashId+"'  class='item'>");
		$(hash).addClass("selected");
		$(hash).load('./portafolio/'+hashId+'.html', function(response, status, xhr) {
			if(status == "success" && $(hash).hasClass("selected"))
			{
				/*$(hash).fadeIn(500, 'easeOutExpo',function(){initializePortfolio(hash);});*/
				$(hash).slideDown(500, function(){initializePortfolio(hash);});
//				$('#portfolio_items').slideDown(500);
				$('#portfolio_items .blocker').hide();
//				$('#portfolio_items').slide("height","auto");
			}
		});
	}
}
function swapPortafolioItem(hash){
	var currentItem = "";
	if ($("#portfolio_items article.item.selected").length > 0) {
		currentItem = $("#portfolio_items article.selected")
		currentItem.removeClass("selected");
		if($(hash).length > 0)
		{
			currentItem.fadeOut(500, function () { showPortafolioItem(hash); });
		}
		else
		{
			$('#portfolio_items .blocker').show();
			currentItem.slideUp(500, function () { showPortafolioItem(hash); });
		}
	} else {
		showPortafolioItem(hash);
	}
}

//$(document).ready(function(){
var hasFlash = false;
$(window).load(function(){
	
				
	$( 'body' ).fadeIn(750,'easeOutQuad');
	initBox();
			var currentItem = "";
			var folio_thumbs = $('.portfolio_thumbs .thumb');
			folio_thumbs.hover( function () {
				$(this).find('.overlay').fadeIn(300);
				$(this).css('cursor','pointer');
				$("p", $(this)).css('color','#ff3300').animate()
								
			}, function () {
				$(this).find('.overlay').fadeOut(135);
				$(this).css('cursor','auto');
				$("p", $(this)).css('color','#414042').fadeIn(500);
			});	
			
			folio_thumbs.click( function(e) { 
				var hash = '#' + $(this).attr('id');
				hash = hash.replace('_thumb','')
				window.location = hash
				
			});
			
			$('#close_btn').click( function(e) { 
				$('#portfolio_items').slideToggle(500, 'easeOutExpo',function(){
				window.location.hash = " ";
				});
			});
			$('#close_btn').hover( function () {
				$(this).css('cursor','pointer');
				$("p", $(this)).css('color','#ff3300').animate()
								
			}, function () {
				$(this).css('cursor','auto');
				$("p", $(this)).css('color','#414042').fadeIn(500);
			});	
			
			$(window).hashchange( function(){
				var hash = location.hash;
				//alert(hash)
				//document.title = 'The hash is ' + ( hash.replace( /^#/, '' ) || 'blank' ) + '.';
				if( hash != ""){
					$.scrollTo('#portfolio', 500);
					if($('#portfolio_items').is(":visible")){
						swapPortafolioItem(hash);
					}else{
						if ($("#portfolio_items article.item.selected").length > 0) {
							currentItem = $("#portfolio_items article.selected")
							currentItem.removeClass("selected");
						}
						$("#portfolio_items article.item").hide();
						if($(hash).length > 0)
						{
							$('#portfolio_items .blocker').hide();
							$(hash).addClass("selected");
							$(hash).css('display','block');
							$('#portfolio_items').slideDown(1000, function(){initializePortfolio(hash);}).delay(1000);
						}
						else
						{
							$('#portfolio_items .blocker').show();
							$('#portfolio_items').slideDown(1000, function(){swapPortafolioItem(hash);}).delay(1000);
						}
					}	
				}
				
			})
			$(window).hashchange();
			
			
			getTwitters('twitter', {
				id: 'andressoler', 
				count: 1, 
				enableLinks: true, 
				ignoreReplies: true,
				template: '<\article class="normal_width"><\h1>%text%<\/h1><\p>Tweeted by <\a href="http://twitter.com/%user_screen_name%">%user_screen_name%<\/a> %time%<\/p><\/artcile><\header><\/header>'
    		});	
		});
