$(document).ready(function() {

	$('#main-nav ul li').hover(
		function(){
			var dd_width =  $(this).find('.dd').width();
			
			$(this).find('.dd').eq(0).show();
			$(this).find('.dd').parent().find('a').eq(0).addClass('active');
			$(this).find('.dd').eq(0).css('width' , dd_width);
			
		}, 
		function(){
			$(this).find('.dd').eq(0).hide();
			$(this).find('.dd').parent().find('a').eq(0).removeClass('active');
	
		}
	);
	
	$('.slider .slider-carousel ul').jcarousel({
		'scroll' : 1,
		'auto': 0,
		'buttonNextHTML': '',
		'buttonPrevHTML': '',
		'initCallback':  init_carousel,
		'wrap': 'both'
	});
	
	function init_carousel(carousel) {
		$('.slider .slider-nav a.prev').click(function(){
			carousel.prev();
			return false;
		});
		
		$('.slider .slider-nav a.next').click(function(){
			carousel.next();
			return false;
		});
		
	};
	
	
	//project slideshow
	$('.top-slider .slider-carousel > ul > li').simpleFade({
		speed: 1000,
		duration: 5000,
		init: function(){ 
			fader = this;
		 },
		onFade: function(index){ 
			$('.top-slider .slider-nav a').each( function () { $(this).find('img:eq(0)').show(); }  );
			$('.top-slider .slider-nav a').each( function () { $(this).find('img:eq(1)').hide(); }  );
			$('.top-slider .slider-nav a').eq(index).find('img:eq(0)').hide();
			$('.top-slider .slider-nav a').eq(index).find('img:eq(1)').show();
			$('.top-slider .slider-nav li').removeClass('active').eq(index).addClass('active');
		 }
	});
	
	//create external controls
	$('.top-slider .slider-nav a').live('click', function(){ 
		fader.fadeTo($(this).parent().index());
		return false;
	});
	
	
	$('.top-slider .slider-nav a').hover(
		function(){
			$(this).find('img:eq(0)').hide();
			$(this).find('img:eq(1)').show();
		}, 
		function(){
			$(this).find('img:eq(0)').show();
			$(this).find('img:eq(1)').hide();
			if($(this).parent().hasClass('active'))
			{
				$(this).find('img:eq(0)').hide();
				$(this).find('img:eq(1)').show();
			}
		});
});
