
if(!sl.loaded['sl.image.js']){sl.require('sl.dom.js');sl.require('sl.http.js');sl.require('sl.effect.js');sl.image={full_size_box:null,image_object:null,close_object:null,thumbs_move_interval:null,dimming_time:100,dimming_step:0.3,opacity_time:100,opacity_step:0.3,rotate_to_left_text:'Rotate left',rotate_to_right_text:'Rotate right',move_thumbs_step_size:4,preview:function(picture,comment){try{if(this.previewWindow){this.previewWindow.close();}}catch(error){}
this.previewWindow=window.open('','picturedetail','resizable=no,location=no,status=no,scrollbars=no');with(this.previewWindow){document.open();document.write('<html>\n<head>\n\t<title>'+comment+'</title>\n\t<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n</head>\n');document.write('<body style="background-color:#333; color:#eee; margin:.4em; text-align:center;">');document.write('<img id="image" src="'+picture+'" alt="'+comment+'" onclick="window.close();">');if(comment){document.write('<div id="description">'+comment+'</div>\n');}
document.write('</body>\n</html>\n');document.close();if(document.images[0]){document.images[0].onload=function(){var document_width=document.images[0].width+20;var document_height=document.images[0].height+40;if(comment){document_height+=16;}
resizeTo(document_width,document_height);}
document.images[0].onload();}
focus();}},initFullSizePreview:function(object_id,baseuri,thumbs_dir,full_size_dir){try{thumbs_dir=thumbs_dir?thumbs_dir:'thumbs';full_size_dir=full_size_dir?full_size_dir:'full-size';image_regexp=thumbs_dir+'/([0-9a-z-]+\.[a-z]{3})';object_images=sl.dom.getElement(object_id).getElementsByTagName('IMG');for(var i=0;i<object_images.length;i++){if(object_images[i].src.match(image_regexp)){object_images[i].style.cursor='pointer';object_images[i].onclick=function(){sl.image.showFullSize(baseuri+'images/'+full_size_dir+'/'+this.src.match(image_regexp)[1]);}}}}catch(e){}},showFullSize:function(image_src,description){description=description?description:'';if(sl.full_size_box){window.top.document.body.removeChild(sl.full_size_box);}
sl.full_size_box=window.top.document.createElement('div');new sl.effect_factory(sl.full_size_box);window.top.document.body.appendChild(sl.full_size_box);sl.full_size_box.id='slImageFullSize';sl.full_size_box.style.position='absolute';sl.full_size_box.style.visibility='hidden';sl.full_size_box.innerHTML="<img src='"+image_src+"' >  ";sl.full_size_box.innerHTML+='<div id="slImageDescription">'+description+'</div>\n';sl.full_size_box.innerHTML+="<div id='slImageClose'></div> ";if(sl.image.image_edit_url){var editbox="<div id='slImageEdit'>";editbox+="<a class='rotateRight' title='"+sl.image.rotate_to_right_text+"' ";editbox+="onclick=\"sl.image.edit('"+image_src+"','rotate','right')\"></a>";editbox+="<a class='rotateLeft' title='"+sl.image.rotate_to_left_text+"' ";editbox+="onclick=\"sl.image.edit('"+image_src+"','rotate','left')\"></a>";editbox+="</div> ";sl.full_size_box.innerHTML+=editbox;}
sl.image.image_object=sl.full_size_box.getElementsByTagName('IMG')[0];var new_image=new Image();new_image.onload=function(){sl.image.setFullSizeBox()};new_image.src=image_src;},setFullSizeBox:function(){if(sl.full_size_box){sl.full_size_box.width=sl.image.image_object.width+30;sl.full_size_box.style.width=sl.full_size_box.width+'px';sl.full_size_box.style.padding='15px';sl.full_size_box.effect_factory.center();sl.dragAndDrop.initElement(sl.full_size_box);sl.image.close_object=sl.dom.getElement('slImageClose',window.top.document);sl.image.close_object.onclick=sl.image.hideImage;sl.image.close_object.style.cursor='pointer';sl.image.image_object.onclick=sl.image.hideImage;sl.image.image_object.style.cursor='pointer';sl.full_size_box.style.display='block';sl.full_size_box.style.visibility='visible';}},hideImage:function(){if(sl.full_size_box){sl.full_size_box.effect_factory.dim();}},showCompactGalleryImage:function(src){var new_image=new Image();new_image.onload=function(){sl.image.setCompactGalleryImage(new_image)};new_image.src=src;},setCompactGalleryImage:function(new_image){var current_image=sl.dom.getElement('compact_gallery_main_image')
var image_window=sl.dom.getElement('compact_gallery_full_size');var opacity_interval=null;var current_opacity=0;if(current_image.style.filter!=undefined){current_image.style.filter='alpha(opacity=0)';}else{current_image.style.opacity=current_opacity;}
if((new_image.height>image_window.offsetHeight)||(new_image.width>image_window.offsetWidth)){if(new_image.width>=new_image.height||new_image.height<=image_window.offsetHeight){new_image.height=Math.round(image_window.offsetWidth*(new_image.height/new_image.width));new_image.width=image_window.offsetWidth;}else{new_image.width=Math.round(image_window.offsetHeight*(new_image.width/new_image.height));new_image.height=image_window.offsetHeight;}}
current_image.style.height=new_image.height+'px';current_image.style.width=new_image.width+'px';current_image.src=new_image.src;clearInterval(opacity_interval);opacity_interval=setInterval(function(){if(current_opacity>=1){clearInterval(opacity_interval);}
current_opacity=current_opacity+sl.image.opacity_step;if(current_image.style.filter!=undefined){current_image.style.filter='alpha(opacity='+(current_opacity*100)+')';}else{current_image.style.opacity=current_opacity;}},sl.image.opacity_time);},moveThumbs:function(direction){var preview_box=sl.dom.getElement('compact_gallery_preview');var thumbs_box=sl.dom.getElement('compact_gallery_thumbs');var thumbs_width=0;var thumbs=sl.dom.getElementsByClass('compact_gallery_item','div',thumbs_box);for(var i=0;i<thumbs.length;i++){thumbs_width=thumbs_width+thumbs[i].offsetWidth;}
var counter=thumbs_box.style.left==''?0:parseInt(thumbs_box.style.left);clearInterval(sl.image.thumbs_move_interval);sl.image.thumbs_move_interval=setInterval(function(){if(direction=='left'){if(counter<=-thumbs_width+(preview_box.offsetWidth)){clearInterval(sl.image.thumbs_move_interval);}else{counter=counter-(sl.image.move_thumbs_step_size);}}else{if(counter>=0){clearInterval(sl.image.thumbs_move_interval);}else{counter=counter+(sl.image.move_thumbs_step_size);}}
thumbs_box.style.left=counter+'px';},30);},stopThumbs:function(){clearInterval(sl.image.thumbs_move_interval);},edit:function(_name,_action,_parameters){if(!sl.image.image_edit_url){throw new Error('Image edit handler uri not set!');}
sl.http.request(sl.image.image_edit_url
+'?name='+escape(_name)
+'&action='+escape(_action)
+'&parameters='+escape(_parameters),function(_data){if(_data=='OK'&&sl.image.image_object){var image_uri=sl.image.image_object.src.split('?')
var _date=new Date();sl.image.image_object.onload=function(){sl.image.setFullSizeBox()};sl.image.image_object.src=image_uri[0]+'?'+_date.getTime();}else if(_data!=''){alert(_data);}});}}
sl.image.initSlideshow=function(_class_name,_document){_class_name=_class_name||'cms-widget-slideshow';_document=_document||document;var _objects=sl.dom.getElementsByClass(_class_name);for(var i=0,length=_objects.length;i<length;i++){var slideshow=new sl.image.slideshow(_objects[i]);}}
sl.image.slideshow=function(_object){this.container;this.images;this.buttons;this.captions;this.visible_key=0;this.timeout_length=4000;this.min_widget_height=100;this.init(_object);}
sl.image.slideshow.prototype={setTimeoutLength:function(_lenght){this.timeout_length=_lenght;if(this.timeout){this.stopSlideShow();this.runSlideShow();}},clickHandler:function(_evnt){this.stopSlideShow();var event=sl.event.getEvent(_evnt);var target=sl.event.getTarget(event);sl.event.stopPropagation(event);sl.event.preventDefault(event);var visible_key=0;for(var key in this.buttons){if(this.buttons[key]==target){visible_key=key;}}
if(visible_key!=this.visible_key){this.swapItem(visible_key);}},swapItem:function(_visible_key){var _this=this;for(var key in this.captions){if(key==this.visible_key){this.captions[key].effect_factory.dim();}}
this.visible_key=_visible_key;setTimeout(function(){_this.setSelectedImage();},500)
setTimeout(function(){_this.setSelectedCaption();_this.setSelectedButton();},1000)},setSelectedImage:function(){for(var key in this.images){if(key==this.visible_key){this.images[key].effect_factory.appear();}else{this.images[key].effect_factory.dim();}}},setSelectedButton:function(){for(var key in this.buttons){if(key==this.visible_key){sl.dom.addClass(this.buttons[key],'slCmsSlideshowSelectedButton');}else{sl.dom.removeClass(this.buttons[key],'slCmsSlideshowSelectedButton');}}},setSelectedCaption:function(){for(var key in this.captions){if(key==this.visible_key){this.captions[key].effect_factory.appear(0.1,30);}else{this.captions[key].effect_factory.dim();}}},showNext:function(){if(this.visible_key==(this.images.length-1)){this.swapItem(0);}else{this.swapItem(this.visible_key+1);}
this.stopSlideShow();this.runSlideShow();},runSlideShow:function(){_this=this;this.timeout=setTimeout(function(){_this.showNext()},this.timeout_length);},stopSlideShow:function(){clearTimeout(this.timeout);},init:function(_object){var _this=this;this.container=_object;this.images=sl.dom.getElementsByClass('slCmsSlideshowImage','img',this.container);var min_image_height;for(var image in this.images){if(!this.images[image].parentNode.href){sl.event.addHandler(this.images[image],'click',function(e){_this.clickHandler(e)});}
new sl.effect_factory(this.images[image]);if(!min_image_height||this.images[image].height<min_image_height&&this.images[image].height>this.min_widget_height){min_image_height=this.images[image].height;}}
var images_container=sl.dom.getElementsByClass('slCmsSlideshowImages','div',this.container)[0];images_container.style.height=min_image_height+'px';this.buttons=sl.dom.getElementsByClass('slCmsSlideshowNavigationButton','',this.container);for(var key in this.buttons){sl.event.addHandler(this.buttons[key],'click',function(e){_this.clickHandler(e)});}
this.captions=sl.dom.getElementsByClass('slCmsSlideshowImageCaption','',this.container);for(var key in this.captions){new sl.effect_factory(this.captions[key]);}
_this.setSelectedImage();_this.setSelectedCaption();_this.setSelectedButton();this.runSlideShow();}}
sl.image.PNGFix=function(){this.objects=[];this.empty_image=sl.baseuri+'images/slImage/pixel.gif';}
sl.image.PNGFix.prototype={addElementsByClass:function(_class_name,_tag_name,_document){if(!sl.isIE6()){return;}
var _objects=sl.dom.getElementsByClass(_class_name,_tag_name,_document);for(var i=0,length=_objects.length;i<length;i++){this.objects.push(_objects[i]);}},addElementChildNodes:function(_element){if(!sl.isIE6()||!_element){return;}
var _objects=_element.getElementsByTagName('*');for(var i=0,length=_objects.length;i<length;i++){this.objects.push(_objects[i]);}},process:function(){if(!sl.isIE6()){return;}
for(var i=0,length=this.objects.length;i<length;i++){var obj=this.objects[i];if(obj.currentStyle.backgroundImage.match(/\.png/i)!==null){var mode='scale';var bg=obj.currentStyle.backgroundImage;var src=bg.substring(5,bg.length-2);if(obj.currentStyle.backgroundRepeat=='no-repeat'){mode='crop';}
obj.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='"+mode+"')";obj.style.backgroundImage='url('+this.empty_image+')';}
if(obj.tagName=='IMG'&&obj.src.match(/\.png$/i)!==null){var src=obj.src;obj.style.width=obj.width+"px";obj.style.height=obj.height+"px";obj.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='scale')";obj.src=this.empty_image;}
if((obj.tagName=='A'||obj.tagName=='INPUT')&&obj.style.position===''){obj.style.position='relative';}}}}
sl.loaded['sl.image.js']=true;}
