/**
 * @author Administrator
 */


function ch_design(){
	
	remove_price();
	set_category();
	set_title();
	
	
	var check_cate_val = check_cate();

	var title_cate_text;
	var head_img_1;
	var head_img_2;
	
	
	
	if(check_cate_val == 1){
		title_cate_text=' &gt; <a href="http://www.takeoff-ltd.com/search-item.html">商品から探す</a>';
		head_img_1 = '<a href="http://www.takeoff-ltd.com/search-item.html"><img src="/design/gmosp1069/img/head_menu01_active.gif" alt="商品から探す" width="204" height="39" border="0"></a>';
		head_img_2 = '<a href="http://www.takeoff-ltd.com/search-shop.html"><img src="/design/gmosp1069/img/head_menu02.gif" alt="店舗から探す" width="199" height="39" border="0" class="btn"></a>';
	}else if(check_cate_val == 2){
		title_cate_text=' &gt; <a href="http://www.takeoff-ltd.com/search-shop.html">店舗から探す</a>';
		head_img_1 = '<a href="http://www.takeoff-ltd.com/search-item.html"><img src="/design/gmosp1069/img/head_menu01.gif" alt="商品から探す" width="204" height="39" border="0" class="btn"></a>';
		head_img_2 = '<a href="http://www.takeoff-ltd.com/search-shop.html"><img src="/design/gmosp1069/img/head_menu02_active.gif" alt="店舗から探す" width="199" height="39" border="0"></a>';
	}
	
	$('#cate_menu li:first').html(head_img_1);
	$('#cate_menu li:last').html(head_img_2);
	
	$('#pankuzu p').append(title_cate_text);
	
	$('#pankuzu p').append(' &gt; '+$('.ttl').text());
	
	//set header arrow
	$('.ttl').find('*').andSelf()
    .contents().not('[nodeType=1]')
        .each(function(){
            this.nodeValue = this.nodeValue.replace('>','|');
        });

	if($('.all').length){
		make_product_list();

	}else{
		make_product_detail();
	}
	
	if(cate_id == 62){
		if (sub_cate_id == 1) {
			$('#tenpo').remove();
		}else{
			$('#jimu').remove();
		}
	}

	
	set_login_window();
}


function remove_price(){
	switch (true) {
		case(cate_id >= 27 && cate_id <= 49):
		case(cate_id == 2):
		case(cate_id == 51):
		case(cate_id == 65):
		case(cate_id == 79):
		case(cate_id == 93):
			$("[color='#f89b22']",'.woong').attr('color','#FFFFFF');
			break;
		default:
			$("[color='#f89b22']",'.woong').addClass('red');
	}
	

}


function check_cate(){

	switch(true){
		
		case(cate_id >= 50 && cate_id <=64):
			return 1;
			break;
		default:
			if (cate_id) {
				var pattern = '/[0-9]/';
				if (cate_id.search(pattern) != -1) {
					return 2;
					break;
				}
			}
	}
}


function set_category(){
	
	var is_sub_cate;
	
	var active_flg = false;
	
	
	
	$('#mainnavi a').each(
		function(){
			var dir_array = $(this).attr('href').split('/');
			

				if(sub_cate_id){
					if(cate_id == dir_array[2] && sub_cate_id == dir_array[3]){
						$(this).addClass('now');
						active_flg = true;
					}
				}else{
					if(cate_id == dir_array[2] && dir_array[3].match(/[^0-9]/g)){
						$(this).addClass('now');
						active_flg = true;
					}
				}
			
		}
	);
	
	
	if(!active_flg){
		$('#mainnavi a').each(
			function(){
				var dir_array = $(this).attr('href').split('/');
				
				if(cate_id == dir_array[2] && dir_array[3].match(/[^0-9]/g)){
					$(this).addClass('now');
				}
			}
		)
	}
	
}

