var GalleryTimeMachine=new Class({initialize:function(c,a,b){this.root_node=c?$(c):null;this.image_viewport_class="mb_gallery_image_viewport";this.image_class="mb_gallery_image";this.image_active_class="mb_gallery_image_active";this.image_hold_class="mb_gallery_image_hold";this.images_class="mb_gallery_images";this.image_prev_class="mb_gallery_image_prev";this.image_next_class="mb_gallery_image_next";this.blocker_class="mb_gallery_blocker";this.active_class="active";this.disabled_class="disabled";this.image_prefix="mb_gallery_image_";this.image_hold_prefix="mb_gallery_image_hold_";a=a?parseInt(a):0;b=b?parseInt(b):500;this.time_interval=isNaN(a)?0:a;this.time_effect=isNaN(b)?0:b;this.timer=null;this.images_amount=0;this.image_width=0;this.image_height=0;this.active_coords=new Array();this.hold_coords=new Array();this.hold_amount=0;this.hold_offset=0;this.hold_position="top";this.front_style={bottom:null,height:null,left:null,opacity:0,right:null,top:null,width:null};this.back_style={bottom:null,height:null,left:null,opacity:0,right:null,top:null,width:null}},start:function(){var n=this;if(this.root_node){var t=this.root_node.getElement("."+this.image_class);var p=this.root_node.getElement("."+this.image_active_class);var k=this.root_node.getElement("."+this.image_hold_class);var d=this.root_node.getElement("."+this.images_class);if(t&&p&&k){this.active_coords=p.getCoordinates(t);var q=k.getElements("div");this.hold_amount=q.length;if(this.hold_amount){var o=t.getSize();this.image_width=o.x;this.image_height=o.y;for(i=0;i<this.hold_amount;i++){var s=q[i];var w=s.getCoordinates(t);this.hold_coords.push(w)}var a=this.hold_coords[0];var g=a.top;var r=a.left;var l=this.image_width-a.right;var u=this.image_height-a.bottom;var m=this.hold_coords[this.hold_amount-1];var v=m.top;var e=m.left;var h=this.image_width-m.right;var f=this.image_height-m.bottom;var c=m.width;var j=m.height;if(g<0){this.hold_offset=-g;if(r<0){this.hold_position="top-left"}else{if(l<0){this.hold_position="top-right"}else{this.hold_position="top"}}}else{if(u<0){this.hold_offset=-u;if(r<0){this.hold_position="bottom-left"}else{if(l<0){this.hold_position="bottom-right"}else{this.hold_position="bottom"}}}else{if(r<0){this.hold_offset=-r;this.hold_position="left"}else{if(l<0){this.hold_offset=-l;this.hold_position="right"}}}}switch(this.hold_position){case"top":this.front_style.top=this.active_coords.top+this.hold_offset;this.front_style.left=this.active_coords.left-this.hold_offset;this.front_style.width=this.active_coords.width+(this.hold_offset*2);this.back_style.top=v-this.hold_offset;this.back_style.left=e+this.hold_offset;this.back_style.width=c-(this.hold_offset*2);break;case"left":this.front_style.top=this.active_coords.top-this.hold_offset;this.front_style.left=this.active_coords.left+this.hold_offset;this.front_style.height=this.active_coords.height+(this.hold_offset*2);this.back_style.top=v+this.hold_offset;this.back_style.left=e-this.hold_offset;this.back_style.height=j-(this.hold_offset*2);break;case"right":this.front_style.top=this.active_coords.top-this.hold_offset;this.front_style.right=(this.image_width-this.active_coords.right)+this.hold_offset;this.front_style.height=this.active_coords.height+(this.hold_offset*2);this.back_style.top=v+this.hold_offset;this.back_style.right=h-this.hold_offset;this.back_style.height=j-(this.hold_offset*2);break;case"bottom":this.front_style.left=this.active_coords.left+this.hold_offset;this.front_style.bottom=(this.image_height-this.active_coords.bottom)+this.hold_offset;this.front_style.width=this.active_coords.width+(this.hold_offset*2);this.back_style.left=e+this.hold_offset;this.back_style.bottom=f-this.hold_offset;this.back_style.width=c-(this.hold_offset*2);break}}}if(d){var b=d.getElements("img");if(b){this.images_amount=b.length;if(this.images_amount>1){if(this.time_interval){this.timer=new Fx({duration:this.time_interval,onComplete:function(){n.showImageSibling(1);n.timer.start()}});this.timer.start()}}}}}this.setEvents()},setEvents:function(){var e=this;if(this.root_node){var d=this.root_node.getElement("."+this.image_hold_class);var c=this.root_node.getElement("."+this.image_prev_class);var a=this.root_node.getElement("."+this.image_next_class);if(d){var b=d.getElements("div");if(b.length){b.addEvent("click",function(){e.showImage(this);e.setTimer(0)})}}if(c&&a){c.addEvent("click",function(){if(!this.hasClass(e.disabled_class)){e.showImageSibling(2);e.setTimer(0)}});a.addEvent("click",function(){if(!this.hasClass(e.disabled_class)){e.showImageSibling(1);e.setTimer(0)}})}}},showImage:function(I,q){var j=this;if(this.root_node&&this.active_coords&&this.hold_coords.length&&I){var L=this.root_node.getElement("."+this.image_class);var B=this.root_node.getElement("."+this.image_active_class);var C=this.root_node.getElement("."+this.image_hold_class);var g=this.root_node.getElement("."+this.images_class);var H=I.get("class");var a=parseInt(H.replace(this.image_hold_prefix,""));if(L&&B&&C&&g&&!isNaN(a)){var h=C.getElements("div");var J=h.length;if(J){var A=null;var e=null;var c=null;var d=null;var s=null;var f=null;var x=B.getStyle("opacity").toFloat();var E=B.getStyle("z-index").toInt();x=isNaN(x)?null:x;E=isNaN(E)?null:E;var o=h[J-1];var O=o.getElement("img");var k=O?O.get("class"):"";var z=parseInt(k.replace(this.image_prefix,""));switch(this.hold_position){case"top":A=this.active_coords.top;e=this.active_coords.left;s=this.active_coords.width;break;case"left":A=this.active_coords.top;e=this.active_coords.left;f=this.active_coords.height;break;case"right":A=this.active_coords.top;c=this.image_width-this.active_coords.right;f=this.active_coords.height;break;case"bottom":e=this.active_coords.left;d=this.image_height-this.active_coords.bottom;s=this.active_coords.width;break}if(!isNaN(z)){for(i=0;i<a;i++){var l=g.getElements("img");var N=l.length;if(N){var v=z+(i+1);if(v>N){v=v-N}var b=this.image_prefix+v;var K=g.getElement("."+b);if(K){var p=K.clone();var Q=this.image_hold_prefix+(J+(i+1));var D=new Element("div",{"class":Q,styles:this.back_style});D.addEvent("click",function(){j.showImage(this);j.setTimer(0)});p.inject(D);D.inject(C)}}}}}h=C.getElements("div");if(h.length){var P=this.time_effect;var r=new Object();var y=0;var u=null;var t=null;var n=null;var F=null;var w=null;var G=null;var R=null;var m=null;for(i=0;i<h.length;i++){var S=h[i];var M=null;if((i+1)<=a){P=this.time_effect*(i+1);if((i+1)<a){M=new Fx.Morph(S,{duration:P,transition:"linear",onComplete:function(T){j.hideImage(T)}})}else{M=new Fx.Morph(S,{duration:P,transition:"linear",onComplete:function(T){j.resetClasses()}})}M.start({bottom:d,height:f,left:e,opacity:x,right:c,top:A,width:s,"z-index":E})}else{new Fx.Morph(S,{duration:P,transition:"linear"}).start({bottom:F,height:G,left:t,opacity:R,right:n,top:u,width:w,"z-index":m});if(y<(this.hold_amount-1)){y++}}switch(this.hold_position){case"top":case"top-left":u=this.hold_coords[y].top;t=this.hold_coords[y].left;w=this.hold_coords[y].width;break;case"left":u=this.hold_coords[y].top;t=this.hold_coords[y].left;G=this.hold_coords[y].height;break;case"right":case"top-right":u=this.hold_coords[y].top;n=this.image_width-this.hold_coords[y].right;G=this.hold_coords[y].height;break;case"bottom":case"bottom-left":t=this.hold_coords[y].left;F=this.image_height-this.hold_coords[y].bottom;w=this.hold_coords[y].width;break;case"bottom-right":n=this.image_width-this.hold_coords[y].right;F=this.image_height-this.hold_coords[y].bottom;G=this.hold_coords[y].height;break}R=h[y].getStyle("opacity").toFloat();m=h[y].getStyle("z-index").toInt();R=isNaN(R)?null:R;m=isNaN(m)?null:m}this.hideImage(B);new Fx({duration:P,onStart:function(){j.displayBlocker(1)},onComplete:function(){j.displayBlocker(0)}}).start()}}}},hideImage:function(b,c){if(b){var a=null;c=!isNaN(parseInt(c))?c:1;switch(c){case 1:a=this.front_style;break;case 2:a=this.back_style;break}new Fx.Morph(b,{duration:this.time_effect,transition:"linear"}).start(a)}},showImageSibling:function(e){if(this.root_node){var d=this.root_node.getElement("."+this.image_active_class);var c=this.root_node.getElement("."+this.image_hold_class);var a=this.root_node.getElement("."+this.images_class);if(d&&c&&a){e=!isNaN(parseInt(e))?e:1;switch(e){case 1:var b=c.getElement("div");if(b){this.showImage(b)}break;case 2:break}}}},resetClasses:function(){if(this.root_node){var f=this.root_node.getElement("."+this.image_active_class);var d=this.root_node.getElement("."+this.image_hold_class);if(f&&d){var b=d.getElements("div");if(b.length){var c=1;var a=b.length-this.hold_amount;for(i=0;i<b.length;i++){var g=b[i];if(i<a){if(i==(a-1)){g.removeEvents();g.set("class",this.image_active_class);g.inject(f,"before");f.dispose()}else{g.dispose()}}else{var e=this.image_hold_prefix+c;g.set("class",e);c++}}}}}},displayBlocker:function(b){if(this.root_node){var a=this.root_node.getElement("."+this.blocker_class);if(a){b=!isNaN(parseInt(b))?b:1;switch(b){case 0:a.setStyle("display","none");break;case 1:a.setStyle("display","block");break}}}},setTimer:function(a){if(this.timer){a=!isNaN(parseInt(a))?a:1;switch(a){case 0:this.timer.cancel();break;case 1:this.timer.start();break}}}});
