
/* methods */

/* fixing fades in IE by over-writing the std jquery functions */

/*jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
};*/ 
 
jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 

/* end of fade fix */

jQuery.fn.swapClass = function(outclass,inclass,alwaysadd){
  return this.each(
    function(){
      if ($(this).hasClass(outclass)) {
        $(this).removeClass(outclass) ;
    if ( !$(this).hasClass(inclass) ) { $(this).addClass(inclass) }
      }
      if ( alwaysadd && (!$(this).hasClass(inclass)) ) { $(this).addClass(inclass) }
    }
  );
};

jQuery.fn.setHoverClass = function(hvrclass){
    return this.each(
      function(){
        $(this).hover(
          function(){ $(this).addClass(hvrclass) ; },
          function(){ $(this).removeClass(hvrclass) ; }
        );
      }
    ) ;
};

jQuery.fn.setFakeLink = function(hvrclass,statustext,url){
    var urlprefix = location.protocol + '//' + location.hostname + location.pathname.substring(0,(location.pathname.lastIndexOf('/'))+1) ;
    var usinghvr = (hvrclass) ? true : false ;
				var href = urlprefix + url ;
    return this.each(
      function(){
						  $(this).attr('title',href) ;
        $(this).hover(
          function(){ 
            if (usinghvr) $(this).addClass(hvrclass) ;
            //window.status = urlprefix + statustext ;
          },
          function(){ 
            if (usinghvr) $(this).removeClass(hvrclass) ; 
            //window.status = '' ;
          }
        );
        $(this).click(function(){
          window.location = href ;
        }) ;
      }
    ) ;
};

jQuery.fn.setFakeImageLink = function(hvrstr,statustext,url,titlestr){
  // function depends on hover image name being same as normal image with value of hvrstr appended to basename
  
    if ( location.pathname.lastIndexOf('/') == 0 ) {
      var urlprefix = location.protocol + '//' + location.hostname ;
    } else { 
      var urlprefix = location.protocol + '//' + location.hostname + location.pathname.substring(0,(location.pathname.lastIndexOf('/'))+1) ;
    }

    return this.each(
      function(){
        $(this).hover(
          function(){ 
            var rx = /\.png/ ;
            this.src = this.src.replace(rx,hvrstr+'.png') ;
            this.title = titlestr ;
            window.status = urlprefix + statustext ;
          },
          function(){ 
            var rx = /-.*\./ ;
            this.src = this.src.replace(rx,'.') ; 
            this.title = '' ;
            window.status = '' ;
          }
        );
        $(this).click(function(){
          window.location = url ;
        }) ;
      }
    ) ;
};

jQuery.fn.setHoverFade = function(){
    return this.each(
      function(){
        $(this).hover(
          function(){ $(this).fadeTo('slow',.65); },
          function(){ $(this).fadeTo('slow',1); }
        );
      }
    ) ;
};

jQuery.fn.setTabSlide = function(){
    return this.each(
      function(){
      var thisId = '#' + this.id ;
        var tabid = '#tab-' + thisId.substr(4) ;
        $(thisId).toggle(
          function(){
          var togmarker = thisId + ' span.accordinator' ;
                $(tabid).slideUp('normal') ;
                $(togmarker).text('+') ;
          },      
          function(){
          var togmarker = thisId + ' span.accordinator' ;
                $(tabid).slideDown('normal') ;
                $(togmarker).html('&ndash;') ;
          }      
        );

      }
  ) ;
};

jQuery.fn.setFocusNoSee = function(){
  return this.each(
    function(){
      $(this).click(
        function(){
          if ('hidefocus' in this) {
            this.hidefocus = true ;
          } else {
            $(this).blur() ;
          }
        }
      );
    }
  ) ;
} ;

jQuery.fn.toggleDisabled = function(){
  var args = jQuery.fn.toggleDisabled.arguments ;
  return this.each(
    function(){
      if ( args.length == 0 ) {
        if ( $(this).is(':disabled') ) {
          $(this).removeAttr('disabled') ;
        } else {
          $(this).attr('disabled','disabled') ;
        }
      } else {
        if ( args[0] == true ) {
          if ( !$(this).is(':disabled') ) $(this).attr('disabled','disabled') ;
        } else {
          if ( $(this).is(':disabled') )$(this).removeAttr('disabled') ;
        }
      }
    }
  );
};

