
//■■共通
$(function() {

	/*-----------------------------------------------------------------------
	■iPhoneまたは、Androidの場合は振り分けを判断■
	------------------------------------------------------------------------*/
	if (document.referrer.indexOf('visual-w.co.jp') == -1 && ((navigator.userAgent.indexOf('iPhone') > 0 && navigator.userAgent.indexOf('iPad') == -1) || navigator.userAgent.indexOf('iPod') > 0 || navigator.userAgent.indexOf('Android') > 0)) {
		if(confirm('株式会社ビジュアルリサーチのホームページです。このサイトにはスマートフォン用のサイトがあります。表示しますか？')) {
			location.href = 'http://www.visual-w.co.jp/smartphone/';
		}
	}

	/*-------------------------------------------------------
	トップメイン部のhover設定
	-------------------------------------------------------*/
	$("#top_solution li:not(:last-child)").hover(function() {
		$(this).css('background-color', '#f2f8fe');
	}, function() {
		$(this).css('background-color', '#fff');
	});
	
	$("#btn_list_01,#btn_list_02,#btn_list_03,#btn_list_04,#btn_list_05,.inquiry img").hover(function() {
		$(this).css('opacity', '0.8');
	}, function() {
		$(this).css('opacity', '1');
	});

	$("#top_product_list li").not('.tit_result').hover(function() {
		$(this).css('background-color', '#f2f8fe');
	}, function() {
		$(this).css('background-color', '#fff');
	});

	/*-------------------------------------------------------
	お知らせの動作設定
	-------------------------------------------------------*/
	function headline() {
		setTimeout(function() {
			headline();
			$("#news li").eq(0).nextAll().css('display', 'none');
//			$("#news li").not(':first').css('display', 'none');
			$("#news li:first").fadeOut('normal', function() {
				$(this).next().fadeIn('normal');
				$(this).clone().appendTo("#news ul");
				$(this).remove();
			});
		}, 5000);
	}
	var n_size = $("#news li").size();
	if(n_size > 1) {
		headline();
	}


	/*-------------------------------------------------------
	サムネイル＆メイン画像の動作設定
	-------------------------------------------------------*/
	
	dflt = -930;
	function p_roll() {
		timer1 = setTimeout(function() {
			p_roll();
			$("#products").animate({left: '-=620px'}, {duration: 600,easing: 'easeOutExpo',complete: function() {
					$(this).find('li:first').appendTo(this).end().end().css('left', dflt); 
				}
			});
		}, 5000);
	}
	function t_roll() {
		timer2 = setTimeout(function() {
			var b_left = $("#bnr_position").position().left;
			var l_left = ($("#thumb li:first").position().left) - 2;
//			var l_left = ($("#thumb li:last").position().left) - 2;
			t_roll();
			if(b_left < l_left) {
				$("#bnr_position").animate({left: '+=60px'}, {duration: 500,easing: 'easeOutExpo'});
			} else {
				$("#bnr_position").animate({left: '-2px'}, {duration: 500,easing: 'easeOutExpo'});
			}
		}, 5000);
	}
	p_roll();
	t_roll();

	/*-------------------------------------------------------
	サムネイルのclick設定
	-------------------------------------------------------*/

	$("#products li").each(function(i) {
		$(this).attr('class', 'products_' + i);
	});
	$("#thumb li").click(function(){
		//サムネイルをクリックしたら、timer1・timer2を解除
		clearTimeout(timer1);
		clearTimeout(timer2);

		var m= $("#products li").eq(0).attr('class');
		var s = m.substring(9);
		var n = $("#thumb li").index(this);	//クリックしたサムネイルの番号取得

		var main_n = $('#products li').eq(n-s).position().left * -1;
		var main_n2 = main_n - 310;
		$("#products").animate({left: main_n2 + 'px'}, {duration: 700,easing: 'easeOutExpo'});

		var thumb_n_l = ($(this).position().left) - 2;
		$("#bnr_position").animate({left: thumb_n_l + 'px'}, {duration: 300,easing: 'easeOutExpo'});
	});

/*-------------------------------------------------------
	サムネイルのhover設定
	-------------------------------------------------------*/
	
	$("#thumb li").hover(function() {
		$(this).css('opacity', '0.5');
	}, function() {
		$(this).css('opacity', '1');
	});

	/*-------------------------------------------------------
	業務から商品を探す
	-------------------------------------------------------*/
	$("#top_product_list .button").click(function() {
		var num = $(this).attr('id').substring(9);
		switch(num) {
			case '01':
				$("#product_list_result ul:eq(0)").siblings().hide();
				$("#product_list_result ul:eq(0)").fadeIn('fast');
				break;
			case '02':
				$("#product_list_result ul:eq(1)").siblings().hide();
				$("#product_list_result ul:eq(1)").fadeIn('fast');
				break;
			case '03':
				$("#product_list_result ul:eq(2)").siblings().hide();
				$("#product_list_result ul:eq(2)").fadeIn('fast');
				break;
			case '04':
				$("#product_list_result ul:eq(3)").siblings().hide();
				$("#product_list_result ul:eq(3)").fadeIn('fast');
				break;
			default:
				$("#product_list_result ul:eq(4)").siblings().hide();
				$("#product_list_result ul:eq(4)").fadeIn('fast');
				break;
		}
	});

});

