
function getDocumentBasePath() {
    documentBasePath = document.location.href;
    
            documentBasePath = documentBasePath.substring(0, documentBasePath.lastIndexOf('/'));
            baseURL = documentBasePath;
      
     
	return baseURL;
}

(function($) {
  
  $.fn.droppy = function(options) {

    options = $.extend({speed: 0, className: 'droppy', trigger: 'click'}, options || {});

    this.each(function() {
		
      var root = this, zIndex = 1000;

      $(root).addClass(options.className);
			$(root).find('li:has(> ul) > a').addClass('has-subnav');

      function getSubnav(ele) {
        if (ele.nodeName.toLowerCase() == 'li') {
          var subnav = $('> ul', ele);
          return subnav.length ? subnav[0] : null;
        } else {
          return ele;
        }
      };

      function getActuator(ele) {
        if (ele.nodeName.toLowerCase() == 'ul') {
		      return $(ele).parents('li')[0];
		  
        } else {
		      return ele;
        }
      };

      function totalhide() {
		$('.subdroppy').hide();
      	 
      };
	  
	  function subnavhide(listidd)
	  {
		  $(listidd).hide();
	  
	  };

      function show() {
var li_title = $(this).attr("class");

	  if($(this).find('li:has(> ul) > a').hasClass('has-subnav'))
	   {
	
		
		if(li_title == "topli")
		{
			$('#dropnav li').removeClass('topli');
			$('#dropnav li').addClass('downli');
			
			
		}
		else if(li_title == "downli")
		{
			 $('#dropnav li').removeClass('downli');
			$('#dropnav li').addClass('topli');		
			$('.subdroppy').hide();
			return false;
		}
		else if(li_title == "lefttopli")
		{
			$('#leftdropnav li').removeClass('lefttopli');
			$('#leftdropnav li').addClass('leftdownli');
		
		}
		else if(li_title == "leftdownli")
		{
			 $('#leftdropnav li').removeClass('leftdownli');
			$('#leftdropnav li').addClass('lefttopli');		
			$('.leftsubdroppy').hide();
			return false;
		}
	  }
		if((li_title == 'leftdownli') || (li_title == 'lefttopli'))	
		{
			subnavhide('.leftsublistdroppy');
		}
		else
		{
				subnavhide('.sublistdroppy');
		}
        var subnav = getSubnav(this);
		
        if (!subnav) return;
        $.data(subnav, 'cancelHide', true);
        $(subnav).css({zIndex: zIndex++}).slideDown(options.speed);
	        if (this.nodeName.toLowerCase() == 'ul') {
          var li = getActuator(this);
		  if(li_title == "ul_country"){var gohturl = getDocumentBasePath();
		 location.href= gohturl+''+lihref;}
		  //var lihref=$(this).hasClass('ul_country').find('a').attr("href");alert(lihref);
		  
		 
		  
          $(li).show();
          $('> a', li).show();
        }
		    return false;
      };
      
      if (options.trigger == 'click') {
	 
        $('> li', this).click(show);
        $('> li ul, > li li', this).click(show, function() {});
       
      }
      
      $('li', this).click(	  
	     function() { 
		 if($(this).hasClass('list_country')) {
		 var lihref=$(this).find('a').attr("href");
		 var htexist = lihref.search("http"); 
		  var spexist = lihref.search("#"); 
		 if((htexist == 0) || (lihref == "#") || (spexist == 0))
		 { 
		 location.href=lihref;
		 return false; 
		 }
		 else 
		 {
		 var gohturl = getDocumentBasePath();
		 location.href= gohturl+''+lihref;
		 return false; 
		 }
		 return false; 
		 }
		 else
		 { $(this).show(); $('> a', this).show(); }
		 }
      );

    });

  };

})(jQuery);