(function($){
jQuery.fn.toggleStateAttr = function(options){
  var opts = jQuery.extend({}, jQuery.fn.toggleStateAttr.defaults, options) ;
  var jfilter = ':' + opts.attr ;
  return this.each(
    function(){
      if ( !opts.force ) {
        if ( $(this).is(jfilter) ) {
          $(this).removeAttr(opts.attr) ;
        } else {
          $(this).attr(opts.attr,opts.attr) ;
        }
      } else {
        if ( opts.remove ) {
          if ( $(this).is(jfilter) ) $(this).removeAttr(opts.attr) ;
        } else {
          if ( !$(this).is(jfilter) ) $(this).attr(opts.attr,opts.attr) ;
        }
      }
    }
  );
};
jQuery.fn.toggleStateAttr.defaults = {
  attr: 'disabled' ,
  force: false ,
  remove: true
}
})(jQuery) ;

jQuery.fn.labelFor = function(){
  return this.each(
    function() {
      if ( $('input',this).attr('type') == 'radio' || $('input',this).attr('type') == 'checkbox' ) {
        $(this).attr('for', $('input',this).attr('id') ) ;
      }
    }
  );
};

jQuery.fn.pngIE = function(reinit) {
   
  return this.each(
    function(){
      var $this = $(this) ;
      if (reinit == true) {
        var reimg = new Image() ;
        reimg.src = $this.data('osrc') ;
        this.src = reimg.src ;
        this.width = reimg.width ;
      }
      $this.data('osrc',this.src) ;
      $this.data('owidth',this.width) ;
      this.filters.item(gp.alphaloader).src = $this.data('osrc') ;
      if ( $this.hasClass('ieScale') ) { this.filters.item(gp.alphaloader).sizingMethod = 'scale' ; }
      this.src = gp.ieimgsub ;
      this.width = $this.data('owidth') ;
    }
  );
};

jQuery.fn.setImgNaturalDims = function(){
  return this.each(
    function(){
      //alert('hello') ;
      if ( ! $.isProp(this.naturalWidth) ) {
      //alert('fixing prop') ;
        var tmpimg = document.createElement('img') ;
        tmpimg.src = this.src ;
        this.naturalWidth = tmpimg.width ;
        this.naturalHeight = tmpimg.height ;
      } else if ( this.naturalWidth == 0 ) {
        //alert('damn your eyes') ;
      }
    }
  );
};


jQuery.fn.showAtPointer = function(ev){
  var evt = (ev) ? ev : window.event ;
  
  return this.each(
    function() {
      var popX = evt.pageX ;
      var popY = evt.pageY ;
      alert(popX) ;
      $(this).css({'top': popY, 'left' : popX}) ;
    }
  );
};

jQuery.fn.infoPop = function(ev){
   var evt = (ev) ? ev : window.event ;

  return this.each(
    function() {

      var ipopitemid = $(this).attr('name') ;
      var $ipopitem = $('#' + ipopitemid + 'ip') ;
      var $ipopshell = $('#infopop') ;

      if ( $('#infopop').is(':visible') ) {
        $('#infopop').hide() ;
  if ( $ipopshell.data('previpop') == ipopitemid ) { return }
      }
      
      var $ipopfill = $('#infopopfill') ;
      var popX = evt.pageX ;
      var popY = evt.pageY ;
      var offX = ( $.isProp(gp.ipopOffsetWidth) ) ? gp.ipopOffsetWidth : $ipopshell.outerWidth() ;
      
      if ( popX + offX > $(window).width() ) { popX -= offX }
      
      $ipopfill.html( $ipopitem.clone(true) ) ;
      $ipopshell.data('previpop',ipopitemid) ;
      $('.ipopfill .hwrp').attr('title','Exit').css('cursor','pointer').click( function(){ $('#infopop').hide(); } );

      $ipopshell.css({'top': popY, 'left' : popX}).show('normal') ;
    }
  );
};

jQuery.fn.setClickInfo = function(displayid){
  return this.each(function(){
    $(this).click(
      function(){
        var itemid = this.id ;
        var infoselector = '#' + itemid + '-info' ;
        var loc = $(this).offset() ;
        var wid = $(this).outerWidth() ;
        var cssobj = {left:loc.left+wid, top:loc.top-12}
        $(displayid + ' div.tbfill').html( $(infoselector).html() ) ;
        if ( !$.support.opacity ) {
          $(displayid).css(cssobj).show() ;
        } else {
          $(displayid).css(cssobj).show('normal') ;
        }
      }
    );
  });
};

