$.noConflict();
	
	//When dom ready
	//jQuery('#work-thumbs img').imgpreload();
	
	//When the page is loaded, delay for .4 second then slide the content out (Firefox seems to have an "urge" to load if you don't delay it
	jQuery(document).ready(function($){	
		
		$('li.hovers').each(function(){
			var linkies = $(this).find('a').attr('href');
			var linkFolder = $(this).find('a').attr('rel');
			var linkTitle = $(this).find('img').attr('alt');
			$('#subnav').append('<span><a href="'+linkies+'" rel="'+linkFolder+'">'+linkTitle+'</a></span> &#92;&#92; ');
		});
		
		var d = $('#subnav');
		d.delay(600).animate({
			'height': $('#h').text()+'px',
			'opacity': 1				 
		},600);
	
	//Categories
	$('#cat-hdr').bind('mouseenter mouseleave', function(){
		 $('ul#cats').stop(true,true).slideToggle();  
	  });
	/*$('#cats a').bind('click',function(event){
    event.preventDefault();
    $.ajax({
     url: "-/php/ajax/categories.php",
     type: "get",
     data: 'cat='+$(this).attr('href')+'&page=works',
     success: function(data){
	   	  //$('.loading').remove();
		     $('#work-thumbs').empty().append(data);
	    }
    });
  }); */
	
	
	//Beginning thumbnails stuff
	var $thumbnails = $('#work-thumbs');
	var $overlays = $('.work-overlay');
	
	$thumbnails.find('img').attr('id',function(x){ return 'img'+x;});
	$('#subnav').find('span').attr('id',function(x){ return 'submenu'+x; });
	
	//Link hover animations and ajax call for the the links on the sidebar
	$('#subnav').find('span').each(function(x){
		$(this).bind('mouseenter',function(event){ 
			$('#submenu'+x).find('a').addClass('active');
				$('#img'+x).stop().fadeTo('normal', 0.2, function(){
					$('#img'+x).after('<div class="loading"></div>');
					$.ajax({	
						   url: "-/php/ajax/tips.php", 
						   type: "get",
						   data: 'folder='+$('#submenu'+x).find('a').attr('rel')+'&type=works',
						   success: function(data){ 
						   		$('.loading').remove();
							   $('#img'+x).after(data);
							   $('.work-overlay').show();
						   }
					});
				});
				
			});
			$(this).mouseout(function(){
				$('#submenu'+x+' > a').removeClass('active');
				$('.work-overlay').remove();
				$('#img'+x).stop().fadeTo('fast', 1);
				
			});
	});
	
	
	//Animations and ajax calls for each of the thumbnail
	$('li.hovers').each(function(x){
			$(this).mouseover(function(){
				if($('.work-overlay').length != 0){ $('.work-overlay').remove(); };
				$('#submenu'+x+' > a').addClass('active');
				$('#img'+x).stop().fadeTo('normal', 0.2, function(){
					$('#img'+x).after('<div class="loading"></div>');
					$.ajax({
						   url: "-/php/ajax/tips.php", 
						   type: "get",
						   data: 'folder='+$('#submenu'+x).find('a').attr('rel')+'&type=works',
						   success: function(data){
							   $('.loading').remove();
							   $('#img'+x).after(data);
							   $('.work-overlay').show();
						   }
					});
				});
			});
			$(this).mouseout(function(){
				$('#submenu'+x+' > a').removeClass('active');
				$('#img'+x).stop().fadeTo('fast', 1);
				
			});
		});

	/*$('a.add').each(function(el){
		$(this).bind('click',function(event){
			//Stop information being process twice
			event.stopPropagation();
			var html = '<ul class="playlist" id="item_'+el+'"><li><span class="list-thumb"><img src="uploads/cabelas/playlist-small-thumb1.jpg" alt=""></span><span class="list-title">Reel 10</span><span class="x" id="'+el+'"><img src="-/images/x.png" alt="" width="10" height="8" class="x-btn"></span></li></ul>';
			var em = $('#empty');
			
			//Grab the title from the overlays to use below
			var addedName = $('#overlay'+el).find('span.work-title').html();
			
			//If the instructions is showing, hide it, then add the first item
			if(em.css('display') == 'block'){
				em.slideUp('slow',addItem);
				em.queue(function(){ errorMsg('Added "'+addedName+'"'); });
			} else {
				//Make sure there isn't more than one of the same item was added
					if($(".playlist[id='item_"+el+"']").length >= 1){
						errorMsg('"'+addedName+'" is already added!');
					} else {
						addItem();
						errorMsg('Added "'+addedName+'"');
						//Auto-save the list so far
						//saveList();
					}
			}
			
			//Function to append items
			function addItem(){
				$(html).appendTo('#work-playlist').animate({
					'height': '25px',
					'opacity': 1
				},'easein');
			}
			
			//Auto-save / save funtion
			function saveList(){
				
			}
			
			function errorMsg(msg){
				$(this).stop(); //This starts a new animation every time instead of continuing the 3 seconds delay
				$('#message').empty().append(msg);
				$('#message').stop().animate({ 'opacity': 1,'height':'15px'},'easein',function(){ $('#message').delay(3000).animate({'height':'0px','opacity':0}); });
			}
					  
		});
	});
	
	
	//When click on the X 
	$('.x').live('click',function(){
		var i = $('#item_'+$(this).attr('id'));
		i.fadeTo('slow',0);
		i.animate({ 'height':0});
		i.queue(function(){ $(this).remove(); $(this).dequeue; });
	});
	
	//Clear list button
	$('#clearlist').bind('click',function(){
		$('.playlist').fadeOut('slow')
		.queue(function(){ $('.playlist').remove(); $('#message').hide(); $(this).dequeue; });
		if($('#empty').css('display') == 'none'){
			$('#empty').delay(800).slideDown('slow').show();
		}
	 });*/
});