/**
 * Cookie plugin
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        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].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && 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 (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


// http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
(function($){$.fn.hint=function(blurClass){if(!blurClass){blurClass='blur'}return this.each(function(){var $input=$(this),title=$input.attr('title'),$form=$(this.form),$win=$(window);function remove(){if($input.val()===title&&$input.hasClass(blurClass)){$input.val('').removeClass(blurClass)}}if(title){$input.blur(function(){if(this.value===''){$input.val(title).addClass(blurClass)}}).focus(remove).blur();$form.submit(remove);$win.unload(remove)}})}})(jQuery);

  $(function(){ 
	$('input[title!=""]').hint();
  });

// HoverIntent - delay drop down for tabs
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:3,interval:200,timeout:50};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

// zebra tables
window.onload=function(){jQuery(".tSkin tr:nth-child(odd)").addClass("alt")};

/*
 Tooltip script
*/

 // 'tooltipObjFlag' can be defined outside the script. It makes the script load tooltip content
 // from object id contained in the title, e.g. title='###test1'... will load content from #test1
 if (typeof(tooltipObjFlag)=='undefined') { var tooltipObjFlag = '###' }

 // 'tooltipSpeed' sets the display speed of the tooltip
 if (typeof(tooltipSpeed)=='undefined') { var tooltipSpeed = 300 }
 
 // 'tooltipLocal' is a flag that tells the script to attach the tooltip locally if set to true. If
 // false the tooltip is added to the body
 if (typeof(tooltipLocal)=='undefined') { var tooltipLocal = false }

 var xOffset = 20; // Don't use negative values here
 var yOffset = 20;

 var tooltipCSS = 'position:absolute;z-index:1000;';

this.tooltip = function(){
// Tooltips
 $('.tooltip').live('mouseover',function(e) {
  this.t = (this.title == '') ? this.t : this.title;
  var ttt = this.t;
  this.title = '';
  // Load tooltip content from an object
  var rx = new RegExp('^' + tooltipObjFlag);
  if (rx.test(ttt)) {
   tte = ttt.replace(rx,'#').split(' ')[0];
   // ignore the tooltipObjFlag if too short or too long (20 characters seemed reasonable)
   if (tte.length < 1 || tte.length > 20) {
    ttt = this.t;
   } else {
    ttt = $(tte).html();
   }
  }
  // replace new line with <br> (thanks Zbigniew!), or you can just use <br> in the title ;)
  ttt = ttt.replace(/\\n/g,'<br>');

  // retrieves width and color information from the rel attribute
  // rel='250,#000000;color:#ffffff;' => tooltip width = 250, background color = #000000, text = #ffffff
  var tmp = (typeof($(this).attr('rel'))=='undefined') ? '' : $(this).attr('rel').split(',');
  this.w = (tmp[0] == '') ? $('#tooltip').width() : tmp[0];
  this.c = (typeof(tmp[1])=='undefined') ? '' : 'background-color:' + tmp[1];
  var tmp = "<div id='tooltip' style='" + tooltipCSS + "width:" + this.w + "px;" + this.c + "'>" + ttt + "</div>";
  if (tooltipLocal){
   $(this).before(tmp);
  } else {
   $('body').append(tmp);
  }
  ttrelocate(e,'#tooltip');
  $('#tooltip').fadeIn(tooltipSpeed);
 })
 $('.tooltip').live('mouseout',function(e) {
  this.title = this.t;
  $('#tooltip').remove();
 });
 $('.tooltip').live('mousemove',function(e) {
  ttrelocate(e,'#tooltip');
 });
// Image & URL screenshot preview
 $('a.preview,a.screenshot').live('mouseover',function(e){
  this.t = this.title;
  this.title = '';
  var tmp = "<div id='preview' style='" + tooltipCSS + "'><img src='";
  var c = (this.t != '') ? '<br/>' + this.t : '';
  /* use websnapr.com to get website thumbnail preview if rel="#" */
  var ss = ($(this).hasClass('screenshot') && this.rel=="#") ? 'http://images.websnapr.com/?url=' + this.href : this.rel;
  tmp += ($(this).hasClass('preview')) ? this.href + "' alt='Image preview' />" : ss + "' alt='URL preview' />";
  tmp += c +"</div>";
  if (tooltipLocal){
   $(this).before(tmp);
  } else {
   $('body').append(tmp);
  }
  ttrelocate(e,'#preview');
  $('#preview').fadeIn(tooltipSpeed);
 })
 $('a.preview,a.screenshot').live('mouseout',function(e){
  this.title = this.t;
  $('#preview').remove();
 }); 
 $('a.preview,a.screenshot').live('mousemove',function(e){
  ttrelocate(e,'#preview');
 });
}
function ttrelocate(e,ttid){
 var ttw = $(ttid).width();
 var tth = $(ttid).height();
 var wscrY = $(window).scrollTop();
 var wscrX = $(window).scrollLeft();
 var curX = (document.all) ? event.clientX + wscrX : e.pageX;
 var curY = (document.all) ? event.clientY + wscrY : e.pageY;
 var ttleft = ((curX - wscrX + xOffset*2 + ttw) > $(window).width()) ? curX - ttw - xOffset : curX + xOffset;
 if (ttleft < wscrX + xOffset) ttleft = wscrX + xOffset;
 var tttop = ((curY - wscrY + yOffset*2 + tth) > $(window).height()) ? curY - tth - yOffset : curY + yOffset;
 if (tttop < wscrY + yOffset) tttop = curY + yOffset;
 $(ttid).css('top', tttop + 'px').css('left', ttleft + 'px');
}

// Convert ddrivetip functions (http://www.dynamicdrive.com/dynamicindex5/dhtmltooltip.htm)
// to work with this tooltip
function ddrivetip(ttt,ttc,ttw){
 var ttc = (ttc == '') ? '' : 'background-color:' + ttc;
 $('body').append("<div id='tooltip2' style='" + tooltipCSS + "width:" + ttw + "px;" + ttc + "'>" + ttt + "</div>");
 $('#tooltip2').fadeIn(tooltipSpeed);
}
function hideddrivetip(){
 $('#tooltip2').remove();
}
function positiontip(evt){
 if ($('#tooltip2').length) ttrelocate(evt,'#tooltip2');
}
document.onmousemove = positiontip;

$(document).ready(function(){
 tooltip();
});


