ie6=false;


/*@cc_on @*/

/*@if (@_jscript_version <= 5.6)
 // The above conditional compilation for IE is equivalent to
 // a conditional comment in HTML of 'if lte IE 6'
ie6 = true;
 /*@end @*/


var ie = /*@cc_on!@*/false;

window.scrollTo(100000,100000);
antigrav.granularity=230;

//these two statements were added to "processflicks()" so as to avoid tem being trggered before there were pictures to show (creating a blank page...)
//antigrav.panAction=insertFlicks;
//window.onscroll=insertFlicks;
	

thisPic=0;
thisQuad=null;
picPage=0;
picPageSize=100;
getFlicks();
openPics=[];
picAddys=[];


function getInfo (thePic) {
	XHR('infogetter.php?photo='+thePic,insertInfo,thePic);
}

function insertInfo (jsonInfo,x,thePic){
	eval('q=('+jsonInfo+')');
	
	//	document.getElementById(thePic+'text').innerHTML="<div><h2>"+q.photo.title._content+"</h2>"+q.photo.description._content+"</div>";
	document.getElementById(thePic+'text').innerHTML="<div>"+q.photo.description._content+"</div>";
	if (q.photo.description!='photo'){
		height=document.getElementById(thePic+"img").height+"px";
	}else{
		height=q.photo.video.height;
	}
	document.getElementById(thePic+'text').style.height=height;
	document.getElementById(thePic+'text').style.overflow="hidden";		

	//add headline
	width=document.getElementById(thePic+'img').width;
	if (typeof(width)=='undefined'){  //it is video
		width=q.photo.video.width;
	}
	titleInnerHTML='<img style=" z-index:2; position:relative; top:-10px; left:-10px; " src="'+'http://artdispenser.com/gdtest/?text='+ q.photo.title._content + '&orientation=0&size=27&width='+width+'">';
	document.getElementById(thePic+'headline').innerHTML=titleInnerHTML;
}

function insertVideo(jsonInfo,x,thePic){
	eval('q=('+jsonInfo+')');
	for (thesize in q.sizes.size){
		if (q.sizes.size[thesize].label=='Site MP4'){
			width=q.sizes.size[thesize].width;
			height=q.sizes.size[thesize].height;		
			mp4url=q.sizes.size[thesize].source;					
			theSwf='<object id="player_api" name="player_api" data="video/flowplayer-3.2.2.swf" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"><param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><param name="quality" value="high"><param name="cachebusting" value="true"><param name="bgcolor" value="#000000"><param name="flashvars" value="config={&quot;playerId&quot;:&quot;player&quot;,&quot;clip&quot;:{&quot;autoPlay&quot;:false,&quot;autoBuffering&quot;:true,&quot;url&quot;:&quot;'+mp4url+'&quot;},&quot;playlist&quot;:[{&quot;url&quot;:&quot;'+mp4url+'&quot;}]}"></object>';
			theVidDiv=picAddys[thePic].id+'img';
			document.getElementById(theVidDiv).style.width=width+'px';
			document.getElementById(theVidDiv).style.height=height+'px';
			document.getElementById(theVidDiv).innerHTML='<div onmouseover="antigrav.dontdrag=true; antigrav.deactivate();"  onmouseout="antigrav.dontdrag=false;  antigrav.activate();">'+theSwf+'</div>';

	//		titleInnerHTML='<img style=" z-index:2; position:relative; top:-10px; left:-10px; " src="'+'http://artdispenser.com/gdtest/?text='+ picAddys[thePic].title + '&orientation=0&size=27&width='+width+'">';
//debug(thepc);
	//		document.getElementById(picAddys[thePic].id+'headline').innerHTML=titleInnerHTML;
		}
	}
}

function makeLightBoxHolder () {   
 	var holder = document.createElement("div");
	holder.setAttribute('id', 'LBHolder');
	holder.style.position='absolute';
	holder.style.zIndex='10000';
	holder.style.top='0px'; 
	holder.style.left='0px';  
	document.body.appendChild(holder);
}

