/* ------------------------------------------------------- */

/* common.js

/* ------------------------------------------------------- */


/* page scroll
-----------------------------------------------------------*/
$(function(){
	$('p.goToTop a').click(function(){
		$.scrollTo($('#pageTop'), { speed:1000, axis:'y', queue:true });
		return false;
	});
})
$(function(){
	$('#goToTop a').click(function(){
		$.scrollTo($('#pageTop'), { speed:1000, axis:'y', queue:true });
		return false;
	});
})

/* each */
function setCrAcPageScroll() {
	$(function(){
		$('li.crAcNaviNagoya a').click(function(){
			$.scrollTo($('#nagoya'), { speed:1000, axis:'y', queue:true });
			return false;
		});
	})
	$(function(){
		$('li.crAcNaviTokyoTop a').click(function(){
			$.scrollTo($('#tokyo'), { speed:1000, axis:'y', queue:true });
			return false;
		});
	})
	$(function(){
		$('li.crAcNaviTokyoBottom a').click(function(){
			$.scrollTo($('#tokyo'), { speed:1000, axis:'y', queue:true });
			return false;
		});
	})
	$(function(){
		$('li.crAcNaviTakayama a').click(function(){
			$.scrollTo($('#takayama'), { speed:1000, axis:'y', queue:true });
			return false;
		});
	})
}

function setCrHsPageScroll() {
	$(function(){
		$('li.crHsNavi1930 a').click(function(){
			$.scrollTo($('#y1930'), { speed:1000, axis:'y', queue:true });
			return false;
		});
	})
	$(function(){
		$('li.crHsNavi1970 a').click(function(){
			$.scrollTo($('#y1970'), { speed:1000, axis:'y', queue:true });
			return false;
		});
	})
	$(function(){
		$('li.crHsNavi1980 a').click(function(){
			$.scrollTo($('#y1980'), { speed:1000, axis:'y', queue:true });
			return false;
		});
	})
	$(function(){
		$('li.crHsNavi1990 a').click(function(){
			$.scrollTo($('#y1990'), { speed:1000, axis:'y', queue:true });
			return false;
		});
	})
	$(function(){
		$('li.crHsNavi2000 a').click(function(){
			$.scrollTo($('#y2000'), { speed:1000, axis:'y', queue:true });
			return false;
		});
	})
}

function setCrAdPageScroll(){
	$(function(){
		$('p.goToSong a').click(function(){
			$.scrollTo($('#song'), { speed:1000, axis:'y', queue:true });
			return false;
		});
	})
}


/* show/hide navi
-----------------------------------------------------------*/
var overtimer = new Array();
var outtimer = new Array();
function showNavi(id) {
	for(i in outtimer) {
		if(i != id) _hideNavi(i);
	}
	if(outtimer[id]) clearTimeout(outtimer[id]);
	if(document.getElementById(id).style.display != 'block') overtimer[id] = setTimeout("_showNavi('" + id + "');", 100);
}
function _showNavi(id) {
	document.getElementById(id).style.display = 'block';
	delete overtimer[id];
}
function hideNavi(id) {
	if(overtimer[id]) clearTimeout(overtimer[id]);
	if(document.getElementById(id).style.display != 'none') outtimer[id] = setTimeout("_hideNavi('" + id + "');", 500);
}
function _hideNavi(id) {
	document.getElementById(id).style.display = 'none';
	delete outtimer[id];
}


/* text size changer
-----------------------------------------------------------*/
function setTextSizeChanger() {
	var className = 'textSizeActive';
	var largeClass = '';
	var defaultClass = '';
	var smallClass = '';
	
	if(title == 'large') {
		largeClass = ' class="' + className + '"'
	} else if(title == 'small') {
		smallClass = ' class="' + className + '"'
	} else {
		defaultClass = ' class="' + className + '"'
	}
	var changer = '\
		<dl id="textSizeChanger">\
			<dt>Change Text Size</dt>\
			<dd>\
				<ul>\
					<li id="textSizeLarge"><a href="javascript:void(0)" onclick="setActiveStyleSheet(\'large\'); return false;"' + largeClass + '>Large</a></li>\
					<li id="textSizeMedium"><a href="javascript:void(0)" onclick="setActiveStyleSheet(\'default\'); return false;"' + defaultClass + '>Medium</a></li>\
					<li id="textSizeSmall"><a href="javascript:void(0)" onclick="setActiveStyleSheet(\'small\'); return false;"' + smallClass + '>Small</a></li>\
				</ul>\
			</dd>\
		</dl>\
	';
	document.write(changer);
}


