﻿
$(function(){
	bodyId = $('body').attr('id');
	bodyCl = $('body').attr('class');
	
	//topic path
	if($('ul#topicPath')){
		$('ul#topicPath li a').after('<span>&nbsp;&gt;</span>');
	}
	
	
	//hnavi
	if($('ul#hNavi')){
		$('ul#hNavi li').each(function(){
			hnavID = $(this).attr('id').split('nv-')[1];
			if(hnavID == bodyId){
				$(this).find('img').css('visibility','hidden');
			}
		});
	}
	
	if($('#header ul li')){
		$('#header ul li').each(function(){
			if($(this).attr('id').split('nv-')[1] == bodyId){
				$(this).find('a').css('visibility','hidden');
			}
		});
	}
	
	
	//snavi
	if($('ul#sNav')){
		$('ul#sNav li').each(function(){
			snavID = $(this).attr('id').split('snv-')[1];
			$(this).css('background','url("images/snav/'+ snavID +'_on.gif") top left no-repeat');
			if(snavID == bodyCl){
				$(this).find('img').css('visibility','hidden');
			}
		});
	}
	
	//project tab
	if($('ul#projectTab li a')){
		$('ul#projectTab li a').each(function(){

			tabImg = $(this).find('img').attr('src').split('.gif')[0] + '_on.gif';
			$(this).css('background','url(' +tabImg+ ') top left no-repeat');
			
			$(this).click(function(){
				$('ul#projectTab li a').attr('class','');
				$(this).attr('class','first');
				
				$('#projectTxt dl').css('display','none');
				clickID = $(this).attr('href');
				$(clickID).css('display','block');
			});
		});

	}
	
	if(bodyId == 'contact' && bodyCl == 'request'){
		fundNm = location.hash;
		if(fundNm == '#amber' || fundNm == '#discovery' || fundNm == '#sevenseas'){
			$(fundNm + 'Fund').attr('checked','checked');
		}
	}
	
	//banner sub
	if($('ul#sNav')){
		$('ul#sNav').after('<ul id="banners"><li><a href="http://www.rst-corp.jp/rst_club/"><img src="http://www.rst-corp.jp/images/common/banner_club.gif" width="192" height="90" alt="" /></a></li><li><a href="http://www.rst-corp.jp/news/index.html"><img src="http://www.rst-corp.jp/images/common/banner_contribution_project.gif" width="192" height="90" alt="" /></a></li></ul>');

	}
	
	//form submit
	if($('input#submit')){
		$('input#submit').click(function(){
			//product
			if($('#selectType')){
				if($('#selectType select').val() == ''){
					selectTxt = $('#selectType b').text();
					alert(selectTxt +'を選択してください');
					return false;
				}
				if($('#selectType select').val() != undefined){
					inpVl = $('input#productName0').attr('value');
					$('input#productName').attr('value',inpVl + '【' + $('#selectType select').val() +'】');
				}
			}
		});
	}

	if($('ul#categoryList')){
		$('ul#categoryList li').css('cursor','pointer');
		$('ul#categoryList li').hover(
			function(){
				$(this).css('background','#edecdf');
			},
			function(){
				$(this).css('background','#fff')
			}
		);
		$('ul#categoryList li').click(function(){
			link = $(this).find('th a').attr('href');
			location.href = link;
		});
	}
	
	if($('ul.categoryList')){
		$('ul.categoryList li').css('cursor','pointer');
		$('ul.categoryList li').hover(
			function(){
				$(this).css('background','#edecdf');
			},
			function(){
				$(this).css('background','#fff')
			}
		);
		$('ul.categoryList li').click(function(){
			link = $(this).find('th a').attr('href');
			location.href = link;
		});
	}
	if($('#productPh ul li')){
		$('#productPh ul li img').each(function(){
			if($(this).attr('class') != 'noImg'){
				$(this).click(function(){
					bigImg = $(this).attr('src').split('_s.jpg')[0] + '_l.jpg';
					$('#productPh dt img').attr('src',bigImg);
				});
			}
		});
	}
	if($('input.submit_seiko')){
		$('input.submit_seiko').click(function(){
			$('#cartForm').submit();
		});
	}
});


/* swapImg */
jQuery.fn.extend({
	swapImg: j$(document).ready(function(){
		return j$('.swapImg').each(function(){
			if(j$(this).attr('class').match('swapImg change')){
				//ImgPreLoad
				swapObj = new Image();
				preLoad = j$(this).attr('class').split('swapImg change(')[1].split(')')[0];
				swapObj.src = preLoad;
				imgNm = j$(this).attr('name',preLoad);
				
				//MouseOver
				j$(this).hover(
					function(){
						j$(this).attr('lowsrc',j$(this).attr('src'));
						j$(this).attr('src',j$(this).attr('name'));
					},
					function(){
						j$(this).attr('src',j$(this).attr('lowsrc'));
					}
				);
			}else if(j$(this).attr('src').match('_no.')){
				//ImgPreLoad
				swapObj = new Image();
				imgpath = j$(this).attr('src');
				preLoad = imgpath.replace('_no.','_ro.');
				swapObj.src = preLoad;
				
				j$(this).hover(
					function(){
						j$(this).attr('src',j$(this).attr('src').replace('_no.','_ro.'));
					},
					function(){
						j$(this).attr('src',j$(this).attr('src').replace('_ro.','_no.'));
					}
				);
			}
		});
	})
});

