

$(document).ready( function() {
		var currentLocation;

		historyHandler = new historyHandling();

});

	if ( $( '#flash_player' ).is( 'div' ) ) {
	
		var flash_playerflash = new SWFObject("http://www.youtube.com/v/C0r_FbARIn8&hl=en", "flash_playerflashpiece", "279", "392", "8", "#0A0A09"); 
		flash_playerflash.addParam("wmode", "transparent"); 
		flash_playerflash.addParam("allowScriptAccess", "always"); 
		flash_playerflash.write("flash_player");
		
	}

// because ajax is used it's needed to add event handlers to new links that appear when the content is changed
function addHistoryToLinks () {
	
	
	// checking if #main has non-ajax class which disables ajax links for whole content
		if ( $( "#main .content" ).attr( "class" ).search( /non-ajax/ ) == -1 )
		{
			// not() makes it possible to put external links in the source.
				$( "a" ).not( ".not-ajax" ).bind ( "click", function () {
					
					// add file name to the address and history
						unFocus.History.addHistory( this.href.substr( this.href.lastIndexOf( "/" ) + 1 ) );
					
					return false;
				});
		}
	
}

// dealing with menu selected item
function menuClick ( name ) {
	
	// removing existing classes
		$( "#nav li a.ui-tabs-selected" ).removeClass( "ui-tabs-selected" );
	
	
	// you will need to change this part of code if you change classes' names
		
		
			currentLocation = name;
	

}




// changing the content using ajax
function openWithAjax ( href ) {
		$( '#ajax-content' ).hide();
		$( '#loading' ).show();
	
	$( '#ajax-content' ).load( href+" #main", function() {
		
		$( '#ajax-content' ).show();
		$( '#loading' ).hide();
		
		menuClick( $( "#main" ).attr( "class" ) );
		addHistoryToLinks();
		addMaps();
	});
	
}


function historyHandling()
{
	this.historyListener = function( hash ) {
	if ( hash == "" )
		{
			hash = location.pathname.substr(location.pathname.lastIndexOf( "/" ) + 1 );
			if (hash == "" )
			{
				hash = 'home.php';
			}
		}
		openWithAjax( hash );
	}
		
		


		
		
		

	unFocus.History.addEventListener( 'historyChange', this.historyListener );		

	
	$( '#ajax-content' ).before( '<div id="loading"><img src="http://www.dsinex.com/logan/imgs/loading.gif" alt="Loding" style="margin-left: 20px;" /></div>' );

	this.historyListener( unFocus.History.getCurrent() );
	
	



}

