/****************************************************************************************/
/*	main.js - Default script															*/
/*	Autore:		Max Kiusso - max AT kiusso DOT net										*/
/*	Data:		2010 01 04																*/
/*																						*/
/****************************************************************************************/

$ (
	function () {
		$( "ul.level2 li a.link" ).parents( "ul:first" ).prev( "a" ).addClass( "link" );
		
		var menu = false;
		$( "ul.level1 li" ).hover(
			function () {
				menu = true;
				$( "ul.level2" , $( this ) )
					.slideDown()
					.hover(
						function () {
							$( this ).show();
						}
						, function () {
							if ( ! menu ) {
								$( this ).slideUp();
							}
						}
					);
			}
			, function () {
				$( "ul.level2" , $( this ) ).slideUp();
				menu = false;
			}
		);
		
		$( "#news" ).imageScroller();
		
		$( "a.top" ).click(
			function () {
				var $this = $( this );
				$( document.body ).append(
					"<div class='overlay'></div><div class='details'><iframe src='" + $this.attr( "href" ) + "' frameborder=0 /></div>"
				);
				
				var pSz = getPageSize();
				$( "div.overlay" ).css({
					  backgroundColor:	"#000"
					, opacity:			0.8
					, width:			pSz[0]
					, height:			pSz[1]
				}).fadeIn();
				
				var pSc = getPageScroll();
				$( "div.details" ).css({
					  top:				pSc[1] + ( pSz[3] / 10 ) - 50
				}).fadeIn();
				
				$(window).resize(function() {
					var pSz = getPageSize();
					$( "div.overlay" ).css({
						  width:	pSz[0]
						, height:	pSz[1]
					});
					
					var pSc = getPageScroll();
					$( "div.details" ).css({
						  top:		pSc[1] + ( pSz[3] / 10 ) - 50
					});
				});
				
				return false;
			}
		);
		
		$( "#sectionspage ul.photo li a" ).lightBox();
		
		mainSize();
	}
);

function mainSize () {
	setTimeout (
		function () {
			var pSz = getPageSize();
			$( "div.main" ).height( pSz[1] );
			
			if ( $.browser.msie && $.browser.version.substr(0,1) == '8' ) {
				if ( ! categories ) {
					$( "div.footer" ).css({
						  'position': 'absolute'
						, 'bottom': '1px'
					});
				}
			} else {
				var offSet = $( "div.footer" ).position();
				$( "div.footer" ).css({
					'margin-top': ( pSz[1] - offSet.top - 13 ) + "px"
				});
			}
		}
		, 300
	);
}

function closeFrame () {
	$( "div.overlay" ).fadeOut( function () { $( this ).remove(); } );
	$( "div.details" ).fadeOut( function () { $( this ).remove(); } );
	$( "a:first" ).focus();
}
