$(document).ready(function(){
Cufon.replace('#logo span, #navigation, #feature h3, #strapline, h2, .projects span.title, #page-heading h1 span.cufon, #project-meta strong, span.cufon, #footer-inner strong, span.surrogate-h2, #feature-vid p, .project-list span.cufon, #featured-slideshow p, #featured-slideshow span.h3, #featured-slideshow span.sub-title');

	
	
	function mycarousel_initCallback(carousel) {
		    jQuery('.next').bind('click', function() {
		        carousel.next();
		        return false;
		    });
		
		    jQuery('.prev').bind('click', function() {
		        carousel.prev();
		        return false;
		    });
		}
		
		// 
		$("ul.caro").jcarousel({
		        scroll: 1,
				wrap: 'circular',
		        initCallback: mycarousel_initCallback,
		        // This tells jCarousel NOT to autobuild prev/next buttons
		        buttonNextHTML: null,
		        buttonPrevHTML: null
		    });
		

						
			$('#more_news').click(function() {
					$('#latest ul span.more').show();
					$(this).hide();
					$('#less_news').show();
					return false;
			});
			
			$('#less_news').click(function() {
					$('#latest ul span.more').hide();
					$(this).hide();
					$('#more_news').show();
					return false;
			});
			

			$('#recent li').hover(function() {
				$('img', this).css('opacity', 0.9);
			}, function() {
				$('img', this).css('opacity', 1);
			});
		
		$('a.close').click(function() {
			$('.category-desc').slideUp();
		});


		// NAVIGATION FUNCTIONS 
		var indexed;
		var selected;
		var pos;
		var returnArrow;
		
		// $('.action').corner('25px');
		
		// confirm buttons 
		$('a.confirm').click(function() {
			return confirm('Are you sure?');
		});
		// HOVERING
		$('ul#navigation li').hover(
			
		  function () {
			
			returnArrow = false;
			// background positiom
			indexed = $('#navigation li').index(this);
					
			
			if (indexed === 0) {	pos = '15px 55px'; }
			if (indexed === 1) {	pos = '100px 55px';	}
			if (indexed === 2) {	pos = '188px 55px';	}
			if (indexed === 3) {	pos = '275px 55px';	}
			if (indexed === 4) {	pos = '380px 55px';	}
			if (indexed === 5) {	pos = '470px 55px';	}
			if (indexed === 6) {	pos = '547px 55px';	}
			
			// console.log(indexed); 
			
			$('#navigation').animate({backgroundPosition: " "+ pos + ""}, 200);
		
		  },
		  function () {
				returnArrow = true;
				window.setTimeout(resetArrow, 100);
		  }
		);
		
		function resetArrow(){
			if (returnArrow) {
		
				// find the selected element, move the arrow
				selected = $('#navigation li a').index($('.selected'));
		
				if (selected === 0) {	pos = '15px 55px'; }
				if (selected === 1) {	pos = '100px 55px'; }
				if (selected === 2) {	pos = '188px 55px'; }
				if (selected === 3) {	pos = '275px 55px'; }
				if (selected === 4) {	pos = '380px 55px'; }
				if (selected === 5) {	pos = '470px 55px'; }
				if (selected === 6) {	pos = '547px 55px'; }
		
				// console.log(selected); 
		
				$('#navigation').animate({backgroundPosition: " "+ pos + ""}, 200);
			}
		}
		
		
		
		// PROJECT LIST
		$('.projects li').hoverIntent(
			function() {
				// $('span.info', this).animate({marginTop: '30%'}, 300);
				$('span.text', this).slideDown({ duration: 150, easing: "easeInQuad"});
				$('span.text', this).animate({opacity: 1}, 150);
			},
			function () {
				// $('span.info', this).animate({marginTop: '55%'}, 300);
				$('span.text', this).slideUp({ duration: 150, easing: "easeOutQuad"});
				
				$('span.text', this).animate({opacity: 0}, 150);
				
			}
		);
		
		$('#share a#title').click(function() {
			return false;
		});
		
		
		// more news 
		$('#share').hoverIntent(
					function () {
						$('#social-links').fadeIn(200);
						$('a#title').css('border-bottom-width', '0px');
						$('ul#social-links, div#share a#title').dropShadow({left : 3, top : 3, opacity : 0.2});
						
					},
					function () {
						$('#social-links').fadeOut(200);
						$('ul#social-links, div#share a#title').removeShadow(); 
						$('a#title').css('border-bottom-width', '1px');
					}
				);
		
		
		// sub category front facing filter
		$('span#filter').click(function(event) {
			event.stopPropagation();
			var pos = $(this).position();
			if ($('ul#filter_options').css('display') == 'none') {
				$('ul#filter_options').show().css('top', (pos.top + 30) + 'px');
			} else {
				$('ul#filter_options').hide();
			}
		});
		
		
		// individual filter options
		$('#filter_options li').click(function() {
			$('span#filter').trigger('toggle');
			$('ul#filter_options').hide();
			$('span#filter attr').html($(this).html());
			var sub_id = $(this).attr('id');
			if (sub_id == 'all') {
				$('ul.projects li').fadeIn('fast');
			} else {
				$('ul.projects li').hide();
				$('ul.projects li.sub-' + sub_id).fadeIn('fast');
			}
			
		});
		// hide the menus when clicking away from the filter menus
		$('body').click(function() {
		$('ul#filter_options').hide();
		});
		
		
		// The home page slideshow
		//---------------------------------------------------------
	
		var slideEasing	= 'easeInOutCubic';
		var slides 		= $('#featured-slideshow');
		var dot			= $('#featured-dots span.dot');
		var imageIndex 	= "";
		
		if (slides.length > 0) {
			
			dot.first().addClass('on');
			
			dot.click(function() {
				
				slides.cycle($(this).index());
				return false;
				
			});
			
			slides.cycle({
				fx: 'scrollHorz',
				speed: 350,
				slideExpr: 'div.slide',
				easing: slideEasing,
				pause: 1,
				after: function(currSlideElement, nextSlideElement) {
					// change the states
					imageIndex	 = $(nextSlideElement).index();
					dot.removeClass('on');
					$(dot[imageIndex]).addClass('on');
					
					
				}
			});

			// slides.cycle('pause');
			
			// Fancybox
			//---------------------------------------------------------
				
			$("a.play").fancybox({
				centerOnScroll : true,
				margin: 0,
				padding: 0,
				onComplete: function() {
					slides.cycle('pause');
				},
				onClosed: function() {
					slides.cycle('resume');
				}
			});
				
			// Meta data hovering
			//---------------------------------------------------------
			
			$('div.slide').hover(function() {
				
				$('div.meta', this).slideDown(300);
				
			}, function() {
				
				$('div.meta', this).slideUp(180);
				
			});

		}
		
	
		
		
		
	
		

});
