/*
 * flickr.js, version 0.3
 * A Flickr API wrapper
 *
 *  (see below for config)
 *
 *
 * Revision history:
 *    0.5  - xmldata bugfixs
 *    0.4  - minor bug fixs
 *    0.3  - 24 Apr 2005 : Initial version
 *
 * Copyright (C) 2005 Gustavo Marin (gustavoandresmarin@gmail.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

//// CONFIGURE THIS  ///////////////////////////////////////////////////

var FLICKR_PROXY_URL = 'flickr.proxy.php';
var PHOTOS_PER_PAGE = 5;
var TAG_MODE = 'any';
var STACK_CALL = 0;

//// CONFIGURATION ENDS HERE ///////////////////////////////////////////


//// Flickr API  ///////////////////////////////////////////////////////

function flickr()
{
	this.proxyURL = FLICKR_PROXY_URL;
	this.photosXPage = PHOTOS_PER_PAGE;
	this.actualPage = 1;

	// TODO: add cookie to store all this
	this.arrayTags = ''; 
	this.tagsMode = TAG_MODE; 
	this.stackCall = STACK_CALL; 
	
	this.status = '';
	this.output = '';
	this.debug = '';

	this.error = new Array();

	this.blogs = new blogs();
	this.contacts = new contacts();
	this.favorites = new favorites();
	this.groups = new groups();
	this.people = new people();
	this.photos = new photos();
	this.photosets = new photosets();
	this.reflection = new reflection();
	this.tags = new tags();
	this.urls = new urls();

	this.flickrUtils = new flickrUtils();
}



//// flickr.blogs  ///////////////////////////////////////////////////////

blogs = function () 
{
	this.baseMethod = FLICKR_PROXY_URL;
	this.flickrUtils = new flickrUtils;
	this.callbacks= new callbacks;
}	

blogs.prototype.getList = 
function ()
{
	this.methodCall = this.baseMethod + '?method=flickr.blogs.getList';
	this.methodCall += '&userAuth=true';
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.blogs_getList );
}

blogs.prototype.postPhoto = 
function (blog_id,photo_id,title,description,blog_password)
{
	this.methodCall = this.baseMethod + '?method=flickr.blogs.postPhoto';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&blog_id='+blog_id;
	this.methodCall += '&photo_id='+photo_id;
	this.methodCall += '&title='+title;
	this.methodCall += '&description='+description;
	this.methodCall += '&blog_password='+blog_password;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.blogs_postPhoto );
}



//// flickr.contacts  ///////////////////////////////////////////////////////

contacts = function () 
{
	this.baseMethod = FLICKR_PROXY_URL;
	this.flickrUtils = new flickrUtils;
	this.callbacks= new callbacks;
}	

contacts.prototype.getList = 
function ()
{
	this.methodCall = this.baseMethod + '?method=flickr.contacts.getList';
	this.methodCall += '&userAuth=true';
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.contacts_getList );
}

contacts.prototype.getPublicList = 
function (user_id)
{
	this.methodCall = this.baseMethod + '?method=flickr.contacts.getPublicList';
	this.methodCall += '&user_id='+user_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.contacts_getPublicList );
}



//// flickr.favorites  ///////////////////////////////////////////////////////

favorites = function () 
{
	this.baseMethod = FLICKR_PROXY_URL;
	this.flickrUtils = new flickrUtils;
	this.callbacks= new callbacks;
}	

favorites.prototype.add =
function ( photo_id )
{
	this.methodCall = this.baseMethod + '?method=flickr.favorites.add';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&photo_id='+photo_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.favorites_add );
}

favorites.prototype.getList = 
function (user_id,extras,per_page,page) 
{
	this.methodCall = this.baseMethod + '?method=flickr.favorites.getList';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&user_id='+user_id;
	if(extras)this.methodCall += '&extras='+extras;
	if(per_page)this.methodCall += '&per_page='+per_page;
	if(page)this.methodCall += '&page='+page;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.favorites_getList );
}

favorites.prototype.getPublicList = 
function (user_id,extras,per_page,page) 
{
	this.methodCall = this.baseMethod + '?method=flickr.favorites.getPublicList';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&user_id='+user_id;
	if(extras)this.methodCall += '&extras='+extras;
	if(per_page)this.methodCall += '&per_page='+per_page;
	if(page)this.methodCall += '&page='+page;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.favorites_getPublicList );
}

favorites.prototype.remove = 
function (photo_id) 
{
	this.methodCall = this.baseMethod + '?method=flickr.favorites.remove';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&photo_id='+photo_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.favorites_remove );
}



//// flickr.groups  ///////////////////////////////////////////////////////

groups = function () 
{
	this.baseMethod = FLICKR_PROXY_URL;
	this.flickrUtils = new flickrUtils;
	this.callbacks= new callbacks;
	this.pools = new pools;
}	

groups.prototype.browse = 
function () 
{
	this.methodCall = this.baseMethod + '?method=flickr.groups.browse';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&cat_id='+cat_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.groups_browse );
}

groups.prototype.getActiveList = 
function () 
{
	this.methodCall = this.baseMethod + '?method=flickr.groups.getActiveList';
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.groups_getActiveList );
}

groups.prototype.getInfo = 
function (group_id) 
{
	this.methodCall = this.baseMethod + '?method=flickr.groups.getInfo';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&group_id='+group_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.groups_getInfo );
}

pools = function () 
{
	this.baseMethod = FLICKR_PROXY_URL;
	this.flickrUtils = new flickrUtils;
	this.callbacks= new callbacks;
}	

pools.prototype.getPhotos = 
function (group_id, tags, extras, per_page, page) 
{
	this.methodCall = this.baseMethod + '?method=flickr.groups.pools.getPhotos';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&group_id='+group_id;
	if( tags ) this.methodCall += '&group_id='+group_id;
	if( extras ) this.methodCall += '&extras='+extras;
	if( per_page ) this.methodCall += '&per_page='+per_page;
	if( page ) this.methodCall += '&page='+page;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.groups_pools_getPhotos );
}



//// flickr.people  ///////////////////////////////////////////////////////

people = function () 
{
	this.baseMethod = FLICKR_PROXY_URL;
	this.flickrUtils = new flickrUtils;
	this.callbacks= new callbacks;
}	

people.prototype.findByEmail = 
function (find_email) 
{
	this.methodCall = this.baseMethod + '?method=flickr.people.findByEmail';
	this.methodCall += '&find_email='+find_email;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.people_findByEmail );
}

people.prototype.findByUsername = 
function (username) 
{
	this.methodCall = this.baseMethod + '?method=flickr.people.findByUsername';
	this.methodCall += '&username='+username;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.people_findByUsername );
}

people.prototype.getInfo = 
function (user_id) 
{
	this.methodCall = this.baseMethod + '?method=flickr.people.getInfo';
	this.methodCall += '&user_id='+user_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.people_getInfo );
}

people.prototype.getOnlineList = 
function () 
{
	this.methodCall = this.baseMethod + '?method=flickr.people.getOnlineList';
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.people_getOnlineList );
}

people.prototype.getPublicGroups = 
function (user_id) 
{
	this.methodCall = this.baseMethod + '?method=flickr.people.getPublicGroups';
	this.methodCall += '&user_id='+user_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.people_getPublicGroups );
}

people.prototype.getPublicPhotos = 
function (user_id,extras,per_page,page) 
{
	this.methodCall = this.baseMethod + '?method=flickr.people.getPublicPhotos';
	this.methodCall += '&user_id='+user_id;
	if(extras)this.methodCall += '&extras='+extras;
	if(per_page)this.methodCall += '&per_page='+per_page;
	if(page)this.methodCall += '&page='+page;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.people_getPublicPhotos );
}



//// flickr.photos  ///////////////////////////////////////////////////////

photos = function () 
{
	this.baseMethod = FLICKR_PROXY_URL;
	this.flickrUtils = new flickrUtils;
	this.callbacks= new callbacks;
}	

photos.prototype.addTags =
function (photo_id,tags) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.addTags';
	this.methodCall += '&photo_id='+photo_id;
	this.methodCall += '&tags='+tags;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_addTags );
}

photos.prototype.getContactsPhotos = 
function (count,just_friends,single_photo,include_self) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.getContactsPhotos';
	this.methodCall += '&userAuth=true';
	if(count)this.methodCall += '&count='+count;
	if(just_friends)this.methodCall += '&just_friends='+just_friends;
	if(single_photo)this.methodCall += '&single_photo='+single_photo;
	if(include_self)this.methodCall += '&include_self='+include_self;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_getContactsPhotos );
}

photos.prototype.getContactsPublicPhotos = 
function (user_id,count,just_friends,single_photo,include_self) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.getContactsPublicPhotos';
	this.methodCall += '&user_id='+user_id;
	if(count)this.methodCall += '&count='+count;
	if(just_friends)this.methodCall += '&just_friends='+just_friends;
	if(single_photo)this.methodCall += '&single_photo='+single_photo;
	if(include_self)this.methodCall += '&include_self='+include_self;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_getContactsPublicPhotos );
}

photos.prototype.getContext = 
function (photo_id) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.getContext';
	this.methodCall += '&photo_id='+photo_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_getContext );
}

photos.prototype.getCounts = 
function (dates,taken_dates) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.getCounts';
	this.methodCall += '&userAuth=true';
	if(dates)this.methodCall += '&dates='+dates;
	if(taken_dates)this.methodCall += '&taken_dates='+taken_dates;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_getCounts );
}

photos.prototype.getExif = 
function (photo_id,secret) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.getExif';
	this.methodCall += '&photo_id='+photo_id;
	if(secret)this.methodCall += '&secret='+secret;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_getExif );
}

photos.prototype.getInfo = 
function (photo_id,secret) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.getInfo';
	this.methodCall += '&photo_id='+photo_id;
	if(secret)this.methodCall += '&secret='+secret;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_getInfo );
}

photos.prototype.getNotInSet = 
function (extras,per_page,page) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.getNotInSet';
	this.methodCall += '&userAuth=true';
	if(extras)this.methodCall += '&extras='+extras;
	if(per_page)this.methodCall += '&per_page='+per_page;
	if(page)this.methodCall += '&page='+page;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_getNotInSet );
}

photos.prototype.getPerms = 
function (photo_id) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.getPerms';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&photo_id='+photo_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_getPerms );
}

photos.prototype.getRecent =
function ( extras, per_page, page ) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.getRecent';
	if( extras ) this.methodCall += '&extras='+extras;
	if( per_page ) this.methodCall += '&per_page='+per_page;
	if( page ) this.methodCall += '&page='+page;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_getRecent );
}

photos.prototype.getSizes = 
function (photo_id) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.getSizes';
	this.methodCall += '&photo_id='+photo_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_getSizes );
}

photos.prototype.getUntagged = 
function (extras,per_page,page) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.getUntagged';
	this.methodCall += '&userAuth=true';
	if( extras ) this.methodCall += '&extras='+extras;
	if( per_page ) this.methodCall += '&per_page='+per_page;
	if( page ) this.methodCall += '&page='+page;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_getUntagged );
}

photos.prototype.removeTag = 
function (tag_id)
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.removeTag';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&tag_id='+tag_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_removeTag );
}

photos.prototype.search =
function ( user_id, tags, tag_mode, text, min_upload_date, max_upload_date, min_taken_date, max_taken_date, license, extras, per_page, page, sort )
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.search';
	this.methodCall += '&user_id='+user_id;
	if( tags ) this.methodCall += '&tags='+tags;
	if( tag_mode ) this.methodCall += '&tag_mode='+tag_mode;
	if( text ) this.methodCall += '&text='+text;
	if( min_upload_date ) this.methodCall += '&min_upload_date='+min_upload_date;
	if( max_upload_date ) this.methodCall += '&max_upload_date='+max_upload_date;
	if( min_taken_date ) this.methodCall += '&min_taken_date='+min_taken_date;
	if( max_taken_date ) this.methodCall += '&max_taken_date='+max_taken_date;
	if( license ) this.methodCall += '&license='+license;
	if( extras ) this.methodCall += '&extras='+extras;
	if( per_page ) this.methodCall += '&per_page='+per_page;
	if( page ) this.methodCall += '&page='+page;
	if( sort ) this.methodCall += '&sort='+sort;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_search );
}

photos.prototype.setDates = 
function (photo_id,date_posted,date_taken,date_taken_granularity) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.setDates';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&photo_id='+photo_id;
	if( date_posted ) this.methodCall += '&date_posted='+date_posted;
	if( date_taken ) this.methodCall += '&date_taken='+date_taken;
	if( date_taken_granularity ) this.methodCall += '&date_taken_granularity='+date_taken_granularity;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_setDates );
}

photos.prototype.setMeta = 
function (photo_id,title,description) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.setMeta';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&photo_id='+photo_id;
	if( title ) this.methodCall += '&title='+title;
	if( description ) this.methodCall += '&description='+description;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_setMeta );
}

photos.prototype.setPerms = 
function (photo_id,is_public,is_friend,is_family,perm_comment,perm_addmeta) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.setPerms';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&photo_id='+photo_id;
	this.methodCall += '&is_public='+is_public;
	this.methodCall += '&is_friend='+is_friend;
	this.methodCall += '&is_family='+is_family;
	this.methodCall += '&perm_comment='+perm_comment;
	this.methodCall += '&perm_addmeta='+perm_addmeta;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_setPerms );
}

photos.prototype.setTags = 
function (photo_id,tags) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photos.setTags';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&photo_id='+photo_id;
	this.methodCall += '&tags='+tags;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photos_setTags );
}



//// flickr.photosets  ///////////////////////////////////////////////////////

photosets = function () 
{
	this.baseMethod = FLICKR_PROXY_URL;
	this.flickrUtils = new flickrUtils;
	this.callbacks= new callbacks;
}	

photosets.prototype.create = 
function (title,description,primary_photo_id) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photosets.create';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&title='+title;
	this.methodCall += '&description='+description;
	this.methodCall += '&primary_photo_id='+primary_photo_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photosets_create );
}

photosets.prototype.deletePhotoset = // 'delete' is a reserved word
function (photoset_id) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photosets.delete';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&photoset_id='+photoset_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photosets_delete );
} 

photosets.prototype.editMeta = 
function (photoset_id,title,description) 
{
	this.methodCall = this.baseMethod + '?method=flickr.photosets.delete';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&photoset_id='+photoset_id;
	this.methodCall += '&title='+title;
	if(description)this.methodCall += '&description='+description;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photosets_delete );
}

photosets.prototype.editPhotos = 
function () 
{
	this.methodCall = this.baseMethod + '?method=flickr.photosets.editPhotos';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&photoset_id='+photoset_id;
	this.methodCall += '&primary_photo_id='+primary_photo_id;
	this.methodCall += '&photo_ids='+photo_ids;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photosets_editPhotos );
}

photosets.prototype.getContext =
function ( photo_id, photoset_id )
{
	this.methodCall = this.baseMethod + '?method=flickr.photosets.getContext';
	this.methodCall += '&photo_id='+photo_id;
	this.methodCall += '&photoset_id='+photoset_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photosets_getContext );
}

photosets.prototype.getInfo =
function ( photoset_id )
{
	this.methodCall = this.baseMethod + '?method=flickr.photosets.getInfo';
	this.methodCall += '&photoset_id='+photoset_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photosets_getInfo );
}

photosets.prototype.getList =
function ( user_id )
{
	this.methodCall = this.baseMethod + '?method=flickr.photosets.getList';
	this.methodCall += '&user_id='+user_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photosets_getList );
}

photosets.prototype.getPhotos =
function ( photoset_id )
{
	this.methodCall = this.baseMethod + '?method=flickr.photosets.getPhotos';
	this.methodCall += '&photoset_id='+photoset_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photosets_getPhotos );
}

photosets.prototype.orderSets = 
function () 
{
	this.methodCall = this.baseMethod + '?method=flickr.photosets.orderSets';
	this.methodCall += '&userAuth=true';
	this.methodCall += '&photoset_ids='+photoset_ids;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.photosets_orderSets );
}



//// flickr.reflection  ///////////////////////////////////////////////////////

reflection = function () 
{
	this.baseMethod = FLICKR_PROXY_URL;
	this.flickrUtils = new flickrUtils;
	this.callbacks= new callbacks;
}	

reflection.prototype.getMethods =
function ( )
{
	this.methodCall = this.baseMethod + '?method=flickr.reflection.getMethods';
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.reflection_getMethods );
}

reflection.prototype.getMethodInfo =
function ( method_name )
{
	this.methodCall = this.baseMethod + '?method=flickr.reflection.getMethodInfo';
	this.methodCall += '&method_name='+method_name;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.reflection_getMethodInfo );
}



//// flickr.tags  ///////////////////////////////////////////////////////

tags = function () 
{
	this.baseMethod = FLICKR_PROXY_URL;
	this.flickrUtils = new flickrUtils;
	this.callbacks= new callbacks;
}	

tags.prototype.getListPhoto =
function ( photo_id )
{
	this.methodCall = this.baseMethod + '?method=flickr.tags.getListPhoto';
	this.methodCall += '&photo_id='+photo_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.tags_getListPhoto );
}

tags.prototype.getListUser =
function ( user_id )
{
	this.methodCall = this.baseMethod + '?method=flickr.tags.getListUser';
	this.methodCall += '&user_id='+user_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.tags_getListUser );
}

tags.prototype.getListUserPopular =
function ( user_id, count )
{
	this.methodCall = this.baseMethod + '?method=flickr.tags.getListUserPopular';
	this.methodCall += '&user_id='+user_id;
	if( count ) this.methodCall += '&count='+count;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.tags_getListUserPopular );
}

tags.prototype.getRelated =
function ( tag )
{
	this.methodCall = this.baseMethod + '?method=flickr.tags.getRelated';
	this.methodCall += '&tag='+tag;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.tags_getRelated );
}



//// flickr.urls  ///////////////////////////////////////////////////////

urls = function () 
{
	this.baseMethod = FLICKR_PROXY_URL;
	this.flickrUtils = new flickrUtils;
	this.callbacks= new callbacks;
}	

urls.prototype.getGroup =
function ( group_id )
{
	this.methodCall = this.baseMethod + '?method=flickr.urls.getGroup';
	this.methodCall += '&group_id='+group_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.urls_getGroup );
}

urls.prototype.getUserPhotos =
function ( user_id )
{
	this.methodCall = this.baseMethod + '?method=flickr.urls.getUserPhotos';
	this.methodCall += '&user_id='+user_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.urls_getUserPhotos );
}

urls.prototype.getUserProfile =
function ( user_id )
{
	this.methodCall = this.baseMethod + '?method=flickr.urls.getUserProfile';
	this.methodCall += '&user_id='+user_id;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.urls_getUserProfile );
}

urls.prototype.lookupGroup = 
function ( url ) 
{
	this.methodCall = this.baseMethod + '?method=flickr.urls.lookupGroup';
	this.methodCall += '&url='+url;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.urls_lookupGroup );
}

urls.prototype.lookupUser = 
function ( url ) 
{
	this.methodCall = this.baseMethod + '?method=flickr.urls.lookupUser';
	this.methodCall += '&url='+url;
	this.flickrUtils.loadXML( this.methodCall, this.callbacks.urls_lookupUser );
}






//// XMLHttpRequest & Utilities Functions //////////////////////////////////////////////////

flickrUtils =  function() 
{ 
	this.stackCall = STACK_CALL;
	this.error = new Array();

	this.xml = '';
	this.userCallbacks = new Array();
}

flickrUtils.prototype.checkString = 
function ( str, sub ) 
{
  var x = new RegExp('\\b'+sub+'\\b');
  if (x.test(str)) return true;
  else return false;
}

flickrUtils.prototype.addString = 
function ( str, sub, split ) 
{
    if (!split) split = ' ';
    if ( !flickrUtils.checkString(str, sub) ) return str+split+sub;
    else return str;
}

flickrUtils.prototype.removeString = 
function ( str, sub ) 
{
    var rep=str.match(' '+sub)?' '+sub:sub;
    return str.replace(rep,'');
}

flickrUtils.prototype.loadXML = 
function (url, callback)
{

//   var req;
   if ( typeof(window["req"]) != "undefined" && req.readyState == 1 )  
   {
       if ( this.stackCall == 1 || req.readyState == 1 ) 
       {
           setTimeout( "flickrUtils.loadXML('"+url+"', "+callback+")", 400);
       }
       return false;
   }

   if (window.XMLHttpRequest)
   {
       req = new XMLHttpRequest();
       req.onreadystatechange = callback;
       req.open("GET", url, true);
       req.send(null);
   }
   else if (window.ActiveXObject)
   {
       req = new ActiveXObject("Microsoft.XMLHTTP");

       if (req)
       {
           req.onreadystatechange = callback;
           req.open("GET", url, true);
           req.send();
       }
   }
}


flickrUtils.prototype.stateOK = 
function (req)
{
	var stateOK;
   if (req.readyState == 4 )
   {
      if (req.status == 200) 
      {
		 stateOK = true;
      }
      else 
      {
         this.logError( 'Error '+ req.status +': '+ req.statusText );
         alert( this.showError()  );
		 stateOK = false;
      }
   }
   if( stateOK )
   {
		   var xdoc = req.responseXML;
		   stat = xdoc.getElementsByTagName('rsp').item(0).getAttribute('stat');
		   if( stat == 'fail')
		   {
				   err = xdoc.getElementsByTagName( 'err').item(0).getAttribute('code');
				   msg = xdoc.getElementsByTagName( 'err').item(0).getAttribute('msg');
				   flickrUtils.logError( 'Error '+ err +': '+ msg );
				   alert( this.showError()  );
				   stateOK = false;
		   }
		   else
		   {
				   stateOK = true;
		   }
   }
   return stateOK;
}

flickrUtils.prototype.logError = 
function ( msg )
{
	this.error[this.error.length] = msg;	
}

flickrUtils.prototype.setStatus = 
function ( msg )
{
	this.status = msg;
}

flickrUtils.prototype.getStatus = 
function ( )
{
	return this.status;
}

flickrUtils.prototype.showError = 
function ( html )
{
	var i, str, next;
	str ='';
	if(html == true) next='<br />';
	else next='\n';

	for(i=0;i<this.error.length;i++)
	{
		str += next + this.error[i];
	}
	return str;
}

flickrUtils.prototype.getMysqlDate =
function( timestamp, useHMS )
{
    var sYear,sMonth,sDate,sHours,sMinutes,sSeconds,strHMS = '';
	var oDate = new Date( timestamp*1000 );
    sDate = oDate.getDate();
    if ( sDate < 10 ) sDate = '0'+sDate;
    sMonth = oDate.getMonth()+1;
    if (sMonth <10 ) sMonth = '0'+sMonth;
    sYear = oDate.getFullYear();

    if(useHMS)
    {
        sHours = oDate.getHours();
        if(sHours <10) sHour = '0'+sHour;
        sMinutes = oDate.getMinutes();
        if(sMinutes < 10 ) sMinutes = '0'+sMinutes;
        sSeconds = oDate.getSeconds();
        if( sSeconds <10 ) sSeconds = '0'+sSeconds;

        strHMS = ' '+sHours+':'+sMinutes+':'+sSeconds;     }

    strDate = sYear+'-'+sMonth+'-'+sDate+strHMS;
    return strDate;
}



//// XMLHttpRequest Function ///////////////////////////////////////////////////////


callbacks = function() {}


//// blogs ///////////////////////////////////////////////////////

callbacks.prototype.blogs_getList = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();
	if( typeof(flickrUtils.userCallbacks["flickr.blogs.getList"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.blogs.getList"](result);
}

callbacks.prototype.blogs_postPhoto = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.blogs.postPhoto"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.blogs.postPhoto"](result);
}


//// contacts ///////////////////////////////////////////////////////

callbacks.prototype.contacts_getList = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();
	
	var xmlContact = flickrUtils.xml.getElementsByTagName('contact');
	var contact = new Array();
	for(x=0;x<xmlContact.length;x++)
	{
		contact[contact.length] = {
			nsid: xmlContact.item(x).getAttribute('nsid'),
			username: xmlContact.item(x).getAttribute('username'),
			realname: xmlContact.item(x).getAttribute('realname'),
			friend: xmlContact.item(x).getAttribute('friend'),
			family: xmlContact.item(x).getAttribute('family'),
			ignored: xmlContact.item(x).getAttribute('ignored')
			};
	}
	result.contact = contact;

	if( typeof(flickrUtils.userCallbacks["flickr.contacts.getList"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.contacts.getList"](result);
}

callbacks.prototype.contacts_getPublicList = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();
	
	var xmlContact = flickrUtils.xml.getElementsByTagName('contact');
	var contact = new Array();
	for(x=0;x<xmlContact.length;x++)
	{
		contact[contact.length] = {
			nsid: xmlContact.item(x).getAttribute('nsid'),
			username: xmlContact.item(x).getAttribute('username'),
			ignored: xmlContact.item(x).getAttribute('ignored')
			};
	}
	result.contact = contact;

	if( typeof(flickrUtils.userCallbacks["flickr.contacts.getPublicList"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.contacts.getPublicList"](result);
}



//// favorites ///////////////////////////////////////////////////////

callbacks.prototype.favorites_add = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.favorites.add"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.favorites.add"](result);
}

callbacks.prototype.favorites_getList = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();

	var photos = flickrUtils.xml.getElementsByTagName('photos');
	result.page = photos.item(0).getAttribute('page');
	result.perpage = photos.item(0).getAttribute('perpage');
	result.total = photos.item(0).getAttribute('total');
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('photo');
	var photo = new Array();
	for(x=0;x<xmlPhoto.length;x++)
	{
			id= xmlPhoto.item(x).getAttribute('id');
			secret= xmlPhoto.item(x).getAttribute('secret');
			server= xmlPhoto.item(x).getAttribute('server');
		photo[photo.length] = {
			id: id,
			owner: xmlPhoto.item(x).getAttribute('owner'),
			secret: secret,
			server: server,
			title: xmlPhoto.item(x).getAttribute('title'),
			ispublic: xmlPhoto.item(x).getAttribute('ispublic'),
			isfriend: xmlPhoto.item(x).getAttribute('isfriend'),
			isfamily: xmlPhoto.item(x).getAttribute('isfamily'),
			img_s: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_s.jpg',
			img_t: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_t.jpg',
			img_m: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg',
			img  : 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'.jpg',
			img_b: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_b.jpg',
			};
	}
	result.photo = photo;
	
	if( typeof(flickrUtils.userCallbacks["flickr.favorites.getList"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.favorites.getList"](result);
}

callbacks.prototype.favorites_getPublicList = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();

	var photos = flickrUtils.xml.getElementsByTagName('photos');
	result.page = photos.item(0).getAttribute('page');
	result.pages = photos.item(0).getAttribute('pages');
	result.perpage = photos.item(0).getAttribute('perpage');
	result.total = photos.item(0).getAttribute('total');
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('photo');
	var photo = new Array();
	for(x=0;x<xmlPhoto.length;x++)
	{
			id= xmlPhoto.item(x).getAttribute('id');
			secret= xmlPhoto.item(x).getAttribute('secret');
			server= xmlPhoto.item(x).getAttribute('server');
		photo[photo.length] = {
			id: id,
			owner: xmlPhoto.item(x).getAttribute('owner'),
			ownername: xmlPhoto.item(x).getAttribute('ownername'),
			iconserver: xmlPhoto.item(x).getAttribute('iconserver'),
			secret: secret,
			server: server,
			title: xmlPhoto.item(x).getAttribute('title'),
			ispublic: xmlPhoto.item(x).getAttribute('ispublic'),
			isfriend: xmlPhoto.item(x).getAttribute('isfriend'),
			isfamily: xmlPhoto.item(x).getAttribute('isfamily'),
			img_s: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_s.jpg',
			img_t: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_t.jpg',
			img_m: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg',
			img  : 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'.jpg',
			img_b: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_b.jpg'
			};
	}
	result.photo = photo;
	
	if( typeof(flickrUtils.userCallbacks["flickr.favorites.getPublicList"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.favorites.getPublicList"](result);
}

callbacks.prototype.favorites_remove = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.favorites.remove"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.favorites.remove"](result);
}



//// groups ///////////////////////////////////////////////////////

callbacks.prototype.groups_browse = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.groups.browse"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.groups.browse"](result);
}

callbacks.prototype.groups_getActiveList = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.groups.getActiveList"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.groups.getActiveList"](result);
}

callbacks.prototype.groups_getInfo = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.groups.getInfo"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.groups.getInfo"](result);
}


callbacks.prototype.groups_pools_getPhotos = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var result = new Object();
	var photos = flickrUtils.xml.getElementsByTagName('photos');
	result.page = photos.item(0).getAttribute('page');
	result.pages = photos.item(0).getAttribute('pages');
	result.perpage = photos.item(0).getAttribute('perpage');
	result.total = photos.item(0).getAttribute('total');
	var xmlPhotos = flickrUtils.xml.getElementsByTagName('photo');

	var photo = new Array();
	for(x=0;x<xmlPhotos.length;x++)
	{
		id= xmlPhotos.item(x).getAttribute('id');
		secret=  xmlPhotos.item(x).getAttribute('secret');
		owner=  xmlPhotos.item(x).getAttribute('owner');
		iconserver= xmlPhotos.item(x).getAttribute('iconserver');
		server= xmlPhotos.item(x).getAttribute('server');
		ispublic= xmlPhotos.item(x).getAttribute('ispublic');
		isfriend= xmlPhotos.item(x).getAttribute('isfriend');
		isfamily= xmlPhotos.item(x).getAttribute('isfamily');
		ownername=  xmlPhotos.item(x).getAttribute('ownername');
		dateadded= xmlPhotos.item(x).getAttribute('dateadded');
		photo[photo.length] = {
			id: id,
			owner: owner,
			ownername: ownername,
			iconserver: iconserver,
			secret: secret,
			server: server,
			title: xmlPhotos.item(x).getAttribute('title'),
			ispublic:ispublic,
			isfriend:isfriend,
			isfamily:isfamily,
			ownername: ownername,
			dateadded: dateadded,
			img_s: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_s.jpg',
			img_t: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_t.jpg',
			img_m: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg',
			img  : 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'.jpg',
			img_b: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_b.jpg'
			};
	}
	result.photo = photo;
			
	if( typeof(flickrUtils.userCallbacks["flickr.groups.pools.getPhotos"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.groups.pools.getPhotos"](result);
}


//// people ///////////////////////////////////////////////////////

callbacks.prototype.people_findByEmail = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var result = new Object();

	result.nsid = flickrUtils.xml.getElementsByTagName('user').item(0).getAttribute('nsid');
	result.username = flickrUtils.xml.getElementsByTagName('username').item(0).firstChild.data;
	
	if( typeof(flickrUtils.userCallbacks["flickr.people.findByEmail"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.people.findByEmail"](result);
}

callbacks.prototype.people_findByUsername = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var result = new Object();

	result.nsid = flickrUtils.xml.getElementsByTagName('user').item(0).getAttribute('nsid');
	result.username = flickrUtils.xml.getElementsByTagName('username').item(0).firstChild.data;
	
	if( typeof(flickrUtils.userCallbacks["flickr.people.findByUsername"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.people.findByUsername"](result);
}

callbacks.prototype.people_getInfo = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var result = new Object();

	var person = flickrUtils.xml.getElementsByTagName('person');
	result.nsid = person.item(0).getAttribute('nsid');
	result.isadmin = person.item(0).getAttribute('isadmin');
	result.ispro = person.item(0).getAttribute('ispro');
	result.iconserver = person.item(0).getAttribute('iconserver');
	result.username = flickrUtils.xml.getElementsByTagName('username').item(0).firstChild.data;
	result.realname = flickrUtils.xml.getElementsByTagName('realname').item(0).firstChild;
	if(result.realname != null) result.realname = result.realname.data;
	result.location = flickrUtils.xml.getElementsByTagName('location').item(0).firstChild;
	if(result.location != null) result.location = result.location.data;
	result.firstdate = flickrUtils.xml.getElementsByTagName('firstdate').item(0).firstChild;
	if( result.firstdate != null ) result.firstdate=result.firstdate.data;
	result.firstdatetaken = flickrUtils.xml.getElementsByTagName('firstdatetaken').item(0).firstChild;
	if( result.firstdatetaken != null ) result.firstdatetaken = result.firstdatetaken.data;
	result.count = flickrUtils.xml.getElementsByTagName('count').item(0).firstChild.data;
	
	if( typeof(flickrUtils.userCallbacks["flickr.people.getInfo"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.people.getInfo"](result);
}

callbacks.prototype.people_getOnlineList = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x,away;
	var result = new Object();

	var xmlUser = flickrUtils.xml.getElementsByTagName('user');
	var user = new Array();
	for(x=0;x<xmlUser.length;x++)
	{
		if ( xmlUser.item(x).firstChild != null ) 
			away= xmlUser.item(x).firstChild.data;
		else away = '';
		user[user.length]= {
			nsid: xmlUser.item(x).getAttribute('nsid'),
			username: xmlUser.item(x).getAttribute('username'),
			online: xmlUser.item(x).getAttribute('online'),
			away: away
			};
	}

	result.user = user;
	
	
	if( typeof(flickrUtils.userCallbacks["flickr.people.getOnlineList"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.people.getOnlineList"](result);
}

callbacks.prototype.people_getPublicGroups = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();
	var xmlGroup = flickrUtils.xml.getElementsByTagName('group');
	var group = new Array();
	for(x=0;x<xmlGroup.length;x++)
	{
		group[group.length]= {
			nsid: xmlGroup.item(x).getAttribute('nsid'),
			name: xmlGroup.item(x).getAttribute('name'),
			admin: xmlGroup.item(x).getAttribute('admin'),
			eighteenplus: xmlGroup.item(x).getAttribute('eighteenplus')
			};
	}
	result.group = group;
	
	if( typeof(flickrUtils.userCallbacks["flickr.people.getPublicGroups"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.people.getPublicGroups"](result);
}

callbacks.prototype.people_getPublicPhotos = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;

	var x;
	var result = new Object();
	result.page = flickrUtils.xml.getElementsByTagName('photos').item(0).getAttribute('page');
	result.pages = flickrUtils.xml.getElementsByTagName('photos').item(0).getAttribute('pages');
	result.perpage = flickrUtils.xml.getElementsByTagName('photos').item(0).getAttribute('perpage');
	result.total = flickrUtils.xml.getElementsByTagName('photos').item(0).getAttribute('total');
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('photo');
	var photo = new Array();
	for(x=0;x<xmlPhoto.length;x++)
	{
		id= xmlPhoto.item(x).getAttribute('id');
		owner= xmlPhoto.item(x).getAttribute('owner');
		secret= xmlPhoto.item(x).getAttribute('secret');
		server= xmlPhoto.item(x).getAttribute('server');
		photo[photo.length] = {
			id: id,
			owner: owner,
			secret: secret,
			server: server,
			title: xmlPhoto.item(x).getAttribute('title'),
			ispublic: xmlPhoto.item(x).getAttribute('ispublic'),
			isfriend: xmlPhoto.item(x).getAttribute('isfriend'),
			isfamily: xmlPhoto.item(x).getAttribute('isfamily'),
			img_s: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_s.jpg',
			img_t: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_t.jpg',
			img_m: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg',
			img  : 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'.jpg',
			img_b: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_b.jpg'
			}
	}
	result.photo = photo;
	
	if( typeof(flickrUtils.userCallbacks["flickr.people.getPublicPhotos"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.people.getPublicPhotos"](result);
}



//// photos ///////////////////////////////////////////////////////

callbacks.prototype.photos_addTags = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.photos.addTags"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.addTags"](result);
}

callbacks.prototype.photos_getContactsPhotos = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	
	var result = new Object();
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('photo');
	var photo = new Array();
	for(x=0;x<xmlPhoto.length;x++)
	{
		id= xmlPhoto.item(x).getAttribute('id');
		owner= xmlPhoto.item(x).getAttribute('owner');
		secret= xmlPhoto.item(x).getAttribute('secret');
		server= xmlPhoto.item(x).getAttribute('server');
		username= xmlPhoto.item(x).getAttribute('username');
		title= xmlPhoto.item(x).getAttribute('title');
		photo[photo.length] = { 
						id:id,
						owner:owner,
						secret:secret,
						server:server,
						username:username,
						title:title,
						img_s: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_s.jpg',
						img_t: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_t.jpg',
						img_m: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg',
						img  : 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'.jpg',
						img_b: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_b.jpg'
						};

	}
	result.photo = photo;
	
	if( typeof(flickrUtils.userCallbacks["flickr.photos.getContactsPhotos"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.getContactsPhotos"](result);
}

callbacks.prototype.photos_getContactsPublicPhotos = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	
	var result = new Object();
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('photo');
	var photo = new Array();
	for(x=0;x<xmlPhoto.length;x++)
	{
		id= xmlPhoto.item(x).getAttribute('id');
		owner= xmlPhoto.item(x).getAttribute('owner');
		secret= xmlPhoto.item(x).getAttribute('secret');
		server= xmlPhoto.item(x).getAttribute('server');
		username= xmlPhoto.item(x).getAttribute('username');
		title= xmlPhoto.item(x).getAttribute('title');
		photo[photo.length] = { 
						id:id,
						owner:owner,
						secret:secret,
						server:server,
						username:username,
						title:title,
						img_s: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_s.jpg',
						img_t: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_t.jpg',
						img_m: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg',
						img  : 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'.jpg',
						img_b: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_b.jpg'
						};

	}
	result.photo = photo;
	
	if( typeof(flickrUtils.userCallbacks["flickr.photos.getContactsPublicPhotos"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.getContactsPublicPhotos"](result);
}

callbacks.prototype.photos_getContext = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();

	var xmlPrev = flickrUtils.xml.getElementsByTagName('prevphoto');
	var xmlNext = flickrUtils.xml.getElementsByTagName('nextphoto');

	result.prev = new Object();
	result.next = new Object();
	
	result.prev.id = xmlPrev.item(0).getAttribute('id');
	result.prev.secret = xmlPrev.item(0).getAttribute('secret');
	result.prev.title = xmlPrev.item(0).getAttribute('title');
	result.prev.url = xmlPrev.item(0).getAttribute('url');
	
	result.next.id = xmlNext.item(0).getAttribute('id');
	result.next.secret = xmlNext.item(0).getAttribute('secret');
	result.next.title = xmlNext.item(0).getAttribute('title');
	result.next.url = xmlNext.item(0).getAttribute('url');

	if( typeof(flickrUtils.userCallbacks["flickr.photos.getContext"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.getContext"](result);
}

callbacks.prototype.photos_getCounts = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object;
	var xmlPhotocount = flickrUtils.xml.getElementsByTagName('photocount');
	var photocount = new Array();
	for(x=0;x<xmlPhotocount.length;x++)
	{
		photocount[photocount.length]= {
			count:  xmlPhotocount.item(x).getAttribute('count'),
			fromdate:  xmlPhotocount.item(x).getAttribute('fromdate'),
			todate:  xmlPhotocount.item(x).getAttribute('todate')
			}
	}
	result.photocount = photocount;
	
	if( typeof(flickrUtils.userCallbacks["flickr.photos.getCounts"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.getCounts"](result);
}

callbacks.prototype.photos_getExif = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;

	var result = new Object();
	var id = flickrUtils.xml.getElementsByTagName('photo').item(0).getAttribute('id');
	var secret = flickrUtils.xml.getElementsByTagName('photo').item(0).getAttribute('secret');
	var server = flickrUtils.xml.getElementsByTagName('photo').item(0).getAttribute('server');
	var xmlExif = flickrUtils.xml.getElementsByTagName('exif');
	var exif = new Array();
	for(x=0;x<xmlExif.length;x++)
	{
		tagspace= xmlExif.item(x).getAttribute('tagspace');
		tagspaceid=  xmlExif.item(x).getAttribute('tagspaceid');
		tag=  xmlExif.item(x).getAttribute('tag');
		label= xmlExif.item(x).getAttribute('label');
		raw=  xmlExif.item(x).getElementsByTagName('raw').item(0).firstChild.data;
		clean=  xmlExif.item(x).getElementsByTagName('clean');
		if( clean.length > 0  ) clean = clean.item(0).firstChild.data;
		else clean = '';
		exif[exif.length] = {
					tagspace: tagspace,
					tagspaceid: tagspaceid,
					tag: tag,
					label: label,
					raw: raw,
					clean: clean
					};
	}
	result.exif = exif;

	if( typeof(flickrUtils.userCallbacks["flickr.photos.getExif"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.getExif"](result);
}

callbacks.prototype.photos_getInfo = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('photo').item(0);
	result.id = xmlPhoto.getAttribute('id');
	result.secret = xmlPhoto.getAttribute('secret');
	result.server = xmlPhoto.getAttribute('server');
	result.isfavorite = xmlPhoto.getAttribute('isfavorite');
	result.license = xmlPhoto.getAttribute('license');
	result.rotation = xmlPhoto.getAttribute('rotation');
	var xmlOwner = xmlPhoto.getElementsByTagName('owner').item(0);
	var owner = new Object();
	owner.nsid = xmlOwner.getAttribute('nsid');
	owner.username = xmlOwner.getAttribute('username');
	owner.realname = xmlOwner.getAttribute('realname');
	owner.location = xmlOwner.getAttribute('location');
	result.owner = owner;
	if( xmlPhoto.getElementsByTagName('title').item(0).firstChild )
		result.title = xmlPhoto.getElementsByTagName('title').item(0).firstChild.data;
	else result.title = '';
	if( xmlPhoto.getElementsByTagName('description').item(0).firstChild )
		result.description = xmlPhoto.getElementsByTagName('description').item(0).firstChild.data;
	else result.description = '';
	var visibility = new Object();
	var xmlVis = xmlPhoto.getElementsByTagName('visibility').item(0);
	visibility.ispublic = xmlVis.getAttribute('ispublic');
	visibility.isfriend = xmlVis.getAttribute('isfriend');
	visibility.isfamily = xmlVis.getAttribute('isfamily');
	result.visibility = visibility;
	var dates = new Object();
	var xmlDates = xmlPhoto.getElementsByTagName('dates').item(0);
	dates.posted = xmlDates.getAttribute('posted');
	dates.taken = xmlDates.getAttribute('taken');
	dates.takengranularity = xmlDates.getAttribute('takengranularity');
	result.dates = dates;
	var permissions = new Object();
	var xmlPerm = xmlPhoto.getElementsByTagName('permissions');
	if (xmlPerm.length > 0 )
	{
			permissions.permcomment = xmlPerm.item(0).getAttribute('permcomment');
			permissions.permaddmeta = xmlPerm.item(0).getAttribute('permaddmeta');
	}
	result.permissions = permissions;
	var editability = new Object();
	var xmlEd = xmlPhoto.getElementsByTagName('editability').item(0);
	editability.cancomment = xmlEd.getAttribute('cancomment');
	editability.canaddmeta = xmlEd.getAttribute('canaddmeta');
	result.editability = editability;
	result.comments = xmlPhoto.getElementsByTagName('comments').item(0).firstChild.data;
	var note = new Array();
	var xmlNote = xmlPhoto.getElementsByTagName('note');
	for(j=0;j<xmlNote.length;j++)
	{
		note[note.length]= {
					id: xmlNote.item(j).getAttribute('id'),
					author: xmlNote.item(j).getAttribute('author'),
					x: xmlNote.item(j).getAttribute('x'),
					y: xmlNote.item(j).getAttribute('y'),
					w: xmlNote.item(j).getAttribute('w'),
					h: xmlNote.item(j).getAttribute('h'),
					text: xmlNote.item(j).firstChild.data
					};
	}
	result.note = note;

	var tag = new Array();
	var xmlTag = xmlPhoto.getElementsByTagName('tag');
	for(x=0;x<xmlTag.length;x++)
	{
		tag[tag.length] = {
				id: xmlTag.item(x).getAttribute('id'),
				author: xmlTag.item(x).getAttribute('author'),
				raw: xmlTag.item(x).getAttribute('raw'),
				text: xmlTag.item(x).firstChild.data
				}
	}
	result.tag = tag;
	if( typeof(flickrUtils.userCallbacks["flickr.photos.getInfo"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.getInfo"](result);
}

callbacks.prototype.photos_getNotInSet = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();

	var photos = flickrUtils.xml.getElementsByTagName('photos');
	result.page = photos.item(0).getAttribute('page');
	result.perpage = photos.item(0).getAttribute('perpage');
	result.total = photos.item(0).getAttribute('total');
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('photo');
	var photo = new Array();
	for(x=0;x<xmlPhoto.length;x++)
	{
			id= xmlPhoto.item(x).getAttribute('id');
			secret= xmlPhoto.item(x).getAttribute('secret');
			server= xmlPhoto.item(x).getAttribute('server');
		photo[photo.length] = {
			id: id,
			owner: xmlPhoto.item(x).getAttribute('owner'),
			secret: secret,
			server: server,
			title: xmlPhoto.item(x).getAttribute('title'),
			ispublic: xmlPhoto.item(x).getAttribute('ispublic'),
			isfriend: xmlPhoto.item(x).getAttribute('isfriend'),
			isfamily: xmlPhoto.item(x).getAttribute('isfamily'),
			img_s: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_s.jpg',
			img_t: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_t.jpg',
			img_m: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg',
			img  : 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'.jpg',
			img_b: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_b.jpg'
			};
	}
	result.photo = photo;
	
	if( typeof(flickrUtils.userCallbacks["flickr.photos.getNotInSet"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.getNotInSet"](result);
}

callbacks.prototype.photos_getPerms = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();
	var xmlPerm = flickrUtils.xml.getElementsByTagName('perms').item(0);
	result.id = xmlPerm.getAttribute('id');
	result.ispublic = xmlPerm.getAttribute('ispublic');
	result.isfriend = xmlPerm.getAttribute('isfriend');
	result.isfamily = xmlPerm.getAttribute('isfamily');
	result.permcomment = xmlPerm.getAttribute('permcomment');
	result.permaddmeta = xmlPerm.getAttribute('permaddmeta');
	
	if( typeof(flickrUtils.userCallbacks["flickr.photos.getPerms"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.getPerms"](result);
}

callbacks.prototype.photos_getRecent = 
function ()
{
	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();

	var photos = flickrUtils.xml.getElementsByTagName('photos');
	result.page = photos.item(0).getAttribute('page');
	result.pages = photos.item(0).getAttribute('pages');
	result.perpage = photos.item(0).getAttribute('perpage');
	result.total = photos.item(0).getAttribute('total');
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('photo');
	var photo = new Array();
	for(x=0;x<xmlPhoto.length;x++)
	{
			id= xmlPhoto.item(x).getAttribute('id');
			secret= xmlPhoto.item(x).getAttribute('secret');
			server= xmlPhoto.item(x).getAttribute('server');
		photo[photo.length] = {
			id: id,
			owner: xmlPhoto.item(x).getAttribute('owner'),
			ownername: xmlPhoto.item(x).getAttribute('ownername'),
			iconserver: xmlPhoto.item(x).getAttribute('iconserver'),
			secret: secret,
			server: server,
			title: xmlPhoto.item(x).getAttribute('title'),
			ispublic: xmlPhoto.item(x).getAttribute('ispublic'),
			isfriend: xmlPhoto.item(x).getAttribute('isfriend'),
			isfamily: xmlPhoto.item(x).getAttribute('isfamily'),
			img_s: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_s.jpg',
			img_t: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_t.jpg',
			img_m: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg',
			img  : 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'.jpg',
			img_b: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_b.jpg'
			};
	}
	result.photo = photo;
	if( typeof(flickrUtils.userCallbacks["flickr.photos.getRecent"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.getRecent"](result);
}

callbacks.prototype.photos_getSizes = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();
	var xmlSize = flickrUtils.xml.getElementsByTagName('size');
	var size = new Array();
	for(x=0;x<xmlSize.length;x++)
	{
		size[size.length]= {
					label: xmlSize.item(x).getAttribute('label'),
					width: xmlSize.item(x).getAttribute('width'),
					height:  xmlSize.item(x).getAttribute('height'),
					source: xmlSize.item(x).getAttribute('source'),
					url: xmlSize.item(x).getAttribute('url')
					};
	}
	result.size = size;
	
	if( typeof(flickrUtils.userCallbacks["flickr.photos.getSizes"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.getSizes"](result);
}

callbacks.prototype.photos_getUntagged = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();

	var photos = flickrUtils.xml.getElementsByTagName('photos');
	result.page = photos.item(0).getAttribute('page');
	result.pages = photos.item(0).getAttribute('pages');
	result.perpage = photos.item(0).getAttribute('perpage');
	result.total = photos.item(0).getAttribute('total');
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('photo');
	var photo = new Array();
	for(x=0;x<xmlPhoto.length;x++)
	{
			id= xmlPhoto.item(x).getAttribute('id');
			secret= xmlPhoto.item(x).getAttribute('secret');
			server= xmlPhoto.item(x).getAttribute('server');
		photo[photo.length] = {
			id: id,
			owner: xmlPhoto.item(x).getAttribute('owner'),
			secret: secret,
			server: server,
			title: xmlPhoto.item(x).getAttribute('title'),
			ispublic: xmlPhoto.item(x).getAttribute('ispublic'),
			isfriend: xmlPhoto.item(x).getAttribute('isfriend'),
			isfamily: xmlPhoto.item(x).getAttribute('isfamily'),
			img_s: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_s.jpg',
			img_t: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_t.jpg',
			img_m: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg',
			img  : 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'.jpg',
			img_b: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_b.jpg'
			};
	}
	result.photo = photo;
	
	if( typeof(flickrUtils.userCallbacks["flickr.photos.getUntagged"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.getUntagged"](result);
}

callbacks.prototype.photos_removeTag = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.photos.removeTag"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.removeTag"](result);
}

callbacks.prototype.photos_search = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();

	var photos = flickrUtils.xml.getElementsByTagName('photos');
	result.page = photos.item(0).getAttribute('page');
	result.pages = photos.item(0).getAttribute('pages');
	result.perpage = photos.item(0).getAttribute('perpage');
	result.total = photos.item(0).getAttribute('total');
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('photo');
	var photo = new Array();
	for(x=0;x<xmlPhoto.length;x++)
	{
			id= xmlPhoto.item(x).getAttribute('id');
			secret= xmlPhoto.item(x).getAttribute('secret');
			server= xmlPhoto.item(x).getAttribute('server');
		photo[photo.length] = {
			id: id,
			owner: xmlPhoto.item(x).getAttribute('owner'),
			ownername: xmlPhoto.item(x).getAttribute('ownername'),
			iconserver: xmlPhoto.item(x).getAttribute('iconserver'),
			secret: secret,
			server: server,
			title: xmlPhoto.item(x).getAttribute('title'),
			ispublic: xmlPhoto.item(x).getAttribute('ispublic'),
			isfriend: xmlPhoto.item(x).getAttribute('isfriend'),
			isfamily: xmlPhoto.item(x).getAttribute('isfamily'),
			img_s: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_s.jpg',
			img_t: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_t.jpg',
			img_m: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg',
			img  : 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'.jpg',
			img_b: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_b.jpg'
			};
	}
	result.photo = photo;
	
	if( typeof(flickrUtils.userCallbacks["flickr.photos.search"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.search"](result);
}

callbacks.prototype.photos_setDates = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.photos.setDates"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.setDates"](result);
}

callbacks.prototype.photos_setMeta = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.photos.setMeta"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.setMeta"](result);
}

callbacks.prototype.photos_setPerms = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.photos.setPerms"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.setPerms"](result);
}

callbacks.prototype.photos_setTags = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.photos.setTags"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photos.setTags"](result);
}



//// photosets ///////////////////////////////////////////////////////

callbacks.prototype.photosets_create = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.photosets.create"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photosets.create"](result);
}

callbacks.prototype.photosets_deletePhotoset = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.photosets.delete"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photosets.delete"](result);
}

callbacks.prototype.photosets_editMeta = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.photosets.editMeta"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photosets.editMeta"](result);
}

callbacks.prototype.photosets_editPhotos = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.photosets.editPhotos"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photosets.editPhotos"](result);
}

callbacks.prototype.photosets_getContext = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();

	var xmlPrev = flickrUtils.xml.getElementsByTagName('prevphoto');
	var xmlNext = flickrUtils.xml.getElementsByTagName('nextphoto');

	result.prev = new Object();
	result.next = new Object();
	
	result.prev.id = xmlPrev.item(0).getAttribute('id');
	result.prev.secret = xmlPrev.item(0).getAttribute('secret');
	result.prev.title = xmlPrev.item(0).getAttribute('title');
	result.prev.url = xmlPrev.item(0).getAttribute('url');
	
	result.next.id = xmlNext.item(0).getAttribute('id');
	result.next.secret = xmlNext.item(0).getAttribute('secret');
	result.next.title = xmlNext.item(0).getAttribute('title');
	result.next.url = xmlNext.item(0).getAttribute('url');

	if( typeof(flickrUtils.userCallbacks["flickr.photosets.getContext"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photosets.getContext"](result);
}

callbacks.prototype.photosets_getInfo = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();

	var xmlSets = flickrUtils.xml.getElementsByTagName('photoset');
	result.id= xmlSets.item(x).getAttribute('id');
	result.primary= xmlSets.item(x).getAttribute('primary');
	result.secret= xmlSets.item(x).getAttribute('secret');
	result.server= xmlSets.item(x).getAttribute('server');

	result.photos= xmlSets.item(x).getAttribute('photos');
	result.title= xmlSets.item(x).getElementsByTagName('title').item(0).firstChild.data;
	result.description= xmlSets.item(x).getElementsByTagName('description').item(0).firstChild;
    if ( result.description != null ) result.description = result.description.data;
	result.img_s= 'http://static.flickr.com/'+result.server+'/'+result.primary+'_'+result.secret+'_s.jpg';
	result.img_t= 'http://static.flickr.com/'+result.server+'/'+result.primary+'_'+result.secret+'_t.jpg';
	result.img_m= 'http://static.flickr.com/'+result.server+'/'+result.primary+'_'+result.secret+'_m.jpg';
	result.img  = 'http://static.flickr.com/'+result.server+'/'+result.primary+'_'+result.secret+'.jpg';
	result.img_b= 'http://static.flickr.com/'+result.server+'/'+result.primary+'_'+result.secret+'_b.jpg';

	if( typeof(flickrUtils.userCallbacks["flickr.photosets.getInfo"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photosets.getInfo"](result);
}

callbacks.prototype.photosets_getList = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();

	var cancreate = flickrUtils.xml.getElementsByTagName('photosets').item(0).getAttribute('cancreate');
	result.cancreate = cancreate;
	
	var xmlSets = flickrUtils.xml.getElementsByTagName('photoset');
	var photoset = new Array();

	for(x=0;x<xmlSets.length;x++)
	{
		id= xmlSets.item(x).getAttribute('id');
		primary= xmlSets.item(x).getAttribute('primary');
		secret= xmlSets.item(x).getAttribute('secret');
		server= xmlSets.item(x).getAttribute('server');
		var description = xmlSets.item(x).getElementsByTagName('description').item(0).firstChild;
		if (description != null ) description= description.data;


		photoset[photoset.length] = {
			id: id,
			primary: primary,
			secret: secret,
			server: server,
			photos: xmlSets.item(x).getAttribute('photos'),
			title: xmlSets.item(x).getElementsByTagName('title').item(0).firstChild.data,
//			description: xmlSets.item(x).getElementsByTagName('description').item(0).firstChild.data,
			description: description,
			img_s: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_s.jpg',
			img_t: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_t.jpg',
			img_m: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg',
			img  : 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'.jpg',
			img_b: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_b.jpg',
			};
	}
	
	result.photoset = photoset;

	if( typeof(flickrUtils.userCallbacks["flickr.photosets.getList"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photosets.getList"](result);
}

callbacks.prototype.photosets_getPhotos = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();

	var photoset_id = flickrUtils.xml.getElementsByTagName('photoset').item(0).getAttribute('id');
	var primary = flickrUtils.xml.getElementsByTagName('photoset').item(0).getAttribute('primary');
	var xmlPhotos = flickrUtils.xml.getElementsByTagName('photo');

	var photo = new Array();
	for(x=0;x<xmlPhotos.length;x++)
	{
		id= xmlPhotos.item(x).getAttribute('id'),
		secret=  xmlPhotos.item(x).getAttribute('secret'),
		server= xmlPhotos.item(x).getAttribute('server'),
		isprimary= xmlPhotos.item(x).getAttribute('isprimary');
		img= 'http://photos'+server+'.flickr.com/'+id+'_'+secret+'_s.jpg';
		if (isprimary == 1) photosetImg = img;
		photo[photo.length] = {
			id: id,
			secret: secret,
			server: server,
			title: xmlPhotos.item(x).getAttribute('title'),
			isprimary:isprimary,
			img_s: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_s.jpg',
			img_t: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_t.jpg',
			img_m: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_m.jpg',
			img  : 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'.jpg',
			img_b: 'http://static.flickr.com/'+server+'/'+id+'_'+secret+'_b.jpg',
			};
	}
	result.photoset_id = photoset_id;
	result.primary = primary;
	result.img = photosetImg;
	result.photo = photo;
			
	
	if( typeof(flickrUtils.userCallbacks["flickr.photosets.getPhotos"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photosets.getPhotos"](result);
}

callbacks.prototype.photosets_orderSets = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	if( typeof(flickrUtils.userCallbacks["flickr.photosets.orderSets"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.photosets.orderSets"](result);
}



//// tags ///////////////////////////////////////////////////////

callbacks.prototype.tags_getListPhoto = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object;
	
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('photo');
	result.id= xmlPhoto.item(0).getAttribute('id');
	var xmlTags = xmlPhoto.item(0).getElementsByTagName('tag');
	var tag = new Array();
	for(x=0;x<xmlTags.length;x++)
	{
		tag[tag.length]= {
			id: xmlTags.item(x).getAttribute('id'),
			author: xmlTags.item(x).getAttribute('author'),
			authorname: xmlTags.item(x).getAttribute('authorname'),
			raw: xmlTags.item(x).getAttribute('raw'),
			name: xmlTags.item(x).firstChild.data
			};
	}
	result.tag = tag;
	
	if( typeof(flickrUtils.userCallbacks["flickr.tags.getListPhoto"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.tags.getListPhoto"](result);
}

callbacks.prototype.tags_getListUser = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object;
	
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('who');
	result.id= xmlPhoto.item(0).getAttribute('id');
	var xmlTags = xmlPhoto.item(0).getElementsByTagName('tag');
	var tag = new Array();
	for(x=0;x<xmlTags.length;x++)
	{
		tag[tag.length]= {
			name: xmlTags.item(x).firstChild.data
			};
	}
	result.tag = tag;
	if( typeof(flickrUtils.userCallbacks["flickr.tags.getListUser"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.tags.getListUser"](result);
}

callbacks.prototype.tags_getListUserPopular = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object;
	
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('who');
	result.id= xmlPhoto.item(0).getAttribute('id');
	var xmlTags = xmlPhoto.item(0).getElementsByTagName('tag');
	var tag = new Array();
	for(x=0;x<xmlTags.length;x++)
	{
		tag[tag.length]= {
			count: xmlTags.item(x).getAttribute('count'),
			name: xmlTags.item(x).firstChild.data
			};
	}
	result.tag = tag;
	if( typeof(flickrUtils.userCallbacks["flickr.tags.getListUserPopular"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.tags.getListUserPopular"](result);
}

callbacks.prototype.tags_getRelated = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object;
	
	var xmlPhoto = flickrUtils.xml.getElementsByTagName('tags');
	result.source= xmlPhoto.item(0).getAttribute('source');
	var xmlTags = xmlPhoto.item(0).getElementsByTagName('tag');
	var tag = new Array();
	for(x=0;x<xmlTags.length;x++)
	{
		tag[tag.length]= {
			name: xmlTags.item(x).firstChild.data
			};
	}
	result.tag = tag;
	if( typeof(flickrUtils.userCallbacks["flickr.tags.getRelated"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.tags.getRelated"](result);
}



//// urls ///////////////////////////////////////////////////////

callbacks.prototype.urls_getGroup = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;

	var result = new Object();
	result.nsid = flickrUtils.xml.getElementsByTagName('group').item(0).getAttribute('nsid');
	result.url = flickrUtils.xml.getElementsByTagName('group').item(0).getAttribute('url');

	if( typeof(flickrUtils.userCallbacks["flickr.urls.getGroup"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.urls.getGroup"](result);
}

callbacks.prototype.urls_getUserPhotos = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;

	var result = new Object();
	result.nsid = flickrUtils.xml.getElementsByTagName('user').item(0).getAttribute('nsid');
	result.url = flickrUtils.xml.getElementsByTagName('user').item(0).getAttribute('url');

	if( typeof(flickrUtils.userCallbacks["flickr.urls.getUserPhotos"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.urls.getUserPhotos"](result);
}

callbacks.prototype.urls_getUserProfile = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;

	var result = new Object();
	result.nsid = flickrUtils.xml.getElementsByTagName('user').item(0).getAttribute('nsid');
	result.url = flickrUtils.xml.getElementsByTagName('user').item(0).getAttribute('url');

	if( typeof(flickrUtils.userCallbacks["flickr.urls.getUserProfile"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.urls.getUserProfile"](result);
}

callbacks.prototype.urls_lookupGroup = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var result = new Object();

	result.id = flickrUtils.xml.getElementsByTagName('group').item(0).getAttribute('id');
	result.groupname = flickrUtils.xml.getElementsByTagName('groupname').item(0).firstChild.data;

	if( typeof(flickrUtils.userCallbacks["flickr.urls.lookupGroup"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.urls.lookupGroup"](result);
}

callbacks.prototype.urls_lookupUser = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;

	var result = new Object();
	result.id = flickrUtils.xml.getElementsByTagName('user').item(0).getAttribute('id');
	result.username = flickrUtils.xml.getElementsByTagName('username').item(0).firstChild.data;

	if( typeof(flickrUtils.userCallbacks["flickr.urls.lookupUser"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.urls.lookupUser"](result);
}



//// reflection ///////////////////////////////////////////////////////

callbacks.prototype.reflection_getMethods = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();
	var methods = new Array();

	xmlMethods = flickrUtils.xml.getElementsByTagName('method');

	for(x=0;x<xmlMethods.length;x++)
	{
			methods[methods.length] = xmlMethods.item(x).firstChild.data;
	}
	flickrUtils.result = result;
	result.methods = methods;

	if( typeof(flickrUtils.userCallbacks["flickr.reflection.getMethods"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.reflection.getMethods"](result);
}

callbacks.prototype.reflection_getMethodInfo = 
function ()
{
   	if( !flickrUtils.stateOK(req) ) return false;
	flickrUtils.xml =  req.responseXML;
	var x;
	var result = new Object();
	
	var xmlMethod = flickrUtils.xml.getElementsByTagName('method').item(0);
	result.name = xmlMethod.getAttribute('name');
	result.needslogin = xmlMethod.getAttribute('needslogin');
	var description = xmlMethod.getElementsByTagName('description').item(0).firstChild;
	if (description != null ) result.description= description.data;
	var response = xmlMethod.getElementsByTagName('response');
	if ( response.length >0 && response.item(0).firstChild != null ) 
		result.response = response.item(0).firstChild.data;
	else result.response = '';
	
	var explanation = xmlMethod.getElementsByTagName('explanation');
	if ( explanation.length >0 && explanation.item(0).firstChild != null ) 
	result.explanation = explanation.item(0).firstChild.data;
	else explanation = '';
	
	var xmlArgs = xmlMethod.getElementsByTagName('argument');
	var arguments = new Array();
	for(x=0;x<xmlArgs.length;x++)
	{
		arguments[arguments.length] = { 
			name: xmlArgs.item(x).getAttribute('name'),
			optional: xmlArgs.item(x).getAttribute('optional'),
			description: xmlArgs.item(x).firstChild.data 
			};
	}
	result.arguments = arguments;

	var xmlErrs = xmlMethod.getElementsByTagName('error');
	var errors = new Array();
	for(x=0;x<xmlErrs.length;x++)
	{
		errors[errors.length] = { 
			code: xmlErrs.item(x).getAttribute('code'),
			message: xmlErrs.item(x).getAttribute('message'),
			description: xmlErrs.item(x).firstChild.data 
			};
	}
	result.errors = errors;

	if( typeof(flickrUtils.userCallbacks["flickr.reflection.getMethodInfo"]) =='function' ) 
		flickrUtils.userCallbacks["flickr.reflection.getMethodInfo"](result);
}


/// END  ///////////



//// Main object Creation //////////////////////////////////////////////////////

flickrAPI = new flickr();
flickrUtils = flickrAPI.flickrUtils;