/* lightbox
-----------------------------------------------------------*/
function setLightBox(path){
	$(function() {
		$('a[@rel*=lightbox]').lightBox({
			overlayBgColor: '#fff',
			overlayOpacity: 0.7,
			containerBorderSize: 20,
			imageLoading: path + 'image/loading_01.gif'
		});
	});
}


/* facebox
-----------------------------------------------------------*/
function setFacebox(path) {
	jQuery(document).ready(function($) {
		$('a[rel*=facebox]').facebox({
			loadingImage : path + 'image/loading_02.gif',
			closeImage   : path + 'image/bt_close_02_df.gif',
			wrapperID : 'wrapper',
			faceboxHtml : '\
			<div id="facebox" style="display:none;">\
				<div class="content">\
				</div>\
			</div>'
		}) 
	})
}


/* key visual fade
-----------------------------------------------------------*/
var kvFadeID, kvFadeObj, kvFadeAlpha;
var kvFlg = null;
var kvFadeID;
var kvFadeInSpeed = 2;
var kvFadeOutSpeed = 2;
var kvFadeAlphaMax = 95;
var kvFadeAlphaMin = 0;

function setKeyVisualFade(id) {
	if(kvFlg == null) {
		kvFlg = true;
		setTimeout("setKeyVisualFade('" + id + "')", 5000);
		return false;
	}
	if(kvFlg) {
		kvFadeObj = document.getElementById(id);
		kvFadeAlpha = kvFadeAlphaMax;
		fadeOutKeyVisual();
		kvFlg = false;
	} else {
		if(kvFadeID) {
			kvFadeObj = document.getElementById(kvFadeID);
			kvFadeObj.style.filter='alpha(opacity=' + kvFadeAlpha + ')';
			kvFadeObj.style.opacity = kvFadeAlpha / 100;
		}else{
			kvFadeID = id;
			kvFadeObj = document.getElementById(kvFadeID);
		}
		kvFadeObj.style.display = 'block';
		kvFadeAlpha = kvFadeAlphaMin;
		fadeInKeyVisual();
		kvFlg = true;
	}
	setTimeout("setKeyVisualFade('" + id + "')", 9000)
}

function fadeInKeyVisual() {
	if(kvFadeAlpha >= kvFadeAlphaMax) kvFadeAlpha = kvFadeAlphaMax;
	kvFadeObj.style.filter = 'alpha(opacity=' + kvFadeAlpha + ')';
	kvFadeObj.style.opacity = kvFadeAlpha / 100;
	if(kvFadeAlpha == kvFadeAlphaMax) return;
	kvFadeAlpha += kvFadeInSpeed;
	setTimeout('fadeInKeyVisual()', 50);
}

function fadeOutKeyVisual() {
	if(kvFadeAlpha <= kvFadeAlphaMin) kvFadeAlpha = kvFadeAlphaMin;
	kvFadeObj.style.filter='alpha(opacity=' + kvFadeAlpha + ')';
	kvFadeObj.style.opacity = kvFadeAlpha / 100;
	if(kvFadeAlpha == kvFadeAlphaMin) {
		kvFadeObj.style.filter='alpha(opacity=0)';
		kvFadeObj.style.opacity = 0;
		return;
	}
	kvFadeAlpha -= kvFadeOutSpeed;
	setTimeout('fadeOutKeyVisual()', 50);
}


/* plant facility map
-----------------------------------------------------------*/
var swapPlFcImageID = 'plFcMap';
var defaultPlFcImage = 'image/im_facility_01.jpg';
var loadPlFcImages = new Array(
	'image/im_facility_02.jpg',
	'image/im_facility_03.jpg',
	'image/im_facility_04.jpg',
	'image/im_facility_05.jpg',
	'image/im_facility_06.jpg',
	'image/im_facility_07.jpg',
	'image/im_facility_08.jpg'
);
var loadedPlFcImages = new Array();

