// Implement simple image swapping in conjunction with jQuery
function imageswap( element_id )
{
	$( element_id ).hover(
		function ()
		{
			$( element_id + "_rollover" ).css( 'display' , 'none' );
		},
		function()
		{
			$( element_id + "_rollover" ).css( 'display' , 'block');
		}
	);
}


// Dropdown on hover in conjunction with jQuery
function dropdown( element_id )
{
	$( element_id ).hover(
		function()
		{
			if( $( element_id + "_dropdown" ).is(":hidden") )
			{
				$( element_id + "_dropdown" ).slideDown( 'fast' );
			}
		},
		function()
		{
			$( element_id + "_dropdown" ).slideUp( 'fast' );
		}
	);
}

// Load specified url into specified div
function open_url( location_url, targetId )
{
	$.ajax(
		{
			url : location_url,
			success : function (data)
			{
				$( "#" + targetId ).html( data );
			}
		}
	);
}

// Load specified url into specified div
function ou( location_url, targetId )
{
	$.ajax(
		{
			url : location_url,
			success : function (data)
			{
				$( ".bottom-left" ).hide( "slide", { direction : "left" }, 1000 );
				$( "#" + targetId ).html( data );
				$( ".bottom-left" ).show( "slide", { direction : "right" }, 1000 );
			}
		}
	);
}

//Function which check if there are anchor changes, if there are, sends the ajax petition  
function checkAnchor()
{
    if( currentAnchor != document.location.hash )
	{
		currentAnchor = document.location.hash; // update hash info
		if( !document.location.hash || document.location.hash == "#" )
		{
			location_url = 'pages/home.html';
		}
		else
		{
			location_url = 'pages/' + currentAnchor + '.html';
			location_url = location_url.replace('#nav_', '');
		}
		
		open_url( location_url, 'main' ); // Causes error in IE
    }
	return;
} 

