/*
	@auther cyocun koiwahara
	@date 10/09/10
*/
document.write('<!--[if lt IE 7]>');
document.write('<link rel="stylesheet" type="text/css" href="/_css/common/ie6.css" />');
document.write('<![endif]--> ');
$(function(){


	// image zooooooooooooom
	if($(".imageZoom").length>0){
		$(".imageZoom").fancybox();
	}
	
	$("#main>*:first-child").addClass("firstChild");
	$("#mainL>*:first-child").addClass("firstChild");
	$("#main>*:last-child").addClass("lastChild");
	$("#mainL>*:last-child").addClass("lastChild");

	//add pdf icon
	$("a[href $=.pdf]").addClass("pdf");
	$("a[href $=.xls]").addClass("xls");
	$("a[href $=.doc]").addClass("doc");
	
	//$("#langE").find("a").attr("href","/en/");
	//$("#langC").find("a").attr("href","/ch/");
	//$("a[href='/service/management.html']").attr("href","#").css("cursor","default").not(".outlink").find("img").css("opacity","0.4").removeClass("swap");



	// Side menu Current sign
	var path = document.URL.replace( /\#.+/, '' );
	path = path.replace( /\?.+/, '' );
	var path_arr = path.split('/');
	path_arr.shift();
	path_arr.shift();
	path_arr.shift();
	var link;
	while(path_arr.length){
		$(".news").length ? link=$('#side').find('a[href^=/'+path_arr.join('/')+']') : link=$('#side').find('a[href$=/'+path_arr.join('/')+']');
		if(link.length){
				link.addClass("current");
				var img = link.find("img");
				if(!img.length){break;}
				var src = img.attr('src');
				var src_on = src.substr(0, src.lastIndexOf('.')) + "_o" + src.substring(src.lastIndexOf('.'));
				img.attr('src', src_on).removeAttr("class");
			break;
		}
		path_arr.pop();
	}
	
	
	//「お手製★ベツページのアンカーリンクMADEトンジャウYO」
	if((document.URL.search(/\?/) != -1)&&($("#search").length==0)&&($("#survey").length==0)){
		var anc_arr = document.URL.split("?");
		anc_arr.shift();
		var anchers = $("#"+anc_arr[0]);
		var ancherOffset = anchers.offset().top - $("#header").outerHeight();
		$('html,body').scrollTop(ancherOffset);
	}else if((document.URL.search(/\?/) != -1)&&($("#survey").length==1)){
		var anc_arr = document.URL.split("?");
		anc_arr.shift();
		var anchers = $("#"+anc_arr[0]);
		var ancherOffset = anchers.offset().top - $("#header").outerHeight() -50;
		//console.log(ancherOffset)
		$('html,body').scrollTop(ancherOffset);
	}
	
	//Swap images
	var postfix = '_o';
	var curentfix = '_c';
	$('.swap').not('[src*="'+ postfix +'."]').not('[src*="'+ curentfix +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.')) + postfix + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(function() {img.attr('src', src_on);},function() {img.attr('src', src);});
	});
	$('.swap').filter('[src*="'+ curentfix +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.replace("_c.","_o.");
		$('<img>').attr('src', src_on);
		img.hover(function() {img.attr('src', src_on);},function() {img.attr('src', src);});
	});

	//Font switcher
	$.browser.msie?$("body").addClass("msie"):0;
	navigator.platform.indexOf("Win") != -1 ? $("body").addClass("win"):0;
	$.browser.msie?$("table").addClass("msie"):0;
	navigator.platform.indexOf("Win") != -1 ? $("table").addClass("win"):0;
		
	//
	$('input[type=text]').focus(function() {
		var title = $(this).attr('title');
		if ($(this).val() == title) {
			$(this).val('');
		}
	}).blur(function() {
		var title = $(this).attr('title');
		if ($(this).val() == '') {
			$(this).val(title);
		}
	});	
	
	
	//
	var txt	
	$('.tip').hover(
		function(e) {
			txt =  $(this).attr('title');
			//console.log(e);
			$(this).attr('title','');
			var xy = $(this).offset();
			$("body").append('<div id="tooltip">' + txt + '</div>');
			$('#tooltip').css('top', xy.top-15);
			$('#tooltip').css('left', xy.left+($(this).width()/2)-($("#tooltip").width()/2));
		},
		function(e) {
			$(this).attr('title',txt);
			$("body").children('#tooltip').remove();
		}
	);
	
	
	//equalHeight
	var tallest
	function equalHeight(group) {
		tallest = 0;
		group.each(function() {
			thisHeight = $(this).height();
			thisHeight > tallest ? tallest = thisHeight : 0;
		});
		group.height(tallest);
	}
	equalHeight($(".listIndex dd"));
	equalHeight($(".categoryList"));
	
	//project story
	var pjStory = $("#storyIndex").find(".catIndex").find("li");
	$(pjStory).each(function(){
		$(this).hover(function() {$(this).addClass("hover")},function() {$(this).removeClass("hover")});
		$(this).click(function() {window.location=$(this).find("a").attr('href');return false;});
	});
	
	$(".pageTop").find("a").click(function() {
		var posY = document.documentElement.scrollTop || window.pageYOffset
		var $target = document.body.offsetTop;
		$('html,body')
			.scrollTop(1000>=posY?posY:1000)
			.stop()
			.animate({scrollTop:$target},500,"easeOutQuint");
		return false;
	});
	
});

