////////////////////////////////////////////////////////////////////////////////
// BEGIN
//

	// -- Menu -----------------------------------------------------------------
	function initializeMenu()
	{
		// Main
		$("#menu a").each( function() { 
		
			// Sub Menu
			if( $(this).attr( "rel" ) != undefined )
			{
				// Position Sub Menu
				var sub_menu = $("#sm_"+ $(this).attr( "rel" ))
					sub_menu.css( "top", $(this).position().top );
					sub_menu.css( "left", $(this).position().left + 5 );
					sub_menu.css( "display", "block" );
					sub_menu.hide();
					sub_menu.hover( function() { hideMenu( $(this) ); }, function() { $("div.sub_menu").hide( "fast" ); } );
				
				// Hover
				$(this).hover( 
					function() {						
						var obj = $("#sm_"+ $(this).attr( "rel" ))
						$("div .sub_menu").hide();
						$("#sm_"+ $(this).attr( "rel" )).show( "fast" );
					}, 
					function() {  } 
				);
			}
		
		});
	}
	function hideMenu( obj )
	{
		$("div.sub_menu").each( function() {
			if( $(this).attr( "id" ) != obj.attr( "id" ) )
				$(this).hide();
		});
	}
	// -------------------------------------------------------------------------
	// -- Gallery --------------------------------------------------------------
	var gindex = 0;
	var galleryTimer;
	function initializeGallery()
	{
		$("#gallery_images img").each( function() {
		
			// Click
			$(this).click( function() {
				clearTimeout( galleryTimer );
				
				
				var im = new Image();
				var cimg = $(this);
				
				$(im)
					.load( function() {
					
						$(this).css( "left", "520px" );
						$(this).insertAfter( $("#gallery_image img:last") );
						
						var new_size = ($(this).height() / $(this).width()) * 500 + 15;	
						$(this).animate( { left: 0 }, 500, "swing", function() { $("#gallery_image img:first").remove(); } );
						
						$("#gallery_image img:first").animate( {opacity: 0}, 500 );				
						$("#gallery_images img").removeClass( "over" );
						
						cimg.addClass( "over" );
						$("#gallery_image").animate( { height: new_size }, 500 );
						
						var cur_pos = $(this).position().left;
							cur_pos -= 5*35;
						//alert( cur_pos );
						$("#gallery_images div").animate( {left: cur_pos*-1}, 666 );
						galleryTimer = setTimeout( nextImage, 5000 );
					
					})
					.attr( "src", cimg.attr( "src" ).toString().replace( "thumbs/", "" ) );
				
				// Update Fullsize
				//$("#gallery_image").attr( "src", $(this).attr( "src" ).toString().replace( "thumbs/", "" ) );
				/*var img = $("#gallery_image img").clone();
					img.attr( "src", $(this).attr( "src" ).toString().replace( "thumbs/", "" ) );
					img.css( "left", "520px" );
					img.insertAfter( $("#gallery_image img:last") );			
*//*
				var new_size = ($(this).height() / $(this).width()) * 500 + 15;	
					img.animate( { left: 0 }, 500, "swing", function() { $("#gallery_image img:first").remove(); } );
				//alert( img.height );
				$("#gallery_image img:first").animate( {opacity: 0}, 500 );
				
				$("#gallery_images img").removeClass( "over" );
				$(this).addClass( "over" );
				$("#gallery_image").animate( { height: new_size }, 500 );
				
				
				// Scroller
				var cur_pos = $(this).position().left;
					cur_pos -= 5*35;
				//alert( cur_pos );
				$("#gallery_images div").animate( {left: cur_pos*-1}, 666 );
				galleryTimer = setTimeout( nextImage, 5000 );*/
			});
		});
		
		$("#gallery_images img:first").addClass( "over" );
		
		galleryTimer = setTimeout( nextImage, 5000 );
	}
	function nextImage()
	{
		$("#gallery_images img.over").next().click();
	}
	// -------------------------------------------------------------------------
	// -- Initialize -----------------------------------------------------------
	$(document).ready(function() {
	
		// Menu?
		if( $("#menu a").length > 0 )
			initializeMenu();
		
		// Gallery?
		if( $("#gallery_images").length > 0 )
			initializeGallery();
	});
	// -------------------------------------------------------------------------

//
// END
////////////////////////////////////////////////////////////////////////////////