
var gallery={config:{},cache:{currentSlide:0,images:new Array(),thumbs:new Array(),captions:new Array(),timerId:null,timerInt:null,timerControls:null,timerObj:null},init:function(){},create:function(id,opts){var opts=gallery.augment({feed:null,viewable:'single',auto:false,cid:null,ctype:false,thumbsize:null,caption:null,cbtn:'a',cnext:null,cprev:null},opts);if(document.getElementById(id)){container=document.getElementById(id);container.style.overflow="hidden";if(opts.feed){gallery.cache.images[id]=new Array();gallery.cache.thumbs[id]=new Array();gallery.cache.captions[id]=new Array();for(var x in opts.feed){if(opts.feed[x]['image']){gallery.cache.images[id][x]=opts.feed[x]['image'];}
if(opts.feed[x]['thumb']){gallery.cache.thumbs[id][x]=opts.feed[x]['thumb'];}else{gallery.cache.thumbs[id][x]='';}
if(opts.feed[x]['caption']){gallery.cache.captions[id][x]=opts.feed[x]['caption'];}else{gallery.cache.captions[id][x]='';}}}
container.innerHTML="";container.style.position="relative";divs=new Array();imgs=new Array();counter=0;totalW=0;for(var x in gallery.cache.images[id]){divs[counter]=document.createElement("div");divs[counter].id=id+'-gallery-item-'+counter;divs[counter].style.position="absolute";divs[counter].style.top="0px";container.appendChild(divs[counter]);imgs[counter]=document.createElement("img");imgs[counter].src=gallery.cache.images[id][counter];divs[counter].appendChild(imgs[counter]);if(opts.viewable=='single'){divs[counter].style.left=container.offsetWidth*counter+"px";}else if(opts.viewable=='continuous'){divs[counter].style.left=totalW+"px";totalW=totalW+imgs[counter].offsetWidth;}
counter++;}
if(opts.ctype){switch(opts.ctype){case"thumbs":if(opts.cid){sandbox=new Array();imgs=new Array();anchors=new Array();ctrlCont=document.getElementById(opts.cid);ctrlCont.innerHTML='';for(var x=0;x<gallery.cache.images[id].length;x++){sandbox[x]=document.createElement("div");ctrlCont.appendChild(sandbox[x]);imgs[x]=document.createElement("img");imgs[x].src=gallery.cache.thumbs[id][x];imgs[x].style.cursor='pointer';sandbox[x].appendChild(imgs[x]);anchors[x]=document.createElement("a");anchors[x].href="javascript:void(0)";anchors[x].className="overlay";anchors[x].innerHTML="&nbsp;";anchors[x].id=id+'-gallery-control-'+x;anchors[x].onclick=function(){gallery.slide(this);}
sandbox[x].appendChild(anchors[x]);}}
break;case"buttons":if(opts.cid){ctrls=document.getElementById(opts.cid).getElementsByTagName("a");if(ctrls.length>0){counter=0;for(var x in ctrls){ctrls[x].id=id+'-gallery-control-'+counter;ctrls[x].href="javascript:void(0)";ctrls[x].onclick=function(){gallery.slide(this);}
if(counter==0){ctrls[x].className="overlay_clicked";}
counter++;}}else{ctrl=document.getElementById(opts.cid);}}
break;default:break;}}
if(opts.caption){document.getElementById(opts.caption).id=id+'-caption-container';capCont=document.getElementById(id+'-caption-container');capCont.innerHTML="";para=document.createElement("p");para.innerHTML=gallery.cache.captions[id][0];capCont.appendChild(para);}}
if(opts.auto){gallery.cache.timerInt=parseInt(opts.auto+'000');gallery.cache.timerId=id;gallery.cache.timerControls=opts.cid;gallery.cache.timerObj=setTimeout("gallery.autoslide()",gallery.cache.timerInt);}},autoslide:function(){curSlide=gallery.cache.currentSlide;nextSlide=curSlide+1;sandbox=document.getElementById(gallery.cache.timerId).getElementsByTagName("div");if(parseInt(sandbox.length-1)<nextSlide){nextSlide=0;}
actCont=document.getElementById(gallery.cache.timerId);ssobj=document.getElementById(gallery.cache.timerId+"-gallery-item-"+nextSlide);csobj=document.getElementById(gallery.cache.timerId+"-gallery-item-"+curSlide);children=actCont.getElementsByTagName('div');for(var x=0;x<children.length;x++){if(nextSlide>curSlide){leftDiff=parseInt(parseInt(ssobj.style.left)-parseInt(csobj.style.left));newPos=parseInt(children[x].style.left)-leftDiff;}else{leftDiff=parseInt(parseInt(csobj.style.left)-parseInt(ssobj.style.left));newPos=parseInt(children[x].style.left)+leftDiff;}
$("#"+gallery.cache.timerId+"-gallery-item-"+x).animate({left:newPos+"px"},200);}
obj=document.getElementById(gallery.cache.timerControls)
anchorcollection=obj.parentNode.parentNode.getElementsByTagName("a");for(var x=0;x<anchorcollection.length;x++){anchorcollection[x].className="overlay";}
obj.parentNode.getElementsByTagName("a").item(nextSlide).className="overlay_clicked";gallery.cache.currentSlide=nextSlide;if(document.getElementById(gallery.cache.timerId+"-caption-container")){caption=document.getElementById(gallery.cache.timerId+"-caption-container").getElementsByTagName("p").item(0);caption.innerHTML=gallery.cache.captions[gallery.cache.timerId][nextSlide];}
gallery.cache.timerObj=setTimeout("gallery.autoslide()",gallery.cache.timerInt);},slide:function(obj){if(typeof(obj)=='string'){switch(obj){case"next":break
case"prev":break;default:break;}}else if(typeof(obj)=='object'){sandbox=obj.id.split("-");galleryIdent=sandbox[0];selectedSlide=sandbox[sandbox.length-1];actCont=document.getElementById(galleryIdent);if(selectedSlide!=gallery.cache.currentSlide){ssobj=document.getElementById(galleryIdent+"-gallery-item-"+selectedSlide);csobj=document.getElementById(galleryIdent+"-gallery-item-"+gallery.cache.currentSlide);children=actCont.getElementsByTagName('div');for(var x=0;x<children.length;x++){if(selectedSlide>gallery.cache.currentSlide){leftDiff=parseInt(parseInt(ssobj.style.left)-parseInt(csobj.style.left));newPos=parseInt(children[x].style.left)-leftDiff;}else{leftDiff=parseInt(parseInt(csobj.style.left)-parseInt(ssobj.style.left));newPos=parseInt(children[x].style.left)+leftDiff;}
$("#"+galleryIdent+"-gallery-item-"+x).animate({left:newPos+"px"},200);}
anchorcollection=obj.parentNode.parentNode.getElementsByTagName("a");for(var x=0;x<anchorcollection.length;x++){anchorcollection[x].className="overlay";}
obj.parentNode.getElementsByTagName("a").item(0).className="overlay_clicked";gallery.cache.currentSlide=selectedSlide;caption=document.getElementById(galleryIdent+"-caption-container").getElementsByTagName("p").item(0);caption.innerHTML=gallery.cache.captions[galleryIdent][selectedSlide];}}},augment:function(oSelf,oOther){if(oSelf==null){oSelf={};}
for(var i=1;i<arguments.length;i++){var o=arguments[i];if(typeof(o)!='undefined'&&o!=null){for(var j in o){oSelf[j]=o[j];}}}
return oSelf;}}