$(document).ready(function()
{
	// extarnal link
	$('a[href^="http://"]').not('a[href^="http://' + location.host + '/' + '"]').not('a[href="http://' + location.host + '"]').attr("rel","external");
	$('a[href^="https://"]').not('a[href^="https://' + location.host + '/' + '"]').not('a[href="https://' + location.host + '"]').attr("rel","external");
	$('a[target="_blank"]').attr("rel","external");
	$("a[rel$='external'],area[class$='external']").click(function() { this.target = "_blank"; });

	// animated scrolling
	$("a[href*='#'],area[href*='#']").click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset},'fast');
				return false;
			}
		}
	});

	// set child class
	var kids = $(".set-child-class").children();
	$(kids).filter(":first-child").addClass("first-child");
	$(kids).filter(":last-child").addClass("last-child");

	$("body#characters-index #content ol a").css({opacity: 0}).addClass("over").hover(
		function() {
			$(this).fadeTo(0,1);
		},
		function() {
			$(this).fadeTo(250,0);
		}

	);

});

/*
rollover
----------------------------------------------------------------------- */
function rollover() {
    var preLoad = new Object();
    $('img.rollover,input.rollover').not("[src*='_o.'],[src*='_d.']").each(function() {
        this.imgOrig = this.src;
        this.imgType = this.imgOrig.substring(this.imgOrig.lastIndexOf('.'));
        this.imgName = this.imgOrig.substr(0, this.imgOrig.lastIndexOf('.'));
        if ($(this).hasClass("na")) {
            this.imgOver = this.imgName + '_na' + this.imgType;
        } else {
            this.imgOver = this.imgName + '_o' + this.imgType;
        }
        preLoad[this.src] = new Image();
        preLoad[this.src].src = this.imgOver;
        $(this).hover(
            function() {
                this.src = this.imgOver;
            },
            function() {
                this.src = this.imgOrig;
            }
        );
    });
    $('.rollsibling').each(function() {
        var target = $(this).siblings('img.rollover').not("[src*='_o.'],[src*='_d.']");
        $(this).hover(
            function() {
                target.each(function() {
                    this.src = this.imgOver;
                })
            },
            function() {
                target.each(function() {
                    this.src = this.imgOrig;
                })
            }
        );
    });
}
$(document).ready(rollover);

