/* Last Updated: 2010.04.23 ( based on top2.js at 2010.03.30 )*/
var asahi = asahi || new Object();


/**************************************************************************
 * ■Cookie
 **************************************************************************/
asahi.Agent = function()
{
	this.initialize.apply(this, arguments);
}

asahi.Agent.prototype =
{
	initialize: function()
	{
		this.agent = navigator.userAgent.toLowerCase();
		this.ver = navigator.appVersion;
		this.win = (this.agent.indexOf("windows") != -1);
		this.mac = (this.agent.indexOf("mac") != -1);
		this.opera = this.agent.indexOf("opera",0) != -1;
		this.safari = this.agent.indexOf("safari") != -1;
		this.ie = this.agent.indexOf("msie") != -1 && !this.opera;
		this.ie5win = (this.agent.indexOf("msie 5.0") != -1) && this.win;
		this.ie55win = (this.agent.indexOf("msie 5.5") != -1) && this.win;
		this.ie6win = (this.agent.indexOf("msie 6.") != -1) && this.win;
		this.ie5mac = (this.agent.indexOf("msie") != -1) && this.mac;
		this.ns = this.agent.indexOf("netscape") != -1 && !this.opera;
		this.ns6 = (this.agent.indexOf("netscape6/6.") != -1) && this.ns;
		this.ns7 = (this.agent.indexOf("netscape7/7.") != -1) && this.ns;
		this.ie50mac = (this.agent.indexOf("msie 5.0") != -1) && this.mac;
	},

	getVer: function()
	{
		if(RegExp)
		{
			if(this.ie)
			{
				return this.agent.match(/msie (\d(.\d+)?)/)[1];
			}
			if(this.ns || this.ns6 || this.ns7)
			{
				return this.agent.match(/netscape\/(\d(.\d+)?)/)[1];
			}
			if(this.opera)
			{
				return this.agent.match(/opera\/? ?(\d(\.\d+)?)/)[1];
			}
			return parseFloat(this.ver);
		}
		else
		{
			return undefined;
		}
	},

	getTarget: function()
	{
		if(this.ie)
		{
			return this.getVer() >= 6;
		}
		if(this.safari)
		{
			var ver = this.agent.match(/applewebkit\/(\d(.\d+)?)/)[1];
			return (ver > 130);
		}
		if(this.ns)
		{
			return this.getVer() >= 7;
		}
		if(this.opera)
		{
			return this.getVer() >= 8.5;
		}
		return true;
	}
}

/**************************************************************************
 * ■Cookie
 **************************************************************************/
asahi.Cookie = function()
{
	this.initialize.apply(this, arguments);
}

asahi.Cookie.prototype =
{
	initialize: function()
	{
	},

	create: function(name,value,days)
	{
		if(days)
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires=" + date.toGMTString();
		}
		else expires = "";
		document.cookie = name + "=" + value + expires + "; path=/; domain=asahi.com";
	},

	read: function(name)
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++)
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	},

	clear: function(name)
	{
		document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	},


	object2String: function(obj)
	{
		var val, output = "";
		if (obj){
			output += "{";
			for (var i in obj) {
				val = obj[i];
				switch (typeof val) {
					case ("object"):
						if (val[0]) {
							output += i + ":" + this.array2String(val) + ",";
						} else {
							output += i + ":" + this.object2String(val) + ",";
						}
						break;
					case ("string"):
						output += i + ":'" + escape(val) + "',";
						break;
					default:
						output += i + ":" + val + ",";
				}
			}
			output = output.substring(0, output.length-1) + "}";
		}
		return output;
	},

	array2String: function(array)
	{
		var output = "";
		if (array) {
			output += "[";
			for (var i in array) {
				val = array[i];
				switch (typeof val) {
					case ("object"):
						if (val[0]) {
							output += this.array2String(val) + ",";
						} else {
							output += this.object2String(val) + ",";
						}
						break;
					case ("string"):
						output += "'" + escape(val) + "',";
						break;
					default:
						output += val + ",";
				}
			}
			output = output.substring(0, output.length-1) + "]";
		}
		return output;
	},

	string2Object: function(string)
	{
		eval("var result = " + string);
		return result;
	},

	string2Array: function(string)
	{
		eval("var result = " + string);
		return result;
	}
}


asahi.agent = new asahi.Agent();
//jQuery.noConflict();

if(asahi.agent.getTarget())
{
	asahi.cookie = new asahi.Cookie();
	jQuery(function()
	{

	});
}




var asahi = asahi || new Object();
/**************************************************************************
 * Scroll
 **************************************************************************/
asahi.Scroll = function()
{
	this.initialize.apply(this, arguments);
}