function updateHash(){
	first=0;
	for (hash in openPics){
		if (first==0){
			theHash=openPics[hash];	
		}else{
			theHash+='_'+openPics[hash];		
		}	
		first++;
	}
	if (first==0){	
		theHash='none';
		openPics=[];
	}
		window.location.hash=theHash;
}


function addToLightbox(picId){	
	thisId ='img'+picAddys[picId].id+'lightbox'
	frameid=' id='+thisId;
	if(document.getElementById(thisId)){return;}  //break if pic already exists.

	openPics[String(picId)+'X']=picAddys[picId].id+'-'+picAddys[picId].server+'-'+picAddys[picId].farm+'-'+picAddys[picId].secret+'-'+picAddys[picId].media;
	updateHash();

	if (!document.getElementById('LBholder')){makeLightBoxHolder();}

	framestyle=" style='-moz-box-shadow: 0px 2px 8px #666; box-shadow: 0px 2px 8px #666;  -webkit-box-shadow: 0px 2px 8px #666;  position:fixed; z-index:10000; left:" + ((antigrav.windowWidth()/2-300)+Math.floor(Math.random()*500)-250) + "px; top:" + ((antigrav.windowHeight()/2-200)+Math.floor(Math.random()*200)-100) + "px; background-color:white; border:1px solid gray; padding:20px; display:block'";
	framemousedown=' onmousedown="';
	framemousedown+=" antigrav.drag('event','"+thisId+"')";
	framemousedown+='" ';

	frameInnerHTML="<div "+frameid+framemousedown+framestyle+"></div>";

	document.getElementById('LBHolder').innerHTML+=frameInnerHTML;
	theFrame=document.getElementById(thisId);

	var theInfo = document.createElement("div");
	text="";
	
	infoInnerHTML="<div id=lester style=''>"+text+"</div>";
	theInfo.innerHTML=infoInnerHTML;

	
	var titleText = document.createElement("div");
	titleText.style.height='30px';
	
	titleText.id=picAddys[picId].id+"headline";
	theFrame.appendChild(titleText);

	theInfo.style.display="none";
	theInfo.style.position="absolute";
	theInfo.style.width="90%";
	theInfo.id=picAddys[picId].id+"text";
	theFrame.appendChild(theInfo);

	if (picAddys[picId].media=='video'){
		var theFlick = document.createElement("div");
		flickInnerHTML="<div id="+picAddys[picId].id+"img style='  background-color:#ccc;  visibility:visible;'></div>";
		XHR('videogetter.php?photo='+picAddys[picId].id,insertVideo,picId);	
		getInfo(picAddys[picId].id);	
	}else{	//media == photo
		var theFlick = document.createElement("div");
		flicksrc='http://farm'+picAddys[picId].farm+'.static.flickr.com/'+picAddys[picId].server+'/'+picAddys[picId].id+'_'+picAddys[picId].secret+'.jpg';						
		flickInnerHTML="<img src='"+flicksrc+"' "
		flickInnerHTML+="id="+picAddys[picId].id+"img style='visibility:visible;' onload='getInfo("+picAddys[picId].id+")'>";
	}
	theFlick.innerHTML=flickInnerHTML;
	theFrame.appendChild(theFlick);

	var closer = document.createElement("div");
	closerInnerHTML='<br><img src="images/close.gif" align=left onclick="';
	closerInnerHTML+="antigrav.close('event','"+thisId+"'); delete openPics['"+picId+"X'];  updateHash(); "
	closerInnerHTML+='">';
	closer.innerHTML=closerInnerHTML;	
	theFrame.appendChild(closer);

	var flipper = document.createElement("div");
	flipper.style.position="absolute";
	flipper.style.right="20px";		
	flipperInnerHTML='<div id="';
	flipperInnerHTML+=picAddys[picId].id;
	flipperInnerHTML+='fliptext" onclick="';
	flipperInnerHTML+="flippit('"+picAddys[picId].id+"');";
	flipperInnerHTML+='">flip&nbsp;photo&nbsp;<img src="images/flip.gif"></div>';
	flipper.innerHTML=flipperInnerHTML;	

	theFrame.appendChild(flipper);
}


