/**
 * @author Tomohiro Tsutsumi @team-chan3.com
 */



function AddressManager(){
	var base = document.title;
	address.init();
	
	$('a[href*=#]').each(function(){
		var ntitle = $(this).attr('title');
		var title = (ntitle) ? ntitle + ' | ' + base : base;
		var page = this.hash.replace('#', '');
		$(this).attr('href', 'javascript:void(0);');
		$(this).bind({
			click : function(){
				address.setTitle(title);
				address.setPage(page);
			}
		});
	});
}

function CenterContainer(){
	var cc = $('.center #container');
	if(cc.length){
		var h = cc.height();
		function _r(){
			var t = ($(window).height() - h) >> 1;
			cc.css({
				top : t
			});
		}
		$(window).bind({
			resize : function(){
				_r();
			}
		});
		_r();
	}
}

function ShakeItem(elm){
	var owner = this;
	
	this._intervalId;
	this._count = 0;
	var range = 1;
	
	this._elm = elm;
	this._elm.css({
		cursor : 'pointer'
	}).bind({
		mouseover : function(){
			owner._stopMove();
			owner._intervalId = setInterval(function(){
				owner._count += 1;
				if(owner._count >= 5){
					owner._stopMove();
				}else{
					var t = Math.floor(2 - Math.random()*4);
					var l = Math.floor(2 - Math.random()*4);
					owner._elm.css({
						'margin-top' : t,
						'margin-left' : l
					});
					if(!$.support.checkOn) owner._elm.rotate(1*range);
					range *= -1;
				}
			}, 60);
		}
	});
}

ShakeItem.prototype._stopMove = function(){
	if(this._intervalId) clearInterval(this._intervalId);
	this._count = 0;
	this._elm.stop().css({
		'margin-top' : 0,
		'margin-left' : 0
	});
	if(!$.support.checkOn) this._elm.rotate(0);
}



var ut;
$(function(){
	utils.init();
	ut = new URLTracker();
	ut.init();
	
	//pngFix
	if(!$.support.opacity) $('.pf').fixPng();
	if(!$.support.tbody) $('.pf67').fixPng();
	
	
	//
	$('.pagetop').bind({
		click : function(){
			utils.scrollTo(0);
		}
	});
	utils.setAlphaBtn($('.ao'), 0.5);
	utils.setPngAlphaBtn($('.pao'));
	
	$('.shake').each(function(){
		new ShakeItem($(this));
	});
	
	//address
	if(typeof( address ) != 'undefined') new AddressManager();
});












///////////////////////////////////////////////
if (!("console" in window)) {
	window.console = {};
	window.console.log = function(str){
		return str;
	};
}

var ie = (function(){
    var undef,
        v = 3,
        div = document.createElement('div'),
        all = div.getElementsByTagName('i');
    while (
        div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
        all[0]
    );
    return v > 4 ? v : undef;
}());

var isIPhone = false;
var isIPad = false;
var isAMob = false;

if(navigator.userAgent.match(/iPhone/i)) isIPhone = true;
if(navigator.userAgent.match(/iPad/i)) isIPad = true;
if(isIPhone || isIPad) isAMob = true;
//alert(isAMob);