function set_title(){
	
	var switch_val = cate_id;
	var switch_sub_val = sub_cate_id;
	
	
	switch(true){
		case(switch_val >= 65 && switch_val <= 78):
		case(switch_val == 120):
			//新宿店
			$('#head_title').attr('src','/design/gmosp1069/img/shinjyuku_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val >= 79 && switch_val <= 92):
		case(switch_val == 121):
			//大阪店
			$('#head_title').attr('src','/design/gmosp1069/img/osaka_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val >= 93 && switch_val <= 107):
		case(switch_val == 122):
			//江東OA店
			$('#head_title').attr('src','/design/gmosp1069/img/oa_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 119):
		case(switch_val == 124):
		case(medi_path == 'member.html'):
		case(medi_path == 'lostpass.html'):
			//医療機器
			$('#head_title').attr('src','/design/gmosp1069/img/medical_title.jpg');
			$('#site_area').attr('href','http://eng-medical.takeoff-ltd.com/medical/');
			break;
		case(switch_val >= 27 && switch_val <= 49):
		case(switch_val == 125):
			//理化学機器
			$('#head_title').attr('src','/design/gmosp1069/img/chemistry_title.jpg');
			$('#site_area').attr('href','http://eng-medical.takeoff-ltd.com/scientific');
			break;
		case(switch_val == 50):
		
			//測量
			$('#head_title').attr('src','/design/gmosp1069/img/sokuryo_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val >= 13 && switch_val <= 26):
		case(switch_val == 123):
			//測定器
			$('#head_title').attr('src','/design/gmosp1069/img/measure_title.jpg');
			$('#site_area').attr('href','http://eng-medical.takeoff-ltd.com/measuring/');
			break;
		case(switch_val == 56):
			//パソコン
			$('#head_title').attr('src','/design/gmosp1069/img/pc_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 52):
			//コピー機
			$('#head_title').attr('src','/design/gmosp1069/img/copy_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 53):
			//ファックス
			$('#head_title').attr('src','/design/gmosp1069/img/fax_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 54):
			//ビジネスホン
			$('#head_title').attr('src','/design/gmosp1069/img/phone_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 55):
			//サーバー
			$('#head_title').attr('src','/design/gmosp1069/img/server_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 57):
			//プリンター
			$('#head_title').attr('src','/design/gmosp1069/img/printer_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 58):
			//CAD
			$('#head_title').attr('src','/design/gmosp1069/img/cad_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 59):
			//AV
			$('#head_title').attr('src','/design/gmosp1069/img/av_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 50):
			//測量
			$('#head_title').attr('src','/design/gmosp1069/img/sokuryo_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 51):
			//ワープロ
			$('#head_title').attr('src','/design/gmosp1069/img/word_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 60):
			//オフィス家具
			$('#head_title').attr('src','/design/gmosp1069/img/jyuki_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 61):
			//シュレッダ
			$('#head_title').attr('src','/design/gmosp1069/img/shredder_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 62 && switch_sub_val==2):
			//店舗機器
			$('#head_title').attr('src','/design/gmosp1069/img/tenpo_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 62 && switch_sub_val==1):
			//事務機器
			$('#head_title').attr('src','/design/gmosp1069/img/jimu_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 63):
			//その他パソコン・オフコン
			$('#head_title').attr('src','/design/gmosp1069/img/elsepc_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		case(switch_val == 64):
			//サプライ
			$('#head_title').attr('src','/design/gmosp1069/img/supply_title.jpg');
			$('#site_area').attr('coords','0');
			break;
		default:
			
			
			
			$('#head_title').attr('src','/design/gmosp1069/img/default_title.jpg');
			$('#site_area').attr('coords','0');
	}
	
	
}



function make_product_list(){
	
	//set all item url
	var all_link = $('.ttl a:first').attr('href');
	$('.all a:first').attr('href',all_link);
	

	$('#category > table').addClass('catetbl');
	$('#category td table td:nth-child(1)').html("");
	$('#category td table td:nth-child(1)').addClass('none');
	$('#category td table td:nth-child(2)').html("");
	$('#category td table td:nth-child(2)').addClass('none');
	$('#category td table td:nth-child(3)').addClass('category_list');
	
	
	$('#list > table > tbody > tr > td:nth-child(1)').addClass('list_border');
	$('#list > table > tbody > tr > td:nth-child(2)').addClass('spacer');
	$('#list > table > tbody > tr > td:nth-child(2) img').addClass('none');
	$('#list > table > tbody > tr > td:nth-child(3)').addClass('list_border');
	
	$('.list_border > table > tbody > tr > td:nth-child(1)').addClass('list_img space');
	$('.list_border > table > tbody > tr > td:nth-child(2)').addClass('space');
	$('.list_border p table').addClass('list_detail');
	
	$('#list > table > tbody > tr:odd').html('<td class="height"><img src="/images/white.gif" width=1 height=10></td><td><img src="/images/white.gif" width=1 height=10></td><td><img src="/images/white.gif" width=1 height=10></td>');
	
	//$("[color='#f89b22']",'.woong').addClass('red');
	
	$("[color='red']",'.clearfix').attr('color','#010101');
	$("[color='#000000']",'.clearfix').attr('color','#0066cc');
	
	
	$("table tr .woong:nth-child(1)").each(
		function(){
			
			var target = $('td:eq(1)',this);
			
			var img_data = $('img',target).clone();
			$('img',target).remove();
			if (img_data) {
				$(target).prepend('&nbsp;');
				$(target).prepend(img_data);
			}
		}
	
	);
}

function make_product_detail(){
	
	$('img','.ttl').remove();
	
	$('.ttl .woong:last').remove();
	$('.ttl .woong:last').remove();
	
	
	var title_dom = $('.pdt_ttl');
	$('img',title_dom).each(
		function(){
			var img_data = $(this).clone();
			
			$(this).remove();
			
			if(img_data){
				$('.icon').prepend(img_data);
			}
		}
	)
	
	
	if ($('.pdt_l a').attr('href')) {
		var img_a_href = $('.pdt_l a').attr('href');
		var img_url = img_a_href.match('[0-9]+\.jpg');
		var new_img_url = '/shopimages/gmosp1069/' + img_url;
		
		$('.pdt_l a').attr('href', new_img_url);
	}
	$('.pdt_l a').attr('rel','product_img');
	$('.pdt_l a').addClass('thickbox');
	
	//set custom form url
	var cust_form_url = $('#cust_form').attr('href');
	cust_form_url += '?p_code='+$('#p_code').text()+'&p_name='+encodeURI($('.pdt_ttl h3').text());
	$('#cust_form').attr('href',cust_form_url);

	var caption = $('.pdt_detail caption').clone();
	$('.pdt_detail caption').remove();
	$('.pdt_detail').prepend(caption.html());
	
	
	//set detail table text align to left
	$('[align="center"]','.pdt_detail td').css('text-align','left');
	$('.pdt_detail td').css('text-align','left');
	
	$('[bgcolor="#ccffcc"]','.pdt_detail').css('background-color','#E5E7EB');
	$('[bgcolor="#ccccff"]','.pdt_detail').css('background-color','#E5E7EB');
	$('[bgcolor="#99ff99"]','.pdt_detail').css('background-color','#E5E7EB');
	$('[bgcolor="#ffff99"]','.pdt_detail').css('background-color','#FFFFFF');

	var detail_tables = $('.pdt_detail table');
	
	detail_tables.removeAttr('width');
	var target_detail_table = detail_tables.eq(detail_tables.length-1);
	
	target_detail_table.wrap('<p class="pdt_detail_in"></p>');
	
	target_detail_table.removeAttr('cellspacing');
	target_detail_table.removeAttr('cellpadding');
	target_detail_table.removeAttr('border');
	
	
}


function set_login_window(){
	if(!$.cookie('login_id')){
		if(cate_id == 119){
			
			$('.list_border a').each(
			
				function(){					
					if($(this).attr('href').indexOf('shopdetail') != -1){
						$(this).attr('href','/design/gmosp1069/medical_popup.htm?placeValuesBeforeTB_=savedValues&TB_iframe=true&height=180&width=320&modal=true&code='+$(this).attr('href'));
						$(this).attr('class','thickbox');
					}
				}
			
			)
			
		}
	}
}


$(document).ready(ch_design);
