<cfinclude template="config.cfm">

<cfset flickr = createobject("component", "CFlickr.Flickr")>
<cfset flickr.init(apikey, secret)>
<cfset intif = flickr.getInterestingnessInterface()>
<cfset pplif = flickr.getPeopleInterface()>
<cfset tagif = flickr.getTagsInterface()>
<cfset pif = flickr.getPhotosInterface()>

<cfinclude template="header.cfm">
<h1>Example 6</h1>

<cfif isdefined("url.user_id") AND isdefined("url.tag")>

	<cfset photoList = pif.search(user_id=url.user_id, tags=url.tag, tag_mode='all')>
	<cfset arrayPhotos = photoList.getPhotos()>
	<cfset owner = pplif.getInfo(url.user_id)>

	<cfoutput>
	<h3>#owner.getUsername()#'s photos tagged with #url.tag#</h3>
	
	<cfloop from="1" to="#arraylen(arrayPhotos)#" index="i">
		<img src="#arrayPhotos[i].getPhotoUrl(arrayPhotos[i].SIZE_SMALL_SQUARE)#" />
	</cfloop>
		
	</cfoutput>

<cfelse>

	<cfset photos = intif.getList(per_page=1,page=randrange(1, 500)).getPhotos()>  <!--- get a user by finding a random interesting photo --->
	<cfset photo = photos[1]>
	<cfset aTags = tagif.getListUserPopular(photo.getOwner().getId(), 100)>
	<cfset owner = pplif.getInfo(photo.getOwner().getId())>
	
	<cfscript>
	minc = 1;  // minimum count	maxc = 1;  // maximum count	minf = 10; // smallest font size	maxf = 40; // largest font size	for(i=1; i LTE arraylen(aTags); i=i+1) {
		if(aTags[i].getCount() LT minc OR NOT minc) minc = aTags[i].getCount();
		if(aTags[i].getCount() GT maxc OR NOT maxc) maxc = aTags[i].getCount();
	}
	d = (maxf-minf)/(maxc-minc); // delta value to increase font size by per count unit	</cfscript>
	
	
	<cfoutput>
	<div style="text-align:justify;">
	<h3>#owner.getUserName()#'s Tag Cloud</h3>
	<cfloop from="1" to="#arraylen(aTags)#" index="i">
		<span style="font-size:#round(minf+(d*aTags[i].getCount()))#px;"><a href="?user_id=#owner.getId()#&tag=#aTags[i].getValue()#" title="#aTags[i].getCount()# photos tagged with #aTags[i].getValue()#">#aTags[i].getValue()#</a></span>&nbsp;
	</cfloop>
	</div>
	</cfoutput>

</cfif>