/**
 * Основной скрипт инициализации всяких приблуд :)
 *
 * Author: Setteros, 2009
 */

$(document).ready(
	function()
	{
		// Init Fancybox
		$( "a.pimage" ).fancybox(
		{
			'overlayOpacity': 0.9,
			'overlayColor': '#000000',
			'cyclic': true,
			'opacity': true,
			'padding': 1,
			'margin': 2,
			'centerOnScroll': true,
			'transitionIn' : 'elastic',
			'transitionOut' : 'elastic'
		});

		// Init Random images
		GalleryScreens.curimage = Math.floor( Math.random( ) * GalleryScreens.images ) + 1;
		GalleryScreens.LoadRandomImage();

		// Init Submenues
		$( "a.submenu" ).each(
			function()
			{
				var hidetime = 1000;
				var handler = null;
				var hide = function( obj )
				{
					if( handler != null )
					{
						return;
					}

					handler = setTimeout(
						function()
						{
							var op = $( obj ).css( 'opacity' );
							$( obj ).fadeTo(
								'normal', 0,
								function()
								{
									$( this ).css(
										{
											'visibility': 'hidden',
											'opacity': op
										} );
								} );

							handler = null;
						},
						hidetime );
				}

				$( this )
					.mouseover(
						function( e )
						{
							clearTimeout( handler );
							handler = null;

							$( ".h0" ).css( 'visibility', 'hidden' );

							$( "div#" + $( this ).attr( "rel" ) )
								.css( {
										'left'			: $( this ).position().left + $( this ).width(),
										'top' 			: $( this ).position().top,
										'visibility' 	: 'visible'
									} )
								.mouseover(
									function( e )
									{
										clearTimeout( handler );
										handler = null;
									} )
								.mouseout( function( e ){ hide( this ); } );
						} )
					.mouseout( function( e ){ hide( "div#" + $( this ).attr( "rel" ) ); } );
			} );
	});