/* smooth-scroll (required jquery.js & jquery.easing.js)
========================================================= */

var lmSmoothScroll = function(t) {
	var lmSSDur = 750;
	var lmSSEas = 'easeOutExpo';
	if(navigator.appName.match(/Opera/)) {
		location.href = t.hash;
		return false;
	}
	if(location.hostname == t.hostname && location.pathname.replace(/^\//,'') == t.pathname.replace(/^\//,'')) {
		$(t).blur();
		$("html, body").queue([]).stop();
		var myAim = $(t.hash);
		var myPos = myAim.offset().top  - 10;
		if(window.scrollMaxY) {
			var myRng = window.scrollMaxY;
		} else {
			var myRng = document.documentElement.scrollHeight - document.documentElement.clientHeight;
		}
		if(myPos < 0) {
			myPos = 0;
		} else if(myPos > myRng) {
			myPos = myRng;
		}
		$("html, body").animate({
			scrollTop: myPos
		}, lmSSDur, lmSSEas);
		return false;
	}
};

$(function() {
	$("#bottomTab").click(function() {
		return lmSmoothScroll(this);
	});
});

$(function() {
	$('a[href^=#]').click(function() {
		return lmSmoothScroll(this);
	});
});

/* rollover (required jquery.js)
========================================================= */

var lmRollOverInit = function() {
	var myTargets = $(".rollover");
	if(myTargets) {
		var myImg = function() {
			this.src = -1;
			this.ext = -1;
			this.alt = -1;
		}
		var imgSrc = "";
		var tmpSrc = "";
		var imgObj = [];
		var imgPre = [];
		myTargets.each(function() {
			imgSrc = $(this).attr("src");
			// myImg
			imgObj[imgSrc] = new myImg();
			imgObj[imgSrc].src = imgSrc;
			imgObj[imgSrc].ext = imgObj[imgSrc].src.slice(imgObj[imgSrc].src.lastIndexOf('.', (imgObj[imgSrc].src.length - 1)));
			imgObj[imgSrc].alt = imgObj[imgSrc].src.replace(imgObj[imgSrc].ext, '_on' + imgObj[imgSrc].ext);
			// preload
			imgPre[imgSrc] = new Image();
			imgPre[imgSrc].src = imgObj[imgSrc].alt;
			// set
			$(this).mouseover(function() {
				tmpSrc = $(this).attr("src");
				$(this).attr("src", imgObj[tmpSrc].alt);
			});
			$(this).mouseout(function() {
				$(this).attr("src", tmpSrc);
			});
		});
	}
};

$(function() {
	$(window).bind('load', function() {
		lmRollOverInit();
	});
});