jQuery.fn.addSetBG = function() {
  return this.each(function(){
    this.setBG = function(fname){
      if (this.style.backgroundImage != $.cssurlwrap(gp.bgdir + fname)) { this.style.backgroundImage = $.cssurlwrap(gp.bgdir + fname) } ;
    }
  });
};

(function($){
  jQuery.fn.lightBox = function() {
    return $(function(){
      $('body').append('<div class="lightbox">&nbsp;</div>') ;
      $('div.lightbox').css({height:$(window).height(),width:$(window).width()}).show() ;
    });
  };
})(jQuery);

(function($){
  jQuery.fn.placement = function() {
    return this.each(function(){
      var args = jQuery.fn.placement.arguments ;
      var pos = {top:'',left:''} ;
      var defaults = {top:'',left:''} ;
      defaults.left = Math.round( ($(window).width() - $(this).width())/2 ) ;
      defaults.top = Math.round( ($(window).height() - $(this).height())/2 ) ;
      if ( defaults.top < 0 ) { defaults.top = 24 }
      if ( defaults.left < 0 ) { defaults.left = 24 }
      
      switch ( args.length ) { 
        case 0:
          pos.top = defaults.top ;
          pos.left = defaults.left ;
          break;
        case 1:
          pos.top = ( args[0] < 0 ) ? defaults.top + args[0] : args[0] ;
          pos.left = defaults.left ;
          break;
        case 2:
          pos.top = ( args[0] < 0 ) ? defaults.top + args[0] : args[0] ;
          pos.left = ( args[1] < 0 ) ? defaults.left + args[1] : args[1] ;
          break;
        default:
          pos.top = args[0] ;
          pos.left = args[1] ;
          break;
      }
      
      if ( pos.top < 0 ) pos.top = 24 ;
      if ( pos.left < 0 ) pos.left = 24 ;
      
      $(this).css(pos) ;
    });
  };
})(jQuery);

jQuery.fn.wipe = function() {
  $('div.lightbox').remove();
  return this.each(function(){
    $(this).empty().hide() ;
  });
};

jQuery.fn.wipeAll = function() {
  $('div.lightbox').remove();
  return this.each(function(){
    $(this).remove() ;
  });
};


(function($){
  /*
    by default, if you pass coords attachMap will skip geocoding.
    if you want to reverse-geocode, pass coords AND lookup:true.
    currently there is no logic for processing reverse-geocode results
    if there's a fulladdress and no marktitle, the former will be copied to the latter
    if there's a fulladdress and no coords, lookup will be set to true
  */
  $.fn.attachMap = function(options) {
    var opts = $.extend({}, $.fn.attachMap.defaults, options) ;
    
    if (!opts.fulladdress && (!opts.coords.lat || !opts.coords.lon) ) {
      opts.coords = opts.defaultcoords ;
    }
    if (opts.fulladdress && (!opts.coords.lat || !opts.coords.lon) ) {
      opts.lookup = true ;
    }
    if (!opts.marktitle && opts.fulladdress) {
      opts.marktitle = opts.fulladdress ;
    }
    if (typeof options == "object"  && $.isProp(options.MTID)) opts.MTID = opts.MTID.toUpperCase() ;
       
    return this.each(function(){
      var oMap = {} ;
      oMap.opts = opts ;
      oMap.target  = this ;
      oMap.point   = new google.maps.LatLng(opts.coords.lat, opts.coords.lon) ;
      oMap.marker = new google.maps.Marker({position:oMap.point});
      oMap.info    = new google.maps.InfoWindow({content:opts.fulladdress}) ;
      oMap.marktitle = opts.marktitle ;
      oMap.options = {
        center: oMap.point,
        zoom: opts.zoom,
        mapTypeId: google.maps.MapTypeId[opts.MTID]
      }
      
      if (opts.lookup) {
        oMap.geocoder = new google.maps.Geocoder() ;
        oMap.geocoder.geocode({address:opts.fulladdress}, function(data,status){ 
          if (status == google.maps.GeocoderStatus.OK){
            oMap.options.center = oMap.point = data[0].geometry.location ;
            oMap.marker.setPosition(oMap.point) ;
          }
          createMap(oMap) ;
        });
      } else {
        createMap(oMap) ;
      }
      
      $.fn.attachMap.maps[opts.name] = oMap ;
    });
  };
  
  function createMap(mObj) {
    mObj.canvas = new google.maps.Map(mObj.target,mObj.options) ;
    mObj.marker.setMap(mObj.canvas);
    if (mObj.marktitle) mObj.marker.setTitle(mObj.marktitle) ;

    google.maps.event.addListener(mObj.marker, 'click', function() {
     mObj.info.open(mObj.canvas,mObj.marker);
    });


  };

  $.fn.attachMap.defaults = {
    name: 'default' ,
    coords: {lat: 0 , lon: 0} ,
    lookup: false ,
    fulladdress: '' ,
    zoom: 13 ,
    MTID: 'ROADMAP' ,
    marktitle: '' ,
    defaultcoords: {lat: 37.871667 , lon: -122.2716667} 
  };
  
  $.fn.attachMap.maps = {} ;
})(jQuery);


