if(typeof Roomar==="undefined"){Roomar={};}Roomar.ImageGallery=function(a){return(function(e){var g={},y=Abl.UI.Overlay($.extend(true,{},Roomar.ImageGallery.defaults,e)),A,j=0,h=0,p,C,c,s,q,o,t,b,z,f,l,x,w,n,r;function u(){b.addClass("open").removeClass("hide").attr("title","show description").text("show description...");t.removeClass("open").animate({top:n+"px"},y.params.descriptionSpeed);}function i(){b.removeClass("open").addClass("hide").attr("title","hide description").text("hide description...");t.addClass("open").animate({top:"-="+(t.outerHeight()+y.params.descriptionOffset)},y.params.descriptionSpeed);}function k(F){var D=F.position().left,E;x.toggleClass("disabled",h>=(p.length-1));w.toggleClass("disabled",h<1);if(D>r){E=D-(r-j-A);p.animate({left:"-="+E},y.params.slideSpeed);}else{if(D<0){E=Math.abs(D)+A;p.animate({left:"+="+E},y.params.slideSpeed);}}}function d(){l.click(function(D){var E=$(this);D.preventDefault();if((E.hasClass("disabled"))||(E.is(":animated"))){return;}if(E.hasClass("next")){p.eq(h+1).click();}else{if(E.hasClass("prev")){p.eq(h-1).click();}}});b.click(function(D){D.preventDefault();if(t.is(":animated")){return;}if(t.hasClass("open")){u();}else{i();}});}function v(){s=$(".gallery-container",c);q=$(".main-image",s);o=$("h1.title span",s);t=$(".description",s);b=$(".show-description",s);z=$(".control-container",s);f=$(".filmstrip",z);l=$(".nav",z);x=l.filter(".next");w=l.filter(".prev");n=t.position().top;r=f.width();A=y.params.imageMargin;d();}function m(D,F){var E=A;f.empty();$.each(D,function(G,H){var I;H.index=G;I=$("<li></li>").data("img",H).css("left",E+"px").appendTo(f);$("<img></img>").attr({src:"/Roomar/RenderImage/"+H.BusinessImageId+"?size=small",alt:H.Title}).appendTo(I);E+=I.outerWidth()+(2*A);});p=$("li",f);j=p.eq(0).outerWidth();p.hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");}).click(function(G){var I=$(this),H=I.data("img");G.preventDefault();if(I.hasClass("active")){return;}if(t.hasClass("open")){u();}h=H.index;p.filter(".active").removeClass("active");I.addClass("active");q.attr("src","/Roomar/RenderImage/"+H.BusinessImageId+"?size=vista");o.text(H.Title);t.text(H.Description||"");if((H.Description)&&(H.Description.length>0)){b.show();}else{b.hide();}k(I);});p.eq(0).click();F();}function B(E){var D;l.addClass("disabled");$.ajax({type:"POST",url:"/ImageGallery/GetImages/"+C,dataType:"json",cache:false,success:function(F){if(F.error){D="Unable to load image data\r\n\r\n"+F.error;alert(D);y.close();}else{m(F,function(){E();});}},error:function(H,F,G){D="ImageGallery.GetImages() - Ajax Error\r\n"+F;alert(D);y.close();}});}y.onBuildHtml=function(D){c=this;$.ajax({type:"POST",url:"/ImageGallery/Index",dataType:"html",cache:false,success:function(E){c.append(E);v();B(function(){D();});},error:function(G,E,F){var H="ImageGallery.GetImages() - Ajax Error\r\n"+E;alert(H);}});};g.open=y.open;y.open=function(E,F,D){C=E;g.open(F,D);};y.onDispose=function(){if((c)&&(c.length)){if(p){p.removeData("img").unbind();}l.unbind();b.unbind();}};return y;}(a));};Roomar.ImageGallery.defaults={resizeContent:false,imageMargin:4,slideSpeed:700,descriptionSpeed:500,descriptionOffset:3};
