var thisTarget = "includes/index.html";
imgTarget = 'images/main-images/index.html.jpg';
sepiaTarget = 'images/main-images/index.html.sepia.jpg';

	//preload and fadein initial image
    $(function () {
        var img = new Image();
        $(img).load(function () {
            $(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
            $(this).hide();
            $('#page-inner').removeClass('loading').append(this);
            $(this).fadeIn(900);
			$(this).fadeTo(1000, 1, function() {
					$('#page').fadeTo(1200, 1).css('background-image','url(' + imgTarget + ')');											 
					//$(this).attr('src', 'images/main-images/index.html.jpg');						
			}).fadeTo(1000, .01);							
        }).error(function () {
            // notify the user that the image could not be loaded
        }).attr({"src": sepiaTarget});
    });

$(document).ready(function() {


	$('#gallery a').livequery(function(event) { 
		$('#gallery a').lightBox({fixedNavigation:true});
	});

	$('a.greybox').livequery('click', function(event) { 
		var t = this.title || this.innerHTML || this.href;
		GB_show(t,this.href,480,720);
		return false;		
	});
	
	$("#gallery").livequery(function(){ 
		//stop double event binding
		if(!this.hasEventHander) {
		   $("#gallery").jCarouselLite({
				btnNext: ".next",
				btnPrev: ".prev",
				easing: "easeOutQuad",
				speed: 1000,
				mouseWheel: true,
				circular: false,
				scroll: 3,				
				visible: 3
			});
		}
		this.hasEventHander = true;
	});
	
	//open or close
	var thisOpen = true;

	//ajax setup	
	$.ajaxSetup({
	  url: "/xmlhttp/",
	  global: false,
	  type: "POST"
	});	

	// -------- AJAX LOAD -------- //
	 $('.ajax').livequery('click', function(event) { 
		
		$("#label-text").html("View&nbsp;&nbsp;Photo");	
		$("#view-photo").removeClass('closed');
		thisOpen = true;
		
		//call analytics pageTrack
		trackTarget = $(this).attr('href');
		pageTracker._trackPageview(trackTarget);
		
		tempTarget = 'includes/' + $(this).attr('href');
		
		if (thisTarget == tempTarget) {
			
		} else {
			// set targets
			thisTarget = 'includes/' + $(this).attr('href');		
			
			headerTarget = 'includes/headers/' + $(this).attr('href');
			imgTarget = 'images/main-images/' + $(this).attr('href') + '.jpg';
			sepiaTarget = 'images/main-images/' + $(this).attr('href') + '.sepia.jpg';
			
			// animate
			if (thisTarget == 'includes/index.html') {
				//animate small
				$("#content-container").animate({
					left: '160px',
					width: '580px',
					top: '-170px'
				}, 1000, "easeOutExpo" );
					
				$("#content").animate({
					height: '90px'
				}, 1000, "easeOutExpo" );			
			} else {
				//animate large
				$("#content-container").animate({
					top: '-270px',
					left: '75',
					width: '750px'
				}, 1000, "easeOutExpo" );
					
				$("#content").animate({
					height: '190px'
				}, 1000, "easeOutExpo" );
			}
	
			//set bg image
			$("#page").fadeTo(1000, 1).css('background-image','url(' + sepiaTarget + ')');
			$("#page-inner>img").fadeTo(1000, .01).attr({"src": imgTarget});
			
			//set header content
			$("#content-header h2").fadeTo(500, .01, function() {
				$(this).load(headerTarget);						
			}).fadeTo(750, 1);
	
			// load main content
			$("#content-inner").fadeTo(500, .01, function() {
				if (thisTarget == 'includes/photos.html') {
					photoTarget = 'photos.html';
					$(this).load(photoTarget);
				} else {
					$(this).load(thisTarget);
				}
			}).fadeTo(1000, 1);	
		
		} //end else
		
		return false;
	});
	//end ajax link

	// view photo link
	$("#view-photo").click(function() {
			
		if (thisOpen == true) {	
		
			$("#label-text").html("View&nbsp;&nbsp;Text");	
			
			$("#content-container").animate({
				top: '-80px'
			}, 1000, "easeOutExpo" );			
			
			if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
				$("#content").hide();			
			} else {
				$("#content").animate({
					height: '1px'
				}, 1000, "easeOutExpo" );
				$("#content").hide();
			}			
			
			$(this).toggleClass("closed");
			thisOpen = false;
			
		} else {
			
			$("#label-text").html("View&nbsp;&nbsp;Photo");	
	
			$("#content-container").animate({
				top: '-270px'
			}, 1000, "easeOutExpo" );

			$("#content").animate({
				height: '190px'
			}, 1000, "easeOutExpo" );	
			$("#content").show();
			
			$(this).toggleClass("closed");
			thisOpen = true;
		}
	});
	// end photo link
	
});
