if(typeof SMC=='undefined'){SMC={};}
var playGallery=false;SMC.Gallery=function(params){this.thPhotosContainer='';this.mainPhotoContainer='';this.currentThumbnailNumber=0;this.speed=1000;this.thumbnails=[];if(params!=null){if(params['speed']!=null&&!isNaN(parseInt(params['speed']))){this.speed=parseInt(params['speed']);}
if(typeof(params['thPhotosContainer'])=="string"){this.thPhotosContainer=params['thPhotosContainer'];}
if(typeof(params['mainPhotoContainer'])=="string"){this.mainPhotoContainer=params['mainPhotoContainer'];}
if(typeof(params['urlregexp'])=="string"){this.urlregexp=new RegExp(params['urlregexp'],'g');}}}
SMC.Gallery.prototype.ShowNext=function(){var _this=this;if(playGallery){this.currentThumbnailNumber++;this.ShowPhoto();setTimeout(function(){_this.ShowNext()},this.speed);}}
SMC.Gallery.prototype.ShowPhoto=function(){if(this.currentThumbnailNumber>=this.thumbnails.length){this.currentThumbnailNumber=0;}
if(this.currentThumbnailNumber<0){this.currentThumbnailNumber=this.thumbnails.length-1;}
var _this=this;$$("#"+this.thPhotosContainer+" .th").each(function(element){Element.removeClassName(element,'view-th');});Element.addClassName('th'+this.currentThumbnailNumber,'view-th');this.setMainPhoto();}
SMC.Gallery.prototype.setMainPhoto=function(){_this=this;$$('#'+this.mainPhotoContainer+' img').each(function(element){element.style.display='none';});setTimeout(function(){Effect.run($('ph'+_this.currentThumbnailNumber),true,5);},100);var alttext=$('th'+this.currentThumbnailNumber).alt;if($('photo-name'))$('photo-name').innerHTML=alttext;if($('main-photo-name'))$('main-photo-name').innerHTML=alttext;}
SMC.Gallery.prototype.start=function(){_this=this;this.currentThumbnailNumber=0;if(this.thPhotosContainer!=''&&$(this.thPhotosContainer)){var thumbnails=$$("#"+this.thPhotosContainer+" .th");this.thumbnails=[];var html_pre_load='';if(thumbnails!=null){for(var i=0;i<thumbnails.length;i++){thumbnails[i].style.position='static';}
for(var i=0;i<thumbnails.length;i++){this.thumbnails[i]=thumbnails[i];thumbnails[i].id='th'+i;Event.observe(thumbnails[i],'click',SMC.ShowClick,false);Event.observe(thumbnails[i],'mouseover',SMC.thMouseOver,false);Event.observe(thumbnails[i],'mouseout',SMC.thMouseOut,false);html_pre_load+='<img id="ph'+i+'" style="display:none" width= "435" height="227" src="'+thumbnails[i].getAttribute('origin')+'" border="0"/>';}
Element.update(this.mainPhotoContainer,html_pre_load);if(thumbnails.length>0){this.ShowPhoto();}}}}
SMC.Gallery.prototype.absolutePositioned=function(absolute){for(var i=0;i<this.thumbnails.length;i++){this.thumbnails[i].style.position='static';}
if(absolute){for(var i=0;i<this.thumbnails.length;i++){var x=Position.positionedOffset(this.thumbnails[i])[0];var y=Position.positionedOffset(this.thumbnails[i])[1];this.thumbnails[i].style.left=x+'px';this.thumbnails[i].style.top=y+'px';}
for(var i=0;i<this.thumbnails.length;i++){this.thumbnails[i].style.position='absolute';}}}
SMC.ShowClick=function(e){Event.stop(e);ele=Event.element(e);SMC.ShowPause();ga.currentThumbnailNumber=parseInt(ele.id.replace('th',''),10);ga.ShowPhoto();}
SMC.ShowPlay=function(){if(playGallery){playGallery=false;$('play-pause').src=$('play-pause').src.replace('pause','play');}else
{$('play-pause').src=$('play-pause').src.replace('play','pause');playGallery=true;}
setTimeout(function(){ga.ShowNext()},1000);}
SMC.ShowPause=function(){playGallery=false;$('play-pause').src=$('play-pause').src.replace('pause','play');}
SMC.ShowBack=function(){playGallery=false;$('play-pause').src=$('play-pause').src.replace('pause','play');ga.currentThumbnailNumber--;ga.ShowPhoto();}
SMC.ShowNext=function(){playGallery=false;$('play-pause').src=$('play-pause').src.replace('pause','play');ga.currentThumbnailNumber++;ga.ShowPhoto();}
var srcThTemp='';var xoffset=5;var yoffset=5;SMC.thMouseOver=function(e){ga.absolutePositioned(true);Event.stop(e);var el=Event.element(e);srcThTemp=el.src;el.width='90';var x=Position.positionedOffset(el)[0];var y=Position.positionedOffset(el)[1];el.style.left=x-xoffset+'px';el.style.top=y-yoffset+'px';Element.addClassName(el,'view-th-zoom');el.zIndex=1000;}
SMC.thMouseOut=function(e){Event.stop(e);var el=Event.element(e);el.width='80';el.src=srcThTemp;var x=Position.positionedOffset(el)[0];var y=Position.positionedOffset(el)[1];el.zIndex=1;el.style.left=x+xoffset+'px';el.style.top=y+yoffset+'px';Element.removeClassName(el,'view-th-zoom');ga.absolutePositioned(false);}