$(function(){
	
	//var pressWindow = $('#pressWindow');
	var hiTxt = '';
	
	// ============= Top Level Variables
	// =====================================================
	
	
	// ============= Initial Build
	// =====================================================
	var initIndex = function(){
		//loadStart();
		if(currPage == "Home"){
			slideShow();
		}else if(currPage == "Menu"){
			scrollBar();
		}else if(currPage == "Private Dining"){
			privateFn();
		}else if(currPage == "Press"){
			pressFn();
		}else if(currPage == "Contact"){
			contactFn();
		}else if(currPage == "Photos"){
			photoFn();
		}
	};
	
	var slideShow = function(){
		$('#slideShow').cycle({ 
			fx:     'fade', 
			delay: 3000,
			timeout:5000,
			speed:  2000,
			sync: 0
		});
	};
	
	var scrollBar = function(){
		$('.scroll-pane').jScrollPane({
			autoReinitialise: true
		});
	};
	
	var privateFn = function(){
		$('#ex').click(function(){
			$('#lightBox').fadeOut('fast');
		});
		
		$('#sample').click(function(){
			$('#lightBox').fadeIn('fast');
			$('.scroll-pane').jScrollPane();
			$('.jspDrag').css("background-image", "url(/assets/img/grip2.jpg)");
			$('.jspDrag').css("background-color", "#a8a5a6");
		});
	}
	
	var pressFn = function(){
		var pane = $('.scroll-pane')
		pane.jScrollPane();
		var api = pane.data('jsp');
		
		var tmpTxt = $('#pressContent div:first-child').html();
		api.getContentPane().html('').css({opacity: 0}).html(tmpTxt).stop().animate({opacity: 1}, 1000);
		api.reinitialise();
		
		$('#press_logos a').unbind('click').bind('click', function(){
			var contentId = $(this).attr('id');
			tmpTxt = $('#pressContent .' + contentId).html();
			
			api.getContentPane().stop().animate({opacity: 0}, 1000, function(){
				console.log('animation complete');
				api.getContentPane().html(tmpTxt).animate({opacity: 1}, 1000);
				api.reinitialise();
				//$(pressWindow).html('').html(tmpTxt).jScrollPane({s}).animate({opacity: 1});
			});
			
			return false;
		});	
	}
	
	var contactFn = function(){
		$('#mapex').click(function(){
			$('#lightBox').fadeOut('fast');
		});
		$('#map').click(function(){
			$('#lightBox').fadeIn('fast');
		});
	}
	
	var photoFn = function(){
		hiTxt = $('.hiTxt');
		var pics = $('.pic');
		$(pics).css({opacity: .6}).unbind('mouseover').bind('mouseover', function(){ onThumbOver($(this)); }).unbind('mouseleave').bind('mouseleave', function(){ onThumbLeave($(this)); });
	}
	
	var onThumbOver = function(whichThumb){
		$(whichThumb).stop().animate({opacity: 1});
	}
	
	var onThumbLeave = function(whichThumb){
		$(whichThumb).not(hiTxt).stop().animate({opacity: .6});
	}
	
	// ============= Load Nav & Footer
	// =====================================================
	var loadStart = function(){
		$('#allContent').html('');
		$.ajax({
			url: 'load/elements/start.php',
			type: 'GET',
			timeout: '6000',
			success: function(result){
				$(document.body).css({opacity: 0});
				$('#allContent').html('');
				$('#allContent').append(result);
				
				// ======= Index Animate In
				// ==============================
				//SETUP Animation
				$('#nav').css({opacity: 0});
				$('#footer').css({opacity: 0});
				$(document.body).css({opacity: 1, color: '#000'});
			}
		})
	};
	
	//START LOAD AFTER COMPLETE FUNCTION SCOPE SET
	initIndex();
	
});


