///////////////////////////////////////////////////////\\
///////////////////////////////////////////////////////\\
//***************************************************\\\\
//              JQuery Drag Forms v1.0               \\\\
//                    ExpBuilder                     \\\\
//                elkadrey@gmail.com                 \\\\
//***************************************************\\\\
///////////////////////////////////////////////////////\\
///////////////////////////////////////////////////////\\
jQuery.fn.dragforms = function(id, heights, options)
{
   var Config = {
                     speed          : 'slow',
                     event          : 'click',
                     width          : '100%',
                     height         : '100%',
                     autoclose      : true,
                     position       : 'top',
                     closeClass     : '.closebuttons'
                };
    if(options)
    {
		jQuery.extend(Config, options);
	};


    //functions
    //{
    function brwstester()
    {
        return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
    }
    function showdropform(id)
    {
        switch(Config.position)
        {
            case 'top':
                $('#' + id + '_topmenu').show().animate({'top': '0px'}, Config.speed);
            break;
            case 'left':
                $('#' + id + '_topmenu').show().animate({'left': '0px'}, Config.speed);
            break;
            case 'right':
                var widths = $('#' + id + '_topmenu').width();
                var lefts = parseInt(widths) + 15;
                $('#' + id + '_topmenu').show().animate({'left': (brwstester().scrollLeft + parseInt(screen.width) - lefts) + 'px'}, Config.speed);
            break;
            case 'bottom':
                var heights = $('#' + id + '_topmenu').height();
                var tops = parseInt(heights) + 200;
                $('#' + id + '_topmenu').css({'top' : brwstester().scrollTop + parseInt(screen.height) + 'px'}).show().animate({'top': (brwstester().scrollTop + parseInt(screen.height) - tops) + 'px'}, Config.speed);
            break;
        }

    }
    function hidedropform(id)
    {
       switch(Config.position)
       {
          case 'top':
               var heights = $('#' + id + '_topmenu').height();
               var tops = parseInt(heights) + 5;
               $('#' + id + '_topmenu').animate({'top': '-' + tops + 'px'}, Config.speed);
          break;
          case'left':
               var widths = $('#' + id + '_topmenu').width();
               var lefts = parseInt(widths) + 5;
               $('#' + id + '_topmenu').animate({'left': '-' + lefts + 'px'}, Config.speed);
          break;
          case'right':

               $('#' + id + '_topmenu').animate({'left': (brwstester().scrollLeft + parseInt(screen.width)) + 'px'}, Config.speed);
          break;
          case 'bottom':
               $('#' + id + '_topmenu').animate({'top': (brwstester().scrollTop + parseInt(screen.height)  - 200) + 'px'}, Config.speed);
          break;
       }
       $('#' + id + '_topmenu').fadeOut('fast');
    }
    //}
          var more;
          switch(Config.position)
          {
              case 'top':
                  more = 'left: 0px;width: ' + Config.width + ';top: -' + heights + 'px';
              break;
              case 'left':
                  more = 'top: 0px;width: ' + $('#' + id).width() + 'px;height: ' + Config.height + ';left: -' + ($('#' + id).width()) + 'px';
              break;
              case 'right':
                  var ds = (parseInt($('#' + id).width())) + 20;
                  more = 'top: 0px;width: ' + ds + 'px;height: ' + Config.height + ';left: ' + (parseInt(screen.width)) + 'px';
              break;
              case 'bottom':
                  var ds = (parseInt(screen.height) - 210);
                  more = 'left: 0px;height: ' + ($('#' + id).height() + 50) + ';width: ' + Config.width + ';top: ' + ds + 'px';
              break;
          }

          $("body").append('<div style="opacity:0.8;filter:alpha(opacity=80);display: none;' + more + '" class="topmenu" id="' + id + '_topmenu">&nbsp;</div>');
          $("#" + id).appendTo('#' + id + '_topmenu');

          if(Config.autoclose == true)
          {
              $('#' + id + '_topmenu').mouseleave(function()
              {
                  hidedropform(id);
              });
          }

          $(Config.closeClass).bind('click' ,function()
          {
              hidedropform(id);
          });
          //load form
          if(Config.event == 'load')
          {
                showdropform(id);
          }
          else
          {
              $(this).bind(Config.event, function()
              {

                  showdropform(id);
                  return false;
              });
          }
          $(window).scroll(function()
          {
             if($('#'+ id + '_topmenu').css('display') != 'none' && (Config.position == 'bottom' || Config.position == 'right'))
             {
                showdropform(id);
             }
          });


}
