$(function() {
	hideLinkDottedLine();
	rollover();
});

/**
 * リンクをフォーカスした際の破線を消す
 */
function hideLinkDottedLine() {
	// 点線を消す
	$('a').focus(function(){this.blur();});
}

/* Common Functions
-------------------------------------------------*/
/**
 * デバッグ関数
 * 
 * @param {String} msg 出力メッセージ
 */
function debug(msg) {
	try {
		window.console.log(msg);
	} catch(e) {
		if ($('#debug').size() == 1) {
			$('#debug').html($('#debug').html() + '<p>' + msg + '</p>');
		} else {
			alert(msg);
		}
	}
}

function rollover() {
	$('input[type=image]').hover(
		function(){
			$(this).attr('src' , $(this).attr('src').replace('.gif','_on.gif'));
		},
		function(){
			$(this).attr('src' , $(this).attr('src').replace('_on.gif','.gif'));
		}
	);
}

/**
 * ブラウザ情報の取得
 * 
 */
var BrowserInfo = function() {

	var ua = navigator.userAgent.toLowerCase();

	// Properties
	this.os      = {};
	this.browser = {};

	// Init Properties
	this.os.mac     = false;
	this.os.iphone  = false;
	this.os.ipad    = false;
	this.os.ipod    = false;
	this.os.linux   = false;
	this.os.bsd     = false;
	this.os.sunos   = false;
	this.os.windows = false;
	this.os.android = false;

	this.os.smartphone = false;

	this.browser.chrome  = false;
	this.browser.iphone  = false;
	this.browser.ipad    = false;
	this.browser.ipod    = false;
	this.browser.safari  = false;
	this.browser.firefox = false;
	this.browser.opera   = false;
	this.browser.ie      = false;
	this.browser.gecko   = false;

	// Set OS
	if (ua.indexOf('macintosh') >= 0) {
		this.os.mac   = true;
		this.os.name    = 'Mac';
		this.os.version = (ua.indexOf("mac os x ")>=0)?ua.match(/mac os x [0-9_.]*/).toString().substr(9, 4).replace(/_/g, '.'):-1;

	} else if (ua.indexOf("iphone") >= 0) {
		this.os.iphone  = true;
		this.os.name    = "iPhone";
		this.os.version = (ua.indexOf("iphone os ")>=0)?ua.match(/iphone os [0-9_.]*/).toString().substr(10, 3).replace(/_/g, "."):-1;

	} else if (ua.indexOf("ipad") >= 0) {
		this.os.ipad    = true;
		this.os.name    = "iPad";
		this.os.version = (ua.indexOf("cpu os ")>=0)?ua.match(/cpu os [0-9_.]*/).toString().substr(7, 3).replace(/_/g, "."):-1;

	} else if (ua.indexOf("ipod") >= 0) {
		this.os.ipod    = true;
		this.os.name    = "iPod touch";
		this.os.version = (ua.indexOf("iphone os ")>=0)?ua.match(/iphone os [0-9_.]*/).toString().substr(10, 3).replace(/_/g, "."):0;

	} else if (ua.indexOf("android") >= 0) {
		this.os.android = true;
		this.os.name    = "Android";
		this.os.version = (ua.indexOf("android ")>=0)?ua.match(/android [0-9_.]*/).toString().substr(8, 3).replace(/_/g, "."):0;

	} else if (ua.indexOf("linux") >= 0) {
		this.os.linux   = true;
		this.os.name    = "Linux";

	} else if (ua.indexOf("bsd") >= 0) {
		this.os.bsd     = true;
		this.os.name    = "BSD";

	} else if (ua.indexOf("sunos") >= 0) {
		this.os.sunos   = true;
		this.os.name    = "SunOS";

	} else if (ua.indexOf("win") >= 0) {
		this.os.windows = true;
		this.os.name    = "Windows";

		if (ua.indexOf("windows nt 5.1") >= 0) this.os.version = "XP";
		if (ua.indexOf("windows nt 6.0") >= 0) this.os.version = "Vista";
		if (ua.indexOf("windows nt 6.1") >= 0) this.os.version = "7";
	}

	// Set Browser
	if (ua.indexOf("chrome") >= 0) {
		this.browser.chrome  = true;
		this.browser.name    = "Chrome";
		this.browser.version = ua.match(/chrome\/[0-9_.]*/).toString().substr(7,3);

	} else if (ua.indexOf("iphone") >= 0 && ua.indexOf("safari") >= 0) {
		this.browser.iphone  = true;
		this.browser.name    = "Mobile Safari";
		this.browser.version = ua.match(/version\/[0-9_.]*/).toString().substr(8);

	} else if (ua.indexOf("ipad") >= 0 && ua.indexOf("safari") >= 0) {
		this.browser.ipad     = true;
		this.browser.name    = "iPad Safari";
		this.browser.version = ua.match(/version\/[0-9_.]*/).toString().substr(8);

	} else if (ua.indexOf("ipod") >= 0 && ua.indexOf("safari") >= 0) {
		this.browser.ipod    = true;
		this.browser.name    = "Mobile Safari";
		this.browser.version = ua.match(/version\/[0-9_.]*/).toString().substr(8);

	} else if (ua.indexOf("safari") >= 0) {
		this.browser.safari  = true;
		this.browser.name    = "Safari";
		this.browser.version = ua.match(/version\/[0-9_.]*/).toString().substr(8);

	} else if (ua.indexOf("firefox") >= 0) {
		this.browser.firefox = true;
		this.browser.name    = "Firefox";
		this.browser.version = ua.match(/firefox\/[0-9_.]*/).toString().substr(8, 3);

	} else if (ua.indexOf("opera") >= 0) {
		this.browser.opera   = true;
		this.browser.name    = "Opera";
		this.browser.version = ua.match(/version\/[0-9_.]*/).toString().substr(8);

	} else if (ua.indexOf("msie") >= 0) {
		this.browser.ie      = true;
		this.browser.name    = "Internet Explorer";
		this.browser.version = ua.match(/msie [0-9_.]*/).toString().substr(5);

	}

	if (ua.indexOf('gecko') >= 0)
		this.browser.gecko  = true;


	if (this.os.iphone || this.os.ipad || this.os.ipod || this.os.android) {
		this.os.smartphone = true;
	}


	this.ua = ua;
	this.debug = function() {
		var code = '';

		code += '[OS]\n' + this.os.name + ' ' + this.os.version + '\n';
		code += '\n[Browser]\n' + this.browser.name + ' ' + this.browser.version + '\n';
		code += 'Gecko :: ' + this.browser.gecko + '\n';
		code += '\n[UserAgent]\n' + this.ua + '\n';

		alert(code);
	}
}

