/*----- user agent -----*/
function readCookieSp(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 false;
}

function createCookieSp(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=/";
}

//UAで振り分ける スマホで尚且つクッキーがないものはリダイレクト
if ((navigator.userAgent.indexOf('iPhone') > 0 && navigator.userAgent.indexOf('iPad') == -1) || navigator.userAgent.indexOf('iPod') > 0 || navigator.userAgent.indexOf('Android') > 0 || navigator.userAgent.indexOf('ANDROID') > 0 ) {
	if( document.referrer.indexOf('/sp/') == -1 && document.referrer.indexOf('www.c-nexco.co.jp/index.html') == -1 && document.referrer.indexOf('/navi/index.html') == -1 && document.referrer.indexOf('/traffic/index.html') == -1 && document.referrer.indexOf('/sapa/index.html') == -1 && document.referrer.indexOf('/drive/index.html') == -1 && document.referrer.indexOf('/card/index.html') == -1 && document.referrer.indexOf('/shop/index.html') == -1 && document.referrer.indexOf('/corporate/index.html') == -1 ){	//前のサイトがスマホじゃないとき
		
		if( document.URL == 'http://www.c-nexco.co.jp/' || document.URL == 'http://www.c-nexco.co.jp/index.html' ){
			location.href = '/sp/index.html';
		}
		else if( document.URL.indexOf('/navi/index.html') > 0 ){
			location.href = '/sp/navi/index.html';
		}
		else if ( document.URL.indexOf('/traffic/index.html') > 0 ){
			location.href = '/sp/traffic/index.html';
		}
		else if ( document.URL.indexOf('/sapa/index.html') > 0 ){
			location.href = '/sp/sapa/index.html';
		}
		else if ( document.URL.indexOf('/drive/index.html') > 0 ){
			location.href = '/sp/drive/index.html';
		}
		else if ( document.URL.indexOf('/card/index.html') > 0 ){
			location.href = '/sp/card/index.html';
		}
		else if ( document.URL.indexOf('/shop/index.html') > 0 ){
			location.href = '/sp/shop/index.html';
		}
		else if ( document.URL.indexOf('/corporate/index.html') > 0 ){
			location.href = '/sp/corporate/index.html';
		}
	}
}

