function Carousel(prefix,countPhotos,photosData,url){this.position=1;this.lastPosition=0;this.locked=false;this.photosData=new Array();this.prefix=prefix;this.countPhotos=countPhotos;this.photosData=photosData;this.url=url;var self=this;var go=[];var w=null;for(var i=1;i<=countPhotos;i++){go[i-1]="."+prefix+"Jump_"+i;}
if($("div."+prefix).hasClass('carouseled')){return false;}
$("div."+prefix).addClass('carouseled')
$("div."+prefix).jCarouselLite({btnNext:"#"+prefix+"Next",btnPrev:"#"+prefix+"Prev",visible:1,scroll:1,circular:false,afterEnd:function(){self.locked=false;},btnGo:go});$("#"+prefix+"Prev").click(function(){if(!self.locked){self.locked=true;self.position--;self.showPreviewImage();self.updateNavigationPrev();}});$("#"+prefix+"Next").click(function(){if(!self.locked){self.locked=true;self.position++;self.showPreviewImage();self.updateNavigationNext();}});$("#"+prefix+"Zoom").click(function(){self.zoom();});}
var __Carousel_zoom_tm__=0;Carousel.prototype={zoom:function(){var el=$("#"+this.prefix+"Popup");var src=this.url+'?pic='+this.photosData[this.position]["previewSrc"]+'&prefix='+this.prefix+'&w='+this.photosData[this.position]["previewWidth"]+'&h='+this.photosData[this.position]["previewHeight"]+'&num='+this.position;clearTimeout(__Carousel_zoom_tm__);var _this=this;__Carousel_zoom_tm__=setTimeout(function(){openJsPopup(_this.prefix,src,_this.photosData[_this.position]["previewWidth"],_this.photosData[_this.position]["previewHeight"],0,_this.countPhotos>8?160:135);},5);},showPreviewImage:function(){if(!this.photosData[this.position]["visible"]){$("#"+this.prefix+"Img_"+this.position).attr("src",this.photosData[this.position]["src"]);this.photosData[this.position]["visible"]=true;}},updateNavigationPrev:function(){if(this.position==1){$("#"+this.prefix+"Prev").hide();$("#"+this.prefix+"PrevText").show();}
$("#"+this.prefix+"Next").show();$("#"+this.prefix+"NextText").hide();this.updatePosition();},updateNavigationNext:function(){if(this.position==this.countPhotos){$("#"+this.prefix+"Next").hide();$("#"+this.prefix+"NextText").show();}
$("#"+this.prefix+"Prev").show();$("#"+this.prefix+"PrevText").hide();this.updatePosition();},updatePosition:function(){$("#"+this.prefix+"Counter").html(this.position+" θη "+this.countPhotos);this.lastPosition=this.position;},updateCounter:function(cnt){if(this.lastPosition==cnt||(cnt==1&&!this.lastPosition)){$("#"+this.prefix+"Zoom").click();}
else{if(cnt>this.position){this.position=cnt;this.updateNavigationNext();}
else if(cnt<this.position){this.position=cnt;this.updateNavigationPrev();}
else{this.lastPosition=cnt;return;}
this.showPreviewImage();this.lastPosition=cnt;}},setIframeSrc:function(url){$("#iframe"+this.prefix).attr("src",url);}}
var popupsOpened=[];function openJsPopup(prefix,src,width,height,widthOffset,heightOffset){function defScroll(x,y){if(document.attachEvent!=null){x=x+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);y=y+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);}else if(!document.attachEvent&&document.addEventListener){x=x+window.scrollX;y=y+window.scrollY;}else{}
return{x:x,y:y};}
var isIE=$.browser.msie&&$.browser.version<7;var el=$("#"+prefix+"Popup");var offset=defScroll(0,0);var top=Math.ceil(($(window).height()-(height+(isIE?0:heightOffset*2)))/2);var left=Math.ceil(($(window).width()-(width+(isIE?0:widthOffset)))/2);top+=offset.y;offset.y+=5;top=top<offset.y?offset.y:top;left=left<0?0:left;if(isIE){window.open(src,"photo","width="+(width+widthOffset)+",height="+(height+heightOffset)+",menubar=no,personalbar=no,resizable=no,scrollbars=no,status=no,"+"titlebar=no,toolbar=no,left="+left+",top="+top);}
else{$("#"+prefix+"PopupContent").html('<iframe scrolling="no" id="iframe'+prefix+'"'+' src="'+src+'" '+'width="'+(width+widthOffset)+'" height="'+(height+heightOffset)+'"'+' frameborder="0" />');el.css("margin",0).css("padding",0).show().css({left:left+'px',top:top+'px',position:'absolute'});function closePopup(event){if(event.keyCode==27){$("#"+prefix+"closePopup").click();}}
function documentClick(event){if(!popupsOpened[prefix]){popupsOpened[prefix]=true;}
else if($(event.target).parents().filter("#"+prefix+"Popup").length!=1){$("#"+prefix+"closePopup").click();}}
$("#"+prefix+"closePopup").click(function(){$("#"+prefix+"Popup").hide();$(document).unbind("keyup",closePopup);$(document).unbind("click",documentClick);popupsOpened[prefix]=false;});popupsOpened[prefix]=false;$(document).bind("keyup",closePopup);$(document).bind("click",documentClick);}}
