/*

　株式会社ネットワーク専用javascript

*/


jQuery.noConflict();


// ページの初期処理
function initialize() {
	document.getElementById('active_menu').style.display = 'block';
	menu_move_active();

	// follow me
	show_followme();
}



var animation_sw = false;
var menuhover_sw = false;
var menu_active_margin = 8;

// 特殊効果
jQuery(function() {

	jQuery('#menu li').mouseover(function(){
		var menus = jQuery('#menu li');
		var movemarginLeft = menu_active_margin;
		menuhover_sw = true;
		for (var idx = 0; idx < menus.length; idx++) {
			if (menus[idx].innerHTML == this.innerHTML) break;
			else if (menus[idx].Width) movemarginLeft += menus[idx].width;
			else movemarginLeft += menus[idx].clientWidth;
			movemarginLeft++;
		}
		animation_sw = true;
		movemarginLeft += menu_active_margin;
		jQuery('#active_menu').animate(
			{marginLeft: movemarginLeft+'px'}
			, {duration: 'fast', easing: 'linear'
			, complete: function(){animation_sw = false;}
			}
		);
	});
	
	jQuery('#menu li').mouseout(function(){
		menuhover_sw = false;
		setTimeout(menu_move_active, 1000);
	});

//	jQuery('.widget-header').mouseover(function(){jQuery(this).fadeTo('fast', 0.8);});
//	jQuery('.widget-header').mouseout(function(){jQuery(this).fadeTo('fast', 1.0);});

//	jQuery('.tbl_products_detail img').mouseover(function(){jQuery(this).fadeTo('fast', 1.0);});
//	jQuery('.tbl_products_detail img').mouseout(function(){jQuery(this).fadeTo('fast', 0.7);});

	jQuery('.left_menu a').mouseover(
		function(){
			jQuery(this).animate(
				{
					backgroundColor: '#B2E3F7',
					color: '#01498E'
				}
				, 'fast'
			);
		}
	);
	jQuery('.left_menu a').mouseout(
		function(){
			jQuery(this).animate(
				{
					backgroundColor: '#ffffff',
					color: '#01498E'
				}
				, 'slow'
			);
		}
	);
	jQuery('.left_pbox a').mouseover(
		function(){
			jQuery(this).animate(
				{
					backgroundColor: '#B2E3F7',
					color: '#01498E'
				}
				, 'fast'
			);
		}
	);
	jQuery('.left_pbox a').mouseout(
		function(){
			jQuery(this).animate(
				{
					backgroundColor: '#ffffff',
					color: '#01498E'
				}
				, 'slow'
			);
		}
	);


	jQuery('#home_menu img').mouseover(function(){jQuery(this).fadeTo('fast', 0.75);});
	jQuery('#home_menu img').mouseout(function(){jQuery(this).fadeTo('fast', 1.0);});

	jQuery('.art img').mouseover(function(){jQuery(this).fadeTo('fast', 0.8);});
	jQuery('.art img').mouseout(function(){jQuery(this).fadeTo('fast', 1.0);});

	//jQuery('#setcourse li').mouseover(function(){jQuery(this).fadeTo('fast', 1.0);});
	//jQuery('#setcourse li').mouseout(function(){jQuery(this).fadeTo('fast', 0.5);});

	// メニュー効果音再生
	jQuery('#navi li').mouseover(function(){if(sound_sw)play();});

});



function menu_move_active() {
	if (!menuhover_sw) {
		var menus = jQuery('#menu li');
		var movemarginLeft = menu_active_margin;
		for (var idx = 0; idx < menus.length; idx++) {
			if(jQuery(menus[idx]).hasClass('active')) break;
			else if (menus[idx].Width) movemarginLeft += menus[idx].width;
			else movemarginLeft += menus[idx].clientWidth;
			movemarginLeft++;
		}
		movemarginLeft += menu_active_margin;
		jQuery('#active_menu').animate(
			{marginLeft: movemarginLeft+'px'}
			, {duration: 700, easing: 'easeOutBack'}
		);
	}
}