// iphone , ipad , android はflv=>mp4
if( navigator.userAgent.indexOf('iPhone') > 0 || navigator.userAgent.indexOf('iPad') > 0 || navigator.userAgent.indexOf('iPod') > 0 || navigator.userAgent.indexOf('Android') > 0 || navigator.userAgent.indexOf('ANDROID') > 0 ) {
	//mp4 replace
	$(function(){
		$('.fancybox').each( function(){
			$(this).removeClass('fancybox');
			var originalHref	= $(this).attr('href');
			var newHref			= originalHref.replace( '.swf' , '.mp4' );
			$(this).attr( 'href' , newHref );
		});
		
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer').length ){
			var strTagMp4	= '<a href="../moviefile/sengen_30sec.mp4"><img src="../images/p_cm.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer2').length ){	
			var strTagMp4	= '<a href="../moviefile/making_web.mp4"><img src="../images/p_making.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer2').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer3').length ){	
			var strTagMp4	= '<a href="../moviefile/nexco_etc.mp4"><img src="../images/p_etc.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer3').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer4').length ){	
			var strTagMp4	= '<a href="../moviefile/its_spot.mp4"><img src="../images/p_its.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer4').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer5').length ){	
			var strTagMp4	= '<a href="../moviefile/chap01.mp4"><img src="../images/p_chap01.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer5').empty().append(strTagMp4);
		}						
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer6').length ){
			var strTagMp4	= '<a href="../moviefile/chap02.mp4"><img src="../images/p_chap02.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer6').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer7').length ){	
			var strTagMp4	= '<a href="../moviefile/chap03.mp4"><img src="../images/p_chap03.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer7').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer8').length ){	
			var strTagMp4	= '<a href="../moviefile/chap04.mp4"><img src="../images/p_chap04.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer8').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer9').length ){	
			var strTagMp4	= '<a href="../moviefile/chap05.mp4"><img src="../images/p_chap05.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer9').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer10').length ){	
			var strTagMp4	= '<a href="../moviefile/chap06.mp4"><img src="../images/p_chap06.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer10').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer11').length ){	
			var strTagMp4	= '<a href="../moviefile/chap07.mp4"><img src="../images/p_chap07.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer11').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer12').length ){	
			var strTagMp4	= '<a href="../moviefile/chap08.mp4"><img src="../images/p_chap08.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer12').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer13').length ){	
			var strTagMp4	= '<a href="../moviefile/chap09.mp4"><img src="../images/p_chap09.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer13').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer14').length ){	
			var strTagMp4	= '<a href="../moviefile/chap10.mp4"><img src="../images/p_chap10.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer14').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer15').length ){	
			var strTagMp4	= '<a href="../moviefile/hashicon06_01.mp4"><img src="../images/p_hashicon06_01.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer15').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer16').length ){	
			var strTagMp4	= '<a href="../moviefile/hashicon06_02.mp4"><img src="../images/p_hashicon06_02.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer16').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer17').length ){	
			var strTagMp4	= '<a href="../moviefile/hashicon06_03.mp4"><img src="../images/p_hashicon06_03.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer17').empty().append(strTagMp4);
		}
		if( $('body#movie div.movieContent div.movieDetail div.movPlayer18').length ){	
			var strTagMp4	= '<a href="../moviefile/hashicon06_04.mp4"><img src="../images/p_hashicon06_04.jpg" /></a>';
			$('body#movie div.movieContent div.movieDetail div.movPlayer18').empty().append(strTagMp4);
		}
				
		//to smartphone page btn
		var domSmartBtn;
		
		switch(document.URL){
			case 'http://www.c-nexco.co.jp/' :
			case 'http://www.c-nexco.co.jp/index.html' :
				domSmartBtn	= '<div id="toSp"><a href="/sp/index.html">スマートフォンサイトはこちら</a></div>';
				$('#recommendTop').before( domSmartBtn );
				break;
				
			case 'http://www.c-nexco.co.jp/navi/' :
			case 'http://www.c-nexco.co.jp/navi/index.html' :
				domSmartBtn	= '<div id="toSp"><a href="/sp/navi/index.html">スマートフォンサイトはこちら</a></div>';
				$('#recommend').before( domSmartBtn );
				break;
			
			case 'http://www.c-nexco.co.jp/traffic/' :
			case 'http://www.c-nexco.co.jp/traffic/index.html' :
				domSmartBtn	= '<div id="toSp"><a href="/sp/traffic/index.html">スマートフォンサイトはこちら</a></div>';
				$('#recommend').before( domSmartBtn );
				break;
				
			case 'http://www.c-nexco.co.jp/sapa/' :
			case 'http://www.c-nexco.co.jp/sapa/index.html' :
				domSmartBtn	= '<div id="toSp"><a href="/sp/sapa/index.html">スマートフォンサイトはこちら</a></div>';
				$('#recommend').before( domSmartBtn );
				break;
				
			case 'http://www.c-nexco.co.jp/drive/' :
			case 'http://www.c-nexco.co.jp/drive/index.html' :
				domSmartBtn	= '<div id="toSp"><a href="/sp/drive/index.html">スマートフォンサイトはこちら</a></div>';
				$('#recommend').before( domSmartBtn );
				break;
				
			case 'http://www.c-nexco.co.jp/card/' :
			case 'http://www.c-nexco.co.jp/card/index.html' :
				domSmartBtn	= '<div id="toSp"><a href="/sp/card/index.html">スマートフォンサイトはこちら</a></div>';
				$('#recommend').before( domSmartBtn );
				break;
				
			case 'http://www.c-nexco.co.jp/shop/' :
			case 'http://www.c-nexco.co.jp/shop/index.html' :
				domSmartBtn	= '<div id="toSp"><a href="/sp/shop/index.html">スマートフォンサイトはこちら</a></div>';
				$('#recommend').before( domSmartBtn );
				break;
				
			case 'http://www.c-nexco.co.jp/corporate/' :
			case 'http://www.c-nexco.co.jp/corporate/index.html' :
				domSmartBtn	= '<div id="toSp"><a href="/sp/corporate/index.html">スマートフォンサイトはこちら</a></div>';
				$('#recommend').before( domSmartBtn );
				break;
		}
	});
}
/*----- END:::user agent -----*/


// preload
function preload() {
	var img01	= new Image();
	var img02	= new Image();
	var img03	= new Image();
	var img04	= new Image();
	var img05	= new Image();
	var img06	= new Image();
	var img07	= new Image();
	var img08	= new Image();
	var img09	= new Image();
	
	img01.src	= "/images/bg_gnavi_card.gif";
	img02.src	= "/images/bg_gnavi_corp.gif";
	img03.src	= "/images/bg_gnavi_drive.gif";
	img04.src	= "/images/bg_gnavi_navi.gif";
	img05.src	= "/images/bg_gnavi_sapa.gif";
	img06.src	= "/images/bg_gnavi_shop.gif";
	img07.src	= "/images/bg_gnavi_traffic.gif";
	img08.src	= "/images/bg_top_sapa_on.png";
}

