/*
 * VJustify (http://michael.futreal.com/jquery/vjustify)
 */
jQuery.fn.vjustify=function() {
    var maxHeight=0;
    this.each(function(){
        if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
    });
    this.each(function(){
        $(this).height(maxHeight + "px");
        if (this.offsetHeight>maxHeight) {
            $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
        }
    });
};

/*
 * Jonathan Howard
 *
 * jQuery Pause
 * version 0.2
 *
 * Requires: jQuery 1.0 (tested with svn as of 7/20/2006)
 *
 */

$.fn.pause = function(milli,type) {
	milli = milli || 1000;
	type = type || "fx";
	return this.queue(type,function(){
		var self = this;
		setTimeout(function(){
			$(self).dequeue();
		},milli);
	});
};

$.fn.unpause = function(type) {
	return this.each(function(){
		type = type || "fx";
		if(this.queue && this.queue[type]) {
			this.queue[type].length = 0;
		}
	});
};

/*
 * JTip
 * By Cody Lindley (http://www.codylindley.com)
 * Under an Attribution, Share Alike License
 * JTip is built on top of the very light weight jquery library.
 
 * Modifications by Rey Bango and Karl Swedberg
 */

//on page load (as soon as it is ready) call JT_init
$(document).ready(JT_init);

function JT_init(){
	// 9/21/06 - Rey Bango added hide() method to correct an issue with FF
	$("a.jTip")
	  .hover(function() {
	    JT_show(this.href,this.id,this.name)
	  },function() {
	    $('#JT, #JT_arrow_left, #JT_arrow_right').hide().remove();
	  })
    .click(function(){return false});	   
}

function JT_show(url,linkId,title){
	if(title == false)title="&nbsp;";
	var de = document.documentElement;
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var hasArea = w - getAbsoluteLeft(linkId);
	var clickElementy = getAbsoluteTop(linkId) - 3; //set y position
	
	var queryString = url.replace(/^[^\?]+\??/,'');
	var params = parseQuery( queryString );
	if(params['width'] === undefined){params['width'] = 250};
	if(params['link'] !== undefined){
  	$('#' + linkId).bind('click',function(){window.location = params['link']});
  	$('#' + linkId).css('cursor','pointer');
	}
	
	if(hasArea>((params['width']*1)+75)){
		$("body").append("<div id='JT' style='width:"+params['width']*1+"px'><div id='JT_close_left'>"+title+"</div><div id='JT_copy'><div class='JT_loader'><div></div></div>");//right side
		$('body').append('<div id="JT_arrow_left"></div>'); 
		var arrowOffset = getElementWidth(linkId) + 11;
		var clickElementx = getAbsoluteLeft(linkId) + arrowOffset; //set x position
    $('#JT_arrow_left').css({left: (clickElementx - 10) + "px", top: clickElementy +"px"});		
	}else{
		$("body").append("<div id='JT' style='width:"+params['width']*1+"px'><div id='JT_close_right'>"+title+"</div><div id='JT_copy'><div class='JT_loader'><div></div></div>");//left side
		$('body').append('<div id="JT_arrow_right"></div>');
		var clickElementx = getAbsoluteLeft(linkId) - ((params['width']*1) + 20); //set x position
	  $('#JT_arrow_right').css({left: (getAbsoluteLeft(linkId) - 20) + "px", top: clickElementy + "px"});		
	}
	if ($.browser.msie) { 
		$('#JT').prepend('<iframe id="jTipiFrame"></iframe>'); // iframe for IE select box z-index issue
	  $('#jTipiFrame').width((params['width']*1) + "px");	
	}	
	$('#JT').css({left: clickElementx+"px", top: clickElementy +"px"});
   
	$('#JT_copy').load(url, function() {
	  //if jtip goes to left side and is partially cut off at left of doc...	  
	  if ($('#JT_arrow_right') && clickElementx < 0) {
	    var JT_width = (getAbsoluteLeft(linkId) - 22);
	    $('#JT').css({left: 2, width: JT_width}); //adjust width to fit
	  }
	  //get the height of the jtip after loading it
	  var jtip_height = $('#JT').height();
	  //adjust the top of jTip
	  move_jtip();
	  if ( (scroll_position + window_height) - clickElementy < jtip_height ) {
	    var adjusted_top = (window_height - jtip_height) - 6 + scroll_position;
      if ( adjusted_top - scroll_position < 0 ) {
        $('#JT').css({top: scroll_position + 1});
      } else {
        $('#JT').css({top: adjusted_top});
      }
    }      
	}); // end .load()
	$('#JT').show();
} // end JT_show()

