/* -----------------------------------------------------------
/* ------------------------- cLone ----------------------------
*/
if (typeof(console) == "undefined") { 
  var console = { 
    log: function() {}
  }
} else {
  var logger = function(message) {
    console.log(message);
  }
};

function Esi_ajax_content() {
  var self = this;
  this.esi_link = this.root;
  this.esi_url = this.esi_link.attr('href');
  this.esi_nurse = this.esi_link.parent();
  
  this.esi_switch = function(data) {
    self.esi_link.replaceWith(data);
    self.esi_nurse.trigger('esi_loaded', self.esi_url);
  }
  
  this.start_up = function() {
    $.get(self.esi_url, '', self.esi_switch);
    return self;
  }
  
  return this;
}
/* -----------------------------------------------------------
/* ------------------------- cLone ----------------------------
*/
function Cookier() {
  this.make_cookie = function (name, value, days_around) {
    if (typeof(seconds) != 'undefined') {
      this.date = new Date();
      date.setTime(date.getDate() + days_around);
      this.expires = "; expires=" + date.toGMTString();
    }
    else {
      this.expires = "";
    }
    document.cookie = name + "=" + value + this.expires + "; path=/";
  }
  this.eat_cookie = function (name) {
    name += "=";
    var carray = document.cookie.split(';');
    for(var i=0;i < carray.length;i++) {
      var c = carray[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return null;
  }
  this.toss_cookie = function (name) {
    this.setCookie(name, "", -1);
  }
}
/* ------------------------- Wrap_up --------------------------
/	** Wrap_up name
  *  wraps all sibbling elements after a given element and returns the wrapper
  *  no specific formatting is necisarry
  *  this way you can use this funciton in a recursive way to do multi level wraps, and also for lists of colapses
  *  @element element{jQuery} this is the element that is going to end up directly inforn of the wrapper
  *  @element stoper_seletor{String} if you wish to have the wrapper stop at a certin selector..
  */
/* --------------------------------------------------------- */
function Wrap_up(element, stoper_seletor) {
  if (!stoper_selector) stoper_seletor = ''
  element = element.next();
  var wrap = element;
  while (!element.is(stoper_seletor) && element.html()) {
    wrap = wrap.add(element);
    element = element.next();
  }
  return wrap.wrapAll('<div class="wrapper"></div>').parent();
}

/* -----------------------------------------------------------
/* ------------------------- cLone ----------------------------
*/
function Snippet_dialog(element) {
	var self = this;
	this.root = element;
	this.dialogizer = function(e) {
		self.root.unbind('click', self.dialogizer);
		e.preventDefault();
		$('#jax_content').append('<div id="new_box"> </div>');
		$('#new_box').load($(this).attr('href')).addClass('dialogized').dialog({
			modal: true,
			overlay: {
				backgroundColor: "#d9d1b6",
				 opacity: '.8'
			 },
			dialogClass: 'deskman',
			height: 700,
			width: 500,
			close: function()  {
				self.root.bind('click', self.dialogizer);
				$(this).dialog('destory').remove();
			}
		});
	}
	this.root.bind('click', this.dialogizer);
}
/* -----------------------------------------------------------
/* ------------------------- cLone ----------------------------
*/
function Text_resizer(element) {
  var self = this;
  this.root = element;
  this.current_size = 10;
  this.content_basins = $('.deskman');
  
  this.increase_size = function(e) {
    self.content_basins.css({fontSize: ++self.current_size});
  }
  this.decrease_size = function(e) {
    if (self.current_size > 10)
      self.content_basins.css({fontSize: --self.current_size});
  }

  this.root.children('a[href="#increase"]').bind('click', this.increase_size);
  this.root.children('a[href="#decrease"]').bind('click', this.decrease_size);
}
/* -----------------------------------------------------------
/* ------------------------- cLone ----------------------------
*/
function Is_image(filename) {
  var extention = new File_extension(filename).toString();
	switch (extention) {
    case 'jpg': case 'jpeg': case 'png': case 'tiff': case 'gif':
      return true;
    case 'mov': case 'mp4': case 'flv': case 'swf':
    default : 
      return false;
  }
}

function File_extension(filename) {
	return (/[.]/).exec(filename) ? (/[^.]+$/).exec(filename) : null;
}
function File_directory(filepath) {
	return (/[\/]/).exec(filepath) ? (/.+[\/^]/).exec(filepath) : null;
}
/* -----------------------------------------------------------
/* ------------------------- cLone ----------------------------
*/
function External_link(element) {
  var self = this;
  this.linkers = element;
  
  this.blank_window = function(e) {
    if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) {
      return true;
    }
    window.open($(e.currentTarget).attr('href'), '_blank');
  }
  this.linkers.bind('click', this.blank_window);
}
/* ------------------------- Sketch ----------------------------
/	** Sketch
  *  a short-cut for animations.. if just the element is passed in, the item will fade away and then be removed
  *  what ever element 
  *  short explination for why done the way that it is
  *  @param element{jQuery} the element to be animated
  *  @param animate_object{object} the object with the css atributes to be animated to
  *  @param callback_function{funtion} a function to be called upon completion.
  *  @param animation_durration{number} the durration of the animation in seconds
  */
/* --------------------------------------------------------- */
function Sketch() {
  this.draw = function(element, animate_object, callback_function, animation_durration, animation_ease) {
    switch (arguments.length) {
      case 0 :
        return false;
      case 1 :
        animate_object = {opacity: 0};
      case 2 :
        if (!animate_object) { return false; }
        if (animate_object.opacity != 0) {
          callback_function = new Function();
        } else {
          callback_function = function() {element.remove();}
        }
      case 3 :
        animation_durration = .65;
      case 4:
        animation_ease = 'easeOutQuart';
      default :
        if (element.length < 1) { return false; }
        break;
    }
    element.animate( animate_object , {
      duration: animation_durration * 1000, 
      easing: animation_ease,
      queue: false,
      complete: callback_function
    });
    
    return element;
  }
  return this;
}
function Overlay(element, full_screen_modal) {
  var self = this;
  this.wind = $(window);
  this.jax_space = element;
  this.full_screen_modal = full_screen_modal;
  this.jax_space.append('<div class="overlay"></div>')
  this.overlay = this.jax_space.children(':last');
  if (this.jax_space.attr('id') == 'jax_container' || this.jax_space.attr('id') == 'full_screen') {
    this.jax_space = this.jax_space.siblings('#container');
  }
  
  this.set_width = function() {
    if (self.full_screen_modal) {
      self.overlay.width(self.wind.width());
    } else {
      self.overlay.width(self.jax_space.width());
    }
    self.overlay.height(self.jax_space.height());
  }
  
  this.get_gone = function() {
    $('form').removeClass('ie6_overlay_hack');
    self.overlay.remove();
  }
  this.wind.bind('resize', this.set_width);
  this.set_width();
  this.overlay.css({opacity :  0.7});
  if ($.browser.msie && $.browser.version < 7) {
    $('form').addClass('ie6_overlay_hack');
  }
}


/* ------------------------- cLone ----------------------------
/	** cLone name
  *  short description of what class does
  *  short description of how html needs to be formated.. if at all
  *  short explination for why done the way that it is
  *  @param cLone{data type} variable: discirption of what the variable does does
  *  @memeber cLone: function: discirption of what the function does and how it is used
  *  @event cLone{event type}: function: discirption of what the event does, and when or why it is called
  */
/* --------------------------------------------------------- */

