//Text Truncate
(function($){$.fn.textTruncate=function(){var userOptions={};var args=arguments;var func=args.callee
if(args.length){if(args[0].constructor==Object){userOptions=args[0];}else if(args[0]=="options"){return $(this).eq(0).data("options-truncate");}else{userOptions={width:parseInt(args[0]),tail:args[1]}}}
this.css("visibility","hidden");var options=$.extend({},func.defaults,userOptions);return this.each(function(){var $this=$(this);$this.data("options-truncate",options);if(options.tail=="..."&&func._native){this.style[func._native]="ellipsis";$this.css("visibility","visible");return true;}
var width=options.width||$this.parent().width();var text=$this.text();var textlength=text.length;var css="padding:0; margin:0; border:none; font:inherit;";var $table=$('<table style="'+css+'width:auto;zoom:1;position:absolute;"><tr style="'+css+'"><td style="'+css+'white-space:nowrap;">'+options.tail+'</td></tr></table>');var $td=$("td",$table);$this.html($table);var tailwidth=$td.width();var targetWidth=width-tailwidth;$td.text(text);if($td.width()>width){if(options.tooltip){$this.attr("title",text);}
while($td.width()>=targetWidth){textlength--;$td.html($td.html().substring(0,textlength));}
text=$.trim($td.html());$this.html(text+options.tail);}else{$this.html(text);}
this.style.visibility="visible";return true;});return true;};var css=document.documentElement.style;var _native=false;if("textOverflow"in css){_native="textOverflow";}else if("OTextOverflow"in css){_native="OTextOverflow";}
$.fn.textTruncate._native=_native;$.fn.textTruncate.defaults={tail:"…",tooltip:true};})(jQuery);

function tree(ul)
{
    this.tree = $(ul);  
    this.tree.find("ul").hide();
    
    this.tree.children("li").bind("click", function(e)
    {
        if(typeof this.expanded == 'undefined')
        {
            this.expanded = false;
        }
        
        if(!this.expanded)
        {
            $(this).children("ul").slideDown();
            this.expanded = true;
        }
        else
        {
            $(this).children("ul").slideUp();
            this.expanded = false;
        }
    });
    
    this.tree.find("a").bind("click", function(e)
    {
        e.stopPropagation();
    });
    
    //Expand First
    this.tree.children("li:first").click();
}

function assignment(ctrlwrap)
{
    this.control = $(ctrlwrap);
    this.moveleft = this.control.find(".moveleft");
    this.moveright = this.control.find(".moveright");
    this.left = this.control.find(".assignleft");
    this.right = this.control.find(".assignright");
    
    var assign = this;
    
    this.moveleft.click(function(e)
    {
        assign.right.children("option:selected").remove().appendTo(assign.left);
        return false;
    });
    
    this.moveright.click(function(e)
    {
        assign.left.children("option:selected").remove().appendTo(assign.right);
        return false;
    });
}

function saveSelect(SelectSelector, HiddenSelector)
{
    this.select = $(SelectSelector);
    this.hidden = $(HiddenSelector);
    
    this.v = "";
    this.options = this.select.children();
   
    ss = this;
   
    $.each(this.options, function()
    {
        if(ss.v != "")
        {
            ss.v = ss.v + ",";
        }
        ss.v = ss.v + $(this).val();
    });
    
    this.hidden.val(this.v);
}


function inputInitialText()
{
    var binding = this;
    
    this.elementSelector;
    this.element;
    this.text;
    
    this.bindText = function(elemSelector, txt)
                    {
                        this.elementSelector = elemSelector;
                        this.text = txt;
                        
                        this.element = $(this.elementSelector);
                        
                        this.reset();
                        this.element.bind("focus", this.clearValue);
                        this.element.bind("blur", this.reset);
                    };
                    
    this.clearValue = function()
                      {
                          if(binding.element.attr("value") == binding.text)
                          {
                              binding.element.attr("value", "");
                          }
                      };
    
    this.reset = function()
                 {
                     if(binding.element.attr("value") == "")
                     {
                         binding.element.attr("value", binding.text);
                     }
                 }
                      
    this.unbindText = function()
                      {
                          this.element.unbind("focus", this.clearValue);
                          this.element.unbind("blur", this.reset);
                      }
}
