var FOTO={};var SKEL={};SKEL.EFFECTS={};FOTO.Slider={bucket:{},imageCache:{},loadingURL:'/Images/Design/spinner.gif',baseURL:'http://localhost/Images/Pictures/',thumbURL:'Thumb/{ID}.jpg',thumbPath:'Thumb/{ID}',mainURL:'Normal/{ID}.jpg',mainPath:'Normal/{ID}',FullSlideShow:0,ShowNavigator:0,ShowTitle:1,UseThumbs:0,duration:3000,data:{},getUrlFromId:function(key,id,isThumb){if(this.bucket[key]!=null&&this.bucket[key][id]!=null){if(isThumb&&this.bucket[key][id]['thumb']!=null){if(FOTO.Slider.UseThumbs){return this.baseURL+this.thumbPath.replace('{ID}',this.bucket[key][id]['thumb'])}else{return this.baseURL+this.mainPath.replace('{ID}',this.bucket[key][id]['main'])}}else if(!isThumb&&this.bucket[key][id]['main']!=null){if(FOTO.Slider.UseThumbs){return this.baseURL+this.thumbPath.replace('{ID}',this.bucket[key][id]['thumb'])}else{return this.baseURL+this.mainPath.replace('{ID}',this.bucket[key][id]['main'])}}}if(isThumb)return this.baseURL+this.thumbURL.replace('{ID}',id);return this.baseURL+this.mainURL.replace('{ID}',id)},getCaptionFromId:function(key,id){if(this.bucket[key]!=null&&this.bucket[key][id]!=null){return this.bucket[key][id]['caption']}},getWidthFromId:function(key,id){if(this.bucket[key]!=null&&this.bucket[key][id]!=null){return this.bucket[key][id]['width']}},getHeightFromId:function(key,id){if(this.bucket[key]!=null&&this.bucket[key][id]!=null){return this.bucket[key][id]['height']}},importBucketFromIds:function(key,ids){this.bucket[key]=new Object();for(i in ids){this.bucket[key][ids[i]]=new Object()}},buildThumbBar:function(key,bar){if(this.bucket[key]==null){return false}var slot=0;for(i in this.bucket[key]){var div=$(document.createElement('div'));div.attr('imageid',i);div.attr('slot',slot++);div.addClass('photoslider_thumb');var img=document.createElement('img');img.src=this.getUrlFromId(key,i,true);img.className='photoslider_thumbimg';div.append(img);$(bar).append(div)}var clear=document.createElement('div');$(clear).addClass('photoslider_clear');$(bar).css('width',((slot+1)*this.data[key]['thumbWidth'])+'px');$(bar).append(clear)},reload:function(key){if(this.data[key]==null){this.data[key]=new Object()}else{clearInterval(this.data[key]['intervalCycle'])}this.data[key]['thumbWidth']=72;this.data[key]['paused']=true;this.data[key]['currentSlot']=0;this.data[key]['currentId']=null;var sliderDiv=$('#'+key);var sliderMain=$('#'+key+' .photoslider_main').get(0);if(sliderMain!=null){$(sliderMain).remove()}if(FOTO.Slider.ShowTitle){var sliderCaption=$(document.createElement('div'));sliderCaption.addClass('photoslider_caption')}sliderMain=$(document.createElement('div'));sliderMain.addClass('photoslider_main');sliderMain.prepend(sliderCaption);sliderMainImg=document.createElement('img');sliderMain.append(sliderMainImg);sliderDiv.append(sliderMain);var sliderNav=$('#'+key+' .photoslider_nav').get(0);if(sliderNav!=null){$(sliderNav).remove()}var sliderControl=$('#'+key+' .photoslider_control').get(0);if(sliderControl!=null){$(sliderControl).remove()}sliderNav=$(document.createElement('div'));sliderNav.addClass('photoslider_nav');sliderDiv.append(sliderNav);thumbBar=$(document.createElement('div'));thumbBar.addClass('photoslider_thumbBar');this.buildThumbBar(key,thumbBar);$(thumbBar).children('.photoslider_thumb').each(function(){$(this).click(function(ev){FOTO.Slider.thumbClick(ev)})});sliderNav.append(thumbBar);var sliderControl=$(document.createElement('div'));sliderControl.addClass('photoslider_control');var sliderPlay=$(document.createElement('div'));sliderPlay.addClass('photoslider_play');var sliderStop=$(document.createElement('div'));sliderStop.addClass('photoslider_stop');var clear=$(document.createElement('div'));clear.addClass('photoslider_clear');sliderControl.append(sliderPlay).append(sliderStop).append(clear);$(sliderPlay).click(function(){if(FOTO.Slider.data[key]['paused']){$(sliderPlay).addClass('slideshow_enabled');$(sliderStop).removeClass('slideshow_disabled');FOTO.Slider.play(key)}});$(sliderStop).click(function(){if(!FOTO.Slider.data[key]['paused']){$(sliderStop).addClass('slideshow_disabled');$(sliderPlay).removeClass('slideshow_enabled')}FOTO.Slider.stop(key)});sliderNav.append(sliderControl);var firstThumb=$('#'+key+' .photoslider_thumb[slot="0"]');firstThumb.click();$(sliderPlay).click()},thumbClick:function(ev){var thumb=null;if(ev.currentTarget){thumb=$(ev.currentTarget)}else if(ev.srcElement){if($(ev.srcElement).attr('src')==null){thumb=$(ev.srcElement)}else{thumb=$(ev.srcElement).parent()}}else if(ev.target){thumb=$(ev.target)}var id=thumb.attr('imageid');var bar=thumb.parent();var nav=bar.parent();var parent=nav.parent();var key=parent.attr('id');var slot=thumb.attr('slot');if(id==null){id=0};if(slot==null){slot=0}if(id==this.data[key]['currentId']){return false}this.resetTimer(key);this.setMainImage(key,id);if(this.data[key]['interval'])SKEL.EFFECTS.Slide.stopByIntervalId(this.data[key]['interval']);if(this.data[key]['intervalThumb'])SKEL.EFFECTS.Slide.stopByIntervalId(this.data[key]['intervalThumb']);if(this.data[key]['currentId']!=null){SKEL.EFFECTS.Slide.animate($('.photoslider_thumb[imageid="'+this.data[key]['currentId']+'"]'),'top','20px','0px',500,SKEL.Transitions.quadOut)}this.data[key]['currentId']=id;this.data[key]['currentSlot']=slot;this.data[key]['intervalThumb']=SKEL.EFFECTS.Slide.animate(thumb,'top','0px','20px',250,SKEL.Transitions.quadOut);var currentPos=this.findRelativePos(bar.get(0));var navWidth=parseInt($(nav).css('width'));var slots=Math.floor(navWidth/this.data[key]['thumbWidth']);var centerStart=(navWidth/2)-((+this.data[key]['thumbWidth']*(slot))+(this.data[key]['thumbWidth']/2));var barFrom=currentPos['x']+'px';var barTo=centerStart+'px';this.data[key]['interval']=SKEL.EFFECTS.Slide.animate(bar,'left',barFrom,barTo,1000,SKEL.Transitions.backOut)},setMainImage:function(key,id){var main=$('#'+key+' .photoslider_main');var mainImg=$('#'+key+' .photoslider_main img').get(0);this.preload(this.getUrlFromId(key,id,false),FOTO.Slider.displayMainImage,{key:key,id:id})},displayMainImage:function(img){var newSrc=($(this).get())[0].src;var args=this.args;var key=args['key'];var id=args['id'];var main=$('#'+key+' .photoslider_main');var mainImg=$('#'+key+' .photoslider_main img').get(0);if(FOTO.Slider.ShowTitle){var caption=$('#'+key+' .photoslider_caption');var captionTxt=FOTO.Slider.getCaptionFromId(key,id)}var navigator=$('#'+key+' .photoslider_nav');var slider=$('#'+key+' .photoslider_thumbBar');var ImageWidth=FOTO.Slider.getWidthFromId(key,id);var ImageHeight=FOTO.Slider.getHeightFromId(key,id);var Ratio=ImageHeight/ImageWidth;var DisplayWidth=$(main).width();var DisplayHeight=$(main).height();if(FOTO.Slider.FullSlideShow){$(mainImg).bind("click",function(){if(FOTO.Slider.data[key]!=null){clearInterval(FOTO.Slider.data[key]['intervalCycle']);clearInterval(FOTO.Slider.data[key]['NavigatorCycle'])}$(mainImg).unbind("click");$(navigator).unbind("mouseover");$(navigator).unbind("mouseleave");$('#'+key).unbind("mousemove");$('#'+key).unbind("mouseleave");$(window).unbind("resize");$('#'+key).hide();EndSlideShow()});DisplayRatioWidth=Math.round(DisplayHeight/Ratio);DisplayRatioHeight=Math.round(DisplayWidth*Ratio);if((DisplayWidth-DisplayRatioWidth)>(DisplayHeight-DisplayRatioHeight)){DisplayRatio=Math.round(DisplayHeight/Ratio);$(mainImg).css('height',DisplayHeight);$(mainImg).css('width',DisplayRatio);if(FOTO.Slider.ShowTitle){$(caption).css('width',DisplayRatio)};$(navigator).css('width',DisplayRatio);if((DisplayRatio)<DisplayWidth){$(mainImg).css('top',0);TopNavigator=DisplayHeight-$(navigator).css('height').match(/\d+/);$(navigator).css('top',DisplayHeight);$(mainImg).css('left',Math.round((DisplayWidth-DisplayRatio)/2));if(FOTO.Slider.ShowTitle){$(caption).css('top',0);$(caption).css('left',Math.round((DisplayWidth-DisplayRatio)/2))}$(navigator).css('left',Math.round((DisplayWidth-DisplayRatio)/2));$(slider).css('left',Math.round($(navigator).css('width').match(/\d+/)/2))}}else{DisplayRatio=Math.round(DisplayWidth*Ratio);$(mainImg).css('width',DisplayWidth);if(FOTO.Slider.ShowTitle){$(caption).css('width',DisplayWidth)};$(navigator).css('width',DisplayWidth);$(mainImg).css('height',DisplayRatio);if((DisplayRatio)<DisplayHeight){$(mainImg).css('left',0);$(navigator).css('left',0);$(slider).css('left',$(navigator).css('width').match(/\d+/)/2);$(mainImg).css('top',Math.round((DisplayHeight-DisplayRatio)/2));if(FOTO.Slider.ShowTitle){$(caption).css('left',0);$(caption).css('top',Math.round((DisplayHeight-DisplayRatio)/2))};TopNavigator=Math.round(DisplayHeight-((DisplayHeight-DisplayRatio)/2)-$(navigator).css('height').match(/\d+/));$(navigator).css('top',Math.round(DisplayHeight-((DisplayHeight-DisplayRatio)/2)))}}if(FOTO.Slider.ShowNavigator){$('#'+key).bind("mousemove",function(e){var x=e.pageX;var y=e.pageY;var left=parseInt($(mainImg).css('left').match(/\d+/));var right=parseInt($(mainImg).css('left').match(/\d+/))+parseInt($(mainImg).css('width').match(/\d+/));var top=parseInt($(mainImg).css('top').match(/\d+/));var bottom=parseInt($(mainImg).css('top').match(/\d+/))+parseInt($(mainImg).css('height').match(/\d+/));if((x>=left&&x<=right)&&(y>=top&&y<=bottom)){$('#'+key+' .photoslider_nav').show();$('#'+key+' .photoslider_nav').animate({top:TopNavigator},750,'',function(e){if(FOTO.Slider.data[key]!=null){if(FOTO.Slider.data[key]['NavigatorCycle']==undefined){FOTO.Slider.data[key]['NavigatorCycle']=setInterval(function(){if(FOTO.Slider.data[key]['NavigatorCycle']){clearInterval(FOTO.Slider.data[key]['NavigatorCycle']);FOTO.Slider.data[key]['NavigatorCycle']=undefined}$('#'+key+' .photoslider_nav').stop(1);$('#'+key+' .photoslider_nav').animate({top:"+=100px"},750,'',function(e){$('#'+key+' .photoslider_nav').hide();$('#'+key+' .photoslider_nav').stop(1)})},5000)}FOTO.Slider.data[key]['slideshow']=true}})}else if(x<left||x>right||y<top||y>bottom){if(FOTO.Slider.data[key]!=null){if(FOTO.Slider.data[key]['NavigatorCycle']){clearInterval(FOTO.Slider.data[key]['NavigatorCycle']);FOTO.Slider.data[key]['NavigatorCycle']=undefined}$('#'+key+' .photoslider_nav').stop(1);$('#'+key+' .photoslider_nav').animate({top:"+=100px"},750,'',function(e){$('#'+key+' .photoslider_nav').hide();$('#'+key+' .photoslider_nav').stop(1)});FOTO.Slider.data[key]['slideshow']=false}}});$(navigator).bind("mouseover",function(e){clearInterval(FOTO.Slider.data[key]['NavigatorCycle'])});$(navigator).bind("mouseout",function(e){if(e.pageY<=$(navigator).css("top").match(/\d+/)){if(FOTO.Slider.data[key]!=null){FOTO.Slider.data[key]['NavigatorCycle']=undefined}}});$('#'+key).bind("mouseleave",function(e){if(FOTO.Slider.data[key]!=null){if(FOTO.Slider.data[key]['NavigatorCycle']){clearInterval(FOTO.Slider.data[key]['NavigatorCycle']);FOTO.Slider.data[key]['NavigatorCycle']=undefined}$('#'+key+' .photoslider_nav').stop(1);$('#'+key+' .photoslider_nav').animate({top:"+=100px"},750,'',function(e){$('#'+key+' .photoslider_nav').hide();$('#'+key+' .photoslider_nav').stop(1)});FOTO.Slider.data[key]['slideshow']=false}})}}else{DisplayRatioWidth=Math.round(DisplayHeight/Ratio);DisplayRatioHeight=Math.round(DisplayWidth*Ratio);if((DisplayWidth-DisplayRatioWidth)>(DisplayHeight-DisplayRatioHeight)){DisplayRatio=Math.round(DisplayHeight/Ratio);$(mainImg).css('height',DisplayHeight);$(mainImg).css('width',DisplayRatio);if(FOTO.Slider.ShowTitle){$(caption).css('width',DisplayRatio)};if((DisplayHeight/Ratio)<DisplayWidth){$(mainImg).css('top',0);$(mainImg).css('left',Math.round((DisplayWidth-DisplayRatio)/2));if(FOTO.Slider.ShowTitle){$(caption).css('top',0);$(caption).css('left',Math.round((DisplayWidth-DisplayRatio)/2))}}}else{DisplayRatio=Math.round(DisplayWidth*Ratio);$(mainImg).css('width',DisplayWidth);if(FOTO.Slider.ShowTitle){$(caption).css('width',DisplayWidth)};$(mainImg).css('height',DisplayRatio);if(DisplayRatio<=DisplayHeight){$(mainImg).css('left',0);$(mainImg).css('top',Math.round((DisplayHeight-DisplayRatio)/2));if(FOTO.Slider.ShowTitle){$(caption).css('left',0);$(caption).css('top',Math.round((DisplayHeight-DisplayRatio)/2))}}}}if(FOTO.Slider.ShowTitle){if(captionTxt==null){captionTxt='&nbsp;'}caption.html(captionTxt)};$(mainImg).attr('src',newSrc)},preload:function(url,onLoadFunc,args){var image=document.createElement('img');if(onLoadFunc){image.onload=onLoadFunc}if(args){image.args=args}image.src=url;this.imageCache[url]=image;return image},enableSlideshow:function(key){$('#'+key+' .photoslider_nav').css('display','block');this.data[key]['slideshow']=true},preloadImages:function(key){if(this.bucket[key]!=null&&this.bucket[key][1]!=null){this.preload(this.getUrlFromId(key,1,false),FOTO.Slider.preloadImageChain,{key:key,slot:1})}},preloadImageChain:function(){var args=this.args;var key=args['key'];var slot=parseInt(args['slot'])+1;if(FOTO.Slider.bucket[key]!=null&&FOTO.Slider.bucket[key][slot]!=null){FOTO.Slider.preload(FOTO.Slider.getUrlFromId(key,slot,false),FOTO.Slider.preloadImageChain,{key:key,slot:slot})}},findAbsolutePos:function(el){var SL=0,ST=0;var is_div=/^div$/i.test(el.tagName);if(is_div&&el.scrollLeft)SL=el.scrollLeft;if(is_div&&el.scrollTop)ST=el.scrollTop;var r={x:el.offsetLeft-SL,y:el.offsetTop-ST};r.width=el.offsetWidth;r.height=el.offsetHeight;if(el.offsetParent){var tmp=this.findAbsolutePos(el.offsetParent);r.x+=tmp.x;r.y+=tmp.y}return r},findRelativePos:function(el){var SL=0,ST=0;var is_div=/^div$/i.test(el.tagName);if(is_div&&el.scrollLeft)SL=el.scrollLeft;if(is_div&&el.scrollTop)ST=el.scrollTop;var r={x:el.offsetLeft-SL,y:el.offsetTop-ST};r.width=el.offsetWidth;r.height=el.offsetHeight;if(el.offsetParent){if($(el.offsetParent).css('position')!='relative'){var tmp=this.findRelativePos(el.offsetParent);r.x+=tmp.x;r.y+=tmp.y}else{r.x+=0;r.y+=0}}return r},cycleImage:function(key){if(FOTO.Slider.data[key]!=null){var slot=parseInt(parseInt(this.data[key]['currentSlot'])+1);var thumb=$('#'+key+' .photoslider_thumb[slot="'+slot+'"]').get(0);if(thumb==null){thumb=$('#'+key+' .photoslider_thumb[slot="0"]').get(0);if(thumb==null){this.data[key]['paused']=true;return false}}$(thumb).click()}},play:function(key){if(this.data[key]['paused']){this.data[key]['intervalCycle']=setInterval(function(){FOTO.Slider.cycleImage(key)},FOTO.Slider.duration)}this.data[key]['paused']=false},stop:function(key){this.data[key]['paused']=true;if(this.data[key]['intervalCycle']){clearInterval(this.data[key]['intervalCycle'])}},resetTimer:function(key){if(!this.data[key]['paused']&&this.data[key]['intervalCycle']){this.stop(key);this.play(key)}}};SKEL.Transitions={quadOut:function(t,b,c,d){return-c*(t/=d)*(t-2)+b},backOut:function(t,b,c,d,s){if(!s)s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b}};SKEL.EFFECTS.Slide={counter:0,fps:50,animate:function(element,cssAttribute,from,to,duration,transition){if(element.css('display')!='block'){element.skel_old_display=element.css('display')}if(!transition){transition=SKEL.Transitions.quadOut}SKEL.EFFECTS.Slide.stop(element);var startTime=new Date().getTime();element.skel_animate_id=setInterval(function(){SKEL.EFFECTS.Slide.step(element,cssAttribute,from,to,duration,startTime,transition)},(1000/SKEL.EFFECTS.Slide.fps));return element.skel_animate_id},stop:function(element){if(element.skel_animate_id){clearInterval(element.skel_animate_id);element.skel_animate_id=0;if(element.skel_old_display){element.css('display',element.skel_old_display)}}},stopByIntervalId:function(id){if(id){clearInterval(id)}},step:function(element,cssAttribute,from,to,duration,start,transition){var curTime=new Date().getTime();if(cssAttribute=='color'||cssAttribute=='background-color'){from=this.hexToRgb(from);to=this.hexToRgb(to)}else{var result=this.splitValue(from);var prefix=result.prefix;if(prefix=='-')prefix='';var postfix=result.postfix;from=parseInt(from);to=parseInt(to)}var newValue=SKEL.EFFECTS.Slide.compute(curTime,from,to,duration,start,transition);var finished=false;if(curTime>(start+duration)){finished=true}if(cssAttribute=='color'||cssAttribute=='background-color'){newValue=this.rgbToHex(newValue)}else{newValue=prefix+Math.round(newValue)+postfix}if(finished){SKEL.EFFECTS.Slide.stop(element)}element.css(cssAttribute,newValue)},compute:function(time,from,to,duration,startTime,transitionFunc){var deltaTime=time-startTime;if(time>(startTime+duration)){return to}else{if(typeof(from)=='object'){from.forEach(function(value,index){newFrom=value;newTo=to[index];newValue=transitionFunc(deltaTime,newFrom,(newTo-newFrom),duration);tmpObject[index]=Math.round(newValue)});return tmpObject}else{return transitionFunc(deltaTime,from,(to-from),duration)}}},hexToRgb:function(str){var hex=str.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);if(hex){if(hex[1]!=''){hex[1]=parseInt(hex[1],16);hex[2]=parseInt(hex[2],16);hex[3]=parseInt(hex[3],16)}}return(hex)?hex.slice(1):false},rgbToHex:function(rgb){if(rgb.length<3)return false;if(rgb[3]&&(rgb[3]==0)&&!rgb)return'transparent';var hex=[];for(var i=0;i<3;i++){var bit=(rgb[i]-0).toString(16);hex.push((bit.length==1)?'0'+bit:bit)}return'#'+hex.join('')},splitValue:function(str){result={prefix:'',postfix:'',value:''};if(str!=''){var res=str.match(/([^0-9]*)([0-9]+)([^0-9]*)/);result={prefix:res[1],postfix:res[3],value:res[2]}}return result}}