//getting the current basename (depends on phptojs library $$)
// $$.basename(window.location.pathname,'.php');

(function($){
  jQuery.fn.initTabs = function() {
				//opentab cookie tracking w/json storage
				var fred = $.parseJSON($.cookie('cTabs')) ;

				if ( !$.isEmptyObject(fred) ) {
				  
				  $.cTabs = $.parseJSON($.cookie('cTabs')) ;
				} else {
				  $.cTabs = {} ;
				}
				
				//$.cTabs = ( !$.isEmptyObject($.cookie('cTabs')) ) ? $.parseJSON($.cookie('cTabs')) : {} ;
    
				if ( ! $.isProp($.cTabs[$.Page]) ) {
				  $.cTabs[$.Page] = '' ;
				}
    
				return this.each(function(){
      if ( $('div.tab div.btm',this).width() == 0) $('div.tab',this).fixTabMask() ;
      //using inline-block css with additional iecond for ie7- instead of this
      //$(this).centerTabDivs() ;
      $('div.tab',this).setTabHoverClass('hvrtab') ;
      $('div.tab',this).setFocusNoSee() ;
      if ( $('.tabpane').length ) $('div.tab',this).setTabPanes() ;
      $('div.tab',this).setTabClick() ;
    });
  };
})(jQuery);

(function($){
  jQuery.fn.setTabPanes = function() {
    return this.each(function(){
      $(this).data('paneId','') ;
      var paneid = this.id.replace(/tab/,'') ;
      if ( paneid ) {
        if ( $('#' + paneid).length ) {
          $(this).data('paneId','#'+ paneid) ;
          if ( !$(this).hasClass('opentab') ) $( $(this).data('paneId') ).hide() ;
        }
      }
    });
  };
})(jQuery);

(function($){
  jQuery.fn.setTabClick = function() {
    return this.each(function(){
      $(this).click(function(){
        var $tabs = $(this).closest('div.tabs') ;
        $('div.tab',$tabs).removeClass('opentab') ;
        $(this).swapClass('hvrtab','opentab',true) ;
        $.cTabs[$.Page] = this.id ;
        $.cookie('cTabs',$.toJSON($.cTabs)) ;
								$.loco.updateHashX('tid',this.id) ;

        var paneid = $(this).data('paneId') ;
        if ( paneid ) {
          $tabs.data('opentab', this.id ) ;
          $('.tabpane',$(paneid).closest('div.panes')).hide() ;
          if ($tabs.data('nofade')) {
            $(paneid).show() ;
          } else {
            $(paneid).fadeIn() ;
          }
        }
      });
    });
  };
})(jQuery);

(function($){
  jQuery.fn.fixTabMask = function() {
    //IE fix for zero-width on empty absolutely positioned div with width:auto in IE
    return this.each(function(){
      var $btm = $('div.btm',this) ;
      var offsets = parseInt($btm.css('margin-left')) + parseInt($btm.css('margin-right')) ;
      $btm.width( ($(this).width() - offsets) + 'px' ) ;
    });
  };
})(jQuery);