function chtype(partstype) {

	jQuery("#edge").fadeOut("normal");
	jQuery("#handle").fadeOut("normal", function (){

		switch (partstype) {
		case 'BR':
			document.getElementById("parts_edge_vk").style.display = 'none';
			document.getElementById("parts_handle_vk").style.display = 'none';
			document.getElementById("parts_edge_br").style.display = 'inline';
			document.getElementById("parts_handle_br").style.display = 'inline';
			document.getElementById("parts_edge_br").selectedIndex = 0;
			document.getElementById("parts_handle_br").selectedIndex = 0;
			chparts(3, 'BR');
			break;
		case 'VK':
			document.getElementById("parts_edge_br").style.display = 'none';
			document.getElementById("parts_handle_br").style.display = 'none';
			document.getElementById("parts_edge_vk").style.display = 'inline';
			document.getElementById("parts_handle_vk").style.display = 'inline';
			document.getElementById("parts_edge_vk").selectedIndex = 0;
			document.getElementById("parts_handle_vk").selectedIndex = 0;
			chparts(3, 'VK10');
			break;
		default:
		}
	});

	jQuery("#edge").fadeIn("normal");
	jQuery("#handle").fadeIn("normal");

}



function chparts(chsw, partsname) {

	if (chsw == 1 || chsw == 3) {
		// 刃の変更
		document.getElementById("edge_image").src = 'images/sample_'+partsname+'_edge.png';
	}

	if (chsw == 2 || chsw == 3) {
		// ハンドルの変更
		document.getElementById("handle_image"). src = 'images/sample_'+partsname+'_handle.png';
	}

}



// twitter表示
function show_twitter() {

	new TWTR.Widget({
		version: 2,
		type: 'search',
		search: '美容',
		interval: 6000,
		title: 'Information',
		subject: 'お知らせ用の枠',
		width: 'auto',
		height: 200,
		theme: {
			shell: {
				background: '#8ec1da',
				color: '#ffffff'
			},
			tweets: {
				background: '#ffffff',
				color: '#444444',
				links: '#1985b5'
			}
		},
		features: {
			scrollbar: false,
			loop: true,
			live: true,
			hashtags: true,
			timestamp: true,
			avatars: true,
			toptweets: true,
			behavior: 'default'
		}
	}).render().start();

}



// twitter表示
function show_info() {

	new TWTR.Widget({
		version: 2,
		type: 'profile',
		rpp: 4,
		interval: 6000,
		width: 'auto',
		height: 150,
		theme: {
			shell: {
				background: '#8ec1da',
				color: '#ffffff'
			},
			tweets: {
				background: '#ffffff',
				color: '#444444',
				links: '#1985b5'
			}
		},
		features: {
			scrollbar: true,
			loop: false,
			live: false,
			hashtags: true,
			timestamp: true,
			avatars: false,
			behavior: 'default'
		}
	}).render().setUser('networkjpn_info').start();

}



// follow me 表示
function show_followme() {
	//<!-- twitter follow badge by go2web20 -->
	tfb.account = 'networkjpn_info';
	tfb.label = 'follow-me';
	tfb.color = '#35ccff';
	tfb.side = 'r';
	tfb.top = 136;
	tfb.showbadge();
	//<!-- end of twitter follow badge -->
}



