﻿$(function(){
	
	//top
	if($('body').attr('id') == 'top'){

		
		//scrollbar
		$('#newsArea').jScrollPane();
		
		function autoSlide(){
			if($('ul.content').css('margin-left') == '-3150px'){
				$('ul.content').animate({
					marginLeft : '0'
				},500);
			}else{
				$('ul.content').animate({
					marginLeft : '-=630px'
				},500);
			}
		}
		timer = setInterval(autoSlide,5000);
		//scrollanime
		$('ul.controls li a').each(function(e){
			$(this).click(function(){
				clearInterval(timer);
				no = $(this).attr('href').split('#section')[1];
				xWidth = 630;
				if(no != 1){
					$('ul.content').animate({
						marginLeft : '-' + xWidth * (no-1) +'px'
					},500);
				}else{
					$('ul.content').animate({
						marginLeft : 0
					},500);
				}
				timer = setInterval(autoSlide,5000);
				return false;
			});
		});
		


		
	}
	
	//topic path
	if($('ul#topicPath')){
		$('ul#topicPath li a').after('<span>&nbsp;&gt;</span>');
	}
  
	//Footer border
	if($('#footer')){
		$('#footer ul li:eq(9)').css('border-right','none');
	}

	//service menu
	if($('#menuBox')){
		$('#menuBox dd:eq(4)')
			.css('border-bottom','1px dotted #333')
			.css('padding','0 0 5px 12px');
	}

	//next
	if($('#nextBox')){
		$('#nextBox dd:eq(2)')
			.css('border-bottom','1px dotted #333')
			.css('margin-bottom','10px');
	}
	
	//special_archive
	if($('ul#specialList')){
		$('ul#specialList li:eq(0)')
			.css('border-top','none');
	}
	
	//faq
	if($('#faqList dl')){
		$('#faqList dl').each(function(){
			$(this).find('dt:eq(0)')
				.css('border','none')
				.css('margin-top','-5px');
		});
	}

	//tooltip
	if($('.tooltip')){
		$('.tooltip').css('opacity',0);
		alt = '';
		$(".titleList dd a img")
			.mouseover(function(){
				if($(this).attr('alt') != ''){
					flg = 1;
					$('.tooltip').stop();
					$('.tooltip').text($(this).attr('alt'));
					alt = $(this).attr('alt');
					$(this).attr('alt','');
					$('.tooltip').animate({
						opacity: 0
					},100);
					$('.tooltip').animate({
						opacity: 1
					},300);
				}
		})
			.mouseout(function(){
				$(this).attr('alt',alt);
				$('.tooltip').stop();
				$('.tooltip').animate({
					opacity: 0
				},400);
				flg = 0;
		})
			.mousemove(function(e){
				$(".tooltip").css({
					"top":e.pageY+10+"px",
					"left":e.pageX+10+"px"
				});
		});
		$("ul#chapters dt img")
			.mouseover(function(){
				if($(this).attr('alt') != ''){
					flg = 1;
					$('.tooltip').stop();
					$('.tooltip').text($(this).attr('alt'));
					alt = $(this).attr('alt');
					$(this).attr('alt','');
					$('.tooltip').animate({
						opacity: 0
					},100);
					$('.tooltip').animate({
						opacity: 1
					},300);
				}
		})
			.mouseout(function(){
				$(this).attr('alt',alt);
				$('.tooltip').stop();
				$('.tooltip').animate({
					opacity: 0
				},400);
				flg = 0;
		})
			.mousemove(function(e){
				$(".tooltip").css({
					"top":e.pageY+10+"px",
					"left":e.pageX+10+"px"
				});
		});
	}
	
	//myNatuDAN
	if($('input#ummCancel')){
		$('input#ummCancel').click(function(){
			if(window.confirm('本当に解約しますか？')){
				location.href = "http://www.natudan.com/umm_cancel.php/";
			}else{
				return false;
			}
		});
	}
	
	//point scroll
	$('ul#selectCard a').click(function(){
		pointID = $(this).attr('href');
		pointSet = $('#aboutPoint').offset().top;
		$('html,body').animate({ scrollTop: pointSet }, 500);
		return false;
	});
	
	//ranking word-break
   $('ul#headerRank4-10 dd a').each(function () {
            var spTxt = $(this).text().split("");
            if($.browser.opera){//opera
                $(this).html(spTxt.join("­"));
            }else if($.browser.msie){//IE
                $(this).css("word-break","break-all");
            }else{//others
                $(this).html(spTxt.join("&#8203;"));
            }
    });

});


/* swapImg */
jQuery.fn.extend({
	swapImg: $(document).ready(function(){
		return $('.swapImg').each(function(){
			if($(this).attr('class').match('swapImg change')){
				//ImgPreLoad
				swapObj = new Image();
				preLoad = $(this).attr('class').split('swapImg change(')[1].split(')')[0];
				swapObj.src = preLoad;
				imgNm = $(this).attr('name',preLoad);
				
				//MouseOver
				$(this).hover(
					function(){
						$(this).attr('lowsrc',$(this).attr('src'));
						$(this).attr('src',$(this).attr('name'));
					},
					function(){
						$(this).attr('src',$(this).attr('lowsrc'));
					}
				);
			}else if($(this).attr('src').match('_no.')){
				//ImgPreLoad
				swapObj = new Image();
				imgpath = $(this).attr('src');
				preLoad = imgpath.replace('_no.','_ro.');
				swapObj.src = preLoad;
				
				$(this).hover(
					function(){
						$(this).attr('src',$(this).attr('src').replace('_no.','_ro.'));
					},
					function(){
						$(this).attr('src',$(this).attr('src').replace('_ro.','_no.'));
					}
				);
			}
		});
	})
});
/*
new function(){
	if(window.opera || navigator.userAgent.indexOf("Firefox") != -1){
		var wordBreak = function() {
			var wordBreakClass = "wordBreak";
			var table = document.getElementsByTagName("table");
			for(var i=0,len=table.length ; i<len ; i++){
				var tbClass = table[i].className.split(/\s+/);
				for (var j = 0; j < tbClass.length; j++) {
					if (tbClass[j] == wordBreakClass) {
						recursiveParse(table[i])
					}
				}
			}
		}
		var recursiveParse = function(pNode) {
			var childs = pNode.childNodes;
			for (var i = 0; i < childs.length; i++) {
				var cNode = childs[i];
				if (childs[i].nodeType == 1) {
					recursiveParse(childs[i]);
				}else if(cNode.nodeType == 3) {
					if(cNode.nodeValue.match("[^\n ]")){
						var plTxt = cNode.nodeValue.replace(/\t/g,"")
						var spTxt = plTxt.split("");
						spTxt = spTxt.join(String.fromCharCode(8203));
						var chNode = document.createTextNode(spTxt);
						cNode.parentNode.replaceChild(chNode,cNode)
					}
				}
			}
		}

	}else{
		var wordBreak = function() {
			if( document.styleSheets[0].addRule ){
				document.styleSheets[0].addRule(".wordBreak","word-break:break-all");
			}else if( document.styleSheets[0].insertRule ){
				document.styleSheets[0].insertRule(".wordBreak{word-break:break-all}", document.styleSheets[0].cssRules.length );
			}else{
				return false;
			}
		}
	}
	var addEvent = function(elm,listener,fn){
		try{
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent("on"+listener,fn);
		}
	}
	addEvent(window,"load",wordBreak);
}
*/