function getElementWidth(objectId) {
	x = document.getElementById(objectId);
	return x.offsetWidth;
}

function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	return oLeft
}

function getAbsoluteTop(objectId) {
	// Get an object top position from the upper left viewport corner
	o = document.getElementById(objectId);
	oTop = 0;
	if(o.offsetParent) {
	  o = o.offsetParent;
	}
	while(o) { // Parse the parent hierarchy up to the document element
		oTop += o.offsetTop; // Add parent top position
		o = o.offsetParent;
	}
	return oTop
}

function parseQuery ( query ) {
   var Params = new Object ();
   if ( ! query ) return Params; // return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) continue;
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}
function move_jtip() {
  if (window.innerHeight) {
	  scroll_position = window.pageYOffset;
	  window_height = window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.scrollTop) {
		scroll_position = document.documentElement.scrollTop;
    window_height = document.documentElement.clientHeight;
	}
	else if (document.body) {
	  scroll_position = document.body.scrollTop;
	  window_height = document.body.clientHeight;
	}
}

function blockEvents(evt) {
  if(evt.target){
    evt.preventDefault();
  }else{
    evt.returnValue = false;
  }
}

/**
 * jQBrowser v0.2 - Extend jQuery's browser detection capabilities
 * Dave Cardwell <http://davecardwell.co.uk/>
 * Copyright (c) 2006 Dave Cardwell, dual licensed under the MIT and GPL
 * licenses:
 *   * http://www.opensource.org/licenses/mit-license.php
 *   * http://www.gnu.org/licenses/gpl.txt
 */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[(function(e){return d[e]})];e=(function(){return'\\w+'});c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('G 3(){h e={\'6\':\'r\',\'f\':{\'q\':m,\'t\':\'r\'},\'j\':\'r\',\'F\':7,\'1c\':7,\'1k\':7,\'14\':7,\'15\':7,\'X\':7,\'17\':7,\'z\':7,\'18\':7,\'I\':7,\'19\':7,\'1h\':7,\'1a\':7,\'E\':7};$.6=e;y(h i=0,c=p.1b,k=p.1d,4=[{\'2\':\'1e\',\'6\':3(){5/1f/.8(k)}},{\'2\':\'1g\',\'6\':3(){5 1i.I!=m}},{\'2\':\'M\',\'6\':3(){5/M/.8(k)}},{\'2\':\'1j\',\'6\':3(){5/Q/.8(k)}},{\'9\':\'F\',\'2\':\'R A\',\'6\':3(){5/S T U/.8(c)},\'f\':3(){5 c.n(/V(\\d+(?:\\.\\d+)+)/)}},{\'2\':\'v\',\'6\':3(){5/v/.8(c)}},{\'2\':\'P\',\'6\':3(){5/P/.8(k)}},{\'2\':\'u\',\'6\':3(){5/u/.8(c)}},{\'2\':\'x\',\'6\':3(){5/x/.8(c)}},{\'9\':\'z\',\'2\':\'W A\',\'6\':3(){5/B/.8(c)},\'f\':3(){5 c.n(/B (\\d+(?:\\.\\d+)+(?:b\\d*)?)/)}},{\'2\':\'O\',\'6\':3(){5/Y|O/.8(c)},\'f\':3(){5 c.n(/10:(\\d+(?:\\.\\d+)+)/)}}];i<4.w;i++){l(4[i].6()){h 9=4[i].9?4[i].9:4[i].2.H();e[9]=L;e.6=4[i].2;h g;l(4[i].f!=m&&(g=4[i].f())){e.f.t=g[1];e.f.q=D(g[1])}11{h K=G 13(4[i].2+\'(?:\\\\s|\\\\/)(\\\\d+(?:\\\\.\\\\d+)+(?:(?:a|b)\\\\d*)?)\');g=c.n(K);l(g!=m){e.f.t=g[1];e.f.q=D(g[1])}}C}};y(h i=0,o=p.Z,4=[{\'9\':\'E\',\'2\':\'12\',\'j\':3(){5/16/.8(o)}},{\'2\':\'J\',\'j\':3(){5/J/.8(o)}},{\'2\':\'N\',\'j\':3(){5/N/.8(o)}}];i<4.w;i++){l(4[i].j()){h 9=4[i].9?4[i].9:4[i].2.H();e[9]=L;e.j=4[i].2;C}}}();',62,83,'||name|function|data|return|browser|false|test|identifier|||ua||private|version|result|var||OS|ve|if|undefined|match|pl|navigator|number|Unknown||string|Firefox|Flock|length|Netscape|for|msie|Explorer|MSIE|break|parseFloat|win|aol|new|toLowerCase|opera|Mac|re|true|iCab|Linux|Mozilla|Camino|KDE|AOL|America|Online|Browser|rev|Internet|konqueror|Gecko|platform|rv|else|Windows|RegExp|flock|icab|Win|mozilla|netscape|safari|mac|userAgent|camino|vendor|Safari|Apple|Opera|linux|window|Konqueror|firefox'.split('|'),0,{}))


