/**
* plugin: jquery.anyDropDown.js
* author: kt.cheung @ Brandammo
* website: www.brandammo.co.uk
* version: 1.0
* date: 25th mar 2011
* description: simple jquery drop down menu with easing, toggle any element using any element
**/

(function($){

  $.fn.anyDropDown = function(options) {  
  
	//set up default options 
	var defaults = {
		dropDownElem: '.dropdown', //the class name for your drop down
		dropDownMenuElem: '.dropdown_menu', //the class name for the drop down menu
		slideDownEasing: 'easeInOutCirc', //easing method for slideDown
		slideUpEasing: 'easeInOutCirc', //easing method for slideUp
		slideDownDuration: 500, //easing duration for slideDown
		slideUpDuration: 500, //easing duration for slideUp
		closeMessage: 'Close this menu'
	}; 
  	
	var opts = $.extend({}, defaults, options); 	
	
	var closedText;
	var dropDown;
	
    return this.each(function() {  
	  var $this = $(this);
	  $this.find(opts.dropDownMenuElem).css('display', 'none');
	  $this.find(opts.dropDownElem).css('cursor','pointer').toggle(showDropDown, hideDropDown);
	  
	  dropDown = $this;
	  closedText = $(opts.dropDownElem).html();
	  
    });
		
	function showDropDown(){
		dropDown.find(opts.dropDownMenuElem).slideDown({duration:opts.slideDownDuration, easing:opts.slideDownEasing});
		dropDown.find(opts.dropDownElem).html(opts.closeMessage);
	}
	
	function hideDropDown(){
		dropDown.find(opts.dropDownMenuElem).slideUp({duration:opts.slideUpDuration, easing:opts.slideUpEasing});//hides the current dropdown
		var label = closedText;
		if($("#tipo_select").html() != undefined && $("#tipo_select").html() != null){
			if($("#tipo_select").val() == 'estado'){
				var label = $("#estado_nome").val();
			}
			else{
				if($("#tipo_select").val() == 'emails'){
					var label = $("#emails").val();
				}
			}
			
		}
		if($("#home").html() != undefined && $("#home").html() != null){
			var label = $("#home").val();
		}
        if($("#suporte_tipo").html() != undefined && $("#suporte_tipo").html() != null){
			var label = $("#suporte_nome").val();
		}
        if($(".aplicacao_container").html() != undefined && $(".aplicacao_container").html() != null){
			if($("#any_tipo").val() == '1'){
                var label = $("#aplicacao_nome").val();
            }
            else{
                var label = $("#subcategoria_nome").val();
            }
		}
        if($("#produto_id, #produto_nome").html() != undefined && $("#produto_id, #produto_nome").html != null){
        	var label = $("#produto_nome").val();
        }        
		dropDown.find(opts.dropDownElem).html(label);
	}
	
  };
})(jQuery);

