var _mouse=true;
var _rolling=true;

$(function()
{
    // insert main menu
	var _menu=new SWFObject("/2010J/main/swf/view_menu.swf","main_menu","958","280","8","#FFFFFF");
	_menu.addParam("quality","high");
	_menu.addParam("wmode","transparent");
	_menu.write("id_main_menu");

    // insert select nation
	var _nation=new SWFObject("/2010J/main/swf/select_nation.swf","select_nation","146","196","8","#FFFFFF");
	_nation.addParam("quality","high");
	_nation.addParam("wmode","transparent");
	_nation.write("id_select_nation");

    // insert main flash
	var _main=new SWFObject("/2010J/main/swf/main.swf","main_flash","958","232","8","#FFFFFF");
	_main.addParam("quality","high");
	_main.addParam("wmode","transparent");
	_main.write("id_main_flash");
	
	//link description
	linkDescriptionMain() ;
    
    // create popup layer
    createPopupLayer2();
});

// create popup layer
function createPopupLayer()
{
    var _layer=new Array('1');
    var _width=new Array('410');
    var _height=new Array('387');
    var _top=new Array('75');
    var _left=new Array('0');
    var _img=new Array('/2010J/popup/images/111019_pop.jpg');
    var _text=new Array('技術革新型中小企業(INNO-BIZ), ベンチャー企業選定');
    var _map=new Array('usemap=#map1');
    var _map_cont="<MAP name='map1'><br /><AREA href='/2010J/promote/news/view.php?no=466' shape='rect' coords=32,278,252,308 /><AREA href='/2010J/promote/news/view.php?no=464' shape='rect' coords=31,317,251,359 /></MAP><MAP name='map2'><br /><AREA href='/2010/data/certList.php?no=11' shape='rect' coords=44,296,226,330 /></MAP>";
    var _source="";
    var _cookie="";

    for (var i=0;i<_layer.length;i++) {
        _cookie=getCookie("qlightkr_popup_"+_layer[i]);
        if (_cookie==null || _cookie=="") {
            _source="<div id=\"popup_"+_layer[i]+"\" style=\"width:"+_width[i]+"px; height:"+(parseInt(_height[i])+50)+"px; position:absolute; top:"+_top[i]+"px; left:"+_left[i]+"px; font-size:0px; border:2px solid #0A246A; display:block;\"><span style=\"width:"+_width[i]+"px; height:25px; position:absolute; top:0px; left:0px; background:#3D5A96; cursor:move; display:block;\"><span style=\"position:relative; top:5px; left:10px; font-weight:bold; color:#FFFFFF;\">"+_text[i]+"</span></span><img src=\""+_img[i]+"\" style=\"position:absolute; top:25px; left:0px; border:0px; \" alt=\""+_text[i]+"\" "+_map[i]+" /><span style=\"width:"+_width[i]+"px; height:25px; position:absolute; top:"+(parseInt(_height[i])+25)+"px; left:0px; background:#390303; display:block;\"><span style=\"position:relative; float:right; margin-left:10px; margin-right:10px; top:6px;\"><a href=\"#top_popup\" onclick=\"closeLayer("+_layer[i]+")\"><span style=\"color:#FFFFFF;\">[CLOSE]</span></a></span><input type=\"checkbox\" onclick=\"closeCookie("+_layer[i]+")\" style=\"width:15px; height:15px; position:relative; float:right; top:5px; display:block;\" /></span>"+_map_cont+"</div>";
            $("#top_popup").append(_source);
            $("#popup_"+_layer[i]).draggable();
        }
    }
}

