/* ------------------------- Ready Up -------------------------
  Copyright (c) 2009 Mark Avery. Copious Creative Inc. -- copiousinc.com --
  
  ther are two different 'acts', load_acts, and jax_acts
  load_acts are the functions to be called upon a 'load' action
  jax_acts are to be called upon an 'jax' action
  for the different 'acts' they take 3 paramaters..
  
  item : the jQuery selector being passed to the function
  handle : the fuction to be called
  extras : any additional argument to be passed as an array
  
  this.start_up() initiates the controler.. and will be called upon instantiation.. of all classes.
  
*/

// magic edit link 
// '<a href="/admin/page_categories/content/pages' + (document.URL.match(/\/\d+/)[0]) + '/edit"> hello </a>'

function Ready_up(element){
  Controler.call(this, element);
  var self = this;
  this.live_site = 'http://mcmenamins.com';
  
  this.linker_force = [{
    hookshot : /^\/galleries\//i,
    handle : Gallery
  },{
    hookshot : /^\/contact\/refer/i,
    handle : Email_page
  },{
    hookshot : /^\/contact\/personal_contact/i,
    handle : Personal_contact
  }]
 
  this.scenes = [{
    item : self.container.find('a.esi_replace'),
    handle : Esi_ajax_content
  },{
    item : self.container.find('#date_picker'),
    handle : MovieDatePicker
  },{
    item : self.container.find('.hotel_date_picker'),
    handle : HotelAvailabilityDates
  },{
    item : self.container.find('.widget'),
    handle : Widgetier
  },{
    item : self.container.find('#locations'),
    handle : Locator
  },{
    item : self.container.find('.section.carousel'),
    handle : Section_carousel
  },{
    item : self.container.find('#quotes'),
    handle : Crystal_Ball
  },{
    item : self.container.find('blockquote'),
    handle : Block_Quote
  },{
    item : self.container.find('.post:odd, .event_listing:odd'),
    handle : Alternating_Stripes
  },{
    item : self.container.find('#content .hotel_body div.rate-package'),
    handle : Package_expander
  },{
	item : self.container.find('a.pano_link'),
	handle : Panoramic_player
  },{
    item : self.container.find('.event_extras'),
    handle : EventDetails
 },{
    item : self.container.find('.column.right.side'),
    handle : Reserve_lightbox
  },{
    item : self.container.find('div.hotel_sidebar'),
    handle : Reservation_sidebar_extender
  },{
    item : self.container.find('.header_navigation'),
    handle : Header_nav_adjuster 
  },{
    item : self.container.find('.more_or_less'),
    handle : MoreOrLessInfoInSearch
  },{
	item : self.container.find('form.search input'),
	handle : ResetSearchField
  },{
    /*item : self.container.find('#main_content'),
    handle : Target_blank
  },{ */
    item : self.container.find('.contact_datepicker'),
    handle : Contact_datepicker
  }];
  
  this.acts = [{
    item : self.container.find('div.hotel_sidebar'),
    handle : Reservation_search
  },{
    /* item: self.container.find('#content .sub_page_navigation'),
    handle: Sub_page_content,
    extras: [self.container.find('#main_content')]
  },{*/
    item: self.container.find('#content .tabs ul li'),
    handle: Fix_Tabs
  },{
    item: self.container.find('#locations .pagination a.tab'),
    handle: Fix_Pagination_Tabs
  },{
    item: self.container.find('#content .flash_tower img'),
    handle : Flash_tower
  }];
  return this;
}