function preloadPlFcMap() {
	for(var i = 0; i < loadPlFcImages.length; i++) {
		loadedPlFcImages[i] = new Image();
		loadedPlFcImages[i].src = loadPlFcImages[i];
	}
}

function setPlFcMap(no) {
	document.getElementById(swapPlFcImageID).src = loadPlFcImages[no];
}

function resetPlFcMap() {
	document.getElementById(swapPlFcImageID).src = defaultPlFcImage;
}


/* access map
-----------------------------------------------------------*/
function initAccessMap() {
	var key = 'ABQIAAAADnzus5m7-yIxNGaz-SDYihTrJzh8bbwh92GCHTR2Y0FmfNS2uBSYS0tmnESCpFRtQuXRCStg6g2cSQ';
	if(location.hostname.indexOf('192.168.') >= 0) key = 'ABQIAAAA3i_VtXXXNSNT21DTjLNtpBRB4nrBOd15Q9ov68K7sUHf5JKZLxSEMrrp8UdX8BPESjRsLIDEFD2P0Q';
	if(location.hostname.indexOf('preview.nishikawa.jp') >= 0) key = 'ABQIAAAA3i_VtXXXNSNT21DTjLNtpBQHAzV6KvAnD8LWrf_nGw7w3OW_khQ0SKkEpAjPebUmHV-n4kkffwGZRw';
	
	document.write('<script src="http://maps.google.com/maps?file=api&v=1&key=' + key + '" type="text/javascript" charset="utf-8"></script>');
}

function setAccessMap() {
	if(GBrowserIsCompatible()){
		var textNagoya = '\
			<span>\
				<img src="../image/ic_taiyo.gif" width="16" height="16" alt="" />\
				Taiyo Pharmaceutical Industry Co., Ltd.\
			</span>\
			<ul>\
				<li>24-11 Taikou 1-chome, Nakamura-ku, Nagoya-city,<br />Aichi, 453-0801, Japan</li>\
				<li>TEL: +81 (0)52-459-5001</li>\
				<li>FAX: +81 (0)52-459-2851</li>\
			</ul>\
		';
		var mapNagoya = new GMap(document.getElementById("mapNagoya"));
		mapNagoya.centerAndZoom(new GPoint(136.8823742866516, 35.16849362135982), 1);
		mapNagoya.addControl(new GLargeMapControl());
		mapNagoya.addControl(new GMapTypeControl());
		mapNagoya.openInfoWindowHtml(new GPoint(136.88054, 35.167134), textNagoya, new GSize(2, 0));
		markerNagoya = new GIcon();
		markerNagoya.image = "../image/ic_taiyo.gif";
		markerNagoya.iconSize = new GSize(16, 16);
		markerNagoya.iconAnchor = new GPoint(0, 5);
		markerPointNagoya = new GMarker(new GPoint(136.88054, 35.167134), markerNagoya);
		mapNagoya.addOverlay(markerPointNagoya);
		
		var textTokyo = '\
			<span>\
				<img src="../image/ic_taiyo.gif" width="16" height="16" alt="" />\
				Tokyo Office (R&amp;D branch)\
			</span>\
			<ul>\
				<li>10F h+ Bldg., 4-11 Yaesu 2-chome, Chuo-ku,<br />Tokyo, 104-0028, Japan</li>\
				<li>TEL: +81 (0)3-3510-2885</li>\
				<li>FAX: +81 (0)3-3510-2663</li>\
			</ul>\
		';
		var mapTokyo = new GMap(document.getElementById("mapTokyo"));
		mapTokyo.centerAndZoom(new GPoint(139.76913392543793, 35.67805179889948), 1);
		mapTokyo.addControl(new GLargeMapControl());
		mapTokyo.addControl(new GMapTypeControl());
		mapTokyo.openInfoWindowHtml(new GPoint(139.76905, 35.67805), textTokyo, new GSize(2, 0));
		markerTokyo = new GIcon();
		markerTokyo.image = "../image/ic_taiyo.gif";
		markerTokyo.iconSize = new GSize(16, 16);
		markerTokyo.iconAnchor = new GPoint(0, 5);
		markerPointTokyo = new GMarker(new GPoint(139.76905, 35.67805), markerTokyo);
		mapTokyo.addOverlay(markerPointTokyo);
		
		var textTakayama = '\
			<span>\
				<img src="../image/ic_taiyo.gif" width="16" height="16" alt="" />\
				Takayama Plant\
			</span>\
			<ul>\
				<li>1040-22 Matsunoki-cho, Takayama-shi,<br />Gifu-ken, 506-0802, Japan</li>\
				<li>TEL: +81 (0)577-33-0811</li>\
				<li>FAX: +81 (0)577-33-0857</li>\
			</ul>\
		';
		var mapTakayama = new GMap(document.getElementById("mapTakayama"));
		mapTakayama.centerAndZoom(new GPoint(137.28790283203125, 36.15236060952405), 4);
		mapTakayama.addControl(new GLargeMapControl());
		mapTakayama.addControl(new GMapTypeControl());
		mapTakayama.openInfoWindowHtml(new GPoint(137.27994740009308, 36.14234119794595), textTakayama, new GSize(4, 7));
		markerTakayama = new GIcon();
		markerTakayama.image = "../image/ic_taiyo.gif";
		markerTakayama.iconSize = new GSize(16, 16);
		markerTakayama.iconAnchor = new GPoint(0, 0);
		markerPointTakayama = new GMarker(new GPoint(137.2798991203308, 36.1423455300044), markerTakayama);
		mapTakayama.addOverlay(markerPointTakayama);
	}
}


