$(document).ready(function(){
	
		$("#content").hide();
		$("#bg").hide();
		$(".menu:not(:first)").hide();
		
		if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
		    $("#footer").hide();
			$("head").append('<style type="text/css">#fancybox-left-ico { left: 20px !important; } #fancybox-right-ico {	left: auto; right: 20px !important; }</style>');
		}
		else {
			
			$("#footer").pinFooter();
			
			$(window).resize(function() {
		    	$("#footer").pinFooter();
			});
		}

		$("a.external").attr("target", "_blank");
		
		$("#content").delay(500).fadeIn(500);
		
		if ($("#bg").length > 0) {
		
		  if ($("#bg_slideshow").length > 0) {
		    
		    $('#bg_slideshow').show().cycle({
    		  delay:  4000,
    		  timeout:  4000,
    		  speed:  1000,
    		  //sync: 0,
    		  pause:  0 // true to enable pause-on-hover
    		  });
    		  
  		  }
		  
		  $("#bg").delay(500).fadeIn(2000);
		  
	  }
	
	
		$(".menu:not(:first)").each(function(i){
			var seconds = (i+1);
			$(this).delay(seconds*100).fadeIn("slow");
		});
	
	$("a.ajax").fancybox({
		'autoScale' : false,
		'autoDimensions' : false,
		'width': 496,
		'height': "auto",
		'titlePosition': 'over'
		
	});
	

	
	function video_title_format(title, currentArray, currentIndex, currentOpts) {
		if (currentArray.length > 1) {
	    	return '<div id="video-titles"><span><a href="javascript:;" onclick="$.fancybox.next();">prev</a> <a href="javascript:;" onclick="$.fancybox.prev();">next</a></span>' +  title + '</div>';
	}
	else {
		return '<div id="video-titles">' +  title + '</div>';
	}
	}
	
	var fb_opts = {
		'padding'		: 20,
		'cyclic'        : true,
		'autoScale'		: false,
		'width'			: 496,
		'height'		: 360,
		'type'			: 'swf',
		'showNavArrows' : false,
		'titlePosition' : 'inside',
		'titleFormat'	: video_title_format
	};
	
	$("a.vimeo").fancybox($.extend(fb_opts, {
			'padding'               : 10, 
			'autoScale'             : false, 
			'title'                 : this.title, 
			'width'      		    : 496, 
			'height'                : 360, 
			'type'                  : 'iframe',
			'overlayColor'			: '#000',
			'overlayOpacity'		: '0.7',
			'titleFormat'	: video_title_format, 
			'onStart' : video_set_bg,
			'onClosed'	: video_restore_bg
	}));

	
	////
	
	$("a.grp").fancybox({	
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'autoDimensions' : true,
			'autoScale'		: false,
			'titlePosition' 	: 'over',
			'titleFormat'		: gallery_formatting
		});
	

	function video_set_bg() {
		$("#fancybox-outer").css("background-color", "#444");
	};
	
	function video_restore_bg() {
		$("#fancybox-outer").css("background-color", "#fff");
	};
	
	
	function gallery_formatting(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
	}
	
	
	/////
	
	
    var activeOpacity   = 1.0,
        inactiveOpacity = 0.4;//0.5;//0.6,
        fadeTime = 350,
        clickedClass = "selected",
        thumbs = ".menu li a:not(."+clickedClass+")";

	    $(thumbs).fadeTo(1, inactiveOpacity);


    $(thumbs).hover(
        function(){
            $(this).fadeTo(fadeTime, activeOpacity);
        },
        function(){
            // Only fade out if the user hasn't clicked the thumb
            if(!$(this).hasClass(clickedClass)) {
                $(this).fadeTo(fadeTime, inactiveOpacity);
            }
        });
     $(thumbs).click(function() {
         // Remove selected class from any elements other than this

		var clicked = $(this);
		
		if(!clicked.hasClass(clickedClass)) {

			already_clicked = ".menu li a:."+clickedClass;

			$(already_clicked).removeClass(clickedClass).fadeTo(fadeTime, inactiveOpacity);
		
			clicked.addClass(clickedClass).fadeTo(fadeTime, activeOpacity);

            }
	//	return false
     });



	$("#show-links a[id]").click(function(){
		
		if ($(this).hasClass("selected")) {
			
		}
		else {
			$("#show-links a").removeClass("selected");
			$(this).addClass("selected");
		}
	});

	
	$("#about-link").click(function(){
		
		$("#about").fadeIn();
		$("#press").hide();

		return false;
	});
	
	$("#press-link").click(function(){

		$("#review-image-area").hide();
		$("#press h2:not(#reviews-title)").hide();
		$("#press #credits").hide();
		$("#about").hide();
		$("#press").fadeIn();
		
		return false;
	});

});
