Shadowbox.init();

(function ($) {
$.fn.vAlign = function() {
  return this.each(function(i){
  var ah = $(this).height();
  var ph = $(this).parent().height();
  var mh = (ph - ah) / 2;
  $(this).css('margin-top', mh);
  });
};
})(jQuery);

(function($) {
  $.extend($.fn, {
    caret: function (start, end) {
      var elem = this[0];

      if (elem) {             
        // get caret range
        if (typeof start == "undefined") {
          if (elem.selectionStart) {
            start = elem.selectionStart;
            end = elem.selectionEnd;
          }
          else if (document.selection) {
            var val = this.val();
            var range = document.selection.createRange().duplicate();
            range.moveEnd("character", val.length)
            start = (range.text == "" ? val.length :
val.lastIndexOf(range.text));

            range = document.selection.createRange().duplicate();
            range.moveStart("character", -val.length);
            end = range.text.length;
          }
        }
        // set caret range
        else {
          var val = this.val();

          if (typeof start != "number") start = -1;
          if (typeof end != "number") end = -1;
          if (start < 0) start = 0;
          if (end > val.length) end = val.length;
          if (end < start) end = start;
          if (start > end) start = end;

          elem.focus();

          if (elem.selectionStart) {
            elem.selectionStart = start;
            elem.selectionEnd = end;
          }
          else if (document.selection) {
            var range = elem.createTextRange();
            range.collapse(true);
            range.moveStart("character", start);
            range.moveEnd("character", end - start);
            range.select();
          }
        }

        return {start:start, end:end};
      }
    }
  });
})(jQuery);

(function($) {
  $.fn.tainsert = function(what) {
    return this.each(function() {
      $this = $(this);
      var range = $this.caret();
      var tmp = $this.val();
      if (!range.start) {
        $this.val(what + tmp.substr(0, tmp.length));
      } else {
        $this.val(tmp.substr(0, range.start) + what + tmp.substr(range.end, tmp.length));
      }
    });
  };
  $.fn.taextend = function(pre, post) {
    return this.each(function() {
      $this = $(this);
      var range = $this.caret();
      var tmp = $this.val();
      $this.val(tmp.substr(0,range.start) + pre + tmp.substr(range.start, range.end-range.start) + post + tmp.substr(range.end, tmp.length));
    });
  };
})(jQuery);
    
/*
$.fn.dropdown = function() {
  $(this).hover(function(){
    $(this).addClass("hover");
    $('> .dir',this).addClass("open");
    $('ul:first',this).css('visibility', 'visible');
  },function(){
    $(this).removeClass("hover");
    $('.open',this).removeClass("open");
    $('ul:first',this).css('visibility', 'hidden');
  });
}
*/

(function($){var textarea,staticOffset;var iLastMousePos=0;var iMin=32;var grip;$.fn.TextAreaResizer=function(){return this.each(function(){textarea=$(this).addClass('processed'),staticOffset=null;$(this).wrap('<div class="resizable-textarea"><span></span></div>').parent().append($('<div class="grippie"></div>').bind("mousedown",{el:this},startDrag));var grippie=$('div.grippie',$(this).parent())[0];grippie.style.marginRight=(grippie.offsetWidth-$(this)[0].offsetWidth)+'px'})};function startDrag(e){textarea=$(e.data.el);textarea.blur();iLastMousePos=mousePosition(e).y;staticOffset=textarea.height()-iLastMousePos;textarea.css('opacity',0.25);$(document).mousemove(performDrag).mouseup(endDrag);return false}function performDrag(e){var iThisMousePos=mousePosition(e).y;var iMousePos=staticOffset+iThisMousePos;if(iLastMousePos>=(iThisMousePos)){iMousePos-=5}iLastMousePos=iThisMousePos;iMousePos=Math.max(iMin,iMousePos);textarea.height(iMousePos+'px');if(iMousePos<iMin){endDrag(e)}return false}function endDrag(e){$(document).unbind('mousemove',performDrag).unbind('mouseup',endDrag);textarea.css('opacity',1);textarea.focus();textarea=null;staticOffset=null;iLastMousePos=0}function mousePosition(e){return{x:e.clientX+document.documentElement.scrollLeft,y:e.clientY+document.documentElement.scrollTop}}})(jQuery);
(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
$(document).ready(function(){
  $('.flash_notice').click(function() {
    $('.flash_notice').clearQueue().slideUp(1000);
  });
  $('.flash_notice').delay(5000).slideUp(1000);

  $('.flash_error').click(function() {
    $('.flash_error').clearQueue().slideUp(1000);
  });
  $('.flash_error').delay(5000).slideUp(1000);

  $('textarea:not(.processed)').TextAreaResizer();
/*
  $('#col3_content a[href^=http]').each(function() {
    $this = $(this);
    $this.wrap('<span style="position:relative;" />');
    $this.parent().prepend('<span style="display:none; position:absolute; top:20px; left: 20px; padding: 5px; border: 1px solid #000; background: #fff;"><img src="http://images.websnapr.com/?size=S&key=7dk0wv7N29Uk&url='+$this.attr('href')+'"/></span>');
    $this.mouseenter(function() {
        $this = $(this);
        $this.prev().show();
      });
    $this.mouseleave(function() {
        $this = $(this);
        $this.prev().hide();
      });
  });
*/
});
