/*
* Aaronfooshee.com by Aaron Fooshee
*
* Uses altered portions of code:
* Copyright (C) 2009 Joel Sutherland. Licensed under the MIT license.
* 
*/


jQuery(document).ready(function($) 
	{	// $() will work as an alias for jQuery() inside of this function, as per Wordpress
	
		
		//
		// FUNCTION: make tag sortable categories and hashtags
		//
		$.fn.filterable = function(settings) {
			settings = $.extend({
				animationSpeed: 500,
				show: { height: 'show', opacity: 'show' },
				hide: { height: 'hide', opacity: 'hide' },
				useTags: true,
				tagSelector: '#portfolio-filter a',
				selectedTagClass: 'current',
				allTag: 'all'
			}, settings);			
			
			return $(this).each(function(){
	
				/* FILTER: select a tag and filter */
				$(this).bind("filter", function( e, tagToShow ){
					if(settings.useTags){
						$(settings.tagSelector).removeClass(settings.selectedTagClass);
						$(settings.tagSelector + '[href=' + tagToShow + ']').addClass(settings.selectedTagClass);
					}
					$(this).trigger("filterportfolio", [ tagToShow.substr(1) ]);
				});
		
				/* FILTERPORTFOLIO: pass in a class to show, all others will be hidden */
				$(this).bind("filterportfolio", function( e, classToShow ){
						if(classToShow == settings.allTag){
						$(this).trigger("show");
					}else{
						$(this).trigger("show", [ '.' + classToShow ] );
						$(this).trigger("hide", [ ':not(.' + classToShow + ')' ] );
					}
					location.hash = '#' + classToShow;

				});
				
				/* SHOW: show a single class*/
				$(this).bind("show", function( e, selectorToShow ){
					$(this).children(selectorToShow).animate(settings.show, settings.animationSpeed);
				});
			
				/* SHOW: hide a single class*/
				$(this).bind("hide", function( e, selectorToHide ){
					$(this).children(selectorToHide).animate(settings.hide, settings.animationSpeed);	
				});
			
				/* Check URL Hash */
					if(location.hash && !$isartworkhash )
						$(this).trigger("filter", [ location.hash ]);
					else
						$(this).trigger("filter", [ '#' + settings.allTag ]);
						
			
				/* Setup Tags */
				if(settings.useTags){
					$(settings.tagSelector).click(function(){
						$('#portfolio-list').trigger("filter", [ $(this).attr('href') ]);
						
						$(settings.tagSelector).removeClass('current');
						$(this).addClass('current');
						$('#portfolio-list li a').removeClass('activeartwork');
					});
				}
			});
		}

		//
		// FUNCTION: make project change
		//
		$.fn.projectselect = function(){
			$('#portfolio-list li a').click(function(){
				
				/* MAKE: project hash */
				var $hashclean = null; 
				var $hashclean = $(this).text();
				var $hashclean = $hashclean.replace(/\s+/g, '-').toLowerCase();
				location.hash = '#' + $hashclean;

				/* SET: classes */
				$('#portfolio-list li a').removeClass('activeartwork');
				$(this).addClass('activeartwork');
								  
				/* REMOVE: hide previous artwork */
				var toLoad = $(this).attr('href')+' #artwork';
				$('#artwork').hide('fast',loadContent);

				/* SHOW: show new artwork */
				function loadContent() {
					$('#artwork').load(toLoad,'',showNewContent());
				}
				function showNewContent() {
					$('#artwork').show('slow');
				}
				return false;
			});
		}
		


$(document).ready(function(){	

	$workarray = [];
	$("#portfolio-list li a").each(function() { $workarray.push($(this).text().replace(/\s+/g, '-').toLowerCase()) });
//	var $workarrayCSV = '"' + $workarray.join('", "') + '"';
//	alert($workarrayCSV); //debugging
	$workhash = location.hash.replace("#",""); //filter hash out
//	alert($workhash); //debugging
	$isartworkhash = false;
	
	$.each($workarray, function(index, value) { 
//		alert(index + ': ' + value); //debugging
  		if ( value === $workhash ) {
  			$isartworkhash = true;
  		} 
	});
//	alert ($isartworkhash);


	$('#portfolio-list').filterable();
	$('#portfolio-list').projectselect();
});




	






	
	
	
	
	
	

	
	





}); // $() will work as an alias for jQuery() inside of this function, as per Wordpress
