(function(jQuery){jQuery.fn.rsscreenshots=function(o){o=jQuery.extend({css_holder:'rsscreenshots_holder',css_slider:'rsscreenshots_slider',css_content:'rsscreenshots_content',css_slider_next:'rsscreenshots_slider_next',css_slider_prev:'rsscreenshots_slider_prev',css_content_next:'rsscreenshots_content_next',css_content_prev:'rsscreenshots_content_prev',css_media:'rsscreenshots_media',dialog_id:'dialog',rel:'screenshots',css_dragging:'dragging',css_active:'active',css_hover:'hover',screenshot_id_prefix:'screenshot_',loader_url:'/cms/img/loader_screenshots.gif',timer_name:'rsscreenshot_slider',dialog_title:'Screenshots',screenshot_height:544,screenshot_width:1024,thumbnail_height:64,thumbnail_width:120,slide_steps:3},o||{});jQuery('#'+o.dialog_id).dialog('close');jQuery('#'+o.dialog_id).html('<div class="'+o.css_holder+'">'+
'<div class="'+o.css_slider+'">'+
this.html()+
'</div>'+
'<div class="'+o.css_slider_prev+'"></div>'+
'<div class="'+o.css_slider_next+'"></div>'+
'<div class="'+o.css_content+'">'+
'<div class="'+o.css_media+'"></div>'+
'<div class="'+o.css_content_prev+'"></div>'+
'<div class="'+o.css_content_next+'"></div>'+
'</div>'+
'</div>');var d={slider:jQuery('#'+o.dialog_id+' .'+o.css_slider),media:jQuery('#'+o.dialog_id+' .'+o.css_media),screenshotlinks:jQuery('#'+o.dialog_id+' a[rel='+o.rel+']'),slider_prev:jQuery('#'+o.dialog_id+' .'+o.css_slider_prev),slider_next:jQuery('#'+o.dialog_id+' .'+o.css_slider_next),content_next:jQuery('#'+o.dialog_id+' .'+o.css_content_next),content_prev:jQuery('#'+o.dialog_id+' .'+o.css_content_prev),dialog:jQuery('#'+o.dialog_id)};function slideLeft()
{var left=d.slider.scrollLeft()-(o.thumbnail_width+7)*o.slide_steps;left=Math.floor(left/(o.thumbnail_width+7))*(o.thumbnail_width+7);d.slider.stop(true,true).animate({scrollLeft:left},250,"linear",function(){updateScrollArrows();});}
function slideRight()
{var left=d.slider.scrollLeft()+(o.thumbnail_width+7)*o.slide_steps;left=Math.ceil(left/(o.thumbnail_width+7))*(o.thumbnail_width+7);d.slider.stop(true,true).animate({scrollLeft:left},250,"linear",function(){updateScrollArrows();});}
function nextShow()
{var id=d.screenshotlinks.filter('.active').attr('id');if(id==null)return;var nextid=parseInt(id.substr(11))+1;if(jQuery('#'+o.screenshot_id_prefix+nextid).size()==0)nextid=0;show(nextid);}
function prevShow()
{var id=d.screenshotlinks.filter('.active').attr('id');if(id==null)return;var previd=parseInt(id.substr(11))-1;if(jQuery('#'+(o.screenshot_id_prefix+previd)).size()==0)previd=d.screenshotlinks.filter(':last').first().attr('id').substr(11);show(previd);}
function getScreenshot(thumbid)
{return jQuery('#'+(o.screenshot_id_prefix+thumbid));}
function show(thumbid)
{if(d.slider.hasClass(o.css_dragging))return;d.screenshotlinks.removeClass(o.css_active);var elem=getScreenshot(thumbid);elem.addClass(o.css_active);d.media.css('background-image','url('+o.loader_url+')');var img=new Image();jQuery(img).load(function(){d.media.hide();d.media.css('background-image','url('+jQuery(this).attr('src')+')');d.media.fadeIn();}).attr('src',elem.attr('href'));scrollSlider(thumbid);}
function updateScrollArrows(){var scrollpos=d.slider.scrollLeft();var scrollwidth=d.slider.get(0).scrollWidth;var width=d.slider.width();if(scrollpos==0)
d.slider_prev.removeClass(o.css_active).hide();else
d.slider_prev.addClass(o.css_active).show();if(scrollpos==scrollwidth-width)
d.slider_next.removeClass(o.css_active).hide();else
d.slider_next.addClass(o.css_active).show();}
function scrollSlider(thumbid)
{var position=getScreenshot(thumbid).find('img').position();var width=d.slider.width();var activeid=d.screenshotlinks.attr('id');if(width-position.left<2*(o.thumbnail_width+7))
{d.slider.stop(true,true).animate({scrollLeft:(parseInt(thumbid)+2-Math.floor(width/(o.thumbnail_width+7)))*(o.thumbnail_width+7)},500,function(){updateScrollArrows();});}else
if(position.left<(o.thumbnail_width+7))
{d.slider.stop(true,true).animate({scrollLeft:(parseInt(thumbid)-1)*(o.thumbnail_width+7)},500,function(){updateScrollArrows();});}}
d.slider.disableTextSelect();var i=0;d.screenshotlinks.each(function(){jQuery(this).attr('id',o.screenshot_id_prefix+i);jQuery(this).click(function(){show(jQuery(this).attr('id').substr(11));return false;});i++;});var img=new Image();jQuery(img).load(function(){d.screenshotlinks.each(function(){var img=new Image();jQuery(img).attr('src',jQuery(this).attr('href'));});}).attr('src',jQuery('#'+o.screenshot_id_prefix+'0').attr('href'));d.content_next.mouseleave(function(){d.content_next.removeClass(o.css_hover);d.content_prev.removeClass(o.css_hover);});d.content_prev.mouseleave(function(){d.content_prev.removeClass(o.css_hover);d.content_next.removeClass(o.css_hover);});d.content_next.mouseenter(function(){d.content_next.addClass(o.css_hover);d.content_prev.removeClass(o.css_hover);});d.content_prev.mouseenter(function(){d.content_prev.addClass(o.css_hover);d.content_next.removeClass(o.css_hover);});d.content_prev.click(function(){prevShow();});d.slider_prev.click(function(){slideLeft();});d.slider_next.click(function(){slideRight();});d.slider_prev.mousedown(function(){jQuery(document).stopTime(o.timer_name);jQuery(document).everyTime(250,o.timer_name,function(){slideLeft();});});d.slider_next.mousedown(function(){jQuery(document).stopTime(o.timer_name);jQuery(document).everyTime(250,o.timer_name,function(){slideRight();});});d.slider_prev.mouseup(function(){jQuery(document).stopTime(o.timer_name);});d.slider_next.mouseup(function(){jQuery(document).stopTime(o.timer_name);});d.content_next.click(function(){nextShow();});d.content_prev.height(o.screenshot_height);d.content_next.height(o.screenshot_height);d.content_next.width(Math.floor(o.screenshot_width/2));d.content_prev.width(Math.floor(o.screenshot_width/2));d.media.height(o.screenshot_height);d.screenshotlinks.find('img').height(o.thumbnail_height);d.screenshotlinks.find('img').width(o.thumbnail_width);d.dialog.dialog({title:o.dialog_title,modal:true,resizable:false,width:(o.screenshot_width+36),height:o.screenshot_height+o.thumbnail_height+73,show:'fade',hide:'fade',open:function(){jQuery('#'+o.screenshot_id_prefix+'0').trigger('click');}});};})(jQuery);jQuery(document).ready(function(){jQuery('.screenshots').hide();});
