function changeart(){
	if (typeof galleries != 'undefined'){
	for (gallery in galleries){
		changegal(gallery);  
	}
	}
}
$(function (){  changeart();$('#splash').fadeOut('slow');pageload();});
	if (window.history && window.history.pushState){
	window.onpopstate = function(event) {  
		if(event.state!=null){
		loadContent(location.pathname);
		//TODO: implement handling of popstate for if gallery images have been displayed.
		
		}
	}
	}
	
	var galleryimgresize = function () {
	  alert('resize');
};

function pageload(){
	if (window.history && window.history.pushState){
	if($('.easel,.menu a').length>0){
	$('.easel,.menu a').off('click').click(function(e) {
				href = $(this).attr("href");
				loadContent(href);
				e.preventDefault();
			});
	}
	}
	$('.overlay').click(function(){
		hidemodal();
	});
}
function changegal(g){
	if(galleries[g].lastart){
		galleries[g].lastart=galleries[g].lastart+1;
		if(galleries[g].lastart>galleries[g].art.length){galleries[g].lastart=1;}
		 $("<img>").attr({
      			src: galleries[g].path+'/thumbs/'+galleries[g].art[galleries[g].lastart-1],
			style:'display:none;'
    			}).appendTo('#easel'+galleries[g].id+' .easelart').fadeIn(3000, function() {
		$('#easel'+galleries[g].id+' .easelart img').first().remove();
      });

		setTimeout("changegal("+g+")",5000);
	}else{
		if(galleries[g].art.length>0){
			img = galleries[g].path+'/thumbs/'+galleries[g].art[0]
		}else{
			img = "/resouces/images/comingsoon.jpg";

		}
		galleries[g].lastart=1;
			 $('#easel'+galleries[g].id+' .easelart img').attr('src', img);
		if(galleries[g].art.length>0){setTimeout("changegal("+g+")",5000);}
	}		
}
function loadimg(imgsrc){
	var img = $('<img>').attr('src',imgsrc).load(function(){
	if (this.height>this.width){
		height=600;
		width=(height/this.height)*this.width;
	}else{
		width=600;
		height=(width/this.width)*this.height;
	}
	img.css({'height':height,'width':width});
	$('.largeartbox').html(img).show('puff',{},1000);
	$('.loadingartbox').fadeOut('slow');
});

	
}
function hidemodal(){
	 $('.nonmodal').fadeIn(1000, function() {
	        	$(this).removeClass('nonmodal');
      });
	
	$('.overlay').hide('puff',{},1000);
	$('.modal').hide('puff',{},1000,function(){$(this).remove();});

}

function loadContent(url){
	$("#loading").show();
			var request = $.ajax({
  url: url,
  type: "GET",
  data: {'ajax':'true'},
  dataType: "html"
});

request.done(function(html) {
	$("#loading").hide();
	$('.easelimg').hide();
	$('.content').slideUp(function(){$('.content').html(html).slideDown(function(){$(window).trigger('resize');});
	FB.XFBML.parse();
	
	
history.pushState('somepage', 'The ART of Arwyn Quick', url);pageload();})
	
});

request.fail(function(jqXHR, textStatus) {
  $("#loading").hide();
  $('<p title="Unable to load page">Sorry, we were unable to retrieve the page you requested.</p>').dialog({
			modal: true,
			buttons: {
				Ok: function() {
					$( this ).dialog( "close" );
				}
			}
		});
});
}



$(function (){ 
if(false){
				var win = $(window);
				// Full body scroll
				var isResizing = false;
				win.bind(
					'resize',
					function()
					{
						if (!isResizing) {
							isResizing = true;
							var container = $('#full-page-container');
							// Temporarily make the container tiny so it doesn't influence the
							// calculation of the size of the document
							container.css(
								{
									'width': 1,
									'height': 1
								}
							);
							// Now make it the size of the window...
			
							container.css(
								{
									'width': win.width(),
									'height': win.height()
								}
							);
							isResizing = false;

							container.jScrollPane({"verticalGutter":0});
						}
					}
				).trigger('resize');

				// Workaround for known Opera issue which breaks demo (see
				// known_issues.html#opera-scrollbar )
				$('body').css('overflow', 'hidden');

				// IE calculates the width incorrectly first time round (it
				// doesn't count the space used by the native scrollbar) so
				// we re-trigger if necessary.
				if ($('#full-page-container').width() != win.width()) {
					win.trigger('resize');
				}
				}
			});