function flippit (thepicid){
		
	flipimgid=thepicid+"img";
	fliptextid=thepicid+"text";
	flipframeid="img"+thepicid+"lightbox";
	flipimg=document.getElementById(flipimgid);
	flipframe=document.getElementById(flipframeid);
	flipframe.style.display="none";

	picwidth=flipimg.width+100;
	picheight=flipimg.height+120;
	
	if (isNaN(picwidth)){   // then it is video - let's get the numbers elsewhere.
		picwidth=antigrav.noPxEm(flipimg.style.width);
		picheight=antigrav.noPxEm(flipimg.style.height)+130;
	}

	flipframecount=0;	
	flipanimation=document.getElementById('theflip');
	flipanimation.style.display='block';
	flipanimation.style.width=(picwidth+120)+'px';
	flipanimation.style.height=picheight+'px';
	flipanimation.style.top=(antigrav.noPxEm(flipframe.style.top)-40)+'px';
	flipanimation.style.left=(antigrav.noPxEm(flipframe.style.left)-50)+'px';	

	doflip(flipimgid,fliptextid,flipframeid);
}


function doflip (flipimgid,fliptextid,flipframeid) {
	flipframecount++;
	flipimg=document.getElementById(flipimgid);
	flipframediv=document.getElementById(flipframeid);
	fliptext=document.getElementById(fliptextid);
	flipanimation=document.getElementById('theflip');
	if (flipframecount<7){
		flipanimation.src='flips/flip'+flipframecount+'.png';	
		setTimeout('doflip(flipimgid,fliptextid,flipframeid)',40);		
	}else{
		if (flipimg.style.visibility=='visible'){

			flipframediv.style.display='block';
			flipanimation.style.display='none';
			flipimg.style.visibility='hidden';
			fliptext.style.display='block';
		}else{
			flipframediv.style.display='block';
			flipanimation.style.display='none';
			flipimg.style.visibility='visible';
			fliptext.style.display='none';
		}
	}
}

function showFlicks (thisPic,picId) {
	thisImg=document.getElementById(thisPic);
	if(ie){thisImg.parentNode.style.display='block';}else
	{$(thisImg.parentNode).fadeIn(800);}
	
	imgHeight=thisImg.height;
	imgWidth=thisImg.width;

	framestyle=" style='position:absolute; z-index:2; left:-20px; top:-15px;";
	framestyle+="width:"+(imgWidth+40)+"px;  height:"+(imgHeight+30)+"px;' ";	
	framedblclick=' ondblclick="addToLightbox('+picId+')" ';
	framemousedown=' onmousedown="';
	framemousedown+="antigrav.drag(event,'pic" + picId + "')";
	framemousedown+='" ';
	frameid=' id=img'+picId;
	
	orientation=Math.ceil(2*Math.random());

	if (imgHeight<imgWidth){
		framesrc='src="images/photoframeh'+orientation+'.png"';
	
		if (orientation==1){
			textoffset=imgHeight-21;	
		}else{
			textoffset=imgHeight-30;			
		}
	}else{
		framesrc='src="images/photoframev'+orientation+'.png"';
		textoffset=imgHeight-30;
	}
	theInnerHTML="<img "+framesrc+framedblclick+framemousedown+framestyle+">";

	var holder = document.createElement("div");
	holder.innerHTML=theInnerHTML;
	holder.innerHTML+='<img style=" z-index:2; position:absolute;  top:'+textoffset+'px;" src="'+'http://artdispenser.com/gdtest/?text='+ picAddys[picId].title + '&orientation='+orientation+'&size=15&width='+imgWidth+'">';

	thisImg.parentNode.appendChild(holder);
	
	document.getElementById('throbber').style.display="none";
}

