
$(document).ready(function(){var captionTimeout;var mouseoverslideshow=false;var disableclick=false;$('.slide-show').each(function(){transition_time=500;slides_html=$(this).html();if(slides_html!=='')
{$(this).html('<div class="slide-area">'+slides_html+'</div');$(this).children('.slide-area').children('img').addClass('slide');area_width=$(this).children('.slide-area').width();area_height=$(this).children('.slide-area').height();slide_amount=$(this).children('.slide-area').children('.slide').size();$(this).children('.slide-area').children('.slide').css({'display':'none'});$(this).children('.slide-area').children('.slide:first').css({'display':'block'});showCaption($(this).children('.slide-area').children('.slide:first'));if(slide_amount>1)
{$(this).append('<a href="#previous-slide" class="slide-prev"><span>Edellinen</span><span class="slide-prev-area">&nbsp;</span></a>');$(this).append('<a href="#next-slide" class="slide-next"><span>Seuraava</span><span class="slide-next-area">&nbsp;</span></a>');i=0;tab_links='';while(i<slide_amount)
{i++;tab_links+='<a href="#"><span>'+i+'</span></a>';}
$(this).append('<div class="slide-tabs">'+tab_links+'</div>');$(this).children('.slide-tabs').children('a').eq(0).addClass('slide-current');$(this).queue(function(){moveButtonState(this,'reset')});}}});function showCaption(source)
{caption='';if(source.is('img'))
{caption=source.attr('title');}
else
{caption=source.find('img').attr('title');}
if(typeof caption=='undefined'){caption='';};if(caption!=='')
{if(source.is('a'))
{caption_link=source.attr('href');caption_html='<div class="slide-caption">'+'<div class="slide-caption-background">&nbsp;</div>'+'<a href="'+caption_link+'" class="slide-caption-content">'+caption+'</a>'+'</div>';}
else
{caption_html='<div class="slide-caption">'+'<div class="slide-caption-background">&nbsp;</div>'+'<div class="slide-caption-content">'+caption+'</div>'+'</div>';}
source.parent().after(caption_html);source.parent().siblings('.slide-caption').fadeIn(200,function(){source.parent().siblings('.slide-caption').children('.slide-caption-content').css({'visibility':'visible'});});}}
function hideCaption(parent)
{$(parent).siblings('.slide-caption').remove();}
function slidesMove(parent,direction,duration,seek_target,seek_origin)
{hideCaption(parent)
if(captionTimeout)
{clearTimeout(captionTimeout);}
cur_index=$(parent).children('.slide:visible').index();last_index=$(parent).children('.slide:last').index();if(seek_target==parseInt(seek_target))
{if(seek_origin==parseInt(seek_origin))
{seek_origin=seek_origin;}
else
{seek_origin=cur_index;}
seek_distance=seek_target-seek_origin;move_duration=Math.floor(duration/Math.abs(seek_distance));if(cur_index<seek_target)
{direction='next';}
else if(cur_index>seek_target)
{direction='prev';}
else
{direction='auto';}}
else
{seek_target=false;seek_origin=false;move_duration=duration;}
if(cur_index==0&&direction=='prev')
{new_index=last_index;}
else if(cur_index==last_index&&direction=='next')
{new_index=0;}
else if(direction=='prev')
{new_index=cur_index-1;}
else if(direction=='next')
{new_index=cur_index+1;}
else
{}
if(seek_target==new_index)
{seek_target=false;seek_origin=false;}
if(direction=='next')
{move_by=area_width*-1;}
else if(direction=='prev')
{move_by=area_width;}
else
{move_by=0;}
$(parent).children('.slide').eq(new_index).css({'left':move_by*-1,'display':'block'})
$(parent).children('.slide:visible').each(function(){this_pos=parseInt($(this).css('left'));new_pos=this_pos+move_by;$(this).stop(false,true).animate({left:new_pos},move_duration,function(){$(parent).children('.slide').eq(cur_index).css({'display':'none','left':0});$(parent).siblings('.slide-tabs').children('a').eq(cur_index).removeClass('slide-current');$(parent).siblings('.slide-tabs').children('a').eq(new_index).addClass('slide-current');moveButtonState($(parent).parent(),'reset');if(seek_target==false)
{disableclick=false;}});});captionTimeout=setTimeout(function()
{showCaption($(parent).children('.slide').eq(new_index));},move_duration+150);if(seek_target==parseInt(seek_target))
{var t;t=setTimeout(function()
{slidesMove(parent,'auto',duration,seek_target,seek_origin);},move_duration+50);}}
function moveButtonState(root,change)
{fadeDuration=100;reset=false;set_next='';set_prev='';if(change=='reset')
{reset=true;if(mouseoverslideshow==false)
{change='hide';}
else if(mouseoverslideshow==true)
{change='show';}}
if($(root).hasClass('show-prev-next')||reset==true)
{if(change=='show'||$(root).hasClass('show-prev-next'))
{change_next='displayBlock';change_prev='displayBlock';}
else if(change=='hide')
{change_next='displayNone';change_prev='displayNone';}}
else
{if(change=='show')
{change_next='fadeIn';change_prev='fadeIn';}
else if(change=='hide')
{change_next='fadeOut';change_prev='fadeOut';}}
if($(root).hasClass('stop-at-end')&&$(root).children('.slide-tabs').children('a:last').hasClass('slide-current'))
{if($(root).hasClass('hide-disabled'))
{change_next='displayNone';}
set_next='disabled';}
else if($(root).hasClass('stop-at-end')&&$(root).children('.slide-tabs').children('a:first').hasClass('slide-current'))
{if($(root).hasClass('hide-disabled'))
{change_prev='displayNone';}
set_prev='disabled';}
if(change_next=='fadeIn')
{$(root).children('.slide-next').fadeIn(fadeDuration);}
else if(change_next=='fadeOut')
{$(root).children('.slide-next').fadeOut(fadeDuration);}
else if(change_next=='displayBlock')
{$(root).children('.slide-next').css({'display':'block'});}
else if(change_next=='displayNone')
{$(root).children('.slide-next').css({'display':'none'});}
else
{}
if(change_prev=='fadeIn')
{$(root).children('.slide-prev').fadeIn(fadeDuration);}
else if(change_prev=='fadeOut')
{$(root).children('.slide-prev').fadeOut(fadeDuration);}
else if(change_prev=='displayBlock')
{$(root).children('.slide-prev').css({'display':'block'});}
else if(change_prev=='displayNone')
{$(root).children('.slide-prev').css({'display':'none'});}
else
{}
if(set_next=='disabled')
{$(root).children('.slide-next').addClass('slide-next-disabled');}
else
{$(root).children('.slide-next').removeClass('slide-next-disabled');}
if(set_prev=='disabled')
{$(root).children('.slide-prev').addClass('slide-prev-disabled');}
else
{$(root).children('.slide-prev').removeClass('slide-prev-disabled');}}
$('.slide-show').mouseenter(function(){mouseoverslideshow=true;moveButtonState(this,'show');});$('.slide-show').mouseleave(function(){mouseoverslideshow=false;moveButtonState(this,'hide');});$('.slide-next').click(function(event){event.preventDefault();if(!$(this).hasClass('slide-next-disabled')&&disableclick==false)
{slidesMove($(this).siblings('.slide-area'),'next',transition_time);disableclick=true;}});$('.slide-prev').click(function(event){event.preventDefault();if(!$(this).hasClass('slide-prev-disabled')&&disableclick==false)
{slidesMove($(this).siblings('.slide-area'),'prev',transition_time);disableclick=true;}});$('.slide-tabs').children('a').click(function(event){event.preventDefault();if(disableclick==false)
{seek_index=$(this).index();slidesMove($(this).parent().siblings('.slide-area'),'auto',transition_time,seek_index,false);disableclick=true;}});});
