$(document).ready(function() {
	//portfolio scripts
	//attach onImagesLoad to portfolio wrapper
	$('#portfolio-wrapper div').onImagesLoad({ 
		selectorCallback: processImages()
	});	
	//attach event to images for transparency
	$('#portfolio-wrapper div[id^="portfolio"] div').hover(function(){
	if($(this).next().css('opacity')=='1')
	{//only show if parent div is active in the filtered list
		$(this).find('.overlaybutton').show();			
	}
		},function(){
			$(this).find('img').prev().hide();			
		}
		
	).find('a').prepend('<div class="overlaybutton"></div>');
	doPortfolioItemSort();//loads filterlisting function	
	/*
	$("div[id^='portfolio-'] a.colorbox").not('.filtered').colorbox({
			width:"720px"			
	});	
	*/
	$("#showcaseScreenshotContainer a").colorbox(); 

});

function processImages()
{//images have been loaded when this is called, so fade them in
	$('#portfolio-wrapper div img').hide().css({visibility:"visible"}).fadeIn(1000);
}
function doPortfolioItemSort()
{//amended version of http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-filterable-portfolio-with-jquery
//fades out any not selected
	$('#filtertags a').click(function() {
		$('#filtertags .active').removeClass('active');
		$(this).parent().addClass('active');
		var filterlistVal = $(this).text().toLowerCase().replace(' ','-');
		if(filterlistVal == 'all') {//reset to defaults
			$('div[id^="portfolio"].filtered').fadeTo('fast',1);
			$('.filtered').removeClass('filtered');			
			$('a, img, p, span').fadeTo('fast',1);//we have to fade child elements not the div as that will bork IE8
		} else {
			$('#portfolio-wrapper div[id^="portfolio"]').each(function() {
				if(!$(this).hasClass(filterlistVal)) {
					$("a, img, p, span", this).fadeTo('fast',0.3).addClass('filtered');					
				} else {
					$("a, img, p, span", this).fadeTo('fast',1).removeClass('filtered');
				}
			});
		}

		return false;
	});
}
