/*!
 * Utils.js
 * Copyright 2011, HUSMA
 * Date: Wed Aug 17 2011
 *
 */

/**
 * Edit by: naotoyanai
 * Date: Thu Nov 24 2011
 */

/**
 * os, browser detect
 **/
var Detect = {
	os: function(){
		if(/ipod/i.test(navigator.userAgent)) return 'ipod';
		if(/iphone/i.test(navigator.userAgent)) return 'iphone';
		if(/ipad/i.test(navigator.userAgent)) return 'ipad';
		if(/android/i.test(navigator.userAgent)) return 'android';
		if(/mac/i.test(navigator.userAgent)) return 'mac';
		if(/win/i.test(navigator.userAgent)) return "win";

		return 'other';
	}
	,
	ios: function(){
		return Detect.os() == "ipod" || Detect.os() == "iphone" || Detect.os() == "ipad";
	}
	,
	android: function(){
		return Detect.os() == "android";
	}
	,
	browser: function(){
		if(/msie 6/i.test(navigator.userAgent)){ return 'ie ie6'; }
		if(/msie 7/i.test(navigator.userAgent)){ return 'ie ie7'; }
		if(/msie 8/i.test(navigator.userAgent)){ return 'ie ie8'; }
		if(/msie 9/i.test(navigator.userAgent)){ return 'ie ie9'; }

		if(/firefox\/3.6/i.test(navigator.userAgent)){ return 'ff ff3'; }
		if(/firefox\/8/i.test(navigator.userAgent)){ return 'ff ff8'; }

		if(/safari/i.test(navigator.userAgent)){
			if(/version\/2/i.test(navigator.userAgent)){ return 'safari safari2'; }
			if(/version\/3/i.test(navigator.userAgent)){ return 'safari safari3'; }
			if(/version\/4/i.test(navigator.userAgent)){ return 'safari safari4'; }
			if(/version\/5/i.test(navigator.userAgent)){ return 'safari safari5'; }
		}
		
		if(/chrome\/4/i.test(navigator.userAgent)){ return 'chrome chrome4'; }
		if(/chrome\/5/i.test(navigator.userAgent)){ return 'chrome chrome5'; }
		if(/chrome\/6/i.test(navigator.userAgent)){ return 'chrome chrome6'; }
		if(/chrome\/7/i.test(navigator.userAgent)){ return 'chrome chrome7'; }
		if(/chrome\/8/i.test(navigator.userAgent)){ return 'chrome chrome8'; }
		if(/chrome\/9/i.test(navigator.userAgent)){ return 'chrome chrome9'; }
		if(/chrome\/10/i.test(navigator.userAgent)){ return 'chrome chrome10'; }
		if(/chrome\/11/i.test(navigator.userAgent)){ return 'chrome chrome11'; }
		if(/chrome\/12/i.test(navigator.userAgent)){ return 'chrome chrome12'; }
		if(/chrome\/13/i.test(navigator.userAgent)){ return 'chrome chrome13'; }
		if(/chrome\/14/i.test(navigator.userAgent)){ return 'chrome chrome14'; }
		if(/chrome\/15/i.test(navigator.userAgent)){ return 'chrome chrome15'; }

		if(/opera/i.test(navigator.userAgent)){
			if(/version\/8/i.test(navigator.userAgent)){ return 'opera opera8'; }
			if(/version\/9/i.test(navigator.userAgent)){ return 'opera opera9'; }
			if(/version\/10/i.test(navigator.userAgent)){ return 'opera opera10'; }
			if(/version\/11/i.test(navigator.userAgent)){ return 'opera opera11'; }
		}
		
		return 'other';
	}
}

/**
 * URL Utils
 **/
var URL = {
	hash:function(__h) {
		if( __h != undefined ) {
			location.hash = __h;
		}
		return location.hash;
	}
}
 
/**
 * Random
 **/
var RANDOM = {
	getRange:function(range){return (Math.random()*range)-(Math.random()*range)} 
}
 
/**
 * Timer Object
 **/
var TIMER = {
	start:function(delay,callback){setTimeout(callback,delay);}
}
