//jQuery.noConflict();
//var $ = jQuery;


/* 00.calScale
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
function calScale(e){
	
	var bannerH = $('div#product').height(),
		articleH = $('div.articles').height(),
		clientH = $('html').exClientHeight(),
		targetArea = 'div.articles',
		variability1 = 83,
		variability2 = 38;
		
		if($('#iipj')[0]){
			variability2 = 37;
		}

	//articleHeight 処理
	if(articleH<bannerH){
		if((bannerH)<clientH){
			$(targetArea).css({"height":clientH-variability1});
		}else{
			$(targetArea).css({"height":bannerH-variability2});
		}
	}else if(articleH>bannerH){
		if(articleH<clientH){
			$(targetArea).css({"height":clientH});
		}else{
			$(targetArea).css({"height":articleH});
		}
	}
}


/* 01.repTimer
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
function repTimer(interval, callback){
	var interval = interval || 100;
	if (!callback){
		return false;
	}
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		this.internalCallback = function () {
			callback(self);
		};
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		var self = this;
	};
	return new _timer(interval, callback);
}


/* 02.jQuery Ready
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
$(function(){

/* 02-1.サイト内共通
=========================================================== */
	//ウィドウ読み込み及び、リサイズ時の処理
	if(!$('body.newsItem')[0]){
		$(window).bind({
			load:function(){//読み込み
				calScale();
			},
			resize:function(){//リサイズ
				calScale();
			}
		});
	}

	//ターゲットブランク
	$("a.blank").click(function(){
		window.open(this.href);
		return false;
	});

	//スムーススクロール
	$("a[href^=#]").click(function() {  
		var hash = this.hash;  
		 if(!hash || hash == "#")  
		 return false;  
		$($.browser.safari ? 'body' : 'html')  
		 .animate({scrollTop: $(hash).offset().top}, 500, "swing");  
		 return false;  
	});

	//ロールオーバー
	var postfix = '_on';
	$('img.rollOver,input.rollOver').not('[src*="'+ postfix +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.'))
		           + postfix
		           + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(
			function() {
				img.attr('src', src_on);
			},
			function() {
				img.attr('src', src);
			}
		);
	});
	
	//glNavi
	var glNavi = (function(){
		var navList = $('#glNavi dd.navi ul li').not('.selected').get();
		var tipList = $('#glNavi dd.tips ul li').not('.selected').get();
		//var flag = false;
		$.each(navList,function(i){
			$(navList[i]).hover(function(){
				$(this).stop(false,false).animate({"left": "0"},100);
				if(i!=6){
					if($.os.name=='win'&&$.browser.name=='msie') {
						$(tipList[i]).fixPng();
					}
					$(tipList[i]).fadeTo(300,1);
					$(tipList[i]).css({"visibility":"visible"});
				}
			},function(){
				$(this).stop(false,false).animate({"left": "18"},100);
				if(i!=6){
					$(tipList[i]).fadeTo(300,0);
				}
			});
		});
	})();

	//prNavi
	var prNavi = (function(){
		var prList = $('#product dl dl').get();
		var inqList = $('#product dl dl dd.tipSs,#product dl dl dd.tipSh').get();
		$.each(prList,function(i){
			$(prList[i]).hover(function(){
				if($.os.name=='win'&&$.browser.name=='msie') {
					$(inqList[i]).fixPng();
				}
				$(this).children('dd.link').children('a').css({backgroundPosition:'0 -165px'});
				$(inqList[i]).stop(false,false).fadeTo(300,1);
				$(inqList[i]).css({"visibility":"visible"});
			},function(){
				$(this).children('dd.link').children('a').css({backgroundPosition:'0 0'});
				$(inqList[i]).stop(false,false).fadeTo(300,0);
			});
		})
	})();
	
	var footerInfo = (function(){
		var flag = false;
		var showArray = new Array('#footer #businessSec','#footer div.jp','#footer div.en','#footer #subInfo');
		var open = function(){
			if($('dl.colorHange')[0]) {
				$('dl.colorHange').css({visibility:'hidden'});
			}
			$.each(showArray,function(i){
				$(showArray[i]).show();
			});
			var tmpH = $('#footer').height();
			$('#footer #btnToggle a').css({
				bottom:tmpH,
				background: 'url(./media/img/share/btnToggle2.jpg) no-repeat 0 0'
			});
			flag = true;
		}
		var close = function(){
			if($('dl.colorHange')[0]) {
				$('dl.colorHange').css({visibility:'visible'});
			}
			$.each(showArray,function(i){
				$(showArray[i]).hide();
			});
			$('#footer #btnToggle a').css({
				bottom:'40px',
				background: 'url(./media/img/share/btnToggle.jpg) no-repeat 0 0'
			});
			flag = false;
		}

		$('#btnToggle').click(function(){
			(flag==false)?open():close();			
		});

	})();


	//WinFont調整
	if($.os.name == 'win') {
		if($('#news')[0]){
			if($.browser.name == 'msie'){
				$('#contents #news ul#newsCat li.infoCat').css({
					background: "url(./media/img/share/iconNewsIs.png) no-repeat 0 5px;"
				});
				$('#contents #news ul#newsCat li.eventCat').css({
					background: "url(./media/img/share/iconNewsEs.png) no-repeat 0 5px;"
				});
				$('#contents #news ul#newsCat li.sugoudeCat').css({
					background: "url(./media/img/share/iconNewsSs.png) no-repeat 0 5px;"
				});
			}
		}
		if($('#about')[0]){
			if($.browser.name == 'msie'){
				$('#companyInfo #policy #pr,#companyInfo #businessDetail dd,#companyInfo #partnerDetail dd').css({fontSize:'87%'});
			}
		}
	}

	//Mac-Font調整
	if($.os.name == 'mac') {
		if($('#footer')[0]){
			if($.browser.name == 'safari'){
				$('#footer #businessSec').css({fontSize:'78%'});
			}
			if($.browser.name == 'firefox'){
				$('#footer #businessSec').css({
					padding:'10px 0 25px 20px',
					width:'600px'
				});
				var itemArray = new Array('#footer .jp','#footer .en');
				$.each(itemArray,function(i){
					$(itemArray[i]).css({
						padding:'0 0 5px 20px',
						width:'600px'
					});
				});
				$('#footer #subInfo').css({
					padding:'0 0 20px 20px',
					width:'600px'
				});
			}
		}
	}


