(function($)
{
	var ADC =
	{
		setData:function(obj,d)
		{
			if (typeof d=='object') $.extend(true,obj._data,d);
			else return obj._data;
		},
		Portfolio:
		{
			_data:{},
			current:null,
			data:function(d){return ADC.setData(this,d);},
			init:function()
			{
				$('#portfolioTree li').click(function(e)
				{
					ADC.Portfolio.getImages($(this).attr('data'));
					// handle current selected element and descendant ULs
					var selected = $(this).siblings('.selected');
					selected.find('ul').slideUp('normal',function(){selected.removeClass('selected')});
					
					// handle clicked element
					$(this).addClass('selected');
					$(this).children('ul').slideDown('normal');
					//return false;
				});
				
				$('#thumb-nav a').click(function(){ADC.Portfolio.clickItem($(this).attr('href').replace("/portfolio/#",""));});
				
				ADC.Portfolio.clickItem(window.location.hash.substr(1));
			},
			getImages:function(key)
			{
				if (key!='')
				{
					$.post('/portfolio/images/',{'key':key},function(r)
					{
						$('#portfolioBody').html(r);
						$("#portfolioBody div.scrollable").scrollable();
						$("#portfolioBody div.scrollable .items img").click(function() 
						{
							var url = $(this).attr("src").replace("_t", "");
							var wrap = $("#image_wrap");
							var img = new Image();
							img.onload = function() {wrap.find("img").attr("src", url);};
							img.src = url;
						}).filter(":first").click();

					},'html');
				}
			},
			clickItem:function(item)
			{
				$('li[data="'+item+'"]').click().parents('ul').each(function(){$(this).click()});
			}
		}
	};
	window.ADC=ADC;
})(jQuery)