
var plg_popup_fortuneCookie = new function(){
	
	this.opened = true;
	_self = this;
	
	this.run = function (){
		$('.jQ_fortuneCookieButton').click(function(){
			_self.show( this );
			return false;
		});
	}
	
	this.show = function( button ){
		
		//$(this).parent().hide();
	
		var popup = $('.jQ_fortuneCookie_popup').clone();
		plg_popup.show(popup);
		
			$(popup).parent().css({backgroundColor:'transparent'});
			
			popup.find('.jQ_presage:first',popup).css({cursor:'pointer'}).unbind('click').click(
				function(){ 
					majax.call_callback('plg_popup_fortuneCookie::cookieReaded',function(d){},[]);
					var _visible = $('.jQ_presage:visible',popup);
					var _hidden = $('.jQ_presage:hidden',popup).click(plg_popup.hide);
					
					$('.jQ_fortuneCookie_popup:visible').parent().animate( { left: '50%' } );
					_visible.fadeOut('fast', function() { 
							$('.jQ_fortuneCookie_popup .popup:last').animate( { cursor: 'normal', width: '542px' },
								'fast', 'linear',  
								function() { _self.opened =true; _hidden.fadeIn('fast'); _hidden.parent().addClass('opened') }
								);
						$('.blockUI').css( 'margin-left', '-271px' );
						} );
					
			return false;
			}
			);
		
		if(_self.opened){
			popup.find('.jQ_presage:first',popup).click();
		};
		
		$('.jQ_fortuneCookie_popup:last').parent().css( { cursor: 'default' } );
		
		if( window['plg_page_pixels'] != undefined ){
			plg_page_pixels.redisplayPixels();
		}
		
	return false;
	} 
}

$('document').ready(function(){
	plg_popup_fortuneCookie.run();
	return false;	
});