(function($){
  jQuery.fn.centerTabDivs = function() {
    return this.each(function(){
      if ( $(this).hasClass('mtabs') ) {
        var menupad = $.cookie('menupad') ;
        if (typeof menupad == 'string'){
          $(this).css('padding-left', menupad + 'px') ;
        } else {
          var tabtotwidth = 0 ;
          $('div.tab',this).each(function(){ tabtotwidth += $(this).width() });
          var padl = ($(this).innerWidth() - tabtotwidth)/2 ;
          if (padl < 0) padl = 0 ;
          $(this).css('padding-left', padl ) ;
          $.cookie('menupad',parseInt(padl)) ;
        }
      } else {
        var tabtotwidth = 0 ;
        $('div.tab',this).each(function(){ tabtotwidth += $(this).width() });
        var padl = ($(this).innerWidth() - tabtotwidth)/2 ;
        if (padl < 0) padl = 0 ;
        $(this).css('padding-left', padl ) ;
      }
    });
  };
})(jQuery);

(function($){
  jQuery.fn.setTabHoverClass = function(hvrclass){
      return this.each(
        function(){
          $(this).hover(
            function(){ if (!$(this).hasClass('opentab')) $(this).addClass(hvrclass) ; },
            function(){ $(this).removeClass(hvrclass) ; }
          );
        }
      ) ;
  };
})(jQuery);


/* functions */

jQuery.switchBG = function(el) {
  if ( typeof(gp.bgindex) == 'undefined' ) { 
    gp.bgindex = 0 ;
    for (var i = 0; i < gp.bg.length; i++) {
      if ( gp.bg[i] == cC.crumbs.currentBG.value ) {
        gp.bgindex = i ;
        break ;
      }
    }
  }
  if (el.value == 'next' || el.value == '&gt;') { gp.bgindex ++ ; }
  if (el.value == 'prev' || el.value == '&lt;') { gp.bgindex -- ; }

  if (gp.bgindex >= gp.bg.length) { gp.bgindex = 0 ; }
  if (gp.bgindex < 0) { gp.bgindex = gp.bg.length-1 ; }

  cC.crumbs.currentBG.update(gp.bg[gp.bgindex]) ;
};

jQuery.cssurlwrap = function(fname) {
  return "url(" + fname + ")" ;
} ;

jQuery.isProp = function(objprop) { 
  if ( (typeof objprop == 'function') || (typeof objprop == 'undefined') ) { return false } ;
  return true ;
};
   

jQuery.popblock = function(e) {
  var popobjid = 'tab-' + e.id.substr(e.id.indexOf('-')+1) ;
  if (e.childNodes) {
    var accordiansymbol = (e.childNodes[0].className == 'accordinator') ? e.childNodes[0] : false ;
  } else {
    var accordiansymbol = false ;
  }
  var ee = document.getElementById(popobjid) ;
  if (ee.style.display == '') {ee.style.display = 'none'}
  if (ee.style.display == 'none') {
   ee.style.display = 'block' ;
   if (accordiansymbol) { accordiansymbol.innerHTML = "&ndash;" }
  } else {
   ee.style.display = 'none' ;
   if (accordiansymbol) { accordiansymbol.innerHTML = "+" }
  }
};


jQuery.popblock2 = function(e) {
  var popobjid = 'tab-' + e.id.substr(e.id.indexOf('-')+1) ;
  var ee = document.getElementById(popobjid) ;
  if (ee.style.display == '') {
    if (ee.offsetHeight > 0) {ee.style.display = 'block'} else {ee.style.display = 'none'} ;
  }
  if (ee.style.display == 'none') {
   ee.style.display = 'block' ;
  } else {
   ee.style.display = 'none' ;
  }
};





jQuery.usd = {

  usd : function(dollars){
    return dollars.toFixed(2) ;
  },

  fCalc : function(dollars,rate){
    return ( parseFloat( dollars ) * parseFloat( rate ) ).toFixed(2) ;
  },

  iCalc : function(dollars,quantity){
    return ( parseFloat( dollars ) * parseInt( quantity ) ).toFixed(2) ;
  },

  sum : function(){
    var args = jQuery.usd.sum.arguments ;
    var total = 0 ;
    if (args.length) {
      for (var i = 0; i < args.length; i++) {
        total += parseFloat(args[i]) ;
      }
    }
    return total.toFixed(2) ;
  },

  less : function(){
    var args = jQuery.usd.less.arguments ;
    var total = (args.length) ? args[0] : 0 ;
    if (args.length > 1) {
      for (var i = 1; i < args.length; i++) {
        total -= parseFloat(args[i]) ;
      }
    } else if (args.length == 1) {
       total = args[0] ;
    } else {
       total = 0 ;
    }
    return total.toFixed(2) ;
  }
  
};

