jQuery.fn.slideFadeUp = function(speed, easing, callback) {
     return this.animate({opacity: '1', height: '450px'}, speed, easing, callback);  
   };
jQuery.fn.slideFadeDown = function(speed, easing, callback) {
     return this.animate({opacity: '0', height: '0'}, speed, easing, callback);  
   };
$.fn.delay = function(time, callback){
    jQuery.fx.step.delay = function(){};
    return this.animate({delay:1}, time, callback);
}
$(document).ready(function(){
//var ie = !($.browser.msie);
if ($.browser.msie && $.browser.version.substr(0,3) < "8.0") {
    // Replace body's content and display loading...
    $('body').html('Loading...');

    // Load content via AJAX
    $('body').load('no-ie.php');
	return;
}

	$.ajaxSetup(); 
	var hash;
	$.history.init(pageload);
   	$('a[href=' + document.location.hash + ']').parent().addClass('selected');
	$('a[rel=ajax]').click(function () {
		if (hash == this.href.replace(/^.*#/, '') ) return false;
		else{
			hash = this.href.replace(/^.*#/, '');
			$('a[rel=ajax]').parent().removeClass('selected');  
			$(this).parent().addClass('selected');
			$.history.load(hash);
			pageUnload();
			return false;
		}
	});
});
function pageload(hash) {  
     if (hash) pageUnload();      
 }
function  pageUnload(){
	$('#progressbar').show();
	$('#page_container').slideFadeDown(700, 'easeInQuart', function(){
			$('#page_container').contents().remove();
			getPage();
		}
	);
}	

function getPage() {  
	var loadUrl =document.location.hash.replace(/^.*#/, '');
	var data = 'page=' + loadUrl;  
	
	$('#page_container').load('a-' + loadUrl + '.php', {}, function(){
		$('#page_container').slideFadeUp(1250);
		if ( loadUrl == "screening-room")
			thumbClick();
		else if (loadUrl == "about") 
			carousel();
		else if (loadUrl == "philosophy"){
			var ml = ($(window).width() - 790 ) / 2 + 30; 
			$('#page1').css({'margin-left': ml});
		}
		
		
		$('#page_container').slideFadeUp(1250);
		$('#progressbar').hide();
			//$('#progressbar').delay(1200, function(){
				
		//	});
			 $.geekGaTrackEvent('page', 'click', loadUrl );
		
	});
}
function thumbClick(e){
	// Thumb Hover Functions
	if ($.browser.msie) {$(this).find('b').remove();}
	else {
		$('a.thumb').hover(function () {
	    	$(this).find('b').stop().fadeTo('normal', .9);
						}, function () {
	    	$(this).find('b').stop().fadeTo('slow', .3);
		});
	}
	$("a[rel^='prettyPhoto']").prettyPhoto();
}
function philosophyCarousel(e){

	
}
function carousel(e){
	var pl = ($(window).width() - 730 ) / 2 + 30; 
	$('#about-carousel ul').css({'padding-left': pl});
	jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};
	jQuery(function( $ ){	
		$('#page_container').serialScroll({
			target:'#about-carousel',
			items:'li',
			prev:'a.next-lane',
			next:'a.prev-johnny',
			axis:'xy',
			duration:700,
			force:true, 
			offset: -pl,
			onBefore:function( e, elem, $pane, $items, pos ){
				e.preventDefault();
				if( this.blur )
					this.blur();
			},
			onAfter:function( elem ){
			}
		});
	});
}	
	function bgSize(e){
		var h =$(window).height(); 
		var c;
		if ( h < 818) { 
			 c = "center " + ( -490 + ((818 - h)/3) + "px" );
		}
		else {
			 c = "center " + "bottom";
		}
			$('#rrr').css({'background-position' : c} );
	}
	$(window).bind("resize", function(){
	    		bgSize(); 
			});
	$(document).ready(function(){
		bgSize(); 
	 	// Navigation fade effects
		// if ($.browser.msie && $.browser.version < 7) return;
	  		$('#navigation li').removeClass('highlite');
			// Create the hover effects
			$('#navigation li a').append('<span class="hover"></span>').each(function(){
				var $span = $('> span.hover', this ).css('opacity', 0);
				$(this).hover(function(){
					//on hover
					$span.stop().fadeTo(300,1);
					$(this).parent().addClass('hovered')
				}, function() {
					//off hover
					$span.stop().fadeTo(600, 0);
					$(this).parent().removeClass('hovered')
					
				})
			})
	 });
	
	
	
