var API=new Class({
    stateChangeHandler:function(){
        if(this.transport.readyState==4&&this.transport.status!=200){
            alert(lang["msg_error"]+"("+this.transport.status+"): "+this.transport.message);
        }
    }
    ,initialize:function(_1,_2,_3,_4,_5,_6){
        this.end_point=_1;
        this.api_key=_3;
        this.auth_token=_5;
        this.secret=_4;
        this.response_format=_6||"json";
    }
    ,_get:function(_7,_8,_9){
        var _a=this.end_point;
        var _b=this._queryString(_7,_9);
        _a+=(_a.match(/\?/)?"&":"?")+_b;
        new Request({
            url:_a,method:"get",methodName:_7,onStateChange:this.stateChangeHandler,onSuccess:_8
        }
        ).send();
    }
    ,_post:function(_c,_d,_e){
        var _f=this.end_point;
        var _10=this._queryString(_c,_e);
        new Request({
            url:_f,data:_10,method:"post",encoding:"",methodName:_c,onStateChange:this.stateChangeHandler,onSuccess:_d
        }
        ).send();
    }
    ,_queryString:function(_11,_12){
//        _12["ypp"]="1";
//        _12["api_key"]=this.api_key;
//        if(this.auth_token){
//            _12["auth_token"]=this.auth_token;
//        }
        _12["method"]=_11;
//        _12["format"]=this.response_format;
        _12["timestamp"]=new Date().getTime();
        var _13=[];
        var _14="";
        for(var _15 in _12){
            _13.push(_15);
            _14+="&"+_15+"="+(_12[_15]?_12[_15].toString().escape_utf8():"");
        }
        _13.sort();
//        var _16=this.secret;
        var _16="vista";
//        for(var i=0;i<_13.length;i++){
//            _16+=_13[i]+_12[_13[i]];
//        }
        _14="api_sig="+_16+_14;
        return _14;
    }
    ,getContacts:function(_18,_19){
        var _1a={
        };
        if(_18){
            _1a["filter"]=_18;
        }
        this._get("yupoo.contacts.getList",_19,_1a);
    }
    ,getContact:function(_1b,_1c){
        this._get("contacts.get",_1c,{
            userid:_1b
        }
        );
    }
    ,addContact:function(_1d,_1e,_1f){
        this._post("contacts.add",_1f,{
            userid:_1d,relationship:_1e
        }
        );
    }
    ,editContact:function(_20,_21,_22){
        this._post("contacts.edit",_22,{
            userid:_20,relationship:_21
        }
        );
    }
    ,deleteContact:function(_23,_24){
        this._post("contacts.remove",_24,{
            userid:_23
        }
        );
    }
    ,getlicenses:function(_25){
        this._post("yupoo.photos.licenses.getInfo",_25,{
        }
        );
    }
    ,setlicenses:function(_26,_27,_28){
        this._post("yupoo.photos.licenses.setLicense",_28,{
            photo_id:_27,license_id:_26
        }
        );
    }
    ,addFavorite:function(_29,_2a){
        this._post("favorites.add",_2a,{
            image_id:_29
        }
        );
    }
    ,removeFavorite:function(_2b,_2c){
        this._post("favorites.remove",_2c,{
            image_id:_2b
        }
        );
    }
    ,getGroupList:function(_2d){
        this._get("groups.getlist",_2d,{
        }
        );
    }
    ,setGroupScore:function(_2e,_2f,_30){
        this._post("yupoo.groups.setScore",_30,{
            group_id:_2e,score:_2f>0?_2f:"0"
        }
        );
    }
    ,getGroupContext:function(_31,_32,_33,_34){
        var opt=$extend({
            prev:true,next:true
        }
        ,_34||{
        }
        );
        var _36="yupoo.groups.pools.getContext";
        if(opt.prev&&!opt.next){
            _36="yupoo.groups.pools.getContextPrev";
        }
        else{
            if(!opt.prev&&opt.next){
                _36="yupoo.groups.pools.getContextNext";
            }
        }
        this._get(_36,_33,{
            group_id:_31,photo_id:_32
        }
        );
    }
    ,getGroupPhotoRating:function(_37,_38,_39){
        this._get("yupoo.groups.pools.getRating",_39,{
            group_id:_37,photo_id:_38
        }
        );
    }
    ,setGroupPhotoRating:function(_3a,_3b,_3c,_3d){
        this._post("yupoo.groups.pools.setRating",_3d,{
            photo_id:_3b,group_id:_3a,rating:_3c>0?_3c:"0"
        }
        );
    }
    ,setUserScore:function(_3e,_3f,_40){
        this._post("yupoo.people.setScore",_40,{
            userid:_3e,score:_3f>0?_3f:"0"
        }
        );
    }
    ,getContext:function(_41,_42,_43){
        var opt=$extend({
            prev:true,next:true
        }
        ,_43||{
        }
        );
        var _45="images.getcontext";
        if(opt.prev&&!opt.next){
            _45="images.getcontextprev";
        }
        else{
            if(!opt.prev&&opt.next){
                _45="images.getcontextnext";
            }
        }
        this._get(_45,_42,{
            image_id:_41
        }
        );
    }
    ,setPhotoMeta:function(_46,_47,_48,_49){
        this._post("image.setmeta",_49,{
            image_id:_46,title:_47,description:_48
        }
        );
    }
    ,setPhotoTags:function(_4a,_4b,_4c){
        this._post("yupoo.photos.setTags",_4c,{
            photo_id:_4a,tags:_4b
        }
        );
    }
    ,searchPhotos:function(_4d,_4e){
        this._get("yupoo.photos.search",_4e,_4d);
    }
    ,addTags:function(_4f,_50,_51){
        this._post("image.addtags",_51,{
            image_id:_4f,tags:_50
        }
        );
    }
    ,removeTag:function(_52,tag,_54){
        this._post("image.removetag",_54,{
            image_id:_52,tag:tag
        }
        );
    }
    ,setPhotoScore:function(_55,_56,_57){
        this._post("yupoo.photos.setScore",_57,{
            photo_id:_55,score:_56>0?_56:"0"
        }
        );
    }
    ,getAddresses:function(_58,_59){
        this._get("yupoo.photos.getAddresses",_59,{
            photo_ids:_58
        }
        );
    }
    ,getUserAlbums:function(_5a){
        this._get("albums.getlist",_5a,{
        }
        );
    }
    ,getAlbumPhotos:function(_5b,_5c){
        this._get("yupoo.albums.getPhotos",_5c,{
            album_id:_5b
        }
        );
    }
    ,getAlbumContext:function(_5d,_5e,_5f,_60){
        var opt=$extend({
            prev:true,next:true
        }
        ,_60||{
        }
        );
        var _62="albums.getcontext";
        if(opt.prev&&!opt.next){
            _62="albums.getcontextprev";
        }
        else{
            if(!opt.prev&&opt.next){
                _62="albums.getcontextnext";
            }
        }
        this._get(_62,_5f,{
            album_id:_5d,photo_id:_5e
        }
        );
    }
    ,editAlbumMeta:function(_63,_64,_65,_66){
        this._post("yupoo.albums.editMeta",_66,{
            album_id:_63,title:_64,description:_65
        }
        );
    }
    ,editPhotos:function(_67,_68,_69,_6a){
        var _6b=this._joinPhotoIds(_69,",");
        var _6c={
            album_id:_67,photo_ids:_6b
        };
        if(_68){
            _6c["cover_id"]=_68;
        }
        this._post("yupoo.albums.editPhotos",_6a,_6c);
    }
    ,orderAlbums:function(_6d,_6e){
        var _6f=_6d.join(",");
        this._post("yupoo.albums.order",_6e,{
            album_ids:_6f
        }
        );
    }
    ,createAlbum:function(_70,_71,_72){
        this._post("albums.create",_72,{
            title:_70,description:_71
        }
        );
    }
    ,deleteAlbum:function(_73,_74){
        this._post("yupoo.albums.delete",_74,{
            album_id:_73
        }
        );
    }
    ,addImageAlbum:function(_75,_76,_77){
        this._post("yupoo.albums.addimage",_77,{
            album_id:_75,image_id:_76
        }
        );
    }
    ,getAlbumList:function(_78){
        this._get("albums.getlist",_78,{
        }
        );
    }
    ,setAlbumScore:function(_79,_7a,_7b){
        this._post("yupoo.albums.setScore",_7b,{
            album_id:_79,score:_7a>0?_7a:"0"
        }
        );
    }
    ,getBlogsList:function(_7c){
        this._get("yupoo.blogs.getList",_7c,{
        }
        );
    }
    ,addPhotoNote:function(_7d,_7e,_7f,_80,_81,_82,_83){
        this._post("image.notes.add",_83,{
            image_id:_7d,note_x:_7e>0?_7e:"0",note_y:_7f>0?_7f:"0",note_w:_80>0?_80:"0",note_h:_81>0?_81:"0",note_text:_82
        }
        );
    }
    ,deletePhotoNote:function(_84,_85){
        this._post("image.notes.delete",_85,{
            note_id:_84
        }
        );
    }
    ,editPhotoNote:function(_86,_87,_88,_89,_8a,_8b,_8c){
        this._post("image.notes.edit",_8c,{
            note_id:_86,note_x:_87>0?_87:"0",note_y:_88>0?_88:"0",note_w:_89>0?_89:"0",note_h:_8a>0?_8a:"0",note_text:_8b
        }
        );
    }
    ,getPhotoNotes:function(_8d,_8e){
        this._get("image.notes.getlist",_8e,{
            image_id:_8d
        }
        );
    }
    ,setPhotosPerm:function(_8f,_90,_91,_92,_93,_94,_95){
        this._post("yupoo.photos.setPerms",_95,{
            photo_id:_8f,view:_90,comment:_91,addmeta:_92,blogthis:_93,viewexif:_94
        }
        );
    }
    ,PhotosDelete:function(_96,_97){
        this._post("yupoo.photos.delete",_97,{
            photo_id:_96
        }
        );
    }
    ,GetPhotosInfo:function(_98,_99){
        this._post("yupoo.photos.getInfo",_99,{
            photo_id:_98
        }
        );
    }
    ,getPhotoTags:function(_9a,_9b){
        this._get("tags.getlistimage",_9b,{
            image_id:_9a
        }
        );
    }
    ,getUserTags:function(_9c,_9d){
        this._get("tags.getlistuser",_9d,{
            userid:_9c
        }
        );
    }
    ,getUserPopularTags:function(_9e,_9f,_a0){
        this._get("yupoo.tags.getListUserPopular",_a0,{
            userid:_9e,count:_9f
        }
        );
    }
    ,getUserRecentTags:function(_a1,_a2,_a3){
        this._get("tags.getlist.userecent",_a3,{
            userid:_a1,count:_a2
        }
        );
    }
    ,getMehtodUrl:function(_a4,_a5){
        var _a6=this._queryString(_a4,_a5);
        return _a6;
    }
    ,_joinPhotoIds:function(_a7,_a8){
        var _a9="";
        for(var i=0;i<_a7.length;i++){
            if(i>0){
                _a9+=_a8;
            }
            _a9+=_a7[i].id;
        }
        return _a9;
    }
    ,updateBlast:function(_ab,_ac){
        this._get("yupoo.account.set",_ac,{
            blast:_ab
        }
        );
    }
}
);
if(window.api_endpoint&&window.auth_hash&&window.api_key&&window.api_secret&&window.api_response_format){
    window.api=new API(api_endpoint,auth_hash,api_key,api_secret,window.api_auth_token?window.api_auth_token:null,api_response_format);
}
