// JavaScript Document
function initRollOverImages() {
  var image_cache = new Object();
  
  $("img.swap").each(function(i) {
    var imgsrc = this.src;
	var active ;
    var dot = this.src.lastIndexOf('.');
    var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;
	
	$(this).hover(
		function() { this.src = imgsrc_on; },
		function() { 
			if(active!=imgsrc_on){
				this.src = imgsrc;
			}
		}
	 );
  });
}

function navi_win(locationURL) {
        self.window.name="main"
        w = window.open('', 'Remocon', 'width=520,height=560,status=yes,scrollbars=yes,directories=no,menubar=no,resizable=yes,toolbar=no');
        if (w != null) {
                if (w.opener == null) {w.opener = self;}
                w.location.href = locationURL;
        }
}
function getMousePosition(e) {
	var mouseobj = new Object();
	if(e) {
		mouseobj.x = e.pageX;
		mouseobj.y = e.pageY;
	}
	return mouseobj;
}
function openCurrentPageList(catName) {
	if(document.getElementById('smn_'+catName) != null){
		targetObj = 'div.siteContentsBlock div.pageContentSub div#smn_'+catName+' ul.subMenu';
	}else{
		return;
	}
	$('h2#sideBarSubHeading').after($('div.siteContentsBlock div.pageContentSub div#smn_'+catName));
	//var buttonID=document.getElementById( "category_" + inputData );
	$('div.siteContentsBlock div.pageContentSub div#smn_'+catName+' h3').addClass('current')
	$(targetObj+' li').addClass('current')
	if($(targetObj).css('display')!='block') {
		$(targetObj).css('display','block');
	}else{
		$(targetObj).css('display','block');
	}
}


////////////////////////////////////////////////////InitProccess
$(document).ready(function(){
	$('a[href*=#]').click(function() {  
		var target = $(this.hash);  
		target = target.length && target;  
		if (target.length) {  
			var sclpos = 30;  
			var scldurat = 1200;  
			var targetOffset = target.offset().top - sclpos;  
			$('html,body')  
				.animate({scrollTop: targetOffset},'slow');  
			return false;  
		}  
	});

//SideBar Link List Open
	var parentDivID;
	var openedObj = new Array();
	var targetObj;
	var clearFlg = true;
    $("div.siteContentsBlock div.pageContentSub div.sideBarSub1 h3").click(function(){
		if(clearFlg){
			flg = !flg;
		}
		targetObj = 'div.siteContentsBlock div.pageContentSub div#'+$(this).parent().attr("id")+' ul.subMenu';
		if(parentDivID != $(this).parent().attr("id")){
			for(i=0;i<openedObj.length;i++){
				$(openedObj[i]).css('display','none');
			}
			flg = true;
		}
		if(flg){
			clearFlg=false;
			parentDivID = $(this).parent().attr("id");
			firstHeight=$(targetObj).height()+40+"px";
			lastHeight=$(targetObj).height()+"px";
			$(targetObj).animate({opacity:0,height:0},0);
			$(targetObj).animate({opacity:0.5,width:"220px",height:firstHeight},300);
			t = setTimeout(function(){$(targetObj).css('display','block');$(targetObj).animate({opacity:1,width:"220px",height:lastHeight},300);clearTimeout(t); }, 200);
			$(targetObj).css('height','auto');
			openedObj.push(targetObj);
			clearFlg=true;
		}else{
			clearFlg=false;
			parentDivID = $(this).parent().attr("id");
			$(targetObj).animate({opacity:0},500);
			t = setTimeout(function(){$(targetObj).css('display','none');clearTimeout(t); }, 500);
			clearFlg=true;
		}
    });


	//Current Category Link List Open
	docURL = location.href;
	if(docURL.match("\/about\/")!=null){
		openCurrentPageList('about');
	}if(docURL.match("\/affiliate\/")!=null){
		openCurrentPageList('affiliate');
	}
	if(docURL.match("\/campaign\/")!=null){
		openCurrentPageList('campaign');
	}if(docURL.match("\/faq\/")!=null){
		openCurrentPageList('faq');
	}if(docURL.match("\/link\/")!=null){
		openCurrentPageList('link');
	}if(docURL.match("\/iso\/")!=null){
		openCurrentPageList('privacy');
	}if(docURL.match("\/privacy\/")!=null){
		openCurrentPageList('privacy');
	}if(docURL.match("\/sitemap\/")!=null){
		openCurrentPageList('sitemap');
	}if(docURL.match("\/work\/")!=null){
		openCurrentPageList('work');
	}
	if(docURL.match("\/warranty\/")!=null){
		openCurrentPageList('warranty');
	}
	if(docURL.match("\/jirei\/")!=null){
		openCurrentPageList('jirei');
	}
	if(docURL.match("\/customer_voice\/")!=null){
		openCurrentPageList('customer_voice');
	}
	if(docURL.match("\/oshiete\/manga\/")!=null){
		openCurrentPageList('manga');
	}else if(docURL.match("\/oshiete\/")!=null){
		openCurrentPageList('oshiete');
	}
	if(docURL.match("\/setting\/")!=null){
		openCurrentPageList('setting');
	}
	if(docURL.match("\/area\/")!=null){
		openCurrentPageList('area');
	}
	if(docURL.match("\/price\/")!=null){
		openCurrentPageList('price');
	}
	if(docURL.match("\/affiliateform\/")!=null){
		openCurrentPageList('affiliate');
	}
	if(docURL.match("\/services\/")!=null){
		openCurrentPageList('services');
	}
	if(docURL.match("\/reserve\/")!=null){
		openCurrentPageList('reserve');
	}
	if(docURL.match("\/media\/")!=null){
		openCurrentPageList('media');
	}

	//Link Buttons Hover FadeOut
	$("a img").hover(function(){
		$(this).parent().addClass('a_hover');
		$(this).animate({opacity:0.7},100);
	},
	function(){
		$(this).animate({opacity:1.0},100,function(){$(this).parent().removeClass('a_hover');});
	}
	);

	
	//Footer Link List Open
	var fl_parentDivID;
	var flg,posy,posx;
    $("div.quickGlobalNavi div.quickMenu p.linkCatTitle").click(function(e){
        flg = !flg;
		targetObj = 'div.quickGlobalNavi div#'+$(this).parent().attr("id")+' ul.subMenu';
		if(fl_parentDivID != $(this).parent().attr("id")){
			for(i=0;i<openedObj.length;i++){
				$(openedObj[i]).css('display','none');
			}
			flg = true;
		}
		posy = getMousePosition(e).y-30;
		posx = getMousePosition(e).x+30;
		if(flg){
			fl_parentDivID = $(this).parent().attr("id");
			$(targetObj).animate({opacity:0},0);
			$(targetObj).css('top',posy,'left',posx);
			$(targetObj).animate({opacity:0.7,width:"350px",top:posy,left:posx},500);
			t = setTimeout(function(){$(targetObj).css('display','block');$(targetObj).animate({opacity:1,top:posy+20},300);clearTimeout(t); }, 500);
			openedObj.push(targetObj);
		}else{
			fl_parentDivID = $(this).parent().attr("id");
			$(targetObj).animate({opacity:0},500);
			t = setTimeout(function(){$(targetObj).css('display','none');clearTimeout(t); }, 500);
		}
	});
	//RollOver Load
	initRollOverImages();
	
});