jQuery.noConflict();
jQuery(document).ready(function($){
	//NengaTemplateCategory
	$("#templateList .template-leftBtn img,#templateList .template-centerBtn img").click(function(){
		sNengaTplId = $(this).siblings(".nenga_tpl_id").val();	
		document.location.href = "?action_customer_LayoutEditNew=1&template_id="+sNengaTplId;
	})
	$("#templateList .template-rightBtn img").click(function(){
		sNengaTplId0 = $(this).siblings(".nenga_tpl_id0").val();
		sNengaTplId1 = $(this).siblings(".nenga_tpl_id1").val();
		sGenre = $(this).siblings(".genre").val();
		$("#siseiForm input[name=nenga_tpl_id[0]]").val(sNengaTplId0);
		$("#siseiForm input[name=nenga_tpl_id[1]]").val(sNengaTplId1);
		$("#siseiForm input[name=genre]").val(sGenre);
		$("#siseiForm").submit();
	})
	
	
	//NengaSelectPaper
	var selectShurui;
	var selectOmote;
	var selectUra;
	
	$("#selectbox-omote-select li,#selectbox-ura-select li").hover(
		function(){
			if(!$(this).is(".select")){
				rollover($(this).find("img"));
			}
		},
		function(){
			if(!$(this).is(".select")){
				rollout($(this).find("img"));
			}
		}
	)
	function rollover(target){
		target.attr("src",target.attr("src").replace(".", "_o."));	
	}
	function rollout(target){
		target.attr("src",target.attr("src").replace("_o", ""));
		target.attr("src",target.attr("src").replace("_check", ""));
	}
	function rollselect(target){
		target.attr("src",target.attr("src").replace(".", "_check."));	
	}
	
	$("#selectbox-shurui #selectbox-shurui-select input[type=radio]")
	.attr("checked",false)
	.click(function(){
		selectShurui = $(this).val();
		$(".arrow").eq(0).css("display","block");
		$("#selectbox-omote").css("display","block");
		$("#selectbox-omote-select li").each(function(){
			selectOmote = "";
			rollout($(this).find("img"));
		}).removeClass("select");
		
		$(".arrow").eq(1).css("display","none");
		$("#selectbox-ura").css("display","none");
		$("#selectbox-ura-select li").each(function(){
			selectUra = "";
			rollout($(this).find("img"));
		}).removeClass("select");
		
		$(".arrow").eq(2).css("display","none");
		$("#main #btn-designEdit").css("display","none");
	});
	
	
	$("#selectbox-shurui #selectbox-shurui-select label")
	.click(function(){
			$("#selectbox-shurui #selectbox-shurui-select input#"+$(this).attr("for")).each(function(){
			selectShurui = $(this).val();
			$(".arrow").eq(0).css("display","block");
			$("#selectbox-omote").css("display","block");
			$("#selectbox-omote-select li").each(function(){
				selectOmote = "";
				rollout($(this).find("img"));
			}).removeClass("select");
			
			$(".arrow").eq(1).css("display","none");
			$("#selectbox-ura").css("display","none");
			$("#selectbox-ura-select li").each(function(){
				selectUra = "";
				rollout($(this).find("img"));
			}).removeClass("select");
			
			$(".arrow").eq(2).css("display","none");
			$("#main #btn-designEdit").css("display","none");
		})
	});
	
	
	$("#selectbox-omote-select li")
	.click(function(){
		if(!$(this).is(".select")){
			selectOmote = $("#selectbox-omote-select li").index(this);
			
			$("#selectbox-omote-select li")
			.each(function(){
				rollout($(this).find("img"));
			})
			.removeClass("select");
			
			
			$(this).addClass("select");
			rollselect($(this).find("img"));
			
			
			$(".arrow").eq(1).css("display","none");
			$("#selectbox-ura").css("display","none");
			$("#selectbox-ura-select li").each(function(){
				selectUra = "";
				rollout($(this).find("img"));
				$(this).removeClass("select");
			})
			$(".arrow").eq(2).css("display","none");
			$("#main #btn-designEdit").css("display","none");
			
			if(selectShurui == 0 || selectShurui == 1){
				$(".arrow").eq(2).css("display","block");
				$("#main #btn-designEdit").css("display","block");
			}else{
				$(".arrow").eq(1).css("display","block");
				$("#selectbox-ura").css("display","block");
			}
		}
	});
	
	$("#selectbox-ura-select li")
	.click(function(){
		if(!$(this).is(".select")){
			selectUra = $("#selectbox-ura-select li").index(this);
			
			$("#selectbox-ura-select li")
			.each(function(){
				rollout($(this).find("img"));
			})
			.removeClass("select");
			
			$(this).addClass("select");
			rollselect($(this).find("img"));
			
			$(".arrow").eq(2).css("display","block");
			$("#main #btn-designEdit").css("display","block");
		}
	});
	
	$("#main #btn-designEdit").click(function(){
		aTypeId = new Array(105,54,13);
		aFrontOrientation =new Array(1,2);
		aBackOrientation =new Array(1,2,0);
		
		$("form[name=frm_orien] input[name=type_id]").val(aTypeId[selectShurui]);
		if(selectShurui == 2){
			$("form[name=frm_orien] input[name=front_orientation]").val(aFrontOrientation[selectOmote]);
			$("form[name=frm_orien] input[name=back_orientation]").val(aBackOrientation[selectUra]);
		}else{
			$("form[name=frm_orien] input[name=front_orientation]").val(1);
			$("form[name=frm_orien] input[name=back_orientation]").val(aFrontOrientation[selectOmote]);
		}
		$("form[name=frm_orien]").submit();
	})
	
	
	var list = document.getElementsByTagName("label");
    for(var i=0; i<list.length; i++){
        list[i].onclick = function (){
            return clickInput(this);
        };
    }
	function clickInput(label){
    //forの指すidのinputタグがあるか探す
    var e = null;
    try{
        e = document.getElementById(label.htmlFor);
    }
    catch(exception){}
    if(e == null){
        //labelタグ以下のinputタグを探す
        var node;
        for(var i=0; i<label.childNodes.length; i++){
            node = label.childNodes.item(i);
            if(node.nodeName == 'INPUT'){
                e = node;
                break;
            }
        }
    }
    if(e != null){
        //inputタグにクリックされたときと同じ動作をさせる
        switch(e.type){
            case 'checkbox':
                e.checked =! e.checked;
                return false;
            case 'radio':
                e.checked = true;
                return false;
            case 'text': case 'password': case 'textarea':
                e.focus();
                return false;
        }
    }
}
	
});
function windowOpen(url){
	if(url == "pop_ex_original.html"){
		window.open(url, "", "width=530,height=710");
	}else{
		window.open(url, "", "width=530,height=650");
	}
}