asahi.Scroll.prototype =
{
	initialize: function()
	{
		this.scrollSpeed = 4;
		this.scrollRange;
		this.interval;

		this.initScroll();
	},


	initScroll: function()
	{
		var html = jQuery('#ScrlArea')
			.addClass('js')
			.prepend('<p id="ScrlLeft"><img src="resource/img/btn_scrl_left.gif" alt="" width="19" height="105" /></p>')
			.append('<p id="ScrlRight"><img src="resource/img/btn_scrl_right.gif" alt="" width="19" height="105" /></p>')
			.html();

		jQuery('#ScrlArea').html(html);

		var lis=jQuery('#caselist > li');
		jQuery("#caselist").css("width",(100*lis.length)+'px');

		/*
		 *
		 */
		this.setButton();


		/*
		 *
		 */
		this.setScrollRange();

		/*
		 * EVENT: resize
		 */
		var self = this;
		jQuery(window).resize(function(){self.setScrollRange()});
	},


	setButton: function()
	{
		jQuery('#ScrlLeft').find('img').hover
		(
			function(self)
			{
				return function()
				{
					self.scroll(self.scrollSpeed);
					self.interval = setInterval(function(){self.scroll(self.scrollSpeed);}, 10);
				};
			}(this),

			function(self)
			{
				return function()
				{
					clearInterval(self.interval);
				};
			}(this)
		);

		jQuery('#ScrlRight').find('img').hover
		(
			function(self)
			{
				return function()
					{
						self.scroll(-self.scrollSpeed);
						self.interval = setInterval(function(){self.scroll(-self.scrollSpeed)}, 10);
					};
			}(this),

			function(self)
			{
				return function()
					{
						clearInterval(self.interval);
					};
			}(this)
		);
	},


	setScrollRange: function()
	{
		this.scrollRange = Math.min(0, jQuery('#ScrlTarget').width() - jQuery('#ScrlTarget').find('ul').width());
		this.scroll(0);
	},


	scroll: function(dx)
	{
		var ox = parseInt(jQuery('#ScrlTarget').find('ul').css('margin-left'));
		var vx = ox + dx;
		if(vx>0)
		{
			vx = 0;
		}
		else if(vx<this.scrollRange)
		{
			vx = this.scrollRange;
		}

		jQuery('#ScrlTarget').find('ul').css('margin-left', vx + 'px');
	}
}




if(asahi.agent.getTarget())
	{
	jQuery(function()
	{
	new asahi.Scroll();
	});
}

/*2010.06.07*/
var asahi = asahi || new Object();
/**************************************************************************
 * Scroll Video Thumbnail
 **************************************************************************/
asahi.VScroll = function()
{
	this.initialize.apply(this, arguments);
}

asahi.VScroll.prototype =
{
	initialize: function()
	{
		this.VscrollSpeed = 5;
		this.VscrollRange;
		this.interval;
		
		this.initVScroll();
	},
	
	
	initVScroll: function()
	{
		var html = jQuery('#VScrlArea')
			.addClass('js')
			.prepend('<p id="VScrlLeft"><img src="resource/img/video_scroll_left.png" alt="" width="12" height="59" /></p>')
			.append('<p id="VScrlRight"><img src="resource/img/video_scroll_right.png" alt="" width="12" height="59" /></p>')
			.html();
		
		jQuery('#VScrlArea').html(html);
		var staflis=jQuery('#staflist > li');
		jQuery("#staflist").css("width",(55*staflis.length)+'px');
		
		/*
		 * 
		 */
		this.setVButton();
		
		
		/*
		 * 
		 */
		this.setVScrollRange();
		
		/*
		 * EVENT: resize
		 */
		var self = this;
		jQuery(window).resize(function(){self.setVScrollRange()});
	},
	
	
	setVButton: function()
	{
		jQuery('#VScrlLeft').find('img').hover
		(
			function(self)
			{
				return function()
				{
					self.scroll(self.VscrollSpeed);
					self.interval = setInterval(function(){self.scroll(self.VscrollSpeed);}, 5);
				};
			}(this),
			
			function(self)
			{
				return function()
				{
					clearInterval(self.interval);
				};
			}(this)
		);
		
		jQuery('#VScrlRight').find('img').hover
		(
			function(self)
			{
				return function()
					{
						self.scroll(-self.VscrollSpeed);
						self.interval = setInterval(function(){self.scroll(-self.VscrollSpeed)}, 5);
					};
			}(this),
			
			function(self)
			{
				return function()
					{
						clearInterval(self.interval);
					};
			}(this)
		);
	},
	
	
	setVScrollRange: function()
	{
		this.VscrollRange = Math.min(0, jQuery('#VScrlTarget').width() - jQuery('#VScrlTarget').find('ul').width());
		this.scroll(0);
	},
	
	
	scroll: function(dxx)
	{
		var oxx = parseInt(jQuery('#VScrlTarget').find('ul').css('margin-left'));
		var vxx = oxx + dxx;
		if(vxx>0)
		{
			vxx = 0;
		}
		else if(vxx<this.VscrollRange)
		{
			vxx = this.VscrollRange;
		}
		
		jQuery('#VScrlTarget').find('ul').css('margin-left', vxx + 'px');
	}
}




if(asahi.agent.getTarget())
	{
	jQuery(function()
	{
	new asahi.VScroll();
	});
}



