/*
 * share.js 1.0.9
 * Modified:  2010-02-28
 * Kosaido.Inc.
 * @author Ryo Ueda & Kazuhito Shiba
 */

(function($) {

$(function() {
	$.yuga.externalLink({
	
		//画像のパスは適時変更
		blankIconPath: '<img src="/common/img/blank.gif" alt="別ウィンドウで開きます" class="externalIcon" />',
	
		//MT等のCMSで勝手に絶対パスで記述され別窓が開いてしまう場合は http://example.com/example/の部分を書き換えること
		notWindowURL: 'a[href^="http://www.kun-ei.ac.jp/"],a[href^="https://www.kun-ei.ac.jp/"],a[href$="pdf"],a[href$="doc"],a[href$="docx"],a[href$="xls"],a[href$="xlsx"]',
	
		//別窓アイコンを表示させたくない要素を書き加える カンマ区切りで追加
		blankIconHidden: '#footer ul,#footer #groupNavi,#header,#pamphlet',
	
		//クラスnoIcon を加えると、絶対パスで記述しても別窓アイコンも別窓開きもなくなる
		noIcon: 'a.noIcon',
		
		// 同じドメインだが、別窓で開きたいURL
		anotherPageURL: 'a[href^="http://www.kun-ei.ac.jp/content/opencampus/2010/"],a[href^="http://www.kun-ei.ac.jp/blog/"],a[href^="http://www.kun-ei.ac.jp/relay/"],a[href^="http://www.kun-ei.ac.jp/kaori/"],a[href^="http://www.kun-ei.ac.jp/houjin/"],a[href^="http://www.kun-ei.ac.jp/content/gendaigp/"]'

	});
	

	$.yuga.tab();
	$.yuga.stripe();

	//画像のパスは適時変更
	$("a[href$='.pdf']").before('<img src="/common/img/icon_pdf.gif" alt="PDFファイルへのリンクです" class="externalbeforeIcon" />');
	$("a[href$='.doc'],a[href$='.docx']").before('<img src="/common/img/icon_doc.gif" alt="Wordファイルへのリンクです" class="externalbeforeIcon" />');
	$("a[href$='.xls'],a[href$='.xlsx']").before('<img src="/common/img/icon_xls.gif" alt="Excelファイルへのリンクです" class="externalbeforeIcon" />');
	$("a[href$='.pdf'],a[href$='.doc'],a[href$='.docx'],a[href$='.xls'],a[href$='.xlsx']").click(function(){window.open(this.href, '_blank');return false;});

	//onload実行
	$("a[href*='#']").filter(function(){return !$(this).parent().parent().hasClass("tabNav");}).slideScroll();
	
	initRollOverImages();
	
	$(".navi-body dt span,.purposeNavi dd a,#subject h2").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});

	$("#blogs h2,#subject h3").each(function(){
		$(this).add($(this).next('p')).wrapAll("<div></div>");
	});
	
	$("#request,#exam,#blog,#toAnyone,#relay,#blogs div,#employment,#opencampus,#subject div,#piano").addClass("blocklink").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});

	$("#information h2 a img").hover(function(){
		$(this).animate({opacity:"0.5"},{duration:300,queue:false});
	},function(){
		$(this).animate({opacity:"1"},{duration:300,queue:false});
	});

	$("#pamphlet a").unbind("click");
	$("#pamphlet").click(function(){
		var pamHref = $(this).find("a").attr("href");
		window.open(pamHref,this.target,'width=1010,height=655');
		return false;
	});
	$("#pamphlet").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	
	//blocklink
	clickArea("dl", "blocklink");
	clickArea("tr", "blocklink");
	clickArea("td", "blocklink");
	clickArea("li", "blocklink");
	clickArea("div", "blocklink");
	$(".blocklink").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	$(".blocklink a").css("outline","0");
	
	// capContain
	$("img.capContain").each(function(){
	var icT = $(this).attr("title").split("｜").join("<br />");
	var icW = $(this).width();
	$(this).removeAttr("title").after('<span class="imgCap">'+ icT +'</span>');
	$(this).next("span.imgCap").width(icW).css("display","block");
	});

	// numList
	$("#contents ol").not("#contents li ol").addClass("numList").each(function(){
		$(this).children("li").each(function(numListNumber){
			numListNumber = numListNumber+1;
			if(numListNumber > 9){
			$(this).prepend('<span class="num">'+ numListNumber +'.' +'</span>');
			}else{
			$(this).prepend('<span class="num">'+'0' + numListNumber +'.' +'</span>');
			}
		});
	});
	
	// numAlphaList (inner)
	if($("#contents li ol").length)	{
		var alphaNum = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
		$.each(alphaNum, function(i, val){
			$("#contents li ol").addClass("numList").each(function(){
				$(this).children("li").eq(i).prepend('<span class="num">'+ val +'.' +'</span>');
			});
		});
	}
	
	//　フラットカラムファンクション
	flatColumns("ul.mass > li","3");
	flatColumns("ul.introduce > li","2");

	// purposeNavi
	if($.browser.msie && $.browser.version <= 7 ){
		$('dl#campusguideNavi > dt').not(":first").css("margin-top","1em");
	}else{
		$('dl#campusguideNavi > dt').not(":first").css("margin-top","1.5em");
	}
	
	// フラットハイトファンクション
	$('dl.purposeNavi').flatHeights();
	
	
	// ボックスコンテンツ　ブロックリンク
	if($.browser.msie && $.browser.version <= 7 ){
		ieFixBox("#information dl dt");
		ieFixBox("#content dl dt");

		$("#information ins,#content ins").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});
		
		$("#information dl ins.hoverable,#content dl ins.hoverable,#subject dl ins.hoverable").each(function(){
			if($(this).find("a").length){
			$(this).find("a").focus(function(){this.blur();});
			var blockAnchorHref = $(this).find("a").attr("href");
			$(this).click(blockAnchor);
			}
			
			// block anchor
			function blockAnchor(){
				if(blockAnchorHref.indexOf("http://www.kun-ei.ac.jp/") != -1){
					if(blockAnchorHref.indexOf("/content/blog/") != -1){
						window.open(blockAnchorHref,'_blank');
					}else if(blockAnchorHref.indexOf("/content/opencampus/") != -1 || blockAnchorHref.indexOf("/kaori/") || blockAnchorHref.indexOf("/houjin/") || blockAnchorHref.indexOf("/content/gendaigp/")){
						window.open(blockAnchorHref,'_blank');
					}else{
						location.href = blockAnchorHref;
					}
				}else{
					if(blockAnchorHref.indexOf("http") != -1){
						window.open(blockAnchorHref,'_blank');
					}else{
						location.href = blockAnchorHref;
					}
				}
			}
			
		});
	
	}else{
		$("#information dl dt,#subject dl dt,#content dl dt").each(function(){
			if($(this).next("dd").children("a").length){
				$(this).next("dd").children("a").css("outline","0");
				var blockAnchorHref = $(this).next("dd").children("a").attr("href");
			}else if($(this).children("a").length){
				$(this).children("a").css("outline","0");
				var blockAnchorHref = $(this).children("a").attr("href");
			}
			
			// block anchor
			function blockAnchor(){
				if(blockAnchorHref.indexOf("http://www.kun-ei.ac.jp/") != -1){
					if(blockAnchorHref.indexOf("/content/blog/") != -1){
						window.open(blockAnchorHref,'_blank');
					}else if(blockAnchorHref.indexOf("/content/opencampus/") != -1 || blockAnchorHref.indexOf("/kaori/") != -1 || blockAnchorHref.indexOf("/houjin/") !=-1 || blockAnchorHref.indexOf("/content/gendaigp/") !=-1 ){
						window.open(blockAnchorHref,'_blank');
					}else{
						location.href = blockAnchorHref;
					}
				}else{
					if(blockAnchorHref.indexOf("http") != -1){
						window.open(blockAnchorHref,'_blank');
					}else{
						location.href = blockAnchorHref;
					}
				}
			}
		if($(this).find("a").length || $(this).next("dd").find("a").length){
			$(this).click(blockAnchor);
		}
		
			$(this).css("cursor","pointer").hover(function(){
				$(this).add($(this).next("dd")).addClass("hover");
			},function(){
				$(this).add($(this).next("dd")).removeClass("hover");
			});
			$(this).next("dd").css("cursor","pointer").hover(function(){
				$(this).add($(this).prev("dt")).addClass("hover");
			},function(){
				$(this).add($(this).prev("dt")).removeClass("hover");
			});
		});
		$("#information dl dd,#content dl dd").each(function(){
			if($(this).children("a").length){
				$(this).children("a").css("outline","0");
				var blockAnchorHref = $(this).children("a").attr("href");
			}else if($(this).prev("dt").children("a").length){
				$(this).prev("dt").children("a").css("outline","0");
				var blockAnchorHref = $(this).prev("dt").children("a").attr("href");
			}
						// block anchor
			function blockAnchor(){
				if(blockAnchorHref.indexOf("http://www.kun-ei.ac.jp/") != -1){
					if(blockAnchorHref.indexOf("/content/blog/") != -1){
						window.open(blockAnchorHref,'_blank');
					}else if(blockAnchorHref.indexOf("/content/opencampus/") != -1 || blockAnchorHref.indexOf("/kaori/") != -1 || blockAnchorHref.indexOf("/houjin/") != -1 || blockAnchorHref.indexOf("/content/gendaigp/") != -1){
						window.open(blockAnchorHref,'_blank');
					}else{
						location.href = blockAnchorHref;
					}
				}else{
					if(blockAnchorHref.indexOf("http") != -1){
						window.open(blockAnchorHref,'_blank');
					}else{
						location.href = blockAnchorHref;
					}
				}
			}
			if($(this).find("a").length || $(this).prev("dt").find("a").length){
				$(this).click(blockAnchor);
			}
		});
	}

	
	//　コンテンツホバー
	$("#contents li").hover(function(){
		$(this).animate({backgroundColor:"#fff5f8"},{duration:500,queue:false});
	},function(){
		$(this).animate({backgroundColor:"#ffffff"},{duration:500,queue:false});
	});
	$("#contents li#information").hover(function(){
		$(this).find("dl .even").animate({backgroundColor:"#fde4eb"},{duration:500,queue:false});
	},function(){
		$(this).find("dl .even").animate({backgroundColor:"#f4f3f1"},{duration:500,queue:false});
	});
	
	//スクロールバー
	$('#information dl,#content dl').jScrollPane();
	$("#information .jScrollPaneContainer").width("575px");
	$("#content .jScrollPaneContainer").width("275px");
	$(".jScrollPaneContainer").find("a").focus(function(){this.blur();});
	$(".jScrollPaneContainer").focus(function(){this.blur();});

});

// for ie
function ieFixBox(boxParentTag){
	$(boxParentTag).each(function(i){
		$(this).addClass("line"+ i);
		$(this).next("dd").addClass("line"+ i);
		$(this).parent("dl").children(".line"+i).wrapAll('<ins class="hoverable"></ins>');
	});
}


// yuga.js + mod
$.yuga = {
Uri: function(path){
	var self = this;
	this.originalPath = path;
	this.absolutePath = (function(){
		var e = document.createElement('span');
		e.innerHTML = '<a href="' + path + '" />';
		return e.firstChild.href;
	})();
	var fields = {'schema' : 2, 'username' : 5, 'password' : 6, 'host' : 7, 'path' : 9, 'query' : 10, 'fragment' : 11};
	var r = /^((\w+):)?(\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/.exec(this.absolutePath);
	for (var field in fields) {
		this[field] = r[fields[field]];
	}
	this.querys = {};
	if(this.query){
		$.each(self.query.split('&'), function(){
			var a = this.split('=');
			if (a.length == 2) self.querys[a[0]] = a[1];
		});
	}
},
externalLink: function(options) {
	var c = $.extend({windowOpen:true}, options);
	if (c.windowOpen) {
			$('a[href^="http"]').not($("#pamphlet").find("a")).not($(c.blankIconHidden).find('a[href^="http"]')).not(c.notWindowURL).not(c.noIcon).click(function(){window.open(this.href, '_blank');return false;}).css("text-decoration","none").wrapInner('<span class="anchorIn"></span>').children("span").after(c.blankIconPath);
			$(c.blankIconHidden).find('a[href^="http"]').not(c.notWindowURL).not(c.noIcon).click(function(){window.open(this.href, '_blank');return false;});
			$(c.anotherPageURL).click(function(){window.open(this.href, '_blank');return false;}).not($(c.blankIconHidden).find('a[href^="http"]')).not("#contents #blog a,#contents #blogs a,#contents #opencampus a").css("text-decoration","none").wrapInner('<span class="anchorIn"></span>').children("span").after(c.blankIconPath);
	}
},
tab: function(options) {
	var c = $.extend({
		tabNavSelector:'.tabNav',
		activeTabClass:'active'
	}, options);
	$(c.tabNavSelector).each(function(){
		var tabNavList = $(this).find('a[href^=#], area[href^=#]');
		var tabBodyList;
		tabNavList.each(function(){
			this.hrefdata = new $.yuga.Uri(this.getAttribute('href'));
			var selecter = '#'+this.hrefdata.fragment;
			if (tabBodyList) {
				tabBodyList = tabBodyList.add(selecter);
			} else {
				tabBodyList = $(selecter);
			}
			$(this).unbind('click');
			$(this).click(function(){
				tabNavList.removeClass(c.activeTabClass);
				$(this).addClass(c.activeTabClass);
				tabBodyList.css({"width":"auto","height":"auto","position":"absolute","top":"-9999px","left":"-9999px"});
				$(selecter).fadeOut(0).css({"width":"auto","height":"auto","position":"static","top":"auto","left":"auto"}).fadeIn(700);
				return false;
			});
		});
		tabBodyList.css({"width":"auto","height":"auto","position":"absolute","top":"-9999px","left":"-9999px"});
		if($(c.tabNavSelector).length){
			var thisWinURL = location.hash;
			var containTabs = $(c.tabNavSelector).html();
			if(thisWinURL.length == 0){
				tabNavList.filter(':first').trigger('click');
			}else if(containTabs.indexOf(thisWinURL) != -1){
				tabNavList.filter("a[href='"+thisWinURL+"']").trigger('click').focus();
			}else{
				tabNavList.filter(':first').trigger('click');
			}
		}
	});
},
stripe: function(options) {
	var c = $.extend({
		oddClass:'odd',
		evenClass:'even'
	}, options);
	$('ul, ol').each(function(){
		$(this).children('li:odd').addClass(c.evenClass);
		$(this).children('li:even').addClass(c.oddClass);
	});
	$('table, tbody').each(function(){
		$(this).children('tr:odd').addClass(c.evenClass);
		$(this).children('tr:even').addClass(c.oddClass);
	});
	$('#information dl').each(function(){
		$(this).children('dt:odd').addClass(c.evenClass);
		$(this).children('dd:odd').addClass(c.evenClass);
	});
}

};
})(jQuery);

// Rollover ----------------------------------------
function initRollOverImages() {
	var image_cache = new Object();
	$("img.imgover").each(function(i) {
	var imgsrc = this.src;
	var dot = this.src.lastIndexOf('.');
	var imgsrc_ro = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
	image_cache[this.src] = new Image();
	image_cache[this.src].src = imgsrc_ro;
	$(this).hover(
		function() { if(!$(this).hasClass("active")){this.src = imgsrc_ro;} },
		function() {if(!$(this).hasClass("active")){this.src = imgsrc; }})
	});
}

// MenuActive ----------------------------------------
function NaviActive(id){
	var target_img = "#"+id+" img";
	if(!$(target_img).attr("src")) {
		target_img = "img#"+id;	
	}
	$(target_img).each(function(i) {
		dot = this.src.lastIndexOf('.');
		var imgsrc_ro = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		this.src = imgsrc_ro;
		$(this).hover(function() { this.src = imgsrc_ro; },function() { this.src = imgsrc_ro; });
	});
}

// SideMenuActive ----------------------------------------
function sideNaviActive(id) {
	var target_navi = "#"+id;
	$(target_navi).addClass("active");
}

function initSideNavi(id , sub_id) {

	var sub_cnt = $("#sideNavi .navi-body dt").length;
	var cnt = 1;

	$("#sideNavi .navi-body dt").each(function() {
		if ($(this).hasClass("none")) {
			$(this).hide();
			$(this).next().addClass("independent");
		}
		if($(this).attr("id") != id && !$(this).hasClass("none")) {
			$("ul" , $(this).next()).hide();
			$(this).addClass("close");
		}else{
			$(this).data("active" , "on");
			$(this).addClass("open");
			if(sub_id != undefined) {
				sideNaviActive(sub_id);	
		}
	}
	$(this).css("cursor" , "pointer").click(function() {
		if($(this).data("active") == "on") {
			$(this).data("active" , "off");
			$(this).removeClass("open");
			$(this).addClass("close");
		}else{
			$(this).data("active" , "on");
			$(this).removeClass("close");
			$(this).addClass("open");
		}
		var target_body_id = $(this).attr("id");
		$("#"+target_body_id+"body ul").slideToggle();
	});
	cnt++;
	});
}

// slideScroll ----------------------------------------

$.fn.slideScroll = function(options){
	var c = $.extend({
		interval: 30,
		easing: 1.0,
		comeLink: false
	},options);
	var d = document;
	var timer;
	var pos;
	function currentPoint(){
		var current = {
			x: d.body.scrollLeft || d.documentElement.scrollLeft,
			y: d.body.scrollTop || d.documentElement.scrollTop
		}
		return current;
	}
	function setPoint(){

		var h = d.documentElement.clientHeight;
		var w = d.documentElement.clientWidth;
		var maxH = d.documentElement.scrollHeight;
		var maxW = d.documentElement.scrollWidth;
		pos.top = ((maxH-h)<pos.top && pos.top<maxH) ? maxH-h : pos.top;
		pos.left = ((maxW-w)<pos.left && pos.left<maxW) ? maxW-w : pos.left;
	}
	function nextPoint(){
		var x = currentPoint().x;
		var y = currentPoint().y;
		var sx = Math.ceil((x - pos.left)/(5*c.easing));
		var sy = Math.ceil((y - pos.top)/(5*c.easing));
		var next = {
			x: x - sx,
			y: y - sy,
			ax: sx,
			ay: sy
		}
		return next;
	}
	function scroll(href){
		var movedHash = href;
		timer = setInterval(function(){
			nextPoint();
			if(Math.abs(nextPoint().ax)<1 && Math.abs(nextPoint().ay)<1){
				clearInterval(timer);
				window.scroll(pos.left,pos.top);
				location.href = movedHash;
			}
			window.scroll(nextPoint().x,nextPoint().y);
		},c.interval);
	}
	function comeLink(){
		if(location.hash){
			if($(location.hash) && $(location.hash).length>0){
				pos = $(location.hash).offset();
				setPoint();
				window.scroll(0,0);
				if($.browser.msie){
					setTimeout(function(){
						scroll(location.hash);
					},50);
				}else{
					scroll(location.hash);
				}
			}
		}
	}
	if(c.comeLink) comeLink();
	$(this).each(function(){
		if(this.hash && $(this.hash).length>0 
			&& this.href.match(new RegExp(location.href.split("#")[0]))){
			var hash = this.hash;
			$(this).click(function(){
				pos = $(hash).offset();
				clearInterval(timer);
				setPoint();
				scroll(this.href);
				return false;
			});
		}
	});
}


// blocklink ----------------------------------------

function clickArea(tagName, className) {
	$("."+className+" a").css("outline","0");
	var els = document.getElementsByTagName(tagName);
	if (els) {
		for (var i = 0; i < els.length; i++){
			if (els[i].className.indexOf(className)>=0) {
				els[i].onmouseover=function() {
					this.className+=" blockhover";
					window.status = this.getElementsByTagName("a")[0].href;
					return true;
				}
				els[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" blockhover\\b"), "");
					window.status = "";
					return true;
				}
				els[i].onclick = function () {
					var elm = this.getElementsByTagName("a")[0];
					if($(elm).attr('href').indexOf("www.kun-ei.ac.jp") != -1){
						location.href = elm.href;
					}else{
						if($(elm).attr('href').indexOf("http") != -1){
							window.open(elm.href,'_blank');
						}else{
							location.href = elm.href;
						}
					}
				}
			}
		}
	}
}


/*
flatheights.js
Version: 2007-08-01
Copyright (c) 2007, KITAMURA Akatsuki
$.changeLetterSize.addHandler(func)
*/

$.changeLetterSize = {
	handlers : [],
	interval : 1000,
	currentSize: 0
};
(function($) {
	var self = $.changeLetterSize;
	var ins = $('<ins>M</ins>').css({display: 'block',visibility: 'hidden',position: 'absolute',padding: '0',top: '0'});
	var isChanged = function() {
		ins.appendTo('#contents');
		var size = ins[0].offsetHeight;
		ins.remove();
		if (self.currentSize == size) return false;
			self.currentSize = size;
			return true;
		};
		$(isChanged);
		var observer = function() {
			if (!isChanged()) return;
			$.each(self.handlers, function(i, handler) {
				handler();
			});
		};
	self.addHandler = function(func) {
		self.handlers.push(func);
			if (self.handlers.length == 1) {
				setInterval(observer, self.interval);
			}
	};
})(jQuery);

(function($) {
	var sets = [];
	var flatHeights = function(set) {
		var maxHeight = 0;
		set.each(function(){
		var height = this.offsetHeight;
		if (height > maxHeight) maxHeight = height;
		});
	set.css('height', maxHeight + 'px');
	};
	$.fn.flatHeights = function() {
		if (this.length > 1) {
			flatHeights(this);
			sets.push(this);
		}
	return this;
	};
	$.changeLetterSize.addHandler(function() {
		$.each(sets, function() {
			this.height('auto');
			flatHeights(this);
		});
	});
})(jQuery);

function flatColumns(flatColum,columNum){
	$(flatColum).parent().each(function(){
		var sets = [], temp = [];
		if(columNum == 2){
			$(this).children().each(function(i){
				temp.push(this);
				if ((i+1)%2 == 0 && i!=0){
					sets.push(temp);
					temp = [];
				}
			});
			if (temp.length) sets.push(temp);
		}else if(columNum == 3){
			$(this).children().each(function(i) {
				temp.push(this);
				if (i % 3 == 2) {
					sets.push(temp);
					temp = [];
				}
			});
			if (temp.length) sets.push(temp);
		}
	
		$.each(sets, function() {
			$(this).flatHeights();
		});
	});
}

/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if (!fx.colorInit) {
				fx.start = getColor(fx.elem, attr);
				fx.end = getRGB(fx.end);
				fx.colorInit = true;
			}

		fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/

	var colors = {
		aqua:[0,255,255],
		azure:[240,255,255],
		beige:[245,245,220],
		black:[0,0,0],
		blue:[0,0,255],
		brown:[165,42,42],
		cyan:[0,255,255],
		darkblue:[0,0,139],
		darkcyan:[0,139,139],
		darkgrey:[169,169,169],
		darkgreen:[0,100,0],
		darkkhaki:[189,183,107],
		darkmagenta:[139,0,139],
		darkolivegreen:[85,107,47],
		darkorange:[255,140,0],
		darkorchid:[153,50,204],
		darkred:[139,0,0],
		darksalmon:[233,150,122],
		darkviolet:[148,0,211],
		fuchsia:[255,0,255],
		gold:[255,215,0],
		green:[0,128,0],
		indigo:[75,0,130],
		khaki:[240,230,140],
		lightblue:[173,216,230],
		lightcyan:[224,255,255],
		lightgreen:[144,238,144],
		lightgrey:[211,211,211],
		lightpink:[255,182,193],
		lightyellow:[255,255,224],
		lime:[0,255,0],
		magenta:[255,0,255],
		maroon:[128,0,0],
		navy:[0,0,128],
		olive:[128,128,0],
		orange:[255,165,0],
		pink:[255,192,203],
		purple:[128,0,128],
		violet:[128,0,128],
		red:[255,0,0],
		silver:[192,192,192],
		white:[255,255,255],
		yellow:[255,255,0]
	};
	
})(jQuery);


/* Copyright (c) 2009 Kelvin Luck (kelvin AT kelvinluck DOT com || http://www.kelvinluck.com)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * 
 * See http://kelvinluck.com/assets/jquery/jScrollPane/
 * $Id: jScrollPane.js 90 2010-01-25 03:52:10Z kelvin.luck $
 */

/**
 * Replace the vertical scroll bars on any matched elements with a fancy
 * styleable (via CSS) version. With JS disabled the elements will
 * gracefully degrade to the browsers own implementation of overflow:auto.
 * If the mousewheel plugin has been included on the page then the scrollable areas will also
 * respond to the mouse wheel.
 *
 * @example jQuery(".scroll-pane").jScrollPane();
 *
 * @name jScrollPane
 * @type jQuery
 * @param Object	settings	hash with options, described below.
 *								scrollbarWidth	-	The width of the generated scrollbar in pixels
 *								scrollbarMargin	-	The amount of space to leave on the side of the scrollbar in pixels
 *								wheelSpeed		-	The speed the pane will scroll in response to the mouse wheel in pixels
 *								showArrows		-	Whether to display arrows for the user to scroll with
 *								arrowSize		-	The height of the arrow buttons if showArrows=true
 *								animateTo		-	Whether to animate when calling scrollTo and scrollBy
 *								dragMinHeight	-	The minimum height to allow the drag bar to be
 *								dragMaxHeight	-	The maximum height to allow the drag bar to be
 *								animateInterval	-	The interval in milliseconds to update an animating scrollPane (default 100)
 *								animateStep		-	The amount to divide the remaining scroll distance by when animating (default 3)
 *								maintainPosition-	Whether you want the contents of the scroll pane to maintain it's position when you re-initialise it - so it doesn't scroll as you add more content (default true)
 *								tabIndex		-	The tabindex for this jScrollPane to control when it is tabbed to when navigating via keyboard (default 0)
 *								enableKeyboardNavigation - Whether to allow keyboard scrolling of this jScrollPane when it is focused (default true)
 *								animateToInternalLinks - Whether the move to an internal link (e.g. when it's focused by tabbing or by a hash change in the URL) should be animated or instant (default false)
 *								scrollbarOnLeft	-	Display the scrollbar on the left side?  (needs stylesheet changes, see examples.html)
 *								reinitialiseOnImageLoad - Whether the jScrollPane should automatically re-initialise itself when any contained images are loaded (default false)
 *								topCapHeight	-	The height of the "cap" area between the top of the jScrollPane and the top of the track/ buttons
 *								bottomCapHeight	-	The height of the "cap" area between the bottom of the jScrollPane and the bottom of the track/ buttons
 *								observeHash		-	Whether jScrollPane should attempt to automagically scroll to the correct place when an anchor inside the scrollpane is linked to (default true)
 * @return jQuery
 * @cat Plugins/jScrollPane
 * @author Kelvin Luck (kelvin AT kelvinluck DOT com || http://www.kelvinluck.com)
 */

(function($) {

$.jScrollPane = {
	active : []
};
$.fn.jScrollPane = function(settings)
{
	settings = $.extend({}, $.fn.jScrollPane.defaults, settings);

	var rf = function() { return false; };
	
	return this.each(
		function()
		{
			var $this = $(this);
			var paneEle = this;
			var currentScrollPosition = 0;
			var paneWidth;
			var paneHeight;
			var trackHeight;
			var trackOffset = settings.topCapHeight;
			var $container;
			
			if ($(this).parent().is('.jScrollPaneContainer')) {
				$container = $(this).parent();
				currentScrollPosition = settings.maintainPosition ? $this.position().top : 0;
				var $c = $(this).parent();
				paneWidth = $c.innerWidth();
				paneHeight = $c.outerHeight();
				$('>.jScrollPaneTrack, >.jScrollArrowUp, >.jScrollArrowDown, >.jScrollCap', $c).remove();
				$this.css({'top':0});
			} else {
				$this.data('originalStyleTag', $this.attr('style'));
				// Switch the element's overflow to hidden to ensure we get the size of the element without the scrollbars [http://plugins.jquery.com/node/1208]
				$this.css('overflow', 'hidden');
				this.originalPadding = $this.css('paddingTop') + ' ' + $this.css('paddingRight') + ' ' + $this.css('paddingBottom') + ' ' + $this.css('paddingLeft');
				this.originalSidePaddingTotal = (parseInt($this.css('paddingLeft')) || 0) + (parseInt($this.css('paddingRight')) || 0);
				paneWidth = $this.innerWidth();
				paneHeight = $this.innerHeight();
				$container = $('<div></div>')
					.attr({'className':'jScrollPaneContainer'})
					.css(
						{
							'height':paneHeight+'px', 
							'width':paneWidth+'px'
						}
					);
				if (settings.enableKeyboardNavigation) {
					$container.attr(
						'tabindex', 
						settings.tabIndex
					);
				}
				$this.wrap($container);
				$container = $this.parent();
				// deal with text size changes (if the jquery.em plugin is included)
				// and re-initialise the scrollPane so the track maintains the
				// correct size
				$(document).bind(
					'emchange', 
					function(e, cur, prev)
					{
						$this.jScrollPane(settings);
					}
				);
				
			}
			trackHeight = paneHeight;
			
			if (settings.reinitialiseOnImageLoad) {
				// code inspired by jquery.onImagesLoad: http://plugins.jquery.com/project/onImagesLoad
				// except we re-initialise the scroll pane when each image loads so that the scroll pane is always up to size...
				// TODO: Do I even need to store it in $.data? Is a local variable here the same since I don't pass the reinitialiseOnImageLoad when I re-initialise?
				var $imagesToLoad = $.data(paneEle, 'jScrollPaneImagesToLoad') || $('img', $this);
				var loadedImages = [];
				
				if ($imagesToLoad.length) {
					$imagesToLoad.each(function(i, val)	{
						$(this).bind('load readystatechange', function() {
							if($.inArray(i, loadedImages) == -1){ //don't double count images
								loadedImages.push(val); //keep a record of images we've seen
								$imagesToLoad = $.grep($imagesToLoad, function(n, i) {
									return n != val;
								});
								$.data(paneEle, 'jScrollPaneImagesToLoad', $imagesToLoad);
								var s2 = $.extend(settings, {reinitialiseOnImageLoad:false});
								$this.jScrollPane(s2); // re-initialise
							}
						}).each(function(i, val) {
							if(this.complete || this.complete===undefined) { 
								//needed for potential cached images
								this.src = this.src; 
							} 
						});
					});
				};
			}

			var p = this.originalSidePaddingTotal;
			var realPaneWidth = paneWidth - settings.scrollbarWidth - settings.scrollbarMargin - p;

			var cssToApply = {
				'height':'auto',
				'width': realPaneWidth + 'px'
			}

			if(settings.scrollbarOnLeft) {
				cssToApply.paddingLeft = settings.scrollbarMargin + settings.scrollbarWidth + 'px';
			} else {
				cssToApply.paddingRight = settings.scrollbarMargin + 'px';
			}

			$this.css(cssToApply);

			var contentHeight = $this.outerHeight();
			var percentInView = paneHeight / contentHeight;
			
			var isScrollable = percentInView < .99;
			$container[isScrollable ? 'addClass' : 'removeClass']('jScrollPaneScrollable');

			if (isScrollable) {
				$container.append(
					$('<div></div>').addClass('jScrollCap jScrollCapTop').css({height:settings.topCapHeight}),
					$('<div></div>').attr({'className':'jScrollPaneTrack'}).css({'width':settings.scrollbarWidth+'px'}).append(
						$('<div></div>').attr({'className':'jScrollPaneDrag'}).css({'width':settings.scrollbarWidth+'px'}).append(
							$('<div></div>').attr({'className':'jScrollPaneDragTop'}).css({'width':settings.scrollbarWidth+'px'}),
							$('<div></div>').attr({'className':'jScrollPaneDragBottom'}).css({'width':settings.scrollbarWidth+'px'})
						)
					),
					$('<div></div>').addClass('jScrollCap jScrollCapBottom').css({height:settings.bottomCapHeight})
				);
				
				var $track = $('>.jScrollPaneTrack', $container);
				var $drag = $('>.jScrollPaneTrack .jScrollPaneDrag', $container);
				
				
				var currentArrowDirection;
				var currentArrowTimerArr = [];// Array is used to store timers since they can stack up when dealing with keyboard events. This ensures all timers are cleaned up in the end, preventing an acceleration bug.
				var currentArrowInc;
				var whileArrowButtonDown = function() 
				{
					if (currentArrowInc > 4 || currentArrowInc % 4 == 0) {
						positionDrag(dragPosition + currentArrowDirection * mouseWheelMultiplier);
					}
					currentArrowInc++;
				};

				if (settings.enableKeyboardNavigation) {
					$container.bind(
						'keydown.jscrollpane',
						function(e) 
						{
							switch (e.keyCode) {
								case 38: //up
									currentArrowDirection = -1;
									currentArrowInc = 0;
									whileArrowButtonDown();
									currentArrowTimerArr[currentArrowTimerArr.length] = setInterval(whileArrowButtonDown, 100);
									return false;
								case 40: //down
									currentArrowDirection = 1;
									currentArrowInc = 0;
									whileArrowButtonDown();
									currentArrowTimerArr[currentArrowTimerArr.length] = setInterval(whileArrowButtonDown, 100);
									return false;
								case 33: // page up
								case 34: // page down
									// TODO
									return false;
								default:
							}
						}
					).bind(
						'keyup.jscrollpane',
						function(e) 
						{
							if (e.keyCode == 38 || e.keyCode == 40) {
								for (var i = 0; i < currentArrowTimerArr.length; i++) {
									clearInterval(currentArrowTimerArr[i]);
								}
								return false;
							}
						}
					);
				}

				if (settings.showArrows) {
					
					var currentArrowButton;
					var currentArrowInterval;

					var onArrowMouseUp = function(event)
					{
						$('html').unbind('mouseup', onArrowMouseUp);
						currentArrowButton.removeClass('jScrollActiveArrowButton');
						clearInterval(currentArrowInterval);
					};
					var onArrowMouseDown = function() {
						$('html').bind('mouseup', onArrowMouseUp);
						currentArrowButton.addClass('jScrollActiveArrowButton');
						currentArrowInc = 0;
						whileArrowButtonDown();
						currentArrowInterval = setInterval(whileArrowButtonDown, 100);
					};
					$container
						.append(
							$('<a></a>')
								.attr(
									{
										'href':'javascript:;', 
										'className':'jScrollArrowUp', 
										'tabindex':-1
									}
								)
								.css(
									{
										'width':settings.scrollbarWidth+'px',
										'top':settings.topCapHeight + 'px'
									}
								)
								.html('Scroll up')
								.bind('mousedown', function()
								{
									currentArrowButton = $(this);
									currentArrowDirection = -1;
									onArrowMouseDown();
									this.blur();
									return false;
								})
								.bind('click', rf),
							$('<a></a>')
								.attr(
									{
										'href':'javascript:;', 
										'className':'jScrollArrowDown', 
										'tabindex':-1
									}
								)
								.css(
									{
										'width':settings.scrollbarWidth+'px',
										'bottom':settings.bottomCapHeight + 'px'
									}
								)
								.html('Scroll down')
								.bind('mousedown', function()
								{
									currentArrowButton = $(this);
									currentArrowDirection = 1;
									onArrowMouseDown();
									this.blur();
									return false;
								})
								.bind('click', rf)
						);
					var $upArrow = $('>.jScrollArrowUp', $container);
					var $downArrow = $('>.jScrollArrowDown', $container);
				}
				
				if (settings.arrowSize) {
					trackHeight = paneHeight - settings.arrowSize - settings.arrowSize;
					trackOffset += settings.arrowSize;
				} else if ($upArrow) {
					var topArrowHeight = $upArrow.height();
					settings.arrowSize = topArrowHeight;
					trackHeight = paneHeight - topArrowHeight - $downArrow.height();
					trackOffset += topArrowHeight;
				}
				trackHeight -= settings.topCapHeight + settings.bottomCapHeight;
				$track.css({'height': trackHeight+'px', top:trackOffset+'px'})
				
				var $pane = $(this).css({'position':'absolute', 'overflow':'visible'});
				
				var currentOffset;
				var maxY;
				var mouseWheelMultiplier;
				// store this in a seperate variable so we can keep track more accurately than just updating the css property..
				var dragPosition = 0;
				var dragMiddle = percentInView*paneHeight/2;
				
				// pos function borrowed from tooltip plugin and adapted...
				var getPos = function (event, c) {
					var p = c == 'X' ? 'Left' : 'Top';
					return event['page' + c] || (event['client' + c] + (document.documentElement['scroll' + p] || document.body['scroll' + p])) || 0;
				};
				
				var ignoreNativeDrag = function() {	return false; };
				
				var initDrag = function()
				{
					ceaseAnimation();
					currentOffset = $drag.offset(false);
					currentOffset.top -= dragPosition;
					maxY = trackHeight - $drag[0].offsetHeight;
					mouseWheelMultiplier = 2 * settings.wheelSpeed * maxY / contentHeight;
				};
				
				var onStartDrag = function(event)
				{
					initDrag();
					dragMiddle = getPos(event, 'Y') - dragPosition - currentOffset.top;
					$('html').bind('mouseup', onStopDrag).bind('mousemove', updateScroll);
					if ($.browser.msie) {
						$('html').bind('dragstart', ignoreNativeDrag).bind('selectstart', ignoreNativeDrag);
					}
					return false;
				};
				var onStopDrag = function()
				{
					$('html').unbind('mouseup', onStopDrag).unbind('mousemove', updateScroll);
					dragMiddle = percentInView*paneHeight/2;
					if ($.browser.msie) {
						$('html').unbind('dragstart', ignoreNativeDrag).unbind('selectstart', ignoreNativeDrag);
					}
				};
				var positionDrag = function(destY)
				{
					$container.scrollTop(0);
					destY = destY < 0 ? 0 : (destY > maxY ? maxY : destY);
					dragPosition = destY;
					$drag.css({'top':destY+'px'});
					var p = destY / maxY;
					$this.data('jScrollPanePosition', (paneHeight-contentHeight)*-p);
					$pane.css({'top':((paneHeight-contentHeight)*p) + 'px'});
					$this.trigger('scroll');
					if (settings.showArrows) {
						$upArrow[destY == 0 ? 'addClass' : 'removeClass']('disabled');
						$downArrow[destY == maxY ? 'addClass' : 'removeClass']('disabled');
					}
				};
				var updateScroll = function(e)
				{
					positionDrag(getPos(e, 'Y') - currentOffset.top - dragMiddle);
				};
				
				var dragH = Math.max(Math.min(percentInView*(paneHeight-settings.arrowSize*2), settings.dragMaxHeight), settings.dragMinHeight);
				
				$drag.css(
					{'height':dragH+'px'}
				).bind('mousedown', onStartDrag);
				
				var trackScrollInterval;
				var trackScrollInc;
				var trackScrollMousePos;
				var doTrackScroll = function()
				{
					if (trackScrollInc > 8 || trackScrollInc%4==0) {
						positionDrag((dragPosition - ((dragPosition - trackScrollMousePos) / 2)));
					}
					trackScrollInc ++;
				};
				var onStopTrackClick = function()
				{
					clearInterval(trackScrollInterval);
					$('html').unbind('mouseup', onStopTrackClick).unbind('mousemove', onTrackMouseMove);
				};
				var onTrackMouseMove = function(event)
				{
					trackScrollMousePos = getPos(event, 'Y') - currentOffset.top - dragMiddle;
				};
				var onTrackClick = function(event)
				{
					initDrag();
					onTrackMouseMove(event);
					trackScrollInc = 0;
					$('html').bind('mouseup', onStopTrackClick).bind('mousemove', onTrackMouseMove);
					trackScrollInterval = setInterval(doTrackScroll, 100);
					doTrackScroll();
					return false;
				};
				
				$track.bind('mousedown', onTrackClick);
				
				$container.bind(
					'mousewheel',
					function (event, delta) {
						delta = delta || (event.wheelDelta ? event.wheelDelta / 120 : (event.detail) ?
-event.detail/3 : 0);
						initDrag();
						ceaseAnimation();
						var d = dragPosition;
						positionDrag(dragPosition - delta * mouseWheelMultiplier);
						var dragOccured = d != dragPosition;
						return !dragOccured;
					}
				);

				var _animateToPosition;
				var _animateToInterval;
				function animateToPosition()
				{
					var diff = (_animateToPosition - dragPosition) / settings.animateStep;
					if (diff > 1 || diff < -1) {
						positionDrag(dragPosition + diff);
					} else {
						positionDrag(_animateToPosition);
						ceaseAnimation();
					}
				}
				var ceaseAnimation = function()
				{
					if (_animateToInterval) {
						clearInterval(_animateToInterval);
						delete _animateToPosition;
					}
				};
				var scrollTo = function(pos, preventAni)
				{
					if (typeof pos == "string") {
						// Legal hash values aren't necessarily legal jQuery selectors so we need to catch any
						// errors from the lookup...
						try {
							$e = $(pos, $this);
						} catch (err) {
							return;
						}
						if (!$e.length) return;
						pos = $e.offset().top - $this.offset().top;
					}
					ceaseAnimation();
					var maxScroll = contentHeight - paneHeight;
					pos = pos > maxScroll ? maxScroll : pos;
					$this.data('jScrollPaneMaxScroll', maxScroll);
					var destDragPosition = pos/maxScroll * maxY;
					if (preventAni || !settings.animateTo) {
						positionDrag(destDragPosition);
					} else {
						$container.scrollTop(0);
						_animateToPosition = destDragPosition;
						_animateToInterval = setInterval(animateToPosition, settings.animateInterval);
					}
				};
				$this[0].scrollTo = scrollTo;
				
				$this[0].scrollBy = function(delta)
				{
					var currentPos = -parseInt($pane.css('top')) || 0;
					scrollTo(currentPos + delta);
				};
				
				initDrag();
				
				scrollTo(-currentScrollPosition, true);
			
				// Deal with it when the user tabs to a link or form element within this scrollpane
				$('*', this).bind(
					'focus',
					function(event)
					{
						var $e = $(this);
						
						// loop through parents adding the offset top of any elements that are relatively positioned between
						// the focused element and the jScrollPaneContainer so we can get the true distance from the top
						// of the focused element to the top of the scrollpane...
						var eleTop = 0;
						
						while ($e[0] != $this[0]) {
							eleTop += $e.position().top;
							$e = $e.offsetParent();
						}
						
						var viewportTop = -parseInt($pane.css('top')) || 0;
						var maxVisibleEleTop = viewportTop + paneHeight;
						var eleInView = eleTop > viewportTop && eleTop < maxVisibleEleTop;
						if (!eleInView) {
							var destPos = eleTop - settings.scrollbarMargin;
							if (eleTop > viewportTop) { // element is below viewport - scroll so it is at bottom.
								destPos += $(this).height() + 15 + settings.scrollbarMargin - paneHeight;
							}
							scrollTo(destPos);
						}
					}
				)
				
				
				if (settings.observeHash) {
					if (location.hash && location.hash.length > 1) {
						setTimeout(function(){
							scrollTo(location.hash);
						}, $.browser.safari ? 100 : 0);
					}
					
					// use event delegation to listen for all clicks on links and hijack them if they are links to
					// anchors within our content...
					$(document).bind('click', function(e){
						$target = $(e.target);
						if ($target.is('a')) {
							var h = $target.attr('href');
							if (h && h.substr(0, 1) == '#' && h.length > 1) {
								setTimeout(function(){
									scrollTo(h, !settings.animateToInternalLinks);
								}, $.browser.safari ? 100 : 0);
							}
						}
					});
				}
				
				// Deal with dragging and selecting text to make the scrollpane scroll...
				function onSelectScrollMouseDown(e)
				{
				   $(document).bind('mousemove.jScrollPaneDragging', onTextSelectionScrollMouseMove);
				   $(document).bind('mouseup.jScrollPaneDragging',   onSelectScrollMouseUp);
				  
				}
				
				var textDragDistanceAway;
				var textSelectionInterval;
				
				function onTextSelectionInterval()
				{
					direction = textDragDistanceAway < 0 ? -1 : 1;
					$this[0].scrollBy(textDragDistanceAway / 2);
				}

				function clearTextSelectionInterval()
				{
					if (textSelectionInterval) {
						clearInterval(textSelectionInterval);
						textSelectionInterval = undefined;
					}
				}
				
				function onTextSelectionScrollMouseMove(e)
				{
					var offset = $this.parent().offset().top;
					var maxOffset = offset + paneHeight;
					var mouseOffset = getPos(e, 'Y');
					textDragDistanceAway = mouseOffset < offset ? mouseOffset - offset : (mouseOffset > maxOffset ? mouseOffset - maxOffset : 0);
					if (textDragDistanceAway == 0) {
						clearTextSelectionInterval();
					} else {
						if (!textSelectionInterval) {
							textSelectionInterval  = setInterval(onTextSelectionInterval, 100);
						}
					}
				}

				function onSelectScrollMouseUp(e)
				{
				   $(document)
					  .unbind('mousemove.jScrollPaneDragging')
					  .unbind('mouseup.jScrollPaneDragging');
				   clearTextSelectionInterval();
				}

				$container.bind('mousedown.jScrollPane', onSelectScrollMouseDown);

				
				$.jScrollPane.active.push($this[0]);
				
			} else {
				$this.css(
					{
						'height':paneHeight+'px',
						'width':paneWidth-this.originalSidePaddingTotal+'px',
						'padding':this.originalPadding
					}
				);
				$this[0].scrollTo = $this[0].scrollBy = function() {};
				// clean up listeners
				$this.parent().unbind('mousewheel').unbind('mousedown.jScrollPane').unbind('keydown.jscrollpane').unbind('keyup.jscrollpane');
			}
			
		}
	)
};

$.fn.jScrollPaneRemove = function()
{
	$(this).each(function()
	{
		$this = $(this);
		var $c = $this.parent();
		if ($c.is('.jScrollPaneContainer')) {
			$this.css(
				{
					'top':'',
					'height':'',
					'width':'',
					'padding':'',
					'overflow':'',
					'position':''
				}
			);
			$this.attr('style', $this.data('originalStyleTag'));
			$c.after($this).remove();
		}
	});
}

$.fn.jScrollPane.defaults = {
	scrollbarWidth : 11,
	scrollbarMargin : 5,
	wheelSpeed : 18,
	showArrows : true,
	arrowSize : 0,
	animateTo : false,
	dragMinHeight : 1,
	dragMaxHeight : 99999,
	animateInterval : 100,
	animateStep: 3,
	maintainPosition: true,
	scrollbarOnLeft: false,
	reinitialiseOnImageLoad: false,
	tabIndex : 0,
	enableKeyboardNavigation: true,
	animateToInternalLinks: false,
	topCapHeight: 0,
	bottomCapHeight: 0,
	observeHash: true
};

// clean up the scrollTo expandos
$(window)
	.bind('unload', function() {
		var els = $.jScrollPane.active; 
		for (var i=0; i<els.length; i++) {
			els[i].scrollTo = els[i].scrollBy = null;
		}
	}
);

})(jQuery);


/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-12-20 09:02:08 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4265 $
 *
 * Version: 3.0
 * 
 * Requires: $ 1.2.2+
 */

(function($) {

$.event.special.mousewheel = {
	setup: function() {
		var handler = $.event.special.mousewheel.handler;
		
		// Fix pageX, pageY, clientX and clientY for mozilla
		if ( $.browser.mozilla )
			$(this).bind('mousemove.mousewheel', function(event) {
				$.data(this, 'mwcursorposdata', {
					pageX: event.pageX,
					pageY: event.pageY,
					clientX: event.clientX,
					clientY: event.clientY
				});
			});
	
		if ( this.addEventListener )
			this.addEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = handler;
	},
	
	teardown: function() {
		var handler = $.event.special.mousewheel.handler;
		
		$(this).unbind('mousemove.mousewheel');
		
		if ( this.removeEventListener )
			this.removeEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = function(){};
		
		$.removeData(this, 'mwcursorposdata');
	},
	
	handler: function(event) {
		var args = Array.prototype.slice.call( arguments, 1 );
		
		event = $.event.fix(event || window.event);
		// Get correct pageX, pageY, clientX and clientY for mozilla
		$.extend( event, $.data(this, 'mwcursorposdata') || {} );
		var delta = 0, returnValue = true;
		
		if ( event.wheelDelta ) delta = event.wheelDelta/120;
		if ( event.detail     ) delta = -event.detail/3;
//		if ( $.browser.opera  ) delta = -event.wheelDelta;
		
		event.data  = event.data || {};
		event.type  = "mousewheel";
		
		// Add delta to the front of the arguments
		args.unshift(delta);
		// Add event to the front of the arguments
		args.unshift(event);

		return $.event.handle.apply(this, args);
	}
};

$.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});

})(jQuery);