
Cufon.replace('h1'); // Works without a selector engine
Cufon.replace('.t'); // Requires a selector engine for IE 6-7, see above

$(function() {
		
		lightboxCheck();
		initBinding();
		
		// Clone all portfolio items for Quicksand plugin
		var cache_list =$('ul.portfolio').clone();
		
		// When clicked on a link in the portfolio menu
		$('ul.portfolio-menu li a').click(function(e) {
		
		// Remove current old active class
		$('ul.portfolio-menu').children('li').children('a').removeClass('active');
		
		// Set active class on clicked element
		$(this).addClass('active');
		
		// If all portfolio items have to be showed
		if($(this).attr('id') == 'all') {
			
			// Refresh Quicksand
			$('.portfolio').quicksand( cache_list.find('li'), {
		
				  duration: 1000,
				  attribute: function(v) {
				  return $(v).find('img').attr('src');
              }

				}, function() {
				
					lightboxCheck(); // refresh lightbox script (binding)
					initBinding();
				
				});
				e.preventDefault();
		
		// If a particular catagorie has to be showed
		} else {
		
			$('.portfolio').quicksand( cache_list.find('li.'+ $(this).attr('id') +''), {
				  duration: 500,
				  attribute: function(v) {
                return $(v).find('img').attr('src');
              }

				}, function() {
				
					lightboxCheck();
					initBinding();
				
				});
				e.preventDefault();
		}

		});
		
		function lightboxCheck() {
			
			// For each image
			$('span.img-polaroid').each(function() {
		
				// If the image has a class of 'zoom' and the previos element doesn't have a 'caption' class
				if($(this).next().attr('class') == 'zoom' && $(this).prev().attr('class') !== 'caption') {
					
					$(this).css('cursor', 'pointer')
					$(this).addClass('lightbox');
					$(this).parent().prepend('<span class="caption"></span>');
			
				}
		
			});
		
		}
	
		function initBinding() {
		
			// prettyPhoto plugin
			$("a[rel^='prettyPhoto']").prettyPhoto();
			
			$('span.img-polaroid').hover(function() {
			
				if($(this).prev().css('opacity') == '0') {
				
					$(this).prev().fadeTo('500', '0.6');
					
				}
		
			}, function() {
			
				$(this).prev().fadeTo('500', '0');
			
			});
			
			$('span.img-polaroid').click(function() {
				
				// When clicked on the span tag before the 'a' element, click on the anchor tag
				if($(this).next().attr('class') == 'zoom') {
				
					$(this).next().click();
				
				}

			});
			
		}
		
		$('div.slider').sliders({
	
			cycle : true, // true or false
			slideWidth : 980, // width per slide
			cycleInterval : 5000 // pause in milleseconds between animation
		
		});
	
		$('div.portfolio-slider').sliders({
	
			cycle : true, // true or false
			cycleInterval : 2000, // pause in milleseconds between animation
			arrowNavigationWrapper : 'div.portfolio-slider', // wrapper class
			slideWidth : 310, // width per slide
			projectSlider : true, // true or false
			sliderdots : false // true or false
		
		});
		
		// Get the position of the contact form
		var position = $('#contact').position(); 
		
		// When clicked on 'add comment' or 'reply' button
		$('a.add-comment').click(function(e) {
			
			// Don't go to the top
			e.preventDefault();
			
			// Animate screen to top of the contact form
			$('html, body').animate({scrollTop: position.top}, 300);
		
		});
		
		$('div.sidebar > div').each(function() {
		
			$(this).append('<span class="default-icon"></span>');
		
		});
		
			
});


			

