$( function() {                        
 
	/**
	 **
	 ** Menu
	 **
	 **/

	$( ".menuItem" ).mouseenter( function() {
	
		// We entered the menu item
		$( this ).stop( true, true ).addClass(
			"boxShadow"
		).animate( {
			opacity: 0.35,
			color: "black",
			backgroundColor: "white"
		}, 500 );
	
	} ).mouseleave( function() {

		// We leaved the menu item
		var sel = Boolean( $( this ).attr( "selected" ) );

		if( ! sel ) {
			$( this ).stop( true, true ).removeClass(
				"boxShadow"
			).animate( {
				opacity: 1.00,
				color: "white"
			}, 250 ).css( {
				'background-color': "transparent"
			}, 250 );
		} 

	} ).click( function() {
		window.location.href = $( this ).attr( "rel" );
	} );

	$( ".menuItemMac" ).mouseenter( function() {
	
		// We entered the menu item
		$( this ).stop( true, true ).addClass(
			"boxShadow"
		).animate( {
			opacity: 0.35,
			color: "black",
			backgroundColor: "white"
		}, 500 );
	
	} ).mouseleave( function() {

		// We leaved the menu item
		var sel = Boolean( $( this ).attr( "selected" ) );

		if( ! sel ) {
			$( this ).stop( true, true ).removeClass(
				"boxShadow"
			).animate( {
				opacity: 1.00,
				color: "white"
			}, 250 ).css( {
				'background-color': "transparent"
			}, 250 );
		} 

	} ).click( function() {
		window.location.href = $( this ).attr( "rel" );
	} );

	/**
	 **
	 ** SubMenu
	 **
	 **/

	$( ".submenuItem" ).mouseenter( function() {
	
		// We entered the submenu item
		$( this ).stop( true, true ).animate( {
			color: "black",
			paddingLeft: "15px"
		}, 500 );
		$( "img", this ).stop( true, true ).animate( {
			marginRight: "10px"
		}, 500 );
	
	} ).mouseleave( function() {

		var sel = Boolean( $( this ).attr( "selected" ) );
		
		// We leaved the submenu item
		$( this ).stop( true, true ).animate( {
			color: "#525353",
			paddingLeft: ( sel ? "15px" : "10px" )
		}, 250 );
		$( "img", this ).stop( true, true ).animate( {
			marginRight: ( sel ? "10px" : "15px" )
		}, 250 );

	} ).click( function() {
		window.location.href = $( this ).attr( "rel" );
	} );

	/**
	 **
	 ** Coverflow FXs
	 **
	 **/

	$( ".cover" ).mouseenter( function() {
		var idx = Number( $( "img", this ).attr( "idx" ) );

		$( ".cover img" ).each( function( i ) {
			var id =  Number( $( this ).attr( "idx" ) );
		
			if( id == ( idx - 1) ) {
				$( this ).stop( true, true ).animate( {
					width      : "270",
					height     : "252",
					marginTop  :  "21",
					paddingLeft: ( idx - 1 ) * 15,
					opacity    : ( $( this ).hasClass( "img_hover" )
						? 0.0
						: 1.0 )
				}, 250 );
			} else if( id == idx ) {
				$( this ).stop( true, true ).animate( {
					width      : "300",
					height     : "280",
					marginTop  :   "0",
					paddingLeft:   "0",
					opacity    :  ( $( this ).hasClass( "img_hover" )
						? 1.0
						: 0.0 )
				}, 350 );
			} else if( id == ( idx + 1 ) ) {
				$( this ).stop( true, true ).animate( {
					width      : "270",
					height     : "252",
					marginTop  :  "21",
					paddingLeft: ( idx + 1 ) * 15,
					opacity    :  ( $( this ).hasClass( "img_hover" )
						? 0.0
						: 1.0 )
				}, 250 );
			} else {
				$( this ).stop( true, true ).animate( {
					width      : "240",
					height     : "224",
					marginTop  :  "42",
					paddingLeft: id * 30,
					opacity    :  ( $( this ).hasClass( "img_hover" )
						? 0.0
						: 1.0 )
				}, 150 );
			}
		} );

	} ).click( function() {
		if( $( this ).attr( "rel" ).length > 0 ){
			window.open( $( this ).attr( "rel" ) );
		}
	} );
	
	$( "#coverstrip" ).mouseleave( function() {

		$( "img", this ).each( function( i ) {
			var id =  Number( $( this ).attr( "idx" ) );

			$( this ).stop( true, true ).animate( {
				width      : "240",
				height     : "224",
				marginTop  :  "42",
				paddingLeft: id * 30,
				opacity    :  ( $( this ).hasClass( "img_hover" )
					? 0.0
					: 1.0 )
			}, 150 );

		} );

	} );
	
	/**
	 **
	 ** INIT OBJECTS
	 **
	 **/

	if( $( "#map_canvas" ).get( 0 ) != undefined ) {

		var map = new GMap2( $( "#map_canvas" ).get( 0 ) );
		
		var mapUI = map.getDefaultUI();

		mapUI.maptypes.normal = false;
		mapUI.maptypes.satellite = false;
		mapUI.maptypes.hybrid = false;
		mapUI.maptypes.physical = false;

		mapUI.controls.scalecontrol = false;
		mapUI.controls.menumaptypecontrol = false;
		
		map.setUI( mapUI );
		
		map.setMapType( G_NORMAL_MAP );

		var point = new GLatLng( 43.681653, 11.753826 );

		map.setCenter( point, 15 );

		map.addOverlay( new GMarker( point ) );
		map.openInfoWindow( map.getCenter(),
							"<big><strong>MiniConf Srl</strong></big><br />Via Provinciale, 1/A<br />52010 Ortignano Raggiolo, Arezzo<br />Tel. +39.0575.5331" );

	}

	$( ".menuItem" ).each( function( idx ) {
	
		var sel = Boolean( $( this ).attr( "selected" ) );
		
		if( sel ) {
			$( this ).addClass(
				"boxShadow"
			).animate( {
				opacity: 0.35,
				color: "black",
				backgroundColor: "white"
			}, 500 );
		}    

	} );

	$( ".menuItemMac" ).each( function( idx ) {
	
		var sel = Boolean( $( this ).attr( "selected" ) );
		
		if( sel ) {
			$( this ).addClass(
				"boxShadow"
			).animate( {
				opacity: 0.35,
				color: "black",
				backgroundColor: "white"
			}, 500 );
		}    

	} );

	$( ".submenuItem" ).each( function( idx ) {
	
		var sel = Boolean( $( this ).attr( "selected" ) );
		
		if( sel ) {
			$( this ).animate( {
				color: "#525353",
				paddingLeft: "15px"
			}, 250 );
			$( "img", this ).animate( {
				marginRight: "10px"
			}, 250 );
		}    

	} );

	$( ".cover .img_base" ).each( function( idx ) {

		$( this ).attr( "idx", idx );
		
		$( this ).parent().children( ".img_hover" ).attr( "idx", idx );
		
		$( this ).animate( {
			width     : "240",
			height    : "224",
			marginTop :  "42",
			paddingLeft: idx * 30
		}, 25 );

		$( this ).parent().children( ".img_hover" ).animate( {
			opacity   : 0.0,
			width     : "240",
			height    : "224",
			marginTop :  "42",
			paddingLeft: idx * 30
		}, 25 );

	} );

} );                                    

