// DELAY PLUGIN
$.fn.delay = function(time, callback){
    jQuery.fx.step.delay = function(){};
    return this.animate({delay:1}, time, callback);
};


jQuery(document).ready(function() {
	
	$('#main_works_img').before('<div id="nav">');

	
	$('#main_works_img').cycle({ 
		fx:    'scrollHorz', 
		speed:  400,
		pager:  '#nav',
		timeout: 5000, 
		pause:   1
	 });
	
	var thumb = $('.link_p_thumb');
	
	var link_thumb = $('.link_thumb');
	var transparency = $('<span> </span>');

	link_thumb.append(transparency);
	var images = $('img', link_thumb);
	
	images.each(function(i) {
		$(this).delay(500*i).fadeIn(500);
	});
	
	thumb.hover(
	  function () {
	    $(this).find('span').stop(true, true).animate({opacity: 0.8}, 600);
	  }, 
	  function () {
	    $(this).find('span').stop(true, true).animate({opacity: 0}, 600);
	  }
	);
	
	
	thumb.click(
		function() {
			window.location = $(this).attr('rel');
		}
	);
	 
});