function createPopupLayer2()
{
    var _layer=new Array('1','2');
    var _width=new Array('410','360');
    var _height=new Array('350','350');
    var _top=new Array('75','75');
    var _left=new Array('0','418');
    var _img=new Array('http://test.qlightkr.com/2010J/popup/images/popup_111216.gif','http://test.qlightkr.com/2010J/popup/images/120106_pop.gif');
    var _text=new Array('','');
    var _map=new Array('usemap=#map2','usemap=#map1');
    var _map_cont="<MAP name='map1'><br /><AREA href='/2010J/promote/news/view.php?no=480' shape='rect' coords=228,289,328,318 /></MAP><MAP name='map2'><br /><AREA href='/2010J/promote/news/view.php?no=475' shape='rect' coords=39,284,210,315 /></MAP>";
    var _source="";
    var _cookie="";

    for (var i=0;i<_layer.length;i++) {
        _cookie=getCookie("qlightkr_popup_"+_layer[i]);
        if (_cookie==null || _cookie=="") {
            _source="<div id=\"popup_"+_layer[i]+"\" style=\"width:"+_width[i]+"px; height:"+(parseInt(_height[i])+50)+"px; position:absolute; top:"+_top[i]+"px; left:"+_left[i]+"px; font-size:0px; border:2px solid #0A246A; display:block;\"><span style=\"width:"+_width[i]+"px; height:25px; position:absolute; top:0px; left:0px; background:#3D5A96; cursor:move; display:block;\"><span style=\"position:relative; top:5px; left:10px; font-weight:bold; color:#FFFFFF;\">"+_text[i]+"</span></span><img src=\""+_img[i]+"\" style=\"position:absolute; top:25px; left:0px; border:0px; \" alt=\""+_text[i]+"\" "+_map[i]+" /><span style=\"width:"+_width[i]+"px; height:25px; position:absolute; top:"+(parseInt(_height[i])+25)+"px; left:0px; background:#390303; display:block;\"><span style=\"position:relative; float:right; margin-left:10px; margin-right:10px; top:6px;\"><a href=\"#top_popup\" onclick=\"closeLayer("+_layer[i]+")\"><span style=\"color:#FFFFFF;\">[CLOSE]</span></a></span><input type=\"checkbox\" onclick=\"closeCookie("+_layer[i]+")\" style=\"width:15px; height:15px; position:relative; float:right; top:5px; display:block;\" /></span>"+_map_cont+"</div>";
            $("#top_popup").append(_source);
            $("#popup_"+_layer[i]).draggable();
        }
    }
}
function createPopupLayer3()
{
    var _layer=new Array('1','2');
    var _width=new Array('350','360');
    var _height=new Array('400','350');
    var _top=new Array('75','75');
    var _left=new Array('0','360');
    var _img=new Array('/2010J/popup/images/2012_qlight_jp.gif','http://test.qlightkr.com/2010J/popup/images/120106_pop.gif');
    var _text=new Array('','');
    var _map=new Array('usemap=#map2','usemap=#map1');
    var _map_cont="<MAP name='map1'><br /><AREA href='/2010J/promote/news/view.php?no=480' shape='rect' coords=228,289,328,318 /></MAP><MAP name='map2'><br /><AREA href='/2010J/promote/news/view.php?no=475' shape='rect' coords=39,284,210,315 /></MAP>";
    var _source="";
    var _cookie="";

    for (var i=0;i<_layer.length;i++) {
        _cookie=getCookie("qlightkr_popup_"+_layer[i]);
        if (_cookie==null || _cookie=="") {
            _source="<div id=\"popup_"+_layer[i]+"\" style=\"width:"+_width[i]+"px; height:"+(parseInt(_height[i])+50)+"px; position:absolute; top:"+_top[i]+"px; left:"+_left[i]+"px; font-size:0px; border:2px solid #0A246A; display:block;\"><span style=\"width:"+_width[i]+"px; height:25px; position:absolute; top:0px; left:0px; background:#3D5A96; cursor:move; display:block;\"><span style=\"position:relative; top:5px; left:10px; font-weight:bold; color:#FFFFFF;\">"+_text[i]+"</span></span><img src=\""+_img[i]+"\" style=\"position:absolute; top:25px; left:0px; border:0px; \" alt=\""+_text[i]+"\" "+_map[i]+" /><span style=\"width:"+_width[i]+"px; height:25px; position:absolute; top:"+(parseInt(_height[i])+25)+"px; left:0px; background:#390303; display:block;\"><span style=\"position:relative; float:right; margin-left:10px; margin-right:10px; top:6px;\"><a href=\"#top_popup\" onclick=\"closeLayer("+_layer[i]+")\"><span style=\"color:#FFFFFF;\">[CLOSE]</span></a></span><input type=\"checkbox\" onclick=\"closeCookie("+_layer[i]+")\" style=\"width:15px; height:15px; position:relative; float:right; top:5px; display:block;\" /></span>"+_map_cont+"</div>";
            $("#top_popup").append(_source);
            $("#popup_"+_layer[i]).draggable();
        }
    }
}

// close popup layer
function closeLayer(_layer)
{
    $("#popup_"+_layer).css("display","none");
    return false;
}

// close popup layer & set cookie during 1 day
function closeCookie(_layer)
{
    setCookie("qlightkr_popup_"+_layer,"N",1);
    $("#popup_"+_layer).css("display","none");
    return false;
}