/* 02-2.Home
=========================================================== */
	
	if($('#home')[0]) {

		//news-lightbox
		$("a[rel^='prettyPopin']").prettyPopin({
			width: 565,
			followScroll:false
		});
		
		var flag;

		$('#news #items li a').click(function(){
			flag = true;
			console.debug(flag);
		});

		//news-list
		var repSett =  (function(){
			var newsList = $('#news #items li').get(),
				res = 5000;
		
			//initialize
			$.each(newsList,function(i){
				var delNum = 200*i;
				if(i<3){
					$(newsList[i]).delay(delNum).fadeTo(100,0.3);
					$(newsList[i]).children('div').children('.more').delay(delNum).fadeTo(100,0.3);
				}
				$(newsList[i]).animate(
					{
						opacity:1,
						"duration": "slow",
						"easing": "easeInQuart"
					}
				);
				if(i<3){
					$(newsList[i]).delay(delNum).fadeTo('slow',1);
					$(newsList[i]).children('div').children('.more').fadeTo('slow',1);
				}
			});
			for(i=3;i<5;i++){
				$(newsList[i]).fadeTo('slow',1);
				$(newsList[i]).children('div').children('.more').fadeTo(0,1);
			}
			

			var repRotation = (function(){
				
				var $list = $('#news #items');
				var height = $list.find('> li:first').height()+12;
				
				repTimer(res, function (repTimer){

					var repRotation = (function(){
					
						$list.find('> li:last').after($list.find('> li:first').clone(true));
						$list.find('> li:first').fadeTo(200,0);
						$list.find('> li:first').children('div').children('.more').fadeTo(200,0);
						$list.animate(
							{
								top:'-'+height+'px',
								"duration": "400",
								"easing": "easeOutExpo"
							},
							function(){
								$list.find('> li:first').remove();
								$list.css({top:'0'});
							}
						);

					})();
					
					$('#news #items li').hover(function(){
						repTimer.stop();
					},function(){
						repTimer.reset(res);
					});
					/*
					$('#news #items li a').click(function(){
						repTimer.stop();
						flag = true;
					});
					var restitution = (function(){
						if(flag==false){
							repTimer.reset(res);
							flag = null;
						}
					})();
					*/
				});
			
			})();

		})();

	}

});