// =========================================================
// jq-innerfade.js
// Datum: 2006-09-01
// Firma: Medienfreunde Hofmann & Baldes GbR
// Autor: Torsten Baldes
// Mail: t.baldes@medienfreunde.com
// Web: http://medienfreunde.com
// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/
// =========================================================

$.fn.innerfade = function(options) {
	return this.each(function(){ 	
		
		var settings = {
			speed: 'normal',
			timeout: 2000,
			type: 'sequence',
			containerheight: 'auto'
		}
		
		if (options) {
			$.extend(settings, options);
		}
		
		var elements = $(this).children().get();
	
		if (elements.length > 1) {
		
			$(this).css('height', settings.containerheight);
			
			for ( var i = 0; i < elements.length; i++ ) {
				$(elements[i]).css('position', 'absolute');
				$(elements[i]).hide();
			}
		
			if ( settings.type == 'sequence' ) {
				setTimeout(function(){
					$.innerfade.next(elements, settings, 1, 0);
				}, settings.timeout);
				$(elements[0]).show();
			}
			else if ( settings.type == 'random' ) {
				setTimeout(function(){
					do { current = Math.floor ( Math.random ( ) * ( elements.length ) ); } while ( current == 0 );
					$.innerfade.next(elements, settings, current, 0);
				}, settings.timeout);
				$(elements[0]).show();
			}
			else {
				alert('type must either be \'sequence\' or \'random\'');
			}
			
		}
		
	});
};

$.innerfade = function() {};
$.innerfade.next = function (elements, settings, current, last) {

	$(elements[last]).fadeOut(settings.speed);
	$(elements[current]).fadeIn(settings.speed);
	
	if ( settings.type == 'sequence' ) {
		if ( ( current + 1 ) < elements.length ) {
			current = current + 1;
			last = current - 1;
		}
		else {
			current = 0;
			last = elements.length - 1;
		}
	}
	else if ( settings.type == 'random' ) {
		last = current;
		while (	current == last ) {
			current = Math.floor ( Math.random ( ) * ( elements.length ) );
		}
	}
	else {
		alert('type must either be \'sequence\' or \'random\'');
	}
	setTimeout(function(){$.innerfade.next(elements, settings, current, last);}, settings.timeout);
};

// pngFix (http://jquery.com/docs/Plugins/pngFix/)
jQuery.fn.pngFix = function() {
	return this.each(function() {
		if ($.browser.msie && $.browser.version.number < 7) {
			$(this).css("filter","progid:DXImageTransform.Microsoft.Alpha(opacity=0);").wrap("<span style=\"width:" + $(this).width() + "px; height: " + $(this).height() + "px; display:inline-block; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + $(this).attr('src') + "');\"></span>");
		}
	});
};
