(function($){
	//Plugin methods
	var base;
	var p_options;
	var methods = {
		init: function(options_a){
			base = this;
			base.menu = $(base).find("ul.controls");
			base.menu_items = $(base.menu).find("li");
			base.title = $(base).parent().find("img.title");
			base.popup_wrapper = $(base).find("ul.popup_panels");
			base.panels = $(base.popup_wrapper).find("li");
			
			$(base.menu_items).click(function(){
				//hide current menu
				base.current_menu_item = $(this).find(".p_id").val()+"-software";
				$("#left_wrapper").animate({opacity:0},300);
				$(".tile_grid_header").animate({opacity:0},300);
				$(".tile_grid").css({
					background:"transparent"
				});
				$(".priv_img").hide();
				$(base.title).fadeOut(300);
				$(base.menu).fadeOut(100,function(){
					//show selected panel
					$(base.popup_wrapper).fadeIn(100,function(){
						$("#"+base.current_menu_item).fadeIn(100);
					});
				});				
			});
			
			base.close_buttons = $(base.panels).find(".close");
			$(base.close_buttons).click(function(){
				var p = $(this).parent();
				$("#left_wrapper").animate({opacity:1},550);
				$(".tile_grid_header").animate({opacity:1},550);
				$(".tile_grid").css({
					background:"url("+base_url+"/images/software/panel_bg.png) no-repeat"
				});
				$(".priv_img").show();
				$(p).fadeOut(200,function(){
					$(base.popup_wrapper).fadeOut(50,function(){
						$(base.menu).fadeIn(250);
						$(base.title).fadeIn(250);
					});
				});
			});
			
			
		}
	} 
	//plugin
	$.fn.jPopup= function(method,options) {
    
		var defaults = {
			
		};
		
		p_options = $.extend({},defaults, options);  

		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.Menu' );
		} 
  		
 	};
 	
})(jQuery);