// javascript link description
function linkDescriptionMain() {
   // auto complete
   $("#input_search_code").focus(function() {
        $.post("/2010J/main/ajax/search.php",{
            param:"code",
            text:$(this).val(),
            type:$(":input[name='code_choice']:checked").val()
        }, function(xml) {
            var _code=[];
            var i=0;
            $("data",xml).each(function(id) {
                _code[i++]=$(this).text();
            });
            $("#input_search_code").autocomplete(_code,{
                matchContains: true
            });
        });
    });
    
    // code search
    $(".btn_code_search").click(function() {
        var code=$("#input_search_code").val();
        var type=$(":input[name='code_choice']:checked").val();
        if (!code){
            alert("入力ください。");
             $("#input_search_code").focus();
             return false;
        }
        location.href="/2010J/product/search.php?code="+code+"&type="+type;
    });
	$("select#id_furl").change(function() {
		var _str="";
		$("select#id_furl option:selected").each(function() {
			if ($(this).val()) {
				openLink($(this).val(),'open_link',800,600,1,1,1,1,1,1,1);
			}
		});
	});
	$("a#id_privacy").click(function() {
		openLink('/2010J/policy/privacy.php','open_privacy',620,549);
		return false;
	});
	$("a#id_deny").click(function() {
		openLink('/2010J/policy/deny.php','open_deny',620,323);
		return false;
	});
	$("a#id_intranet").click(function() {
		openLink('/2010J/separate/intranet.php','open_intranet',408,280);
		return false;
	});
	$("a#id_contact").click(function() {
		openLink('/2010J/separate/email.php?part=QLIGHT&email=qlightkr@qlightkr.com','open_intranet',650,579);
		return false;
	});
	
    $(".cate_check").click(function() {
        if ($(this).is(":checked")==true) {
		    $(this).attr("checked","");
		} else {
            $(this).attr("checked","checked");
        }
    });

    $(".external_check").click(function() {
        if ($(this).is(":checked")==true) {
		    $(this).attr("checked","");
		} else {
            $(this).attr("checked","checked");
        }
    });

    $(".light_check").click(function() {
        if ($(this).is(":checked")==true) {
		    $(this).attr("checked","");
		} else {
            $(this).attr("checked","checked");
        }
    });

    $(".volume_check").click(function() {
        if ($(this).is(":checked")==true) {
		    $(this).attr("checked","");
		} else {
            $(this).attr("checked","checked");
        }
    });

	$("li.li_cate").mouseover(function() {
		$(this).css({"background":"#3169C6"});
		$(this).css({"color":"#ffffff"});
		$(this).css({"cursor":"pointer"});
	});

	$("li.li_cate").mouseout(function() {
		$(this).css({"background":"#ffffff"});
		$(this).css({"color":"#333333"});
	});

	$("li.li_cate").click(function() {
		var no=$(this).attr("id").split("_");

		if ($("input[name='cate_"+no[2]+"']").is(":checked")==true) {
			$("input[name='cate_"+no[2]+"']").attr("checked","");
		} else {
			$("input[name='cate_"+no[2]+"']").attr("checked","checked");
		}

	});

	$("li.li_light").mouseover(function() {
		$(this).css({"background":"#3169C6"});
		$(this).css({"color":"#ffffff"});
		$(this).css({"cursor":"pointer"});
	});

	$("li.li_light").mouseout(function() {
		$(this).css({"background":"#ffffff"});
		$(this).css({"color":"#333333"});
	});

	$("li.li_light").click(function() {
		var no=$(this).attr("id").split("_");

		if ($("input[name='light_"+no[2]+"']").is(":checked")==true) {
			$("input[name='light_"+no[2]+"']").attr("checked","");
		} else {
			$("input[name='light_"+no[2]+"']").attr("checked","checked");
		}

	});

	$("li.li_external").mouseover(function() {
		$(this).css({"background":"#3169C6"});
		$(this).css({"color":"#ffffff"});
		$(this).css({"cursor":"pointer"});
	});

	$("li.li_external").mouseout(function() {
		$(this).css({"background":"#ffffff"});
		$(this).css({"color":"#333333"});
	});

	$("li.li_external").click(function() {
		var no=$(this).attr("id").split("_");

		if ($("input[name='external_"+no[2]+"']").is(":checked")==true) {
			$("input[name='external_"+no[2]+"']").attr("checked","");
		} else {
			$("input[name='external_"+no[2]+"']").attr("checked","checked");
		}

	});

	$("li.li_volume").mouseover(function() {
		$(this).css({"background":"#3169C6"});
		$(this).css({"color":"#ffffff"});
		$(this).css({"cursor":"pointer"});
	});

	$("li.li_volume").mouseout(function() {
		$(this).css({"background":"#ffffff"});
		$(this).css({"color":"#333333"});
	});

	$("li.li_volume").click(function() {
		var no=$(this).attr("id").split("_");

		if ($("input[name='volume_"+no[2]+"']").is(":checked")==true) {
			$("input[name='volume_"+no[2]+"']").attr("checked","");
		} else {
			$("input[name='volume_"+no[2]+"']").attr("checked","checked");
		}

	});

	$(".check_all").click(function() {
		var tot=$(".cate_check").length;
		for (i=1;i<=tot;i++) {
			$("input[name='cate_"+i+"']").attr("checked","checked");
		}
		$(this).css({"display":"none"});
		$(".check_cancel").css({"display":"block"});
	});
	$(".check_cancel").click(function() {
		var tot=$(".cate_check").length;
		for (i=1;i<=tot;i++) {
			$("input[name='cate_"+i+"']").attr("checked","");
		}
		$(this).css({"display":"none"});
		$(".check_all").css({"display":"block"});
	});
	$(".cate_ok").click(function() {
		var tot=$(".cate_check").length;
		var cate="";
		for (i=1;i<=tot;i++) {
			if ($("input[name='cate_"+i+"']").is(":checked")==true) {
				cate+=$("input[name='cate_"+i+"']").val()+",";
			}
		}
		if (!cate) {
			alert("");
			return false;
		} else {
			$("input[name='cate']").val(cate);
			$(".cate_area").css({"display":"none"});
		}
	});
	$(".cate_cancel").click(function() {
		var tot=$(".cate_check").length;
		for (i=1;i<=tot;i++) {
			$("input[name='cate_"+i+"']").attr("checked","checked");
		}
		$(".cate_area").css({"display":"none"});
	});

	$(".sch_cate").click(function() {
		if ($(".cate_area").css("display")=="none") {
			$(".cate_area").css({"display":"block"});
		} else {
			$(".cate_area").css({"display":"none"});
		}
		$(".light_area").css({"display":"none"});
		$(".external_area").css({"display":"none"});
        $(".volume_area").css({"display":"none"});
	});

	$(".check_all2").click(function() {
		var tot=$(".light_check").length;
		for (i=1;i<=tot;i++) {
			$("input[name='light_"+i+"']").attr("checked","checked");
		}
		$(this).css({"display":"none"});
		$(".check_cancel2").css({"display":"block"});
	});
	$(".check_cancel2").click(function() {
		var tot=$(".light_check").length;
		for (i=1;i<=tot;i++) {
			$("input[name='light_"+i+"']").attr("checked","");
		}
		$(this).css({"display":"none"});
		$(".check_all2").css({"display":"block"});
	});
	$(".light_ok").click(function() {
		var tot=$(".light_check").length;
		var light="";
		for (i=1;i<=tot;i++) {
			if ($("input[name='light_"+i+"']").is(":checked")==true) {
				light+=$("input[name='light_"+i+"']").val()+",";
			}
		}
		if (!light) {
			alert("");
			return false;
		} else {
			$("input[name='light']").val(light);
			$(".light_area").css({"display":"none"});
		}
	});
	$(".light_cancel").click(function() {
		var tot=$(".light_check").length;
		for (i=1;i<=tot;i++) {
			$("input[name='light_"+i+"']").attr("checked","checked");
		}
		$(".light_area").css({"display":"none"});
	});
	$(".sch_light").click(function() {
		if ($(".light_area").css("display")=="none") {
			$(".light_area").css({"display":"block"});
		} else {
			$(".light_area").css({"display":"none"});
		}
		$(".cate_area").css({"display":"none"});
		$(".external_area").css({"display":"none"});
        $(".volume_area").css({"display":"none"});
	});

	$(".check_all3").click(function() {
		var tot=$(".external_check").length;
		for (i=1;i<=tot;i++) {
			$("input[name='external_"+i+"']").attr("checked","checked");
		}
		$(this).css({"display":"none"});
		$(".check_cancel3").css({"display":"block"});
	});
	$(".check_cancel3").click(function() {
		var tot=$(".external_check").length;
		for (i=1;i<=tot;i++) {
			$("input[name='external_"+i+"']").attr("checked","");
		}
		$(this).css({"display":"none"});
		$(".check_all3").css({"display":"block"});
	});
	$(".external_ok").click(function() {
		var tot=$(".external_check").length;
		var external="";
		for (i=1;i<=tot;i++) {
			if ($("input[name='external_"+i+"']").is(":checked")==true) {
				external+=$("input[name='external_"+i+"']").val()+",";
			}
		}
		if (!external) {
			alert("");
			return false;
		} else {
			$("input[name='external']").val(external);
			$(".external_area").css({"display":"none"});
		}
	});
	$(".external_cancel").click(function() {
		var tot=$(".external_check").length;
		for (i=1;i<=tot;i++) {
			$("input[name='external_"+i+"']").attr("checked","checked");
		}
		$(".external_area").css({"display":"none"});
	});
	$(".sch_external").click(function() {
		if ($(".external_area").css("display")=="none") {
			$(".external_area").css({"display":"block"});
		} else {
			$(".external_area").css({"display":"none"});
		}
		$(".cate_area").css({"display":"none"});
		$(".light_area").css({"display":"none"});
        $(".volume_area").css({"display":"none"});
	});

	$(".check_all4").click(function() {
		var tot=$(".volume_check").length;
		for (i=1;i<=tot;i++) {
			$("input[name='volume_"+i+"']").attr("checked","checked");
		}
		$(this).css({"display":"none"});
		$(".check_cancel4").css({"display":"block"});
	});
	$(".check_cancel4").click(function() {
		var tot=$(".volume_check").length;
		for (i=1;i<=tot;i++) {
			$("input[name='volume_"+i+"']").attr("checked","");
		}
		$(this).css({"display":"none"});
		$(".check_all4").css({"display":"block"});
	});
	$(".volume_ok").click(function() {
		var tot=$(".volume_check").length;
		var volume="";
		for (i=1;i<=tot;i++) {
			if ($("input[name='volume_"+i+"']").is(":checked")==true) {
				volume+=$("input[name='volume_"+i+"']").val()+",";
			}
		}
		if (!volume) {
			alert("");
			return false;
		} else {
			$("input[name='volume']").val(volume);
			$(".volume_area").css({"display":"none"});
		}
	});
	$(".volume_cancel").click(function() {
		var tot=$(".volume_check").length;
		for (i=1;i<=tot;i++) {
			$("input[name='volume_"+i+"']").attr("checked","checked");
		}
		$(".volume_area").css({"display":"none"});
	});

	$(".sch_volume").click(function() {
		if ($(".volume_area").css("display")=="none") {
			$(".volume_area").css({"display":"block"});
		} else {
			$(".volume_area").css({"display":"none"});
		}
		$(".light_area").css({"display":"none"});
		$(".external_area").css({"display":"none"});
        $(".cate_area").css({"display":"none"});
	});


	$(".btn_search").click(function() {
		var tot=$(".cate_check").length;
		var cate="";
		for (i=1;i<=tot;i++) {
			if ($("input[name='cate_"+i+"']").is(":checked")==true) {
				cate+=$("input[name='cate_"+i+"']").val()+",";
			}
		}
		if (!cate) {
			alert("");
			return false;
		}
		$("input[name='cate']").val(cate);

		tot=$(".light_check").length;
		var light="";
		for (i=1;i<=tot;i++) {
			if ($("input[name='light_"+i+"']").is(":checked")==true) {
				light+=$("input[name='light_"+i+"']").val()+",";
			}
		}
		if (!light) {
			alert("");
			return false;
		}
		$("input[name='light']").val(light);

		tot=$(".external_check").length;
		var external="";
		for (i=1;i<=tot;i++) {
			if ($("input[name='external_"+i+"']").is(":checked")==true) {
				external+=$("input[name='external_"+i+"']").val()+",";
			}
		}
		if (!external) {
			alert("");
			return false;
		}
		$("input[name='external']").val(external);

		tot=$(".volume_check").length;
		var volume="";
		for (i=1;i<=tot;i++) {
			if ($("input[name='volume_"+i+"']").is(":checked")==true) {
				volume+=$("input[name='volume_"+i+"']").val()+",";
			}
		}
		if (!volume) {
			alert("");
			return false;
		}
		$("input[name='external']").val(external);
		location.href="/2010J/product/search.php?cate="+cate.substr(0,(cate.length-1))+"&light="+light.substr(0,(light.length-1))+"&external="+external.substr(0,(external.length-1))+"&volume="+volume.substr(0,(volume.length-1));
	});
}