// 会社概要のアクセスマップ用
function gmap_init(idx) {

	var company = [
		{ /* 本社 */
			centerlat: '35.678407'
			, centerlng: '139.678309'
			, pointlat: '35.677614'
			, pointlng: '139.67925'
			, zoom: 17
			, content: '<div dir="ltr"><img src="images/logo_company_200x44.gif" style="width:200px; height:44px;"><br \/>〒151-0066<br \/>東京都渋谷区西原1-28-6 第8岩田ビルA101<br \/>TEL: 03-3376-5255　FAX: 03-3376-6042<br \/><a style="color:rgb(0, 102, 0)" href="http://www.networkjpn.com/" target="_blank">http://www.networkjpn.com/<\/a><\/div>'
		}
	];
	

	if (!idx) idx = 0;

	var myOptions = {
		zoom: company[idx].zoom,
		center: new google.maps.LatLng(company[idx].centerlat, company[idx].centerlng),
		scaleControl: true,
		scrollwheel: false,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);


	// ルート表示 ここから
	var directionsRenderer = new google.maps.DirectionsRenderer();
	directionsRenderer.setOptions(
		{
			suppressMarkers: true
		});
	directionsRenderer.suppressPolylines = false;
	directionsRenderer.setMap(map);


	// ルート検索を行う
	var request = {
		origin: "幡ヶ谷駅",
		destination: "東京都渋谷区西原1-28-6",
		travelMode: google.maps.DirectionsTravelMode.WALKING /* 徒歩 */
	};

	var directionsService = new google.maps.DirectionsService();
	directionsService.route(request, function(result, status)
		{
			if (status == google.maps.DirectionsStatus.OK) {
				directionsRenderer.setDirections(result);
			}
		});
	// ルート表示 ここまで

	var image = new google.maps.MarkerImage('images/googlemap_mark.png', new google.maps.Size(32,32));
	var myLatLng = new google.maps.LatLng(company[idx].pointlat, company[idx].pointlng);
	var beachMarker = new google.maps.Marker(
		{
			position: myLatLng,
			map: map,
			icon: image,
			title: 'networkjpn'
		});

	var infowindow = new google.maps.InfoWindow(
		{
			content: company[idx].content,
			size: new google.maps.Size(200,30)
		});
	
	google.maps.event.addListener(
		beachMarker,
		'click',
		function() {
			infowindow.open(map,beachMarker);
		});
	google.maps.event.trigger(beachMarker, 'click');


}



// お問い合わせ（郵便番号から住所を取得）

function get_addr(zipcode) {

	if(zipcode){

		// 通信処理
		var callback = {
			success:function(httpObj) {
				// 成功時の処理
				set_data(httpObj.responseText);
				
			}
			//fairule:function(httpObj) {
				// 失敗時の処理
			//	document.getElementById('result').innerHTML = '取得エラー';
			//}
		}
	
		cacheTime = (new Date()).getTime();
		YAHOO.util.Connect.asyncRequest('get', '/zip_to_addr.php?z='+zipcode, callback, null ); // 通信

	}

}

function set_data(data){

	data_array = data.split(',');

	if(!data_array[0]) data_array[0]='';
	if(!data_array[1]) data_array[1]='';
	if(!data_array[2]) data_array[2]='';

	for(idx=0;idx<document.getElementById('pref').options.length-1;idx++){
		if(document.getElementById('pref').options[idx].value==data_array[0]){
			document.getElementById('pref').selectedIndex=idx;
			break;
		}
	}

	document.getElementById('addr1').value=data_array[1];
	if(data_array[2]){
		document.getElementById('addr1').value+=data_array[2];
	}
	
}

function showhide(eleid, label) {
	ele = document.getElementById(eleid);
	if (ele.style.display != 'none') {
		ele.style.display = 'none';
		label.innerHTML = '＋';
	} else {
		ele.style.display = 'block';
		label.innerHTML = '－';
	}
}

function showhide2(eleid, label) {
	ele = document.getElementById('category_'+eleid);
	eleicon1 = document.getElementById('icon1_'+eleid);
	if (ele.style.display != 'none') {
		ele.style.display = 'none';
		label.innerHTML = '製品一覧を表示する';
		eleicon1.src = 'images/icon_case_c.gif';
	} else {
		ele.style.display = 'block';
		label.innerHTML = '製品一覧を隠す';
		eleicon1.src = 'images/icon_case_o.gif';
	}
}

function showhide_h3(eleid) {
	ele = document.getElementById('category_'+eleid);
	eleicon1 = document.getElementById('icon1_'+eleid);
	eleicon2 = document.getElementById('icon2_'+eleid);
	if (ele.style.display != 'none') {
		eleicon1.src = 'images/icon_plus.gif';
		eleicon2.src = 'images/icon_case_c.gif';
		ele.style.display = 'none';
	} else {
		eleicon1.src = 'images/icon_minus.gif';
		eleicon2.src = 'images/icon_case_o.gif';
		ele.style.display = 'block';
	}
}


