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


$(function(){
	new function(){
		var name_space = 'utils';
		var self = window[name_space] || {};
		window[name_space] = self;
		
		//private
		var _isInit = false;
		
		
		//public API
		self.init = function(){
			if(_isInit) return;
			_isInit = true;
		}
				
		self.getDocHeight = function(){
		    return Math.max(
		        $(document).height(),
		        $(window).height(),
		        document.documentElement.clientHeight
		    );
		}
		
		self.scrollTo = function(t){
			$('html,body').animate({ scrollTop: t }, 1000, 'easeInOutQuart');
		}
		
		self.setAlphaBtn = function(elm, alpha){
			var a = (alpha) ? alpha : 0.4;
			elm.css({
				cursor : 'pointer'
			}).hover(function(){
				$(this).stop().animate({
					opacity : a
				}, 400);
			}, function(){
				$(this).stop().animate({
					opacity : 1
				}, 300, 'linear');
			})
		}
		
		self.setPngAlphaBtn = function(elm, alpha){
			if(!$.support.opacity){
				elm.each(function(){
					var img = $(this).children('img');
					var url = img.attr('src');
					$(this).css("background-image","url('" + url + "')");
					$(this).css({
						display : 'block',
						width : img.attr('width'),
						height : img.attr('height')
					});
					img.attr('src', '/asset/img/s.gif');
					$(this).fixPng();
					self.setAlphaBtn(elm, alpha);
				});
				
			}else{
				self.setAlphaBtn(elm, alpha);
			}
		}
		
		self.createFixBox = function($color, $zIndex){
			var box = $('<div />');
			var position = (!$.support.opacity) ? 'absolute' : 'fixed';
			box.css({
				'position' : position,
				'top' : '0px', 'left' : '0px',
				'opacity': 0, 'z-index' : $zIndex
			});
			
			if(!!$color) box.css('background-color', $color);
			else box.css('background-color', 'transparent');
			
			box.resize = function(){
				box.css({
					'width' : $(window).width() + 'px',
					'height' : $(window).height() + 'px'
				});
				
				if(!$.support.noCloneEvent || isAMob){
					box.css({
						'left' : $(window).scrollLeft() + 'px',
						'top' : $(window).scrollTop() + 'px'
					});
				}
			}
			
			box.resize();
			return box;
		}
		
	}
});

