/*
* lm 1.3
* Automatic functions for webpages
* Require:
*  jquery.js
*  frame.css
*  content_font.css
*
* Copyright: (c) 2008 ludicmind.net
**************************************/

// Initialization
$.lm = {
	init: function() {
		for (func in $.lm) {
			if ($.lm[func].init)
				$.lm[func].init();
		}
	}
};

$(document).ready(function(){
	$.lm.init();
	$("div#mainLink").hover(function(){
		$(this).css("background", "url(img/bg_box_01.gif) no-repeat 2px 2px");
	},
	function(){
		$(this).css("background", "none");
	});
	$("div.pBlock > div").hover(function(){
		$(this).css("background", "url(img/bg_box_02.gif) no-repeat left top");
	},
	function(){
		$(this).css("background", "none");
	});
	$("div#mainLink").click(function(){location.href="http://www.sony.jp/nav-u/singing/odekake2/"; return false});
	$("div#link2").click(function(){location.href="http://www.sony.jp/nav-u/cycling/"; return false});
	$("div#link3").click(function(){location.href="http://www.sony.jp/nav-u/singing/odekake/"; return false});
	$("div#link4").click(function(){location.href="http://www.sony.jp/nav-u/products/NV-U35/"; return false});
	$("div#link5").click(function(){location.href="http://www.sony.jp/nav-u/singing/main.html"; return false});
	$("div#link6").click(function(){location.href="http://www.sony.jp/nav-u/singing/research_03.html"; return false});
	$("div#link7").click(function(){location.href="http://www.sony.jp/nav-u/products/NV-U75V/"; return false});
	$("div#link8").click(function(){location.href="http://www.sony.jp/nav-u/singing/research_02.html"; return false});
	$("div#link9").click(function(){location.href="http://www.sony.jp/nav-u/singing/research_01.html"; return false});
});


// Image hover
$.lm.hover = {
	init: function() {
		$('.hover')
			.bind('mouseover', this.enter)
			.bind('mouseout', this.exit)
			.bind('focus', this.enter)
			.bind('blur', this.exit)
			.each(this.preload);
	},

	preload: function() {
		this.preloaded = new Image;
		this.preloaded.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_o$2");
	},

	enter: function() {
		if (!this.src.match(/^(.+)_o(\.[a-z]+)$/) && !this.src.match(/^(.+)_a(\.[a-z]+)$/)){
			this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, "$1_o$2");
		}
	},

	exit: function() {
		if (this.src.match(/^(.+)_o(\.[a-z]+)$/)){
			this.src = this.src.replace(/^(.+)_o(\.[a-z]+)$/, "$1$2");
		} else {
			this.src = this.src.replace(/^(.+)_a(\.[a-z]+)$/, "$1$2");
		}
	}
};


// Opacity Change hover
$.lm.oHover = {
	init: function() {
		$('.oHover')
			.live('mouseover', this.enter)
			.live('mouseout', this.exit)
			.live('focus', this.enter)
			.live('blur', this.exit);
	},

	enter: function() {
		$(this).animate({opacity: 0.7}, 200);
	},

	exit: function() {
		$(this).animate({opacity: 1}, 200);
	}
};


// Add "first-child" class to all elements in #content
$.lm.firstChild = {
	init: function() {
		var ua = window.navigator;
		if (ua.appName == "Microsoft Internet Explorer" && ua.appVersion.indexOf("MSIE 7.0") == -1) {
			$("#content *:first-child").addClass("first-child");
		}
	}
};


// Add "nolink" class to Heading without a[href]
$.lm.noLink = {
	init: function() {
		$("a:not([href])").parent("h2").addClass("nolink");
		$("a:not([href])").parent("h3").addClass("nolink");
		$("a:not([href])").parent("h4").addClass("nolink");
	}
};


// Replace "abbr" with "acronym" (only IE6)
$.lm.changeAbbr = {
	init: function() {
		var ua = window.navigator;
		if (ua.appName == "Microsoft Internet Explorer" && ua.appVersion.indexOf("MSIE 7.0") == -1) {
			var abbrs = document.getElementsByTagName('abbr');
			for (var i = 0; i < abbrs.length; i++) {
				var oldAbbr = abbrs.item(i);
				var newAbbr = document.createElement('abbr');
				newAbbr.title = oldAbbr.title;
				oldAbbr.parentNode.insertBefore(newAbbr, oldAbbr);
				while (oldAbbr.nextSibling.nodeName != '/ABBR') {
					newAbbr.appendChild(oldAbbr.nextSibling);
				}
				oldAbbr.parentNode.removeChild(oldAbbr.nextSibling);
				oldAbbr.parentNode.removeChild(oldAbbr);
			}
		}
	}
};

//Inner Link
$.lm.innerLink = {
	init: function() {
		$("a[href]").each(function(){
			if($(this).attr("href").indexOf("#") == 0){
				if(!$(this).hasClass("lNav")){
					if($(this).attr("href").indexOf("#top") == 0){
						$(this).click(function(){
							$.scrollTo($(this).attr("href"), {duration: 700, easing: "easeOutExpo"});
							return false;
						});
					} else {
						$(this).click(function(){
							$.scrollTo($(this).attr("href"), {duration: 700, easing: "easeOutExpo", offset: {top: -30}});
							return false;
						});
					}
				}
			}
		});
		$("a.lNav").each(function(){
			$(this).click(function(){
				$.scrollTo($(this).attr("href"), {
					duration: 700,
					easing: "easeOutExpo",
					offset: {top: -30}
				});
				$("#navigation dl dd").slideUp("normal");
				$(this).parent("dt").next("dd").slideDown("normal");
				return false;
			});
		});
	},

	accordion: function() {
		if($.browser.safari){
			$("#navigation dl dd").hide();
			$(this).parent("dt").next("dd").show();
		} else {
			$("#navigation dl dd").slideUp("normal");
			$(this).parent("dt").next("dd").slideDown("normal");
		}
	}
};


// Menu List Add Class "first" and "last" - use to ul
(function($) {
	jQuery.fn.addClassFL = function(colNum) {
		return this.children("li").each(function(i){
			if (i % colNum == 0){
				$(this).addClass("first");
			}
			if (i % colNum == colNum - 1){
				$(this).addClass("last");
			}
		});
	};
})(jQuery);


// Menu List Add Class "first" and "last" - use to div
(function($) {
	jQuery.fn.addDivClassFL = function(colNum) {
		return this.children("div").each(function(i){
			if (i % colNum == 0){
				$(this).addClass("first");
			}
			if (i % colNum == colNum - 1){
				$(this).addClass("last");
			}
		});
	};
})(jQuery);


