// Runs when the DOM has been loaded
var currentDiv;
$(window).keypress(function(event){
	if(currentDiv == "content_1")
	{
		if(event.keyCode == 27)
		{
			$("#content_1").fadeOut(1000);
			$("#georgeColvinOverlayBackground_1").fadeOut(1000);
		}
		currentDiv="";
	}
	if(currentDiv == "content_2")
	{
		if(event.keyCode == 27)
		{
			$("#content_2").fadeOut(1000);
			$("#content_2").html("");
			$("#georgeColvinOverlayBackground_2").fadeOut(1000);
			$("#content_1").fadeIn(1000);
			currentDiv="content_1";
		}
	}
});

$(window).load(function() 
{
	$('.georgeColvinBackground').delay(500).fadeIn(3000, function(){
		$('.georgeColvinTitle').fadeIn(3000, function(){
			$('.georgeColvinNavigation').fadeIn(1000);
		});
	});
});

function openGalleryIndex()
{
	$('#georgeColvinOverlayBackground_1').fadeIn(1000, function(){
		$.ajax({
			type: "POST",
			url: "/script/georgeColvinGalleryIndex.php",
			cache: false,
			success: function(html){
				$("#content_1").append(html);
				$("#content_1").fadeIn(1000);
			}
		});
	});
	currentDiv="content_1";
}

function openGallery()
{
	$("#content_1").fadeOut(1000);
	$('#georgeColvinOverlayBackground_2').fadeIn(1000, function(){
		$.ajax({
			type: "POST",
			url: "/script/georgeColvinGallery.php",
			cache: false,
			success: function(html){
				$("#content_2").append(html);
				pikachoose();
				$(".dialog").dialog({
					autoOpen: false,
					show: "blind",
					hide: "blind",
					minWidth: 400,
					resizable: "false"
				})
				.parent()
				.position({ my: 'top', at: 'top', of: '#galleryContainer' });
			}
		});
	});
	$("#content_2").delay(500).fadeIn(3000, function(){
		$( "#opener" ).click(function() {
			$( "#dialog"+this.title ).dialog( "open" );
			return false;
		});
	});
	
	currentDiv="content_2";
}

function pikachoose()
{
	$(document).ready(
		function()
		{
			$("#pikame").PikaChoose({autoPlay:false, showCaption: true, showTooltips: false, transition:[0]});
			$("#pikame").jcarousel(
			{
				scroll:4,
				initCallback: function(carousel) 
				{
    		    	$(carousel.list).find('img').click(function() 
    		    	{
    		   			//console.log($(this).parents('.jcarousel-item').attr('jcarouselindex'));
			    	    carousel.scroll(parseInt($(this).parents('.jcarousel-item').attr('jcarouselindex')));
    				});
			    }
			});
		});
}