jQuery.insertAtCaret = function(areaId,text) { 
  var txtarea = document.getElementById(areaId);
  //alert(txtarea.tagName) ;
  var scrollPos = txtarea.scrollTop; 
  var strPos = 0;
  var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false ) );
  if (br == "ie") { 
    txtarea.focus();
    var range = document.selection.createRange();
    range.moveStart ('character', -txtarea.value.length);
    strPos = range.text.length;
  } else if (br == "ff") {
    strPos = txtarea.selectionStart;
  }
  
  var front = (txtarea.value).substring(0,strPos);
  var back = (txtarea.value).substring(strPos,txtarea.value.length);
  txtarea.value=front+text+back;
  strPos = strPos + text.length;
  
  if (br == "ie") { 
    txtarea.focus();
    var range = document.selection.createRange();
    range.moveStart ('character', -txtarea.value.length);
    range.moveStart ('character', strPos);
    range.moveEnd ('character', 0);
    range.select();
  } else if (br == "ff") { 
    txtarea.selectionStart = strPos;
    txtarea.selectionEnd = strPos;
    txtarea.focus();
  } 
  
  txtarea.scrollTop = scrollPos;
  
};


//window.location object manipulations
jQuery.extend({
  loco: {
    getVars: function(){
      var vars = [], hash;
      var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
      for(var i = 0; i < hashes.length; i++)
      {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
      }
      return vars;
    },
    getVar: function(name){
      return $.getUrlVars()[name];
    },
  		getHash: function(name){
  		  var hash = location.hash.substring(1) ;
  				if (!hash) return '' ;
  				if (name === false) return hash ;
  				if (!hash.indexOf(':')) return '' ;
  		  var directive = hash.split(':') ;
  				if ( directive[0] == name ) {
    				return directive[1] ;
  				} else {
  				  return '' ;
  				}
  		},
  		updateHashX: function(name,value){
  		  var hash = location.hash.substring(1) ;
  				var newval = '#' + name + ':' + value ;
  				if ( hash.indexOf(name) != -1 ) {
  				  if ( location.hash != newval ) location.hash = newval ;
  				}
  		},
  		setHashX: function(name,value){
  				var newval = '#' + name + ':' + value ;
  				location.hash = newval ;
  		}
  }
});

jQuery.gapiReady = function(sub){
  if (typeof google == 'undefined') return false ;
		if (sub) {
		  if (typeof google[sub] == 'object') return true ;
		}
		return false ;
}

jQuery.isUndefined = function(x) {
  var u ;
  return x === u ;
};


/* other people's code */

/* original file: jquery.cookie.js Copyright (c) 2006 Klaus Hartl */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined'  ||  (name  &&  typeof name != 'string')) { // name and value given, set cookie
        if (typeof name == 'string') {
            options = options || {};
            if (value === null) {
                value = '';
                options.expires = -1;
            }
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                } else {
                    date = options.expires;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            // CAUTION: Needed to parenthesize options.path and options.domain
            // in the following expressions, otherwise they evaluate to undefined
            // in the packed version for some reason...
            var path = options.path ? '; path=' + (options.path) : '';
            var domain = options.domain ? '; domain=' + (options.domain) : '';
            var secure = options.secure ? '; secure' : '';
            document.cookie = name + '=' + encodeURIComponent(value) + expires + path + domain + secure;
        } else { // `name` is really an object of multiple cookies to be set.
          for (var n in name) { jQuery.cookie(n, name[n], value||options); }
        }
    } else { // get cookie (or all cookies if name is not provided)
        var returnValue = {};
        if (document.cookie) {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (!name) {
                    var nameLength = cookie.indexOf('=');
                    returnValue[ cookie.substr(0, nameLength)] = decodeURIComponent(cookie.substr(nameLength+1));
                } else if (cookie.substr(0, name.length + 1) == (name + '=')) {
                    returnValue = decodeURIComponent(cookie.substr(name.length + 1));
                    break;
                }
            }
        }
        return returnValue;
    }
};