function showhide_s(eleid, label) {
	ele = document.getElementById('scategory_'+eleid);
	eleicon1 = document.getElementById('icon_h3_'+eleid);
	if (ele.style.display != 'none') {
		ele.style.display = 'none';
		label.innerHTML = '製品一覧を表示する';
		eleicon1.src = 'images/icon_case_c.gif';
	} else {
		ele.style.display = 'block';
		label.innerHTML = '製品一覧を隠す';
		eleicon1.src = 'images/icon_case_o.gif';
	}
}

function ch_img(scid, fname) {
	eleimg = document.getElementById('scimg_'+scid);
	//eleimga = document.getElementById('scimga_'+scid);
	if (fname) {
		//eleimga.href = 'images/products_scissors_'+fname+'.jpg';
		eleimg.src = 'images/products_scissors_'+fname+'_s.jpg';
	} else {
		//eleimga.href = '';
		eleimg.src = 'images/products_scissors_noimage_s.jpg';
	}
}

function chp(scid, pid) {
	if (pid) {
		jQuery.getJSON('getpdata.php?id='+pid, function(json, status){
			// 詳細ページへのリンク
			//jQuery('#sbox_img_'+scid).attr('href', 'product.php?id='+pid);
			// 製品名
			jQuery('#sbox_pname_'+scid).text('■'+json.name);
			// 価格
			jQuery('#sbox_price_'+scid).text('価格:￥'+addFigure(json.price));
			// 画像
			//jQuery('#scimg_'+scid).src = 'images/products_scissors_'+json.thumb+'_s.jpg';
			jQuery('#scimg_'+scid).attr('src', 'images/products_scissors_'+json.thumb+'_s.jpg');
			// アイコン初期化
			jQuery('#sbox_'+scid+' .tbl_ico img').each(function (index, domEle) {
				// domEle == this
				if (jQuery(domEle).hasClass('opacity25')) jQuery(domEle).removeClass('opacity25');
				if (jQuery(domEle).hasClass('opacity75')) jQuery(domEle).removeClass('opacity75');
				if (jQuery(domEle).hasClass('opacity100')) jQuery(domEle).removeClass('opacity100');
				if (!jQuery(domEle).hasClass('opacity50')) jQuery(domEle).addClass('opacity50');
			});
			jQuery('#sbox_'+scid+' .tbl_ico2 img').each(function (index, domEle) {
				// domEle == this
				if (jQuery(domEle).hasClass('opacity75')) jQuery(domEle).removeClass('opacity75');
				if (jQuery(domEle).hasClass('opacity100')) jQuery(domEle).removeClass('opacity100');
				if (!jQuery(domEle).hasClass('opacity50')) jQuery(domEle).addClass('opacity50');
			});
			// 仕様
			jQuery('#sbox_'+scid+' .tbl_ico img').each(function (index, domEle) {
				// domEle == this
				for(var key in json){
					if (key.indexOf('icon_') > -1) {
						icon_id = key.replace('icon_', '');
						if (jQuery(domEle).is('#icon1_'+scid+'_'+icon_id)) {
							if (jQuery('#icon1_'+scid+'_'+icon_id).hasClass('opacity50')) jQuery('#icon1_'+scid+'_'+icon_id).removeClass('opacity50');
							if (!jQuery('#icon1_'+scid+'_'+icon_id).hasClass('opacity100')) jQuery('#icon1_'+scid+'_'+icon_id).addClass('opacity100');
						}
					}
				}
			});
			// カスタマイズ仕様
			jQuery('#sbox_'+scid+' .tbl_ico2 img').each(function (index, domEle) {
				// domEle == this
				for(var key in json){
					if (key.indexOf('icon_') > -1) {
						icon_id = key.replace('icon_', '');
						if (jQuery(this).is('#icon2_'+scid+'_'+icon_id)) {
							if (jQuery('#icon2_'+scid+'_'+icon_id).hasClass('opacity50')) jQuery('#icon2_'+scid+'_'+icon_id).removeClass('opacity50');
							if (!jQuery('#icon2_'+scid+'_'+icon_id).hasClass('opacity100')) jQuery('#icon2_'+scid+'_'+icon_id).addClass('opacity100');
						}
					}
				}
			});
		});
	}
}

function addFigure(str) {
	var num = new String(str).replace(/,/g, "");
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	return num;
}


