    	var g_snproxy_root = "http://snproxy.dream.jp/";
	var g_snbase;
	var g_snhost;

        function onJSONPAuth( rjson )
        {
                if( !EvAuth ){
                        alert( "Listener for auth is not set");
                } else {
                        EvAuth( "auth", rjson );
                }
        }

	function onJSONP( rjson)
	{
		var json = rjson.response;

		switch( json.action){
			case "sn.file.getList":
				if( !EvFileGetList){
					alert( "Listner for getList is not set");
				} else {
					EvFileGetList( "getList",json);
				}
				break;
                        case "sn.search.query":
                                if( !EvSearchFile ){
                                        alert( "Listener for search.query is not set");
                                } else {
                                        EvSearchFile( "query", json);
                                }
                                break;
		}
	}
	function SNode_request( action, query, pub)
	{
		var actionpath = "/do";
		var heads = document.getElementsByTagName("head");
		var elem = document.createElement( "script");
		this.lastaction = action;

		if( pub){
			actionpath = "/_pub/do";
		}

		elem.src = g_snbase + actionpath+"?rformat=JSONP&action="+action+"&"+query;
		heads[0].appendChild( elem);
	}

        function SNode_Auth( egid, pass )
        {

                var heads = document.getElementsByTagName("head");
                var elem = document.createElement("script");
                this.lastaction = "auth";

                elem.src = g_snproxy_root + "gw/" + g_snhost + "/?action=auth&egid="+egid+"&password="+pass+"&rformat=JSONP&noCacheIE="+(new Date).getTime();
                heads[0].appendChild( elem );
        }

        function SNode_File_Search( query, page )
        {
            SNode_request( "sn.search.query", "q="+query+"&page="+page, false );
        }

	function SNode_File_getList( path, page)
	{
		var pub = false;
		var prepath = path.substring( 0, 6);
		if( prepath == "/_pub/"){
			pub = true;
		}

		SNode_request( "sn.file.getList",  "path="+path, pub);
	}

	function SNode_File_Constructor()
	{
		this.getList = SNode_File_getList;
	}

        function SNode_Search_Constructor()
        {
                this.fileSearch = SNode_File_Search;
        }

        function SNode_Auth_Constructor()
        {
                this.auth = SNode_Auth;
        }

	function SNode_CreateInterface( action, opt)
	{
		switch( action){
		case "sn.file":
			if( opt){
				EvFileGetList = opt.handler;
			}
			return new SNode_File_Constructor;
                case "sn.search":
                        if( opt ){
                                EvSearchFile = opt.handler;
                        }
                        return new SNode_Search_Constructor;
                case "auth":
                        if( opt ){
                                EvAuth = opt.handler;
                        }
                        return new SNode_Auth_Constructor;
		}
	}
	function SNode_GetFileInterface( handler)
	{
		return( SNode_CreateInterface( "sn.file", {handler:handler}));
	}

        function SNode_SearchFileInterface( handler )
        {
                return( SNode_CreateInterface( "sn.search", {handler:handler}));
        }

        function SNode_AuthInterface( handler )
        {
                return( SNode_CreateInterface( "auth", {handler:handler}));
        }

	function SNode_SetNodeName( name)
	{
		g_snhost = name;

		g_snbase = g_snproxy_root+"sn/"+g_snhost;
	}
	function SemantiqNode( snhost)
	{
		if( !snhost){
			alert( "SemantiqNode API: ノード名を指定してください。");
			return;
		}
		SNode_SetNodeName( snhost);

		this.createInterface = SNode_CreateInterface;
		this.getFileInterface = SNode_GetFileInterface;
                this.getSearchInterface = SNode_SearchFileInterface;
                this.getAuthInterface = SNode_AuthInterface;
		this.setNodeName = SNode_SetNodeName;
		this.getBasePath = function(){ return g_snbase; }
	}