function Panoramic_player() {
	var self = this;
	this.start_up = function() {
		self.root.bind('click', self.panoramic_loadup)
	}
	this.panoramic_loadup = function(e) {
		e.preventDefault();
		// window.location = '/panoramic_viewer?' + escape(self.root.attr('href'));
		window.open('/panoramic_viewer?' + escape(self.root.attr('href')), 'Panoramic_Viewer');
	}
	return this;
}

 function Flash_tower() {
  var self = this;

  this.root.addClass('manual_load');
  
  this.flash_source = this.root.attr('src');
  if (this.root.attr('src').match(/^\/system\//i) && window.location.port != "") {
    this.root.attr('src', 'http://mcmenamins.com' + this.root.attr('src'));
  } 
  this.root.media({
    width : 440,
    height : 587,
    autoplay : true,
    wmode: 'opaque',
    bgColor: '#ffffff'
  });
  return this;  
} 

function Sub_page_content(content_holder) {
  var self = this;
  this.content_holder = content_holder;
  this.sub_links = this.root.find('a').addClass('loading');
  this.current_link = this.sub_links.filter('.active');
  this.current_hash = '';

  this.root.append('<li class="helper"><a class="button" href="#navi">&nbsp;</a></li>');
  this.navi_help = this.root.children(':last')
  
  this.jax_matchup = function(html) {
    var new_content = $(html).find('#main_content');
    if (new_content.length < 1) {
       var new_content = $('<div>' + html + '</div>');
    }
    var linker = self.sub_links.filter('[href='+this.url+']');
    linker.removeClass('loading').data('page_content', new_content);
    if (location.hash.match(RegExp(this.url))) {
      linker.trigger('click');
    }
  }
  
  this.explorer_hack = function(current_state) {
    self.ie_history.open();
    self.ie_history.write('<html><head></head><body>' + current_state + '</body></html>');
    self.ie_history.close();
  }
  
  this.explorer_history_change = function() {
    self.ie_history_text = self.ie_history.getElementsByTagName('body')[0].innerHTML;
    if (!location.hash.match(RegExp(self.ie_history_text)) && self.ie_history_text != '') {
      self.sub_links.filter('[href=' + self.ie_history_text  + ']').eq(0).trigger('click');
    }
  }
  
  this.explorer_hack_setup = function() {
    $('div#jax_container').append('<iframe id="history_hack" frameborder="0" src="/assets/ie_fix/history_hack.html" style="display:none;"></iframe>');
    $(document.getElementById('history_hack')).bind('load', function() {
      self.ie_history = document.getElementById('history_hack').contentWindow.document;
      setTimeout(function() {setInterval(self.explorer_history_change, 100)}, 1000);
    });
  }
  
  this.history_change = function() {
    if (self.current_hash != location.hash) {
      self.current_hash = location.hash;
      self.sub_links.filter('[href=' + self.current_hash.replace('#','')  + ']').eq(0).trigger('click');
    }
  }
  
  this.w3compliant = function() {
    setTimeout(function() {setInterval(self.history_change, 100)}, 1000);
  }
  
  this.link_trigger = function(e) {
    e.preventDefault();
    self.current_link.parent().removeClass('active')
    self.current_link = $(e.currentTarget);
    self.current_link.parent().trigger('mouseenter');
    self.current_link.parent().addClass('active')
    location.hash = self.current_link.attr('href');
    if (self.current_link.data('page_content')) {
      if ($.browser.msie) {
        self.explorer_hack(self.current_link.attr('href'));
      } else {
        self.current_hash = location.hash;
      }
      self.content_holder.html(self.current_link.data('page_content').html());
      new Ready_up(self.content_holder).start_up();
    } else {
      self.content_holder.html('<img src="/core/images/loader_tall.gif" alt="preloader" class="preloader_image" />')
    }
    return false;
  }
  
  this.check_change = function(e) {
    e.preventDefault();
  }
  
  this.set_hover = function(e) {
    var me = $(e.currentTarget);
    self.sketcher.draw(self.navi_help, {
      left: me.position().left + 5,
      width: me.outerWidth(),
      top: me.position().top + 5
    }, new Function(), 0);
  }
  
  this.release_hover = function(e) {
    if (!self.sub_links.parent('.active')[0]) return false;
    e.currentTarget = self.sub_links.parent('.active')[0]
    self.set_hover(e);
    
  }
  
  this.start_up = function() {
    for (var i = 0; i < self.sub_links.length; i++) {
      $.ajax({
        url: self.sub_links.eq(i).attr('href'),
        success: self.jax_matchup
      });
    }
    self.sub_links.bind('click', self.link_trigger);
    self.sub_links.parent().bind('mouseenter', self.set_hover);
    self.sub_links.parent().parent().bind('mouseleave', self.release_hover);
    self.sub_links.parent().parent().trigger('mouseleave');
    if ($.browser.msie) {
      self.explorer_hack_setup();
    } else {
      self.w3compliant();
    }
    return self;
  }
  return this;
}

/* ------------------------- Gallery ----------------------------
/	** Gallery
  *  --Variables--
  *  this.gallery_interface - the thumbnail tab container.
  *  this.gallery_interface.basins - the main image being displayed.
  *  this.gallery_interface.tabs - all of the thumbnails
  *
  *  this.timeline_interface - the category tabs container
  *  this.timeline_interface.basins - the category tabs
  *  this.timeline_interface.sliders - back/next buttons
  *  
  */
/* --------------------------------------------------------- */
function Gallery() {
  var self = this;
  this.gallery_link = this.root;
  this.gallery_path = this.gallery_link.attr('href');
  this.gallery = null;
  this.wind = $(window);
  this.bod = $('#container');
  this.body_height = self.bod.height();
  this.reservation = self.gallery_path.match(/type\=reservation/i);
  this.old_boy = null;
  this.preload_off = true;
  
  this.old_index = 0;
  
  this.gallery_interface = null;
  this.number_visible = 3;
  
  this.start_up = function() {
    self.gallery_link.bind('click', self.get_gallery);
    return self;
  }
  
  /*
   * Resize Gallery
   */
  this.resize_gallery = function(e) {
    var wind_width = self.wind.width();
    var gallery_tabs = self.gallery_interface.tab_wrapper.parents('div.thumb_list');
    var main_image = self.gallery_interface.active.children('img.main_image');
    var slide_wrap= gallery_tabs.find('div.slide_wrap');
    var slide_wrap_width = wind_width - slide_wrap.prev().width() - slide_wrap.next().width();
    var max_width = wind_width - main_image.siblings('div.content').outerWidth();
    var title_height = gallery_tabs.siblings('div.title').outerHeight(true)
    var max_height = self.wind.height() - gallery_tabs.outerHeight(true) - title_height;
    var width = main_image.width();
    var height = main_image.height();
    
     if (max_height < 400) 
    {
		max_height = 400;
    } 
    if (max_height * (width / height) > max_width) {
	 main_image.height('auto');
      main_image.width(max_width - 3);
    } else {
      main_image.width('auto');
      main_image.height(max_height);
    }
    
    if (max_height > self.body_height) {
      self.gallery.height(max_height);
    } else {
      self.gallery.height(self.body_height);
    }
    self.gallery_interface.basin_wrapper.height(max_height);
    //main_image.css({marginTop : (max_height - main_image.height())/2});
    gallery_tabs.css({ top : max_height + title_height});
    slide_wrap.width(slide_wrap_width);
    
    self.number_visible = Math.floor(slide_wrap_width / self.gallery_interface.tabs.eq(0).outerWidth(true));
    self.gallery_interface.tab_slide_seed = Math.floor(self.number_visible/2);
    main_image.parent().show();
  }

  /*
   * Close Gallery
   */
  this.close_gallery = function(e) {
    e.preventDefault();
    if (self.reservation) {
      self.reservation_overlay.get_gone();
    }
    self.gallery.parent().html('');
  }
  
  /*
   * Preload Gallery
   */
  this.preload_go = function() {
    if (self.gallery_interface.basins.eq(self.gallery_interface.active_index).is('span')) {
      self.gallery_interface.basins.eq(self.gallery_interface.active_index).replaceWith(self.all_basins.eq(self.gallery_interface.active_index));
      self.gallery_interface.basins = self.gallery_interface.basin_wrapper.children();
      self.gallery_interface.active = self.gallery_interface.basins.eq(self.gallery_interface.active_index);
	 self.gallery_interface.basins.eq(self.gallery_interface.active_index).append('<img class="main_image" src="'+self.gallery_interface.active.find('a.main_image').attr('href')+'" />');
	 self.gallery_interface.active.find('a.main_image').remove();
      //new Underdevelop_img(self.gallery_interface.basin_wrapper, 'http://mcmenamins.com');
	 //self.resize_gallery();
    }
    
    if (!self.preload_off) { 
		var preload_amount = self.gallery_interface.active_index - self.old_index;
		if (preload_amount > 0) {
		 self.gallery_interface.tab_wrapper.append($(self.extra_tabs.splice(0, preload_amount)));
		 
		 self.gallery_interface.thumbed_basins.basins = self.gallery_interface.tab_wrapper.children();
		 self.gallery_interface.tabs = self.gallery_interface.tab_wrapper.children();
		 
		 self.gallery_interface.rebind();
		}
	}else{
		return false;
	}
	
     new Underdevelop_img(self.gallery_interface.tab_wrapper, 'http://mcmenamins.com');
     self.old_index = self.gallery_interface.active_index;
	self.gallery_interface.basins.trigger('rewidth');
	//self.gallery_interface.basin_wrapper.trigger('new_active');
  }
  
  /*
   * Resize Initializer
   */
  this.resize_initilizer = function(e) {
    self.gallery_interface.basin_wrapper.bind('new_active', self.preload_go);
    self.gallery_interface.basin_wrapper.bind('new_active', self.resize_gallery);
    self.wind.bind('resize', self.resize_gallery);
    self.bring_in_gallery();
    self.gallery_interface.basin_wrapper.trigger('new_active');
  }
  
  /*
   * Bring In Gallery
   */
  this.bring_in_gallery = function() {
    if (self.reservation) {
      self.reservation_overlay = new Overlay($('div#full_screen'), true);
    }
    self.old_boy.remove();
    self.gallery.css({opacity : 1});
  }
  
  /*
   * Get Gallery List
   */
  this.get_gallery_list = function(e) {
    var temp_draw = new Sketch();
    temp_draw.draw($(e.currentTarget), {top : '0' });
  }
  
  /*
   * Hide Gallery List
   */
  this.hide_gallery_list = function(e) {
    if (e.type == "click") {
      self.close_gallery(e);
    }
    var temp_draw = new Sketch();
    temp_draw.draw($(e.currentTarget), {top : '-90%' });
  }

  /*
   * Filter Timeline
   */
  this.filter_timeline = function(e) {
    e.preventDefault();
	
    var more_found = false;
	var $target = $(e.currentTarget);
	
    for (var j = 0; j < self.extra_tabs.length; j++) {
      if (self.extra_tabs[j].title == $target.html()) {
        self.gallery_interface.tab_wrapper.append($(self.extra_tabs.splice(j, j+1)));
        more_found = true;
        j--
      }
    }
    //self.gallery_interface.basins.append('<img src="http://mcmenamins.com'+self.gallery_interface.active.find('a').attr('href')+'" />'); 
     // new Underdevelop_img(self.gallery_interface.basin_wrapper, 'http://mcmenamins.com');
    
    //if (more_found) {
      new Underdevelop_img(self.gallery_interface.tab_wrapper, 'http://mcmenamins.com');
      self.gallery_interface.thumbed_basins.basins = self.gallery_interface.tab_wrapper.children();
      self.gallery_interface.tabs = self.gallery_interface.tab_wrapper.children();
      self.gallery_interface.rebind();
      self.old_index = self.gallery_interface.active_index;
      self.timeline_interface.active_index = $(e.currentTarget).prevAll().length;
      self.gallery_interface.basins.trigger('rewidth');
    //}
    
      if (!$target.data('direction')) {
      $target.addClass('active').siblings('.active').removeClass('active');
    } 
    var temp_next_active = 0;
    var got_first_available_item = false;
    
    //for each thumbnail,
      for (var i = 0; i < self.gallery_interface.tabs.length; i++) {
      //if the name of the category matches the title attribute of the thumbnail
      if (self.gallery_interface.tabs[i].title == $target.html()) {
	   if (!got_first_available_item) {
          temp_next_active = i;
          got_first_available_item = true;
        }
	   //
        //self.gallery_interface.basins.eq(i).data('not_available', false);
        self.gallery_interface.tabs.eq(i).show();
      } else {
        //self.gallery_interface.basins.eq(i).data('not_available', true);
        self.gallery_interface.tabs.eq(i).hide();
      }
    }  
    
    self.timeline_interface.active_index = $(e.currentTarget).prevAll().length;
    //self.timeline_interface.slide_to(self.timeline_interface.active_index);
   self.gallery_interface.slide_to(temp_next_active);
    //self.timeline_interface.active_index = $(e.currentTarget).prevAll().length;
  }
  
  /*
   * Build Gallery
   */
  this.build_gallery = function(html, textStatus) {
    var raw_gallery = $(html);
    self.old_boy = $('#full_screen').children();
    self.all_basins = raw_gallery.find('div.basin').remove();
    var temp_basins = '';
    for (var i = 0; i < self.all_basins.length; i++) {
      temp_basins += '<span></span>';
    } 
    
    self.extra_tabs = $(raw_gallery.children('div.thumb_list').children('div.gallery_items').children('div.slide_wrap').find('img').splice(20, -1)).remove();
    
    self.gallery = raw_gallery.appendTo('#full_screen');
    self.gallery.children('.main_item').html(temp_basins);
    window.scrollTo(0, 0);
    new Ready_up(self.gallery).start_up();
    
	self.gallery_interface = new Runes({
	 //self.gallery_interface.basins is the main image being displayed.
      basins : self.gallery.children('.main_item').children(),
      reset_holder_width : !self.reservation,
      no_amini : true
    },{
	 //self.gallery_interface.tabs 
      tabs : self.gallery.children('div.thumb_list').children('div.gallery_items').children('div.slide_wrap').find('img'), 
      switch_method : (!self.reservation ? 'basic_switch' : 'basic_switch')
    },{
      sliders : self.gallery.children('.thumb_list').children('.gallery_items').children('a'),
      switch_method : (!self.reservation ? 'basic_switch' : 'basic_switch'),
      auto : false,
      basin_click_advance : !self.reservation,
      delay : 7
    },{
      switch_method : 'all_slide_switch'
    }).start_up();
    
    //------- If there is a category wrapper, --------//
    if (self.gallery.find('div.timeline_items').length > 0) {
	  // Create tabs for the categories
      self.timeline_interface = new Runes({
	   // Basins are the tabs for each category
        basins : self.gallery.children('div.thumb_list').children('div.timeline_items').children('div.slide_wrap').find('a'),
        reset_holder_width : !self.reservation,
        seed : 4
      },{
	   // Sliders are next/back buttons
         sliders : self.gallery.children('.thumb_list').children('.timeline_items').children('a'),
        switch_method : 'all_slide_switch',
        auto : false 
      }).start_up();
    }
    
    //self.resize_gallery();
    
	self.gallery.children('.title').children('a').bind('click', self.close_gallery);
	
    if (!self.reservation) {
      //self.preload_off = true;
      /* self.gallery_interface.tab_wrapper.children('img:first').bind('load', function(){
		self.resize_initilizer();
	}); */
	 self.resize_initilizer();
	 //self.gallery_interface.tab_wrapper.children('img:first').trigger('load');
	 //self.resize_gallery();
    } else {
      //self.preload_off = true;
	  self.gallery_interface.basin_wrapper.bind('new_active', self.preload_go);
	  self.gallery_interface.basin_wrapper.trigger('new_active');
      self.gallery.addClass('reservation_gallery');
      self.gallery.children('div.thumb_list').height(self.gallery.height()-20)
      self.bring_in_gallery();
      self.gallery.children('.title').children('a').html('Close Window');
      self.gallery_interface.sliders.eq(0).html('Previous Photo');
      self.gallery_interface.sliders.eq(1).html('Next Photo');
	  
      self.gallery_interface.basin_wrapper.find('img.main_image').bind('mouseenter', function() {
        self.gallery_interface.sliders.parent().show();
        self.gallery_interface.sliders.parent().bind('mouseenter', function() {
          self.gallery_interface.sliders.parent().show();
        });
      });
      self.gallery_interface.basin_wrapper.find('img.main_image').bind('mouseleave', function() {
        self.gallery_interface.sliders.parent().hide();
      }); 
    }
	
    
	//------- If there is a category wrapper, --------//
    if (self.gallery.find('div.timeline_items').length > 0) {
      //self.preload_off = true;
      self.timeline_interface.basins.unbind();
	 // This adds the click event for each category tab.
      self.timeline_interface.basins.bind('click', self.filter_timeline);
	 
	 // This adds the click event for the back/next buttons in the timeline div.
	 //self.timeline_interface.sliders.bind('click', function(e) {
	   //console.log("click");
	   //self.timeline_interface.basins.eq(self.gallery_interface.active_index).tri
	   //alert(self.timeline_interface.basins.eq(self.timeline_interface.active_index).html);
	   //self.timeline_interface.basins.eq(self.timeline_interface.active_index).trigger('click');
      //}); 
      if (self.gallery_path.match(/category/)) {
        var first_category = self.gallery_path.match(/category\=.*\&/).toString().replace('category=','');
        first_category = first_category.replace('&','').replace('+',' ');
        self.timeline_interface.basins.filter(function(index) {
          return self.timeline_interface.basins.eq(index).html() == first_category
        }).trigger('click');
      } else {
        self.timeline_interface.basins.eq(0).trigger('click');
      }
    }
    
  }
  
  /*
   *	Get Gallery
   */
  this.get_gallery = function(e) {
    e.preventDefault();
    if (self.current_gallery) {
      self.current_gallery.abort();
    }
    self.current_gallery = $.ajax({
      url: self.gallery_path,
      success: self.build_gallery,
      dataType: 'html'
    });
    return false;
  } 
  return this;
}

/* ------------------------- 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
  */
/* --------------------------------------------------------- */
function Section_carousel() {
  var self = this;
  var seats = this.root.children();
  var cushions = seats.children('.content');
  var number_loaded = 0;
  //var no_stuffing;
  
  for (var i = 0; i < cushions.length; i++) {
    //seats.eq(i).data('seat_back', -cushions.eq(i).outerHeight());
    if (cushions.eq(i).children().length > 0) {
      cushions.eq(i).css({marginTop : -cushions.eq(i).outerHeight()});
    } else {
      cushions.eq(i).css({marginTop : -35, paddingTop : 35});
      var no_stuffing = true;
    }
  }
  
  if (seats.length >= 1) {  
    this.root.wrapInner('<div class="slider"></div>');
    this.root.append('<div class="pagination"></div>');
    var pagin = this.root.children(':last');
	pagin.append('<a href="#previous"> <img src="/images/icons/arrow_left.png" alt="left arrow" /> </a>');
    pagin.append('<a href="#next"> <img src="/images/icons/arrow_right.png" alt="right arrow" /> </a>');
    if (no_stuffing) {
      pagin.css({top:272})
    }
    var carousel_runes = new Runes({
      basins : seats,
      no_amini : true
    },{
      sliders : pagin.children('a'),
      switch_method : 'all_slide_switch',
      auto : true,
      delay : 6
    }).start_up();
  } else {
    //cushions.css({marginTop : -15, paddingTop : 15});
  }
  
  this.img_switchout = function() {
    var span_out = seats.eq(number_loaded).children('span.img_swap');
    var img_in = '<img src="' + span_out.html() + '" alt="' + span_out.attr('title') + '" />';
    span_out.replaceWith(img_in);
    new Underdevelop_img(seats.eq(number_loaded), 'http://www.mcmenamins.com');
    if (number_loaded < seats.length) {
      number_loaded++;
    }
  }
  
  this.roll_on = function(e) {
    self.time_delay = setTimeout( function() {
      self.sketcher.draw(cushions, { marginTop : $(e.currentTarget).data('seat_back') });
      if (pagin) {
        self.sketcher.draw(pagin, { marginTop : 0 });
      }
    }, 300);
 }
  
  this.roll_out = function(e) {
    clearTimeout(self.time_delay);
    self.sketcher.draw(cushions, { marginTop : -20 });
    if (pagin) {
      self.sketcher.draw(pagin, { marginTop : 75 });
    }
  }

  this.start_up = function() {
    //seats.bind('mouseenter', self.roll_on);
    //self.root.bind('mouseleave', self.roll_out);
    self.img_switchout();
    if (seats.length > 1) {
      self.img_switchout();
    }
    carousel_runes.sliders.bind('click', self.img_switchout);
  }
  return this;
}
/* ------------------------- 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
  */
/* --------------------------------------------------------- */
function MovieDatePicker() {
  var self = this;
  
  this.start_up = function() {
    self.root.datepicker({
      onSelect: function(dateText, inst) {
        //pass the selected date into the location string
	   //$('#datepicker-attrs').serialize();
        window.location = '/events/search/Any?start_date=' + dateText;
      }
    });
    return self;
  }
  return this;
}

function HotelAvailabilityDates() {
  var self = this;
  
  this.start_up = function() {
    var textField = self.root.find(':input');
    textField.datepicker({
        dateFormat: 'mm/dd/yy',
        showOn: 'both',
        buttonImage: '/images/calendar_date_select/calendar.gif',
        buttonImageOnly: true,
        buttonText: 'calendar',
        duration: '',
        beforeShow: function(input, datepicker) {
          if(isValidDate(input.value)) {
            $(input).datepicker('setDate', new Date(input.value));
          }
        },
        onSelect: function(dateText, datepicker) {
          var selDate = new Date(dateText);

          if(isValidDate(dateText)) {
            var dp = $(datepicker.input);
            /* Copy over start date to end date if the field isn't set yet or if it's earlier than
             * the new start date. */
            if(dp.is(".date_start_date")) {
              var endDp = dp.parents("fieldset").find(".date_end_date");
              var endDate = new Date(endDp.val());
              if(!isValidDate(endDp.val()) || endDate <= selDate) {
                endDp.datepicker('setDate', new Date(selDate.getTime() + 86400000));
              }
            }
          }
        }
      });

    return self;
  }
  
  return this;
}

function EventDetails() {
  var self = this;

  this.start_up = function() {
    var more_info = this.root.children('.more_info');
    var details_btn = this.root.children('.details_btn');
    var map_btn = this.root.children('.event_location');
    var event_id = details_btn.attr('event_id');
    var info = more_info.children('.info');
    var close_btn = more_info.children('.close');
    details_btn.bind('click', function(e) {
      e.preventDefault();
      info.html('&nbsp;');
      info.addClass('loading');
      more_info.show();
      $.ajax({
        url: '/events/' + event_id + '?ajax=true',
        dataType: 'html',
        success: function(data) {
          info.html(data);
          info.removeClass('loading');
		
		var tickets = info.children('p.tickets');
		tickets.children('a').attr('target', '_blank');
        }});
    });
    map_btn.bind('click', function(e) {
      e.preventDefault();
      info.html('<iframe width="350" height="300" src="' + map_btn.attr('href') + '&output=embed"></iframe><a class="button" href="' + map_btn.attr('href') + '">Larger Map</a>');
      more_info.show();
    });
    close_btn.bind('click', function(e) {
        e.preventDefault();
        info.removeClass('loaded');
        info.removeClass('loading');
        more_info.hide();
    });
    return self;
  }

  return this;
}

function MoreOrLessInfoInSearch() {
  var self = this;

  this.start_up = function() {
    var more = this.root.children('.more');
    var less = this.root.children('.less');
    var more_info = this.root.siblings('.more_fields');
    var tags = more_info.children('.tags').children('label');

    if (this.root.children('#start_with_advanced_search_open').length > 0) {
      more_info.show();
      less.show();
      more.hide();
    } else {
      more_info.hide();
      less.hide();
      more.show();
    }

    less.bind('click', function(e) {
      e.preventDefault();
      less.hide();
      more.show();
      more_info.hide();
	  
      $('html,body').animate({scrollTop: 0},'slow');

	  
      more_info.find(':text').each(function(i, elem) {
        elem.value = "";
      });
      more_info.find(':select').each(function(i, elem) {
        elem.selected = false;
      });
      more_info.find(':checkbox').each(function(i, elem) {
        elem.checked = false;
      });
    });

    more.bind('click', function(e) {
      e.preventDefault();
      more.hide();
      less.show();
      more_info.show();
	  $('html,body').animate({scrollTop: $("#content").offset().top},'slow');
    });
    
    for(var i=0; i<tags.length; i++)
    {
       if(i%3 == 0){
		tags.eq(i).css({'clear': 'left'});
	  }	  
    }

    return self;
  }

  return this;
}

/* ------------------------- Widgetier ----------------------------
/	** Widgetier
  *  This class creates the tab functionality for the widget classes
  *  The class applies the functionality to a ".widget" class.
  *  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
  */
/* --------------------------------------------------------- */
function Widgetier() {
  var self = this;
  this.number_visible = 0; /* this number needs to be zero for some reason. 
						    * If not, the results for movies, music, and events
							* will not appear
							*/
  
  this.tabs = new Runes({
    basins : this.root.children('.basin').children(),
    change_wrapper_height : true
  },{
    tabs : this.root.children('.tabs').children('ul').children('li'),
    switch_method : 'two_slide_switch'
  });
  this.lists = null;

  this.start_up = function() {
	$(window).bind('load', self.set_height);
	
    if (self.filling.length > 0) {
      if (self.filling.children().hasClass('esi_replace')) {
        self.filling.bind('esi_loaded', self.filling_setup);
      } else {
        var e = {
          currentTarget : self.filling[0]
        }
        self.filling_setup(e);
      }
    }
    self.tabs.start_up();
    return self;
  }
  
  this.set_height = function()
  {
	if(self.root.siblings().hasClass('loc_reserve'))
	{
		self.root.find('.filling').height(300);
	}else{
		self.root.find('.filling').height(340);
	}
  }
  
  this.pagination_links = this.root.find('.pagination').children(':last').prev().andSelf();
  this.filling = this.root.find('.filling .filling_content');

  this.filling_setup = function(e, esi_path) {
    var me = $(e.currentTarget);
    self.lists = new Runes({
      basins : me.children()
    },{
      sliders : me.parents('li').children('div.pagination').children(':last').prev().andSelf(),
      switch_method : 'vertical_all_slide',
      auto : false,
      delay : 7,
      number_visible: self.number_visible,
      seed : 2
    }).start_up();
    
    var new_height = 0;
    me.parent().parent().show();
    for (var i = 0; i < self.number_visible; i++) {
      new_height += me.children().eq(i).outerHeight(true);
    }
    if (new_height) {
	  me.parent().height(new_height - 3).parent().removeAttr('style');
    } 
   Clean_up_event_widgets();
  }

  return this;
}

/* ------------------------- CrystalBall ----------------------------
/	** Crystal_Ball
  *  used to pull in and animate different random ruby quotes
  *  looks for a element with and id of 'quotes'
  *  this element is used to insert the new random quotes
  *  @memeber start_up basic constructor
  *  @memeber get_quotes uses ajax get request to pull in html data from server
  *  @memeber handle_data uses a set interval to create a random number which is used to select a random quote and insert it onto the page 
  */
/* --------------------------------------------------------- */
function Crystal_Ball() {
  var self = this;
  this.quotes  = self.root.children('a');
  this.active_index = 0;
  
  this.start_up = function() {
    self.quotes.eq(0).addClass('active');
    self.animate_quotes();
    $('.ruby_img').bind('click', function() {
      self.skip_quote();
    });
  }
  
  this.animate_quotes = function() {
    self.skip_quote();
      setTimeout(function() { self.animate_quotes() }, 9000);
  }
  
  this.skip_quote = function() {
    if (self.active_index >= self.quotes.length) {
      self.active_index = 0;
    }
    
    $('.active', '#quotes').fadeOut("fast", function() {
        $(this).removeClass('active');
        
        self.quotes.eq(self.active_index).fadeIn("fast", function() {
          $(this).addClass('active');
        self.active_index++;
        });
    });
  }
  
  return this;
}


/* ------------------------- BlockQuote ----------------------------
/	** Block_Quote
  *  used to construct block quote
  *  looks for p tag inside of blockquote element
  *  injects spans with quote images
  *  @memeber get_quote appends and prepends spans
  */
/* --------------------------------------------------------- */

function Block_Quote() {
  var self = this;
  if (this.root.children('p').length < 1) {
    this.root.wrapInner('<p></p>');
  }
  this.quote = this.root.children();
  this.quote.prepend('<span class="quote_l"></span>').append('<span class="quote_r"></span>');
  
  return this;
}

/* ------------------------- Alternating_Stripes ----------------------------
/**  Alternating_Stripes
  *  used to construct block quote
  *  looks for p tag inside of blockquote element
  *  injects spans with quote images
  *  @memeber get_quote appends and prepends spans
  */
/* --------------------------------------------------------- */


function Alternating_Stripes() {
  var self = this;
  
  this.start_up = function() {
    self.stripe()
  }
  
  this.stripe = function() {
    self.root.addClass('stripe');
  }
  
  return this;
}

/* ------------------------- 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
  */
/* --------------------------------------------------------- */

function Fix_Tabs() {
  var self = this;
  this.linkers = this.root;
  this.start_up = function() {
    self.linkers.hover(function() {$(this).addClass('over');},function(){$(this).removeClass('over');});
    self.remove_spans();
  }
  
  this.remove_spans = function() {
    self.linkers.parent().find('span:first').remove();
    self.linkers.parent().find('span:last').remove();
    self.linkers.parent().find('li:first').addClass('first')
    self.linkers.parent().find('li:last').addClass('last')
  }
  return this;
}

function Fix_Pagination_Tabs() {
  var self = this;
  this.linkers = this.root;
  this.start_up = function() {
  self.linkers.hover(
      function() {
        $(this).prev('span').addClass('over');
        $(this).next('span').addClass('over');
        $(this).addClass('over');
      },
      function(){
        $(this).prev('span').removeClass('over');
        $(this).next('span').removeClass('over');
        $(this).removeClass('over');
      });
    self.remove_spans();
  }
  
  this.remove_spans = function() {
    self.linkers.parent().find('span:first').remove();
    self.linkers.parent().find('span:last').remove();
    self.linkers.parent().find('li:first').addClass('first')
    self.linkers.parent().find('li:last').addClass('last')
  }
  return this;
}

function Subnav_Marker() {
  var self = this;
  
  this.start_up = function() {
    self.addMarker();
  }
  
  this.addMarker = function() {
    self.root.each(function() {
      $(this).parent('li').prepend('<img class="has_subnav" src="/images/global/subnav_star.png" />');
    });
  }
  return this
}

$(document).ready(function() {
  new Ready_up($('#container')).start_up();
});
/* ------------------------- cLone ----------------------------
  Copyright (c) 2009 cLone. Copious Inc. -- copiousinc.com --
  
/	** 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
  */
/* --------------------------------------------------------- */
/* ------------------------- 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
  */
/* --------------------------------------------------------- */
function Reservation_search() {
  var self = this;
  this.side_bar = this.root;
  
  Runes.call(this, {
    basins: this.side_bar.children('div.search_forms').children('form')
  },{
    tabs: this.side_bar.children('ul#search_nav').children('li'),
    switch_method: 'basic_switch'
  });
  
  this.side_bar.children('ul#search_nav').children('li').bind('click', function() {
    $(this).siblings('li').removeClass('active');
    $(this).addClass('active');	
  });
  return this;
}	

function Reservation_sidebar_extender() {
	var self = this;
	this.side_bar = this.root;
	this.container = this.side_bar.parent();
	
	this.start_up = function() {
		$(window).bind('load', self.extend_sidebar);
	}
	
	this.extend_sidebar = function() {
		self.side_bar.height(self.container.height());
	}
	
	return this;
}
/* ------------------------- 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
  */
/* --------------------------------------------------------- */
function SelectRoom() {
  var self = this;
  // Simulates the loading of available rooms.
  this.start_up = function() {
    var t = setTimeout(function() {$(".select_room_loading").toggle();$(".select_room_results").toggle();}, 2000); 
  }
  return this
}

function Package_expander() {
  var self = this;

  this.room_package = this.root;
  this.package_height = this.room_package.css({ height : 'auto' }).height();
  this.room_package.css({ height : 18 });
  this.package_link = self.room_package.children('div.price').children('span').eq(0)
  
  this.expand_package = function(e) {
    if (self.room_package.hasClass('open')) {
      self.sketcher.draw(self.room_package.removeClass('open'), { height: 18});
      self.package_link.html('View Details');
    } else {
      self.sketcher.draw(self.room_package.addClass('open'), { height: self.package_height});
      self.package_link.html('Hide Details');
    }
  }
  
  this.start_up = function() {
    self.package_link.html('View Details');
    self.package_link.bind('click', self.expand_package);
  }
  
  return this;
}

function countryAndStateSelector() {
  var self = this;
  this.country_selectory = $('.select-country select');
  this.state_box = $('.select-state');
  
  this.get_states = function() {
		$.getJSON('/countries/'+ $(this).val() +'/states.json', self.populate_state);
  }
  this.populate_state = function(states) {
    if (states.length > 0) {
      self.state_box.html('<select id="address_state" name="address[state]"><option value="">Choose a state or province</option></select>');
      var state_selectory = self.state_box.find('select');
      for (var i = 0; i < states.length; i++) {
        states[i] = eval('(' + states[i] + ')');
        state_selectory.append('<option value="'+states[i].state.code+'">' + states[i].state.name + '</option>');
        self.state_box.siblings('td').find('.required').html('*');
      }
    } else {
      self.state_box.html('<input type="text" id="address_state" name="address[state]" />');
      self.state_box.siblings('td').find('.required').html('&nbsp;');
    }
  }
  this.start_up = function() {
    self.country_selectory.bind('change', self.get_states);
  }
  
  return this;
}

// When a country or region is selected, updates the state/provinces selector
function countryAndStateSelectorStandalone() {
	$('.select-country :input').change(function() {
			var country_id	= $(this).val();
			var state_entry = $('.select-state');
			var state_selector;
			$.getJSON('/countries/'+country_id+'/states.json', function(states) {
				if (states.length > 0) {
					state_entry.html('<select id="address_state" name="address[state]"><option value="">Choose a state or province</option></select>');
					state_selector = state_entry.find(':input');
					for (i = 0; i < states.length; i++) {
						states[i] = eval('(' + states[i] + ')');
						state_selector.append('<option value="'+states[i].code+'">' + states[i]['name'] + '</option>');
                                        state_entry.siblings('.required:first').html('&nbsp;');
					}
				} else {
					state_entry.html('<input type="text" id="address_state" name="address[state]" />');
                                        state_entry.siblings('.required:first').html('&nbsp;');
				}
			});
	});
}


function isValidDate(strDate) {
  var parsedDate = strDate.split ("/");
  if (parsedDate.length != 3) return false;
  var day, month, year;
  month = parsedDate[0]-1;
  day = parsedDate[1];
  year = parsedDate[2];

  var objDate = new Date(strDate);
  if (month != objDate.getMonth()) return false;
  if (day != objDate.getDate()) return false;
  if (year != objDate.getFullYear()) return false;

  return true;
} 

function Clean_up_event_widgets() {
  $(".widget").each(function() {
    var widget = $(this);
    var empty_basins = widget.find('.basin li:has(.filling_content):not(:has(.filling_content a))').map(function() { return this.className.replace('first', '').replace('active', '').replace(/\s+/, ''); });
    widget.find('.tabs li').show();
    $(empty_basins).each(function() {
      widget.find('.tabs li:has(a[href=#' + this + '])').hide();
    });
    if(empty_basins.length == 2) {
      widget.hide();
      $("#no_mme").show();
    } else {
      widget.show();
    }
    widget.find(".tabs a:visible:first").click();
  });
}

function Header_nav_adjuster() 
{
  var self = this;
  this.titles = this.root.children().children().children('li'); // Main titles
  this.sub_titles = this.titles.children('ul').children('li'); // 2nd level navigation names
  this.sub_sub_titles = this.sub_titles.children('ul');  // 3rd level background container
  this.sub_sub_sub_titles = this.sub_sub_titles.children().children('ul'); // 3rd level li container
  this.css_object = {'float':'right'};
  
  this.start_up = function()
  {
    adjust_subnav_elements();
  }
  
  function adjust_subnav_elements()
  {
	self.titles.each(function(i)
	{
		var sub_menu = self.titles.eq(i).children('ul').children('li');
		var sub_menu_length = sub_menu.length;
		var not_aligned_right = sub_menu_length - 4;
		
		// For the last 4 top nav elements,
		// have their secondary nav titles float right.
		if(i > 4)
		{
			sub_menu.css(self.css_object);
		}
		// For all the secondary nav titles
		// that have sub menus
		if(sub_menu.children().length > 0)
		{
			// For each secondary nav title,
			for(var j=0; j<sub_menu_length; j++)
			{
				// Set the width for the submenus. An arbitrary number multiplied 
				// by the amount of columns.
				sub_menu.eq(j).children('ul').width(150 * sub_menu.eq(j).children().children('li').length);
				
				// If it is the first 4 top nav elements,
				if(i < 5) 
				{
					// If there are more than 4 secondary nav titles, 
					// align their sub menus to the right.
					if( j > 4)
					{
						sub_menu.eq(j).children('ul').addClass('right');
					}
				// For the rest of the top nav elements,
				}else{
					// If there are more than 4 sub navigation items,
					if(sub_menu_length > 3)
					{
						// then align right the submenus for the
						// last 4 secondary nav titles.
						if( j < sub_menu_length - 3)
						{
							sub_menu.eq(j).children('ul').addClass('right');
						}
					// If there are less, then just align all
					// the submenus to the right.
					}else{
						sub_menu.eq(j).children('ul').addClass('right');
					}
				}
			}
		}
	});
  }
  
  return this;
}

function Reserve_lightbox()
{
  var self = this;
  this.first_widget = this.root.children('.widget').eq(0);
  this.btn_html = '<div class="loc_reserve"><a href="/reserve.html">Make a reservation</a></div>';
  //this.location_title = $('.side_navigation h2 a').html();
  this.option_id = '0';
  //this.location_title = this.root.children('loc_reserve')
  
  this.start_up = function()
  {
    // if current location is a hotel, insert the reservation
	// button functionality
	//if(self.isHotel())
	if(self.root.children('.loc_reserve').length > 0)
	{
		var location_title = self.root.children('.loc_reserve').attr('title');
	  //self.first_widget.after(self.btn_html);
	  
	  $('.loc_reserve a').fancybox(
	  {
		'hideOnContentClick': false,
		'frameWidth':270,
		'overlayShow':true,
		'overlayOpacity':0.3,
		'overlayColor':'#000',
		'callbackOnShow':function(e) 
		{
		  var _hotel_sidebar = $(".hotel_sidebar");
		  var textField = $('.hotel_date_picker').children(':input');
		  var select_box = $('#hotel_stay_hotel_id option');
		  
		  
		  /* Adds tab switch functionality
		   */
		  var reserve = new Runes({
		    basins: _hotel_sidebar.children('div.search_forms').children('form')
		  },{
		    tabs: _hotel_sidebar.children('ul#search_nav').children('li'),
			switch_method: 'basic_switch'
		  }).start_up();
			
		  _hotel_sidebar.children('ul#search_nav').children('li').bind('click', function(){
		    $(this).siblings('li').removeClass('active');
			$(this).addClass('active');
		  }); 
		  
		  
		  /* Adds date picker functionality
		   */
		   textField.datepicker({
		     dateFormat: 'mm/dd/yy',
			 showOn: 'both',
			 buttonImage: '/images/calendar_date_select/calendar.gif',
             buttonImageOnly: true,
             buttonText: 'calendar',
             duration: '',
		   beforeShow: function(input, datepicker) {
			if(isValidDate(input.value)) {
				$(input).datepicker('setDate', new Date(input.value));
			}
		   },
		   onSelect: function(dateText, datepicker) {
          var selDate = new Date(dateText);

          if(isValidDate(dateText)) {
            var dp = $(datepicker.input);
            /* Copy over start date to end date if the field isn't set yet or if it's earlier than
             * the new start date.*/
            if(dp.is(".date_start_date")) {
              var endDp = dp.parents("fieldset").find(".date_end_date");
              var endDate = new Date(endDp.val());
              if(!isValidDate(endDp.val()) || endDate <= selDate) {
                endDp.datepicker('setDate', new Date(selDate.getTime() + 86400000));
              }
            }
          }
        }
		   });
		   
		    select_box.each(function(i) {
				var option_text = select_box.eq(i).html();
				if(option_text == location_title)
				{
					select_box.eq(i).attr('selected', 'selected');
				}
			  /* var option_text = select_box.eq(i).val();
			  if (option_text == self.option_id) {
				select_box.eq(i).attr('selected', 'selected');
			  } */
		    }); 
		}
	  });
	}
  }
  
  /*
	textField.datepicker({
        dateFormat: 'mm/dd/yy',
        showOn: 'both',
        buttonImage: '/images/calendar_date_select/calendar.gif',
        buttonImageOnly: true,
        buttonText: 'calendar',
        duration: '',
        beforeShow: function(input, datepicker) {
          if(isValidDate(input.value)) {
            $(input).datepicker('setDate', new Date(input.value));
          }
        },
        onSelect: function(dateText, datepicker) {
          var selDate = new Date(dateText);

          if(isValidDate(dateText)) {
            var dp = $(datepicker.input);
            /* Copy over start date to end date if the field isn't set yet or if it's earlier than
             * the new start date. 
            if(dp.is(".date_start_date")) {
              var endDp = dp.parents("fieldset").find(".date_end_date");
              var endDate = new Date(endDp.val());
              if(!isValidDate(endDp.val()) || endDate <= selDate) {
                endDp.datepicker('setDate', new Date(selDate.getTime() + 86400000));
              }
            }
          }
        }
      });
  
  */
  /* Function checks to see if the current location is a hotel.
   * Also assigns the option_id. The option_id is necessary in order
   * to automatically assign the correct select box option.
   */
  this.isHotel = function()
  {
    switch(self.location_title)
	{
		case "Kennedy School":
		  self.option_id = '10';
		  return true;
		  break;
		case "Edgefield":
		  self.option_id = '9';
		  return true;
		  break;
		case "Grand Lodge":
		  self.option_id = '14';
		  return true;
		  break;
		case "Hotel Oregon":
		  self.option_id = '11';
		  return true;
		  break;
		case "Old St. Francis School":
		  self.option_id = '15';
		  return true;
		  break;
		case "Olympic Club":
		  self.option_id = '12';
		  return true;
		  break;
		case "White Eagle":
		  self.option_id = '13';
		  return true;
		  break;
	}
  }
  
  return this;
}

/* ------------------------- Contact_datepicker ----------------------------
/	** Contact_datepicker
  *  This class applies datepickers to the inputs that ask for a specific date
  *  on the wedding and event contact form pages.
  *  The input textfield needs to have a class of "contact_datepicker" to have a datepicker applied.
  *  The date picker div needs to have a CSS z-index of 100 to appear or it will show behind the main content.
  *  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
  */
/* --------------------------------------------------------- */

function Contact_datepicker()
{
  var self = this;
  this.textfield = this.root;
  
  this.start_up = function()
  {
    self.textfield.datepicker(
	{
	  dateFormat: 'mm/dd/yy',
	  showOn: 'both',
	  buttonImage: '/images/calendar_date_select/calendar.gif',
	  buttonImageOnly: true,
	  buttonText: 'calendar',
	  duration: '',
	  beforeShow: function(input, datepicker)
	  {
	    if(isValidDate(input.value))
		{
		  $(input).datepicker('setDate', new Date(input.value));
		}
	  },
	  onSelect: function(dateText, datepicker)
	  {
	    var selDate = new Date(dateText);
		
		if(isValidDate(dateText))
		{
		  var dp = $(datepicker.input);
		  
		  if(dp.is(".date_start_date"))
		  {
		    var endDp = dp.parents("fieldset").find(".date_end_date");
			var endDate = new Date(endDp.val());
			if(!isValidDate(endDp.val()) || endDate <= selDate)
			{
              endDp.datepicker('setDate', new Date(selDate.getTime() + 86400000));
            }
		  }
		}
	  }
	});
  }
  
  return this;
}

/* ------------------------- Target_blank ----------------------------
/	** Target_blank
  *  This class adds a target attribute '_blank' to the links on
  *  the event pages.
  *  
  *  
  *  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
  */
/* --------------------------------------------------------- */

function Target_blank() {
	var self = this;
	this.content = this.root;
	
	this.start_up = function()
	{
		self.content.find("a[href^='http:']:not([href*='" + window.location.host + "'][target='_blank'])").live('click', function(){
			$(this).attr('target', '_blank');
		});

		/* self.link.each(function(i) {
			var dev = /localhost/;
			var staging = /mcmsite/;
			var p2 = /^\//;
			if(!dev.test(self.link.eq(i).attr('href')))
			{
				if(!p2.test(self.link.eq(i).attr('href')))
				{
					self.link.eq(i).attr('target', '_blank');
				}else{
					if(self.link.eq(i).attr('target') == "_blank")
					{
						self.link.eq(i).removeAttr('target');
					}
				}
			}
		}); */
	}
	
	return this;
}
function ResetSearchField() {
	var self = this;
	var defaultText = 'Keyword Search...';
	this.input = this.root;
	
	// Checks to see if the search input field exists
	if(this.root.length > 0)
	{
		// Assigns the onfocus event to the search input field.
		self.root.focus(function()
		{
			// If the input's value is "Keyword Search..." when clicked,
			// remove the 'defaultText' class and the text "Keyword Search..."
			if(self.root.val() == defaultText)
			{
				self.root.removeClass('defaultText');
				self.root.val('');
			}
		}).blur(function()
		{
			if(self.root.val() == '')
			{
				self.root.addClass('defaultText');
				self.root.val(defaultText);
			}
		});
	}
	
	return this;
}



