$(document).ready(function(){	
  $('a.projectCat').click(function(){
  	$('a.projectCat').removeClass("selected");
  	$(this).addClass("selected"); 	
  	$('.reset').hide();
    $('#projectList li').fadeOut(500);
    $('.loading').fadeIn(1000);
    $.mySection = this.id;
    $('#projectContent ').load('/projectdata/'+$.mySection, function(data){
    	attach();
    	Shadowbox.clearCache();
    	Shadowbox.setup();
	});
 	$('a[rel*=shadowbox]').click(function(){
        Shadowbox.open(this);
        return false;
    }); 
  	return false;
  });
  
  function selChange() {
  	var selyear =  $("select#selyear option:selected").val();
	var selmed =  $("select#selmed option:selected").val();
	if( $.mySection =="movies" || $.mySection =="tv") {
		var selgenre =  $("select#selgenre option:selected").val();
	} else {
		var selgenre = "all";
	};
	
    $('#projectList li').fadeOut(500);
    $('.reset').hide();
    $('.loading').fadeIn(1000);
    $('#projectContent ').load('/projectdata/'+$.mySection+'/'+selyear+'/'+selmed+'/'+selgenre, function(data){
    	attach();
    	Shadowbox.clearCache();
    	Shadowbox.setup();
    	$('.reset').fadeIn(500); 
    	reset();   	
	});
	return false;   
  }  
  function attach(){
  	$('#projectForm select').change(selChange); 	
  }
  function reset(){
  	$('.reset').click(function() {
  		$(this).hide();
	  	$('#projectList li').fadeOut(500);
	    $('.loading').fadeIn(1000);
	  	$('#projectContent ').load('/projectdata/'+$.mySection, function(data){
    	attach();
    	Shadowbox.clearCache();
    	Shadowbox.setup();
	});
	  });
  }
  attach();
  
});