/**
 * jQuery.timers - Timer abstractions for jQuery
 * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
 * Date: 2009/02/08
 *
 * @author Blair Mitchelmore
 * @version 1.1.2
 *
 **/

jQuery.fn.extend({
 everyTime: function(interval, label, fn, times, belay) {
  return this.each(function() {
   jQuery.timer.add(this, interval, label, fn, times, belay);
  });
 },
 oneTime: function(interval, label, fn) {
  return this.each(function() {
   jQuery.timer.add(this, interval, label, fn, 1);
  });
 },
 stopTime: function(label, fn) {
  return this.each(function() {
   jQuery.timer.remove(this, label, fn);
  });
 }
});

jQuery.event.special

jQuery.extend({
 timer: {
  global: [],
  guid: 1,
  dataKey: "jQuery.timer",
  regex: /^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/,
  powers: {
   // Yeah this is major overkill...
   'ms': 1,
   'cs': 10,
   'ds': 100,
   's': 1000,
   'das': 10000,
   'hs': 100000,
   'ks': 1000000
  },
  timeParse: function(value) {
   if (value == undefined || value == null)
    return null;
   var result = this.regex.exec(jQuery.trim(value.toString()));
   if (result[2]) {
    var num = parseFloat(result[1]);
    var mult = this.powers[result[2]] || 1;
    return num * mult;
   } else {
    return value;
   }
  },
  add: function(element, interval, label, fn, times, belay) {
   var counter = 0;
   
   if (jQuery.isFunction(label)) {
    if (!times) 
     times = fn;
    fn = label;
    label = interval;
   }
   
   interval = jQuery.timer.timeParse(interval);

   if (typeof interval != 'number' || isNaN(interval) || interval <= 0)
    return;

   if (times && times.constructor != Number) {
    belay = !!times;
    times = 0;
   }
   
   times = times || 0;
   belay = belay || false;
   
   var timers = jQuery.data(element, this.dataKey) || jQuery.data(element, this.dataKey, {});
   
   if (!timers[label])
    timers[label] = {};
   
   fn.timerID = fn.timerID || this.guid++;
   
   var handler = function() {
    if (belay && this.inProgress) 
     return;
    this.inProgress = true;
    if ((++counter > times && times !== 0) || fn.call(element, counter) === false)
     jQuery.timer.remove(element, label, fn);
    this.inProgress = false;
   };
   
   handler.timerID = fn.timerID;
   
   if (!timers[label][fn.timerID])
    timers[label][fn.timerID] = window.setInterval(handler,interval);
   
   this.global.push( element );
   
  },
  remove: function(element, label, fn) {
   var timers = jQuery.data(element, this.dataKey), ret;
   
   if ( timers ) {
    
    if (!label) {
     for ( label in timers )
      this.remove(element, label, fn);
    } else if ( timers[label] ) {
     if ( fn ) {
      if ( fn.timerID ) {
       window.clearInterval(timers[label][fn.timerID]);
       delete timers[label][fn.timerID];
      }
     } else {
      for ( var fn in timers[label] ) {
       window.clearInterval(timers[label][fn]);
       delete timers[label][fn];
      }
     }
     
     for ( ret in timers[label] ) break;
     if ( !ret ) {
      ret = null;
      delete timers[label];
     }
    }
    
    for ( ret in timers ) break;
    if ( !ret ) 
     jQuery.removeData(element, this.dataKey);
   }
  }
 }
});

jQuery(window).bind("unload", function() {
 jQuery.each(jQuery.timer.global, function(index, item) {
  jQuery.timer.remove(item);
 });
});


// jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
// Copyright © 2008 George McGinley Smith
// t: current time, b: begInnIng value, c: change In value, d: duration

jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});


/*
 * jQuery JSON Plugin
 * version: 2.1 (2009-08-14)
 *
 * This document is licensed as free software under the terms of the
 * MIT License: http://www.opensource.org/licenses/mit-license.php
 *
 * Brantley Harris wrote this plugin. It is based somewhat on the JSON.org 
 * website's http://www.json.org/json2.js, which proclaims:
 * "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that
 * I uphold.
 *
 * It is also influenced heavily by MochiKit's serializeJSON, which is 
 * copyrighted 2005 by Bob Ippolito.
 */