function insertFlicks () {
	newQuads=antigrav.getNewQuads();
	for (xy in newQuads){
		if (!picAddys[thisPic]){return;}
		x=Math.round(xy/1000);
		y=xy-(x*1000);
		var holder = document.createElement("div");
		holder.setAttribute('id', 'pic'+thisPic);
		holder.style.position='absolute';
		holder.style.display='none';
		holder.style.zIndex=thisPic;
		holder.style.top=y*antigrav.granularity+Math.ceil(200*Math.random())+'px';
		holder.style.left=x*antigrav.granularity+Math.ceil(200*Math.random())+'px';
		url='http://farm'+picAddys[thisPic].farm+'.static.flickr.com/'+picAddys[thisPic].server+'/'+picAddys[thisPic].id+'_'+picAddys[thisPic].secret+'_m.jpg';						
		holder.innerHTML="<img src="+url+" style='position: absolute;' id=img"+thisPic+" onload=showFlicks('img" + thisPic +"',"+thisPic+");>";		
		document.body.appendChild(holder);
		thisPic++;	
	
	}
	if (thisPic>picPage*picPageSize-(picPageSize/3)){
		getFlicks();		
	}
}

function getFlicks () {
	picPage++;
	XHR('getter.php?page='+picPage+'&pagesize='+picPageSize+'&search='+search+'&method='+method+'&extra='+extra+'&media='+media,processFlicks,'')	
}


if ((window.location.hash)&&(window.location.hash!="#none")){
	initPics=window.location.hash.slice(1).split('_');
	for (hash in initPics){
		initPic=initPics[hash].split('-');				
		picAddys[hash]={id:initPic[0],server:initPic[1],farm:initPic[2],secret:initPic[3],media:initPic[4]};
		addToLightbox(thisPic);
		thisPic++;
	}

}

function processFlicks(datums,x,x){
	datums=datums.replace('photoset','photos');
	newPicAddys=[];
	eval('p=('+datums+')');
	var i=0;
	while (p.photos.photo[i]){
		var title= p.photos.photo[i].title;
		var farm= p.photos.photo[i].farm;		
		var secret= p.photos.photo[i].secret;
		var server= p.photos.photo[i].server;
		var media= p.photos.photo[i].media;		
		var id= p.photos.photo[i].id;
		newPicAddys[i]={title:title,farm:farm,secret:secret,server:server,id:id,media:media};
		i++;
	}
	picAddys=picAddys.concat(newPicAddys);
	insertFlicks();
	window.onscroll=insertFlicks;
}

function XHR(URL,donext,passvars){						
	var XHRreq = null;    	                       					
	if (window.XMLHttpRequest) { XHRreq=new XMLHttpRequest();} else {XHRreq=new ActiveXObject("Microsoft.XMLHTTP");}
	XHRreq.onreadystatechange = function() {                     	
		if ((XHRreq.readyState==4) || (XHRreq.readyState=="complete")) {  
			donext(XHRreq.responseText, XHRreq.status, passvars);	//  functions should go "data, status, passed vars")
		}                                                       		
   	}
	XHRreq.open("GET", URL, true);
	XHRreq.send(null);
}


angle=1;
radius=600;
angle2=1;
radius2=200;
play=false;

autoPlay(play);

if (autoplay){autoPlay(play);}
function autoPlay(){
	
	if(autoplay){
		oldPlayX=Math.cos(angle)*radius+Math.cos(angle2)*radius2;
		oldPlayY=Math.sin(angle)*radius+Math.sin(angle2)*radius2;
		angle+=2/radius;
		radius+=.1;
		angle2+=.01;
		newPlayX=Math.cos(angle)*radius+Math.cos(angle2)*radius2;
		newPlayY=Math.sin(angle)*radius+Math.sin(angle2)*radius2;
	//	window.scrollTo(Math.cos(angle)*radius+Math.cos(angle2)*radius2+100000,	Math.sin(angle)*radius+Math.sin(angle2)*radius2+100000);
	//	window.scrollBy(Math.cos(angle)*radius+Math.cos(angle2)*radius2-oldPlayX,	Math.sin(angle)*radius+Math.sin(angle2)*radius2-oldPlayY);
		if ((Math.round(oldPlayX)!=Math.round(newPlayX))||(Math.round(oldPlayY)!=Math.round(newPlayY))){		
			window.scrollBy(Math.round(oldPlayX)-Math.round(newPlayX),Math.round(oldPlayY)-Math.round(newPlayY));
		}
	}
	setTimeout(autoPlay,40);
}

document.body.onclick=function(){autoplay=false;}


