	(function($) {
	  
	  // plugin definition
	  $.fn.az_animation_box = function(options) {		
		var opts = $.extend({}, $.fn.az_animation_box.defaults, options);
		
		opts.obj = $(this);
		opts.obj_id = this.attr('id');
		
		if ( opts.search ) {
			$('form[name="quick_find"] input[@name=keywords]').focus(
						function(){						
							clearTimeout(opts.az_timer);
							if(opts.az_fetch == false){
								opts.obj.html(opts.az_loading_image);
								loadData();							
							}
							animatedbox("show");	   					
		 				});
		} else {
			$("#btn_"+opts.obj_id).hover(					
						function(){						
							clearTimeout(opts.az_timer);
							if(opts.az_fetch == false){
								opts.obj.html(opts.az_loading_image);
								loadData();							
							}
							animatedbox("show");	   					
		 				},
						function(){							
		   					if ( opts.az_selfclose )
		   						opts.az_timer = setTimeout( function(){ animatedbox( "hide") },opts.az_timeout);
		 				}
			);	  
		}
	  	opts.obj.hover(					
					function(){
						clearTimeout(opts.az_timer);						
					},
					function(){
						if ( opts.az_selfclose )
							opts.az_timer = setTimeout( function(){ animatedbox( "hide") },opts.az_timeout);
					}
		);
		
		// center target div
		function reposition() {	
	  		var btn_width = $("#btn_"+opts.obj_id).outerWidth();
	  		var btn_height = $("#btn_"+opts.obj_id).outerHeight();
	  		var btn_position = $("#btn_"+opts.obj_id).position();
	  		
	  		// set new width if defined in options
	  		if ( opts.box_width ) $("#"+opts.obj_id).css({ 'width':opts.box_width });
	  		 
	  		var obj_width = $("#"+opts.obj_id).outerWidth();
	  		
	  		var obj_top = btn_position.top + btn_height;
	  		var obj_left = Math.floor(btn_position.left + btn_width/2 - obj_width/2);
	  		
	  		$("#"+opts.obj_id).css({ 'top':obj_top, 'left':obj_left });
	  		
		}
		
		function animatedbox(action) {	
	  		if(action=="show") {
	  			reposition();
	  			opts.obj.animate({height: "show", opacity: "show"}).animate({opacity:opts.az_box_opacity});
	  		}	
			else opts.obj.animate({height: "hide", opacity: "hide"});
		}
		  
		  
		function loadData(){
			  $.ajax({
					type: 'GET',
					url: opts.az_fetch_file+'?'+opts.session_id,
					success: function(returned_data){
							parseData(returned_data);						
							opts.az_fetch = true;
						}
					});
		  }
		  
		  function parseData(data){
			opts.obj.html(data);
			if (jQuery.browser.msie && $('#search_style').length>0 ) {
				var search_style = new YAHOO.Hack.FixIESelectWidth( 'search_style'  );
				var search_type = new YAHOO.Hack.FixIESelectWidth( 'search_type'  );
				var search_cat = new YAHOO.Hack.FixIESelectWidth( 'search_cat'  );
			}
			
		  }
		
		
				
	  };
	  
	  // defaults
	  $.fn.az_animation_box.defaults = {
			box_width:				'',
			session_id:				'',
            az_fetch_file:			'',
			az_fetch: 				false,
            az_loading_image: 		'<center><img src="images/az_ajax_loading_image.gif" align="center" /></center>',
			az_box_opacity: 		0.9,
			az_box_status: 			false,
			az_timer: 				"",
			az_speed: 				"fast",						
			az_timeout: 			500,
			az_selfclose:			true
	  };

	})(jQuery);
