
//jQuery.History minified (jquery.history-yui.js)
jQuery.extend({historyCurrentHash:undefined,historyCallback:undefined,historyIframeSrc:undefined,historyNeedIframe:jQuery.browser.msie&&(jQuery.browser.version<8||document.documentMode<8),historyInit:function(e,d){jQuery.historyCallback=e;if(d){jQuery.historyIframeSrc=d}var c=location.hash;jQuery.historyCurrentHash=c;if(jQuery.historyNeedIframe){if(jQuery.historyCurrentHash==""){jQuery.historyCurrentHash="#"}jQuery("body").prepend('<iframe id="jQuery_history" style="display: none;" src="javascript:false;"></iframe>');var a=jQuery("#jQuery_history")[0];var b=a.contentWindow.document;b.open();b.close();b.location.hash=c}else{if(jQuery.browser.safari){jQuery.historyBackStack=[];jQuery.historyBackStack.length=history.length;jQuery.historyForwardStack=[];jQuery.lastHistoryLength=history.length;jQuery.isFirst=true}}if(c){jQuery.historyCallback(c.replace(/^#/,""))}setInterval(jQuery.historyCheck,100)},historyAddHistory:function(a){jQuery.historyBackStack.push(a);jQuery.historyForwardStack.length=0;this.isFirst=true},historyCheck:function(){if(jQuery.historyNeedIframe){var a=jQuery("#jQuery_history")[0];var d=a.contentDocument||a.contentWindow.document;var f=d.location.hash;if(f!=jQuery.historyCurrentHash){location.hash=f;jQuery.historyCurrentHash=f;jQuery.historyCallback(f.replace(/^#/,""))}}else{if(jQuery.browser.safari){if(jQuery.lastHistoryLength==history.length&&jQuery.historyBackStack.length>jQuery.lastHistoryLength){jQuery.historyBackStack.shift()}if(!jQuery.dontCheck){var b=history.length-jQuery.historyBackStack.length;jQuery.lastHistoryLength=history.length;if(b){jQuery.isFirst=false;if(b<0){for(var c=0;c<Math.abs(b);c++){jQuery.historyForwardStack.unshift(jQuery.historyBackStack.pop())}}else{for(var c=0;c<b;c++){jQuery.historyBackStack.push(jQuery.historyForwardStack.shift())}}var e=jQuery.historyBackStack[jQuery.historyBackStack.length-1];if(e!=undefined){jQuery.historyCurrentHash=location.hash;jQuery.historyCallback(e)}}else{if(jQuery.historyBackStack[jQuery.historyBackStack.length-1]==undefined&&!jQuery.isFirst){if(location.hash){var f=location.hash;jQuery.historyCallback(location.hash.replace(/^#/,""))}else{var f="";jQuery.historyCallback("")}jQuery.isFirst=true}}}}else{var f=location.hash;if(f!=jQuery.historyCurrentHash){jQuery.historyCurrentHash=f;jQuery.historyCallback(f.replace(/^#/,""))}}}},historyLoad:function(d){var e;d=decodeURIComponent(d);if(jQuery.browser.safari){e=d}else{e="#"+d;location.hash=e}jQuery.historyCurrentHash=e;if(jQuery.historyNeedIframe){var a=jQuery("#jQuery_history")[0];var c=a.contentWindow.document;c.open();c.close();c.location.hash=e;jQuery.lastHistoryLength=history.length;jQuery.historyCallback(d)}else{if(jQuery.browser.safari){jQuery.dontCheck=true;this.historyAddHistory(d);var b=function(){jQuery.dontCheck=false};window.setTimeout(b,200);jQuery.historyCallback(d);location.hash=e}else{jQuery.historyCallback(d)}}}});


jQuery.noConflict();
function pageload(hash) {
	// hash doesn't contain the first # character.
	if(hash) {
		// restore ajax loaded state
		jQuery(".ajax-nav-content").hide();
		if(typeof(ajax_nav_loaded) == 'function')
			jQuery(".ajax-nav-content").load(hash,ajax_nav_loaded);
		else
			jQuery(".ajax-nav-content").load(hash);
			
	} else {
		// start page
		//jQuery(".ajax-nav-content").empty();
	}
}

jQuery(document).ready(function(){
	// Initialize history plugin.
	// The callback is called at once by present location.hash. 
	jQuery.historyInit(pageload);
	set_ajax_nav_clicks(".ajax-nav-links a,.internal-link:not(.no-ajax-nav)");
});

function set_ajax_nav_clicks(selectors)
{
	// set onlick event for buttons
	jQuery(selectors).click(ajax_nav_click_event);	
}

function ajax_nav_click_event(e)
{
	// moves to a new page. 
	// pageload is called at once. 
	// hash don't contain "#", "?"
	jQuery.historyLoad(ajax_nav_get_hash_link(this));
	e.preventDefault();
	return false;
}

function ajax_nav_get_hash_link(element)
{
	var hash = jQuery(element).attr("href");
	//console.log(element);
	if(!hash)
		return;
		
	hash = hash.replace(/^.*#/, '');
	return hash;
}