// fontsize
function setActiveStyleSheet(title) {
	var i, a, main;
	
	var max_link	= document.getElementsByTagName('link').length;
	
	for(i=0; i<max_link; i++) {
		a	= document.getElementsByTagName("link")[i];
		if( a.getAttribute('rel') ){
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
				a.disabled = true;
				if(a.getAttribute("title") == title){
					a.disabled = false;
				}
			}
		}
	}
}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if( a.getAttribute('rel') ){
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled){
				return a.getAttribute("title");
			}
		}
	}
	return 'Default';
}

function getPreferredStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1

&& a.getAttribute("rel").indexOf("alt") == -1
&& a.getAttribute("title")
) return a.getAttribute("title");
}
return null;
}

function createCookie(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=/";
}

function readCookie(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 'Default';
}

window.onload = function(e) {
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
//setActiveStyleSheet(title);
}

window.onunload = function(e) {
var title = getActiveStyleSheet();
createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);


// yuga.js 0.7.1
(function($) {

$(function(){
var $targetElement = '.wordBreak';
if($.browser.msie) {
$($targetElement).css('word-break', 'break-all');
} else {
$($targetElement).each(function(){
if(navigator.userAgent.indexOf('Firefox/2') != -1) {
$(this).html($(this).text().split('').join('<wbr />'));
} else {
$(this).html($(this).text().split('').join(String.fromCharCode(8203)));
}
});
}
});

$(function() {
$.yuga.rollover();
$.yuga.scroll();
$.yuga.tab();
$.yuga.stripe();
/*----- 110808.add -----*/
if( document.URL.indexOf('www.c-nexco.co.jp/campaign/') == -1 ){
	$.yuga.css3class();
}
/*----- END:::110808.add -----*/
});

//---------------------------------------------------------------------

$.yuga = {
// URIを解析したオブジェクトを返すfunction
Uri: function(path){
var self = this;
this.originalPath = path;
//絶対パスを取得
this.absolutePath = (function(){
var e = document.createElement('span');
e.innerHTML = '<a href="' + path + '" />';
return e.firstChild.href;
})();
//絶対パスを分解
var fields = {'schema' : 2, 'username' : 5, 'password' : 6, 'host' : 7, 'path' : 9, 'query' : 10, 'fragment' : 11};
var r = /^((\w+):)?(\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/.exec(this.absolutePath);
for (var field in fields) {
this[field] = r[fields[field]];
}
this.querys = {};
if(this.query){
$.each(self.query.split('&'), function(){
var a = this.split('=');
if (a.length == 2) self.querys[a[0]] = a[1];
});
}
},
//ロールオーバー
rollover: function(options) {
var c = $.extend({
hoverSelector: '.imgover, .allimg img',
groupSelector: '.imggroup',
postfix: '_on'
}, options);
//ロールオーバーするノードの初期化
var rolloverImgs = $(c.hoverSelector).filter(isNotCurrent);
rolloverImgs.each(function(){
this.originalSrc = $(this).attr('src');
this.rolloverSrc = this.originalSrc.replace(new RegExp('('+c.postfix+')?(\.gif|\.jpg|\.png)$'), c.postfix+"$2");
this.rolloverImg = new Image;
this.rolloverImg.src = this.rolloverSrc;
});
//グループ内のimg要素を指定するセレクタ生成
var groupingImgs = $(c.groupSelector).find('img').filter(isRolloverImg);
//通常ロールオーバー
rolloverImgs.not(groupingImgs).hover(function(){
$(this).attr('src',this.rolloverSrc);
},function(){
$(this).attr('src',this.originalSrc);
});
//グループ化されたロールオーバー
$(c.groupSelector).hover(function(){
$(this).find('img').filter(isRolloverImg).each(function(){
$(this).attr('src',this.rolloverSrc);
});
},function(){
$(this).find('img').filter(isRolloverImg).each(function(){
$(this).attr('src',this.originalSrc);
});
});
//フィルタ用function
function isNotCurrent(i){
return Boolean(!this.currentSrc);
}
function isRolloverImg(i){
return Boolean(this.rolloverSrc);
}
},
//ページ内リンクはするするスクロール
scroll: function(options) {
//ドキュメントのスクロールを制御するオブジェクト
var scroller = (function() {
var c = $.extend({
easing:100,
step:30,
fps:60,
fragment:''
}, options);
c.ms = Math.floor(1000/c.fps);
var timerId;
var param = {
stepCount:0,
startY:0,
endY:0,
lastY:0
};
//スクロール中に実行されるfunction
function move() {
if (param.stepCount == c.step) {
//スクロール終了時
setFragment(param.hrefdata.absolutePath);
window.scrollTo(getCurrentX(), param.endY);
} else if (param.lastY == getCurrentY()) {
//通常スクロール時
param.stepCount++;
window.scrollTo(getCurrentX(), getEasingY());
param.lastY = getEasingY();
timerId = setTimeout(move, c.ms); 
} else {
//キャンセル発生
if (getCurrentY()+getViewportHeight() == getDocumentHeight()) {
//画面下のためスクロール終了
setFragment(param.hrefdata.absolutePath);
}
}
}
function setFragment(path){
location.href = path
}
function getCurrentY() {
return document.body.scrollTop  || document.documentElement.scrollTop;
}
function getCurrentX() {
return document.body.scrollLeft  || document.documentElement.scrollLeft;
}
function getDocumentHeight(){
return document.documentElement.scrollHeight || document.body.scrollHeight;
}
function getViewportHeight(){
return (!$.browser.safari && !$.browser.opera) ? document.documentElement.clientHeight || document.body.clientHeight || document.body.scrollHeight : window.innerHeight;
}
function getEasingY() {
return Math.floor(getEasing(param.startY, param.endY, param.stepCount, c.step, c.easing));
}
function getEasing(start, end, stepCount, step, easing) {
var s = stepCount / step;
return (end - start) * (s + easing / (100 * Math.PI) * Math.sin(Math.PI * s)) + start;
}
return {
set: function(options) {
this.stop();
if (options.startY == undefined) options.startY = getCurrentY();
param = $.extend(param, options);
param.lastY = param.startY;
timerId = setTimeout(move, c.ms); 
},
stop: function(){
clearTimeout(timerId);
param.stepCount = 0;
}
};
})();

$('a[href^=#], area[href^=#]').not('a[href=#], area[href=#]').each(function(){
this.hrefdata = new $.yuga.Uri(this.getAttribute('href'));
}).click(function(){
var target = $('#'+this.hrefdata.fragment);
if (target.length == 0) target = $('a[name='+this.hrefdata.fragment+']');
if (target.length) {
scroller.set({
endY: target.offset().top,
hrefdata: this.hrefdata
});
return false;
}
});
},
//タブ機能
tab: function(options) {
var c = $.extend({
tabNavSelector:'.tabNav',
activeTabClass:'active'
}, options);
$(c.tabNavSelector).each(function(){
var tabNavList = $(this).find('a[href^=#], area[href^=#]');
var tabBodyList;
tabNavList.each(function(){
this.hrefdata = new $.yuga.Uri(this.getAttribute('href'));
var selecter = '#'+this.hrefdata.fragment;
if (tabBodyList) {
tabBodyList = tabBodyList.add(selecter);
} else {
tabBodyList = $(selecter);
}
$(this).unbind('click');
$(this).click(function(){
tabNavList.removeClass(c.activeTabClass);

/*----- 20110530 modified.KOBAYASHI -----*/
tabNavList.each( function(){
$(this).find('img').attr('src' , $(this).find('img').attr('src').replace( '_on.gif' , '.gif' ) );
});
/*----- END:::20110530 modified.KOBAYASHI -----*/

$(this).addClass(c.activeTabClass);

/*----- 20110530 modified.KOBAYASHI -----*/
$(this).find('img').attr('src' , $(this).find('img').attr('src').replace( '.gif' , '_on.gif' ) );
/*----- END:::20110530 modified.KOBAYASHI -----*/

tabBodyList.hide();
$(selecter).show();
return false;
});
});
tabBodyList.hide();
tabNavList.filter('.active').trigger('click');
});
},
//奇数、偶数を自動追加
stripe: function(options) {
var c = $.extend({
oddClass:'odd',
evenClass:'even'
}, options);
$('ul, ol').each(function(){
//JSでは0から数えるのでevenとaddを逆に指定
$(this).children('li:odd').addClass(c.evenClass);
$(this).children('li:even').addClass(c.oddClass);
});
$('table, tbody').each(function(){
$(this).children('tr:odd').addClass(c.evenClass);
$(this).children('tr:even').addClass(c.oddClass);
});
},
//css3のクラスを追加
css3class: function() {
//:first-child, :last-childをクラスとして追加
$('body :first-child').addClass('firstChild');
$('body :last-child').addClass('lastChild');
//css3の:emptyをクラスとして追加
$('body :empty').addClass('empty');
}
};
})(jQuery);


// Popup Window
function Popup_win(theURL,winName,features) {
window.open(theURL,winName,features);
}

