﻿/**
 * Name: Southern Air Popup Boxes Plugin
 * 
 * Author: Robert McInnes (www.mcinnes-coding.com.au)
 */


(function( $ ){

  var methods = {
    init : function( options ) {
    	$(this).menu('bind');
    },
    bind : function( ) { 
    	$(this).each(function(){
    	
    		//var o = $('<div class="menupopup" style="position:absolute;top:-5000px;"></div>');
    		var o = $('<div class="menupopup"></div>').hide();
    		
    		$(o).appendTo(this);
    		$(this).data('attachedObjHeight',o.height());
    		o.css('height',0);
    		$(this).data('attachedObj',o);
    		    		
    		$(this).hover(function(){
    			//over
    			var o = $(this).data('attachedObj');
    			var h = $(this).data('attachedObjHeight');
    			o.stop().show().animate({'height':h},500);
    		},
    		function(){
    			//out
    			var o = $(this).data('attachedObj');
    			o.stop().show().animate({'height':0},500,function(){$(this).hide();});
    		});
    	});
    },
    copy : function( targets ) {  
    	for(t in targets)
    	{
    		$('.cat-'+targets[t]+'-item').each(function(){
	    		var h = parseInt($('.cat-'+targets[t]+'-container').data('attachedObjHeight'),10);
	    		$('.cat-'+targets[t]+'-container').data('attachedObjHeight',h+$($(this)).height());
	    		$(this).appendTo($('.cat-'+targets[t]+'-container > .menupopup'));
    		});
    	}
    },
    update : function( content ) { }
  };

  $.fn.menu = function( method ) {
    
    // Method calling logic
    if ( methods[method] ) {
      return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    } else {
      $.error( 'Method ' +  method + ' does not exist on jQuery.tooltip' );
    }    
  
  };

})( jQuery );
