// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var application = {
  alert:function(html, args){
    options = {
      cls: "success",
      defaultCls: "message",
      autoClose: true,
      autoCloseInterval: 3000
    }
    $.extend(options, args);
    //close any current alerts
    application.close_alert("fast", options);
    //create element
    var add_box = $("<div></div>").addClass(options.defaultCls).addClass(options.cls).html(html);
    var close_btn = $("<a></a>").addClass("close").attr("title", "Click to close").html("close");
    add_box.append(close_btn);  
    $(document.body).append(add_box)
    //get position
    scroll_top = $(window).scrollTop();
    scroll_left = ($(document).width() / 2) - (add_box.width()/2);
    //set position
    add_box.css({top:(scroll_top), left: scroll_left});
    //append to page    
    height = add_box.attr("clientHeight") || add_box.height();    
    add_box.css("top", scroll_top-height);
    //IE 6 fix
    if($.browser.msie &&  parseInt($.browser.version) < 7){
      $("input[type=checkbox], select").hide();    
    }    
    //show box    
    add_box.show("fast", function(){      
      $(this).animate({top: (scroll_top)}, "fast");
      $(window).bind("scroll", function(){
        add_box.css({top: $(this).scrollTop()})
      })
      if(options.autoClose){
          application.alert.timeout = setTimeout(function(){
          application.close_alert("fast", options);
        }, options.autoCloseInterval);        
      }
      
    })
    add_box.find(".close").click(function(){
      application.close_alert("fast", options);  
    })   
    return add_box;
  },
  close_alert:function(speed, options,callback){
    $("input[type=checkbox], select").show();
    speed = speed || "fast";
    options = options || {};
    callback = callback || function(){}
    //clear timeout if one is set
    if(application.alert.timeout){clearTimeout(application.alert.timeout);}
    //fadeout and remove alert
    $('.'+options.defaultCls).fadeOut(speed, function(){
      $(this).remove();
      callback();
    })
  },
  billhound: {
    add: function(url){
      $("<div></div>").load(url,null, function(){
        application.alert($(this).html(), {cls:""})
      });      
      return false;
    }
  } 
}
openTrackingWindow = application.billhound.add;