/* tvcm
-----------------------------------------------------------*/
function initCrAdTvcm() {
	Shadowbox.init({
		language: 'en',
		players:  ['html', 'swf'],
		adapter: 'base',
		overlayColor : '#ffffff',
		overlayOpacity : 0.7,
		errors : {
			fla : {
				name : 'the latest Adobe Flash Player',
				url : 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&Lang=English'
			}
		}
	});
}


/* show virtual tour content
-----------------------------------------------------------*/
function cmClose(dummy) {
	Shadowbox.close();
}


/* show virtual tour content
-----------------------------------------------------------*/
function showVTContent() {
	var ver = deconcept.SWFObjectUtil.getPlayerVersion();
	if(ver['major'] > 8) {
		var content = '\
			<div class="vtEnter">\
				<p class="vtEnterIntro">This is a virtual tour using video images of the Takayama Plant. Our navigator guide will show you how medicines are made.</p>\
				<p class="vtEnterBtn"><a href="tour.html" target="_blank" onclick="openVTFlash(this.href);return false;"><img src="image/bt_enter_df.gif" width="237" height="53" alt="ENTER" class="swapImage" /></a></p>\
				<div class="vtEnterNote">\
					<p>If your PC\'s image processing capabilities or your Internet connection speed are insufficient, images or sound may become intermittent. A display size of at least 1024 x 768 pixels is required. Depending on system settings, some of the content may not be viewable.</p>\
				</div>\
			</div>\
		';
	} else {
		var content = '\
			<div class="vtDownload">\
				<p class="vtDownloadIntro">This is a virtual tour using video images of the Takayama Plant. Our navigator guide will show you how medicines are made.</p>\
				<div class="vtDownloadNote">\
					<p class="vtDownloadNoteTitle">To view this content, you must have Adobe Flash Player 8 or later installed.</p>\
					<p class="vtDownloadNoteText">Please follow the instructions to download appropriate files on the download site listed as below.<br />After installation is complete, please reload this page.</p>\
					<p class="vtDownloadBtn"><a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&Lang=English" target="_blank"><img src="image/bt_download_df.gif" width="237" height="53" alt="DOWNLOAD FLASH PLAYER" class="swapImage" /></a></p>\
				</div>\
			</div>\
		';
	}
	document.write(content);
}


/* open virtual tour flash
-----------------------------------------------------------*/
function openVTFlash(url) {
	var x = screen.width;
	var y = screen.height;
	var option = 'top=0,left=0,screenX=0,screenY=0,width=' + x + ',height=' + y + ',toolbar=no,resizable=yes,scrollbars=no';
	var openWindow = window.open(url, 'tour', option);
}
