$(document).ready(function() {

	// Centre Gallery
	var $gallery = $("#gallery");
	var $zoom = $("#zoom");
	var $zoomInfo = $zoom.children(".info");
	$("ul", $gallery).jcarousel({
		scroll: 4,
		buttonNextHTML: '<a href="#next" class="next">Next</a>',
		buttonPrevHTML: '<a href="#prev" class="prev">Previous</a>'
	});
	
	$("li a", $gallery).click(function(e) {
		e.preventDefault();
		var $this = $(this);
		$zoom.children("img").remove();
		var $img = $("<img />").attr("src", $this.attr("href")).prependTo($zoom);
		$zoomInfo.children("span").text($this.data("caption"));
		$zoom.fadeIn(300);
	});
	
	$(".close", $zoomInfo).click(function(e) {
		e.preventDefault();
		$zoom.fadeOut(300);
	});
	
	
	
	
	// Action buttons
	var $actionButtons = $("#action-buttons a");
	$actionButtons.hover(function() {
		$(this).children("img").animate({
			width: 65,
			height: 65,
			left: -5,
			top: -5
		}, 150);
	},
	function() {
		$(this).children("img").animate({
			width: 55,
			height: 55,
			left: 0,
			top: 0
		}, 150);
	});
	
	$("#slideshow").cycle();
	
	// Working together animation
	var $images = $("#anim img");
	var imageLength = $images.size();
	$images.each(function(i) {
		var $this = $(this);
		
		window.setTimeout(function() {
			$this.animate({
				height: 52
			}, 300, function() {
				$this.delay(300).animate({
					height: 44
				}, 300);
			});
			
			
		}, 1000*(i+1));
	});
	
	// Top Navigation
    $(function() {
        $("#nav li").hover(function() {
            $(this).children("a").addClass("hover");
            $(this).parent().children("a").addClass("hover");
            $("ul:first", this).css('visibility', 'visible');
        }, function() {
            $(this).children("a").removeClass("hover");
            $(this).parent().children("a").removeClass("hover");
            $("ul:first", this).css('visibility', 'hidden');
        });

        $("#right-nav li").hover(function() {
            $(".sub-nav", this).slideDown(300);
        }, function() {
            $(".sub-nav", this).slideUp(300);
        });
    });
});