(function($) {
    /** jQuery.toJSON( json-serializble )
        Converts the given argument into a JSON respresentation.

        If an object has a "toJSON" function, that will be used to get the representation.
        Non-integer/string keys are skipped in the object, as are keys that point to a function.

        json-serializble:
            The *thing* to be converted.
     **/
    $.toJSON = function(o)
    {
        if (typeof(JSON) == 'object' && JSON.stringify)
            return JSON.stringify(o);
        
        var type = typeof(o);
    
        if (o === null)
            return "null";
    
        if (type == "undefined")
            return undefined;
        
        if (type == "number" || type == "boolean")
            return o + "";
    
        if (type == "string")
            return $.quoteString(o);
    
        if (type == 'object')
        {
            if (typeof o.toJSON == "function") 
                return $.toJSON( o.toJSON() );
            
            if (o.constructor === Date)
            {
                var month = o.getUTCMonth() + 1;
                if (month < 10) month = '0' + month;

                var day = o.getUTCDate();
                if (day < 10) day = '0' + day;

                var year = o.getUTCFullYear();
                
                var hours = o.getUTCHours();
                if (hours < 10) hours = '0' + hours;
                
                var minutes = o.getUTCMinutes();
                if (minutes < 10) minutes = '0' + minutes;
                
                var seconds = o.getUTCSeconds();
                if (seconds < 10) seconds = '0' + seconds;
                
                var milli = o.getUTCMilliseconds();
                if (milli < 100) milli = '0' + milli;
                if (milli < 10) milli = '0' + milli;

                return '"' + year + '-' + month + '-' + day + 'T' +
                             hours + ':' + minutes + ':' + seconds + 
                             '.' + milli + 'Z"'; 
            }

            if (o.constructor === Array) 
            {
                var ret = [];
                for (var i = 0; i < o.length; i++)
                    ret.push( $.toJSON(o[i]) || "null" );

                return "[" + ret.join(",") + "]";
            }
        
            var pairs = [];
            for (var k in o) {
                var name;
                var type = typeof k;

                if (type == "number")
                    name = '"' + k + '"';
                else if (type == "string")
                    name = $.quoteString(k);
                else
                    continue;  //skip non-string or number keys
            
                if (typeof o[k] == "function") 
                    continue;  //skip pairs where the value is a function.
            
                var val = $.toJSON(o[k]);
            
                pairs.push(name + ":" + val);
            }

            return "{" + pairs.join(", ") + "}";
        }
    };

    /** jQuery.evalJSON(src)
        Evaluates a given piece of json source.
     **/
    $.evalJSON = function(src)
    {
        if (typeof(JSON) == 'object' && JSON.parse)
            return JSON.parse(src);
        return eval("(" + src + ")");
    };
    
    /** jQuery.secureEvalJSON(src)
        Evals JSON in a way that is *more* secure.
    **/
    $.secureEvalJSON = function(src)
    {
        if (typeof(JSON) == 'object' && JSON.parse)
            return JSON.parse(src);
        
        var filtered = src;
        filtered = filtered.replace(/\\["\\\/bfnrtu]/g, '@');
        filtered = filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']');
        filtered = filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, '');
        
        if (/^[\],:{}\s]*$/.test(filtered))
            return eval("(" + src + ")");
        else
            throw new SyntaxError("Error parsing JSON, source is not valid.");
    };

    /** jQuery.quoteString(string)
        Returns a string-repr of a string, escaping quotes intelligently.  
        Mostly a support function for toJSON.
    
        Examples:
            >>> jQuery.quoteString("apple")
            "apple"
        
            >>> jQuery.quoteString('"Where are we going?", she asked.')
            "\"Where are we going?\", she asked."
     **/
    $.quoteString = function(string)
    {
        if (string.match(_escapeable))
        {
            return '"' + string.replace(_escapeable, function (a) 
            {
                var c = _meta[a];
                if (typeof c === 'string') return c;
                c = a.charCodeAt();
                return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
            }) + '"';
        }
        return '"' + string + '"';
    };
    
    var _escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;
    
    var _meta = {
        '\b': '\\b',
        '\t': '\\t',
        '\n': '\\n',
        '\f': '\\f',
        '\r': '\\r',
        '"' : '\\"',
        '\\': '\\\\'
    };
})(jQuery);

