(function($){
var _myAgent = navigator.userAgent;
var _asIE6 = (_myAgent.indexOf('MSIE 6') > -1)? true : false;
var _asIE7 = (_myAgent.indexOf('MSIE 7') > -1)? true : false;

var _pointCK = document.cookie;
var _accessVal = false;
if(_pointCK.indexOf('mq_point') > -1){
	_accessVal = true;
}else{
	document.cookie = 'mq_point';
}


$(function(){
	//First Access Animation --------------------------------------------------------------------------
	if(_accessVal == false){
	$('body').addClass('start');
	$('div#header1').fadeIn(400, function(){
			$('div#contents').children('div').hide();
			$('div#main').children('div, p').hide().css({'position':'absolute', 'top':'0px','left':'0px'});
			$('div#main').css('overflow','hidden');
			
			$('div#contents').show();
			$('div#main').show();
			
			var _cmLink = $('div#cmLinks');
			var _trendLinks = $('div#trendLinks');
			var _allItemLinks = $('div#allItemLinks');
			var _simulationLinks = $('div#simulationLinks');
			var _makeupLinks = $('div#makeupLinks');
			var _newItemLinks = $('div#newItemLinks');
			var _flashMenu = _newItemLinks.prev();
			
			var _duration = 300;
			var _easeType  = 'easeOutQuart';
			
			//div#cmLinks show -----------------------------------------------------------------------------1
			_cmLink.css({'opacity':'0', 'display':'block'});
			_cmLink.animate({'opacity':'1'},_duration,_easeType,function(){
				$(this).animate({'top':'194px'},_duration,_easeType,function(){
					//div#trendLinks show ----------------------------------------------------------------------2
					_trendLinks.css({'opacity':'0', 'display':'block'});
					
					_trendLinks.animate({ 'opacity':'1'},_duration,_easeType,function(){
						_cmLink.animate({'top':'300px'},_duration,_easeType);																																			
						$(this).animate({'top':'106px'},_duration,_easeType,function(){
							//div#allItemLinks show ----------------------------------------------------------------3
							_allItemLinks.css({'opacity':'0', 'display':'block'});
							_allItemLinks.animate({ 'opacity':'1'},_duration,_easeType,function(){
								_cmLink.animate({'top':'409px'},_duration,_easeType);
								_trendLinks.animate({'top':'215px'},_duration,_easeType);
								$(this).animate({'top':'109px'},_duration,_easeType,function(){
									//div#simulationLinks show ---------------------------------------------------------4
									_simulationLinks.css({'opacity':'0', 'display':'block'});
									_simulationLinks.animate({ 'opacity':'1'},_duration,_easeType,function(){
										_cmLink.animate({'top':'643px'},_duration,_easeType);
										_trendLinks.animate({'top':'449px'},_duration,_easeType);
										_allItemLinks.animate({'top':'343px'},_duration,_easeType);
										
									});
								});
							});
						});
					});
				})																					
			});
	});
	}
	
	$('div#newItemLinks>ul>li>a, div#trendLinks>ul>li>a, div#trendLinks>p>a').hover(
		function(){
			var _targetH = ($(this).children().attr('alt') == 'MQ Trend News')? 80 : 100;
			//alert(_targetH);
			$(this).children('span').stop().animate(
				{'top':'67'},200,function(){$(this).parent().removeClass('fadeOut').addClass('fadeIn')}
			);
		},
		function(){
			//alert("fd");
			$(this).children('span').stop().animate(
				{'top':'95px'},200,function(){$(this).parent().removeClass('fadeIn').addClass('fadeOut')}
			);
		}
	);
	
		$('div#newItemLinks1>ul>li>a, div#trendLinks1>ul>li>a, div#trendLinks1>p>a').hover(
		function(){
			var _targetH = ($(this).children().attr('alt') == 'MQ Trend News')? 80 : 100;
			//alert(_targetH);
			$(this).children('span').stop().animate(
				{'left':'0px'},200,function(){$(this).parent().removeClass('fadeOut1').addClass('fadeIn1')}
			);
		},
		function(){
			//alert("fd");
			$(this).children('span').stop().animate(
				{'left':'-214px'},200,function(){$(this).parent().removeClass('fadeIn1').addClass('fadeOut1')}
			);
		}
	);

	
	$('div#makeupLinks>div#changeMode>ul>li>a').hover(
		function(){
			var _id = $(this).parent().attr('id');
			var _className = (_id == 'makeup01')? 'onMU01' : 'onMU02';
			$(this).children('span.off').fadeOut(400);
			$(this).children('span.over').fadeIn(400);
			$(this).parents('li').css({'z-index':'10'});
			$(this).children('img.keyImg').stop().animate({'width':'475px'},400);
			$(this).parent().stop().animate({'width':'475px'},400);
		},
		function(){
			$(this).children('span.off').fadeIn(400);
			$(this).children('span.over').fadeOut(400);
			$(this).parents('li').css({'z-index':'1'});
			$(this).children('img.keyImg').stop().animate({'width':'384px'},400);
			$(this).parent().stop().animate({'width':'356px'},400);
		}
	);
	
	$('div#header1>p>a, div#modeChange>ul>li>a').bind('click', function(){
		var _url = $(this).attr('href');
		
		if(_asIE6 || _asIE7){
			var _winW = $(window).width();
			var _targetW = _winW-((_winW-1004)/2);
			$('div#modeChange').hide();
			$('body').append($('<div></div>', {'class':'ie6Mod'}).append($('div#modeChange').clone().show()));
			$('div.ie6Mod').animate({'right':'0px','width':_targetW},600,'easeOutQuart', function(){
				location.href = _url;
			});
		}else{
			$('div#modeChange').css({'z-index':'9999','background-color':'#FFF'});
			$('div#modeChange').animate({'width':'970px'},600,'easeOutQuart', function(){
				location.href = _url;
			});
		}
		return false;
	});
	
});
})(jQuery);
