/*

* Copyright (C) 2009 Joel Sutherland.

* Liscenced under the MIT liscense

*/



(function($) {

	$.fn.slider = function(settings) {

		settings = $.extend({

            selectedClass: 'current',

			show: { width: 'show', opacity: 'show' },

			hide: { width: 'hide', opacity: 'hide' },

         	animationSpeed: 1000,

			tagSelector:'#portfolio-filter a',

            tagfilteredportfolio:'#portfolio-list',

			tagfilteredportfolioChildren:'#portfolio-list li',

            tagSlideSelector:'#show_slide', 

			tagSlideSelectorChildren:'#show_slide > li',

			tabContainers: 'div.imageholder > div',

            tabContainerClick:'div.projectscreen ul.screenNavigation a',  

			allTag: 'all'



		}, settings);

		

		      $(settings.tagfilteredportfolioChildren).not('.' +$(settings.tagSelector+':first').attr('href').substr(1)).hide();

		      $(settings.tagSelector+':first').addClass('current');

		      $(settings.tagSlideSelectorChildren+"."+$(this).children('.' + $(settings.tagSelector+':first').attr('href').substr(1)+":first > a").attr("rel")+"-container").show();

			

			

		return $(this).each(function(){

			
			$(settings.tagSelector).click(function(){

					

				/*removes the class*/

				$(settings.tagSelector).removeClass('current');

				/*adds current class to current tag*/

				$(this).addClass('current');

				/*trigger the filteredportfolio*/

			    $(settings.tagfilteredportfolio).trigger("showfilteredportfolio", [$(this).attr('href').substr(1)]);

				      

					

				});

		

			

			/* SHOW FILTERED PORTFOLIO : pass  the class to show, all others will be hidden */

			$(this).bind("showfilteredportfolio", function( e, classToShow ){

					/*hide slider child*/

				$(settings.tagSlideSelectorChildren).hide();

				

				if(classToShow == settings.allTag){

					//$(this).trigger("show");

				}else{

					$(this).trigger("show", [ '.' + classToShow ] );

					$(this).trigger("hide", [ ':not(.' + classToShow + ')' ] );		}

                $(settings.tagSlideSelectorChildren+"."+$(this).children('.' + classToShow+":first > a").attr("rel")+"-container").show();

				location.hash = '#' + classToShow;

					

				

			});



			$(settings.tagfilteredportfolioChildren).click(function(){

				  $(settings.tagSlideSelectorChildren).hide();

				  $(this).trigger("showslide",[ '.' +$(this).find('a').attr("rel") ]);

			});



			$(settings.tagfilteredportfolioChildren).hover(function(){

				   $(this).find('span').animate({opacity:1},'fast');;

			},function(){

			    $(this).find('span').animate({opacity:0},'slow');

			

			});



			$(this).bind("showslide",function(e,slideToShow){



				

				$(settings.tagSlideSelectorChildren+slideToShow+'-container').show(); //animate(settings.show, settings.animationSpeed);

				$(settings.tabContainers).hide().filter(':first').show();

				$(settings.tabContainerClick).click(function () {

					$(settings.tabContainers).hide();

			      	$(settings.tabContainers).filter(this.hash).show();

					$(this).addClass('selected');

				     return false;

			    }).filter(':first').click();



			





			});





			/* 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);	

			});



			

		

			

			

			

		});

	}

})(jQuery);





$(document).ready(function(){

	

	$('#portfolio-list').slider();



});