/* jquery_ex.js 0.1.0
 *
 * Copyright (c) 2006 Kyosuke Nakamura (kyosuke.jp)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Since:     2006-10-30
 * Modified:  2006-11-15
 * Arranged:  2007-05-09
 */

var jqueryEx = {
	preloader: {
		loadedImages: [],
		load: function (url){
			var img = this.loadedImages;
			var l = img.length;
			img[l] = new Image();
			img[l].src = url;
		}
	},
	uri: {
		dirName: function(uri){
			var ary = uri.split('/');
			ary.pop();
			return ary.join('/');
		},
		path: function (uri){
			return uri.split('#')[0];
		},
		anchorName: function (uri){
			return uri.split('#')[1];
		},
		isSelfLink: function(href){
			return ((this.path(href) == this.path(location.href)) || (this.path(href) == this.dirName(location.href)+'/'));
		}
	}
};

$(function(){
	
	//Set rollover
	$('a img.btn').each(function(){
		this.originalSrc = $(this).src();
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_on$1");
		jqueryEx.preloader.load(this.rolloverSrc);
	}).hover(function(){
		$(this).src(this.rolloverSrc);
	},function(){
		$(this).src(this.originalSrc);
	});

	//Set new window
	$('a[@href^="http://"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');
	
	//Set smooth scroll
	$('a[@href^="#"]').click(function(){
		var href = jqueryEx.uri.anchorName($(this).href());
		$('#'+href).ScrollTo(500,'easeout');
		return false;
	});

	//Automatic add on even number and uneven number
	$('ul').each(function(){
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
	});
	$('table').each(function(){
		$(this).find('tr:odd').addClass('even');
		$(this).find('tr:even').addClass('odd');
	});
	
	//Add ":first-child, :last-child" as class
	$(':first-child').addClass('firstChild');
	$(':last-child').addClass('lastChild');
	
	//Add :empty as class
	$(':empty').addClass('empty');

});
