$(document).ready( function() {
	$("#carousel").removeClass('no-script');
	$("#carousel").show();
	//jQuery('#mycarousel').jcarousel();


	var citems = $("ul.carousel li").length;
	var cvis = 2;
	
	window.cpages = Math.ceil( citems / cvis );
	window.curcpage = 0;
	
	window.cItemWidth = 87;
	$("ul.carousel").width( citems * $("ul.carousel li:eq(0)").outerWidth() + (citems*2) + 2 );
	if( citems > cvis ) {
		$("#carousel").prepend('<a class="c-left"></a><a class="c-right"></a>');
		
		$("a.c-left").addClass('c-active');
		
		$("a.c-left").click(
			function() {
				if( window.curcpage < window.cpages - 1 ) {
					window.curcpage++;
					var newpos = (window.curcpage * window.cItemWidth * 2 * -1) + 12;
					$("ul.carousel").stop().animate( { right: newpos + 'px' } );
					$("a.c-right").addClass('c-active');
					if( window.curcpage >= window.cpages -1 ) {
						$(this).removeClass('c-active');
					}
				}
			}
		);
		$("a.c-right").click(
			function() {
				if( window.curcpage > 0 ) {
					window.curcpage--;
					var newpos = (window.curcpage * window.cItemWidth * 2 * -1) + 12;
					$("ul.carousel").stop().animate( { right: newpos + 'px' } );
					$("a.c-left").addClass('c-active');
					if( window.curcpage == 0 ) {
						$(this).removeClass('c-active');
					}
				}
			}
		);
	}



	if( hasFlash ) $("#buttons").show();
	

	$("#sidebar ul.nav li").click(
		function() {
			$('.popdown').hide();
			swapMovie( $(this).find('span').attr('rel'), 30, 10 );
			$(this).find('.popdown').slideDown('fast');
		}
	);
	$("#bottom a.open-slide").click(
		function(event) {
			event.preventDefault();
			$(".slider-content").hide() 
			$( "#"+$(this).attr('rel') ).show();
			$(".slider").slideDown();
			return false;
		}
	);
	$(".slider a.close-slider").click(
		function(event) {
			event.preventDefault();
			$(this).parent(".slider").slideUp('fast', function() { $(".slider-content").hide() });
			
		}
	);
	
	$("#carousel li a").hover(
		function() {
			$(this).find('img').hide();
			$(this).find('span').show();
		},
		function() {
			$(this).find('span').hide();
			$(this).find('img').show();
		}
	);
	
	$("#m5-lift").hover(
		function() {
			$(this).children('p.roll-out').hide();
			$(this).children('p.roll-over').show();
		},
		function() {
			$(this).children('p.roll-out').show();
			$(this).children('p.roll-over').hide();
		}
	);
	
	
	
	
	
	$(".button")
		.hover(
			function() {
				$(this).not('.active').children('.hover').fadeIn('fast');
			},
			function() {
				$(this).not('.active').children('.hover').fadeOut('fast');
			}
		);
	
	$(".show-gallery")
		.click( function() {
			if( !$(this).hasClass('active') ) {
				$('#buttons .active').children('.hover').fadeOut('fast');
				$('.button').removeClass('active');
			}
			$(this).addClass('active');
			$("#sidebar").hide();
			$("#flash-content").hide();
			$("#m5-lift").hide();
			$("#rotate").hide();
			$("#gallery").show();
			$("#back-to-basics").show();
			return false;
		 });
	$(".show-rotate")
		.click( function() {
			if( !$(this).hasClass('active') ) {
				$('#buttons .active').children('.hover').fadeOut('fast');
				$('.button').removeClass('active');
			}
			$(this).addClass('active');
			$("#m5-lift").hide();
			$("#sidebar").hide();
			$("#flash-content").hide();
			$("#gallery").hide();
			$("#rotate").show();
			$("#back-to-basics").show();
			return false;
		 });
	

	$("#gallery-thumbs a")
		.click(
			function() {
				$("#gallery-thumbs .active img.hover").fadeOut('fast');
				$("#gallery-thumbs .active").removeClass('active');
				$(this).addClass('active');
				$("#picture-holder img").attr( 'src', $(this).attr('href') );
				return false;
			}
		)
		.hover(
			function() {
				$(this).not('.active').children('.hover').fadeIn('fast');
			},
			function() {
				$(this).not('.active').children('.hover').fadeOut('fast');
			}
		);
	$("#back-to-basics")
		.click(
			function() {
				$("#rotate").hide();
				$("#gallery").hide();
				$("#flash-content").show();
				$("#sidebar").show();
				$("#m5-lift").show();
				$(this).hide();
				return false;
			}
		);


});

