// fancy menu
if ( $( '#leasingOffers' )[0] ) {
	(function( offersMenu ){
		function offersMenu( e ){
			$( '#menuOffers ul .active' ).removeClass( 'active' );
			$( '#leasingOffers .target' ).removeClass( 'target' );

			$( this.parentNode ).addClass( 'active' );
			$( this.hash.replace( /anch-/,'' )+'_id' ).addClass( 'target' );

			this.hideFocus=1;
			//e.preventDefault();
		}

		$( '#menuOffers ul a' ).live( 'mouseover', offersMenu );

		if ( window.location.hash ) {
			$( 'a[href$=' + window.location.hash + ']' ).trigger( 'mouseover' );
		}
	})();
}

/*

(function(){

  // Bind the event.
  $('#menuOffers ul a').bind( 'click', function(e){
  	e.preventDefault();
  })

})();
*/
// overlay ala lightbox
(function( offerLayerCreate, offerLayerFill ){
	function offerLayerCreate( e ) {
		e.preventDefault();
		$( 'body' ).append( '<div id="overlayOffer"><img class="preloader" src="/images/lightbox-ico-loading.gif"/></div>' );
		$( '#overlayOffer' ).css( 'min-height', $( 'body' ).height() );
		var hash = this.href.split('?load=')[1].replace('%23','#');//nasty hack
		$.get( this.href.replace( this.hash, ''), { 'ajax':'true', 'load':hash }, offerLayerFill);
	}
	function offerLayerFill( data ){
		$( '#overlayOffer' )
			.empty()
			.append( data )
			.append( '<a href="#anch-content"><img class="close" src="/images/btnClose.png" alt="X"/></a>' );

		// submit form in overlay
		// (no live, because IE sux)
		$( '#overlayOffer #formAsk' ).submit( function( e ){
			e.preventDefault();
			$.post( this.action, $( this ).serialize(), offerLayerFill);
		});
	}

	$( '#leasingOffers div.offer p.check a, #leasingOffers div.offer p.more a' ).live( 'click', offerLayerCreate );

	// hide overlay
	$( '#overlayOffer' ).live( 'click', function( e ){
		if ( $( e.target ).is( '#overlayOffer' ) ) {
			$( e.target ).remove();
		}
	});

	$( '#overlayOffer a img.close' ).live( 'click', function(){
		$( '#overlayOffer' ).trigger( 'click' );
	});

	// expand offer form
	$( '#formAsk p.more a' ).live( 'click', function(){
		$( '#formAsk' ).addClass( 'extended' );
	});

	$( '#formAsk p.less a' ).live( 'click', function(){
		$( '#formAsk' ).removeClass( 'extended' );
	});

})();


