/* Author: gummibearlab */

$(function() {

	// ! hack visibilità ie
	
	if ($.cssHooks.opacity.set) {
	  $.cssHooks.opacity.defaultSet = $.cssHooks.opacity.set
	  $.cssHooks.opacity.set = function(elem, value) {
	    $.cssHooks.opacity.defaultSet(elem, value)
	    if (!elem.style.filter.replace(/\ *(alpha\(opacity=100\))?/, ''))
	      elem.style.removeAttribute('filter')
	  }
	}


	title = '';

	$(window).hashchange( function(){
		var hash = location.hash;
		
		document.title = 'Götz Göppert - Photograpy' + ' - ' + ( title || '' );
		
		// Iterate over all nav links, setting the "selected" class as-appropriate.
		$('#nav a').each(function(){
		  var that = $(this);
		  that[ that.attr( 'href' ) === hash ? 'addClass' : 'removeClass' ]( 'selected' );
		});
	})
  
 
  $(window).hashchange();
  
	
/*
	var viewportWidth = $(window).width();
	var myWidth = { width : viewportWidth };
	$(window).resize(function() {
	    if(this.resizeTO) clearTimeout(this.resizeTO);
	    this.resizeTO = setTimeout(function() {
	        $(this).trigger('resizeEnd');
	    }, 500);
	});
	$(window).bind('resizeEnd', function() {
		viewportWidth = $(window).width();
		myWidth = { width : viewportWidth };
		$('#gallery').css(myWidth);		
	});	
*/
	
	$('ul li a').not('.external-link').click(function() {
		if (!$.browser.msie) {
			$('body').prepend('<div id="loader">Loading...</div>');
		}	
        url = $(this).attr('href').replace( /^#/, '' );
        title = $(this).attr('title')
		$('ul li a').removeClass('selected');
        $(this).addClass('selected');
		if ( $.browser.msie ) {
			$('#gallery').load(url);	
		} else {
	        $('#gallery').animate({opacity : 0},500, function() {
				var api = $('#gallery').jScrollPane(
						{
							//horizontalDragMinWidth : 100, 
							horizontalDragMaxWidth : 100,
							autoReinitialise : true, 
							autoReinitialiseDelay : 1500,
							hideFocus : true,
							stickToRight : false,
							maintainPosition : true
						}
					).data('jsp');
	
					api.getContentPane().load(
						url, function() {
							api.reinitialise();
							$('#gallery').animate({opacity : 1},500);
							$('#loader').animate({opacity : 0},500, function() {
								$(this).remove();
							});
						});
					api.scrollToX(0);
			}); 
		}
        // $(window).hashchange();
		return false;
    });
	
	$(window).load(function(){ 
		$('#gallery').animate({opacity : 1},1000);
		$('#loader').animate({opacity : 0},500, function() {
			$(this).remove();
		});
	});
});




















