var hypes=[];jQuery.fn.getHyper=function(){var hypers=this;$(hypers).each(function(i){hypes[i]=[this.href];})}
jQuery.fn.gallery=function(sSpeed,tSpeed,showList,autoStart,tLocation,styling){var gallery=this;var img=[];var currentImage=0;var speed=5000;if(sSpeed)speed=(parseInt(sSpeed,10));var transitionSpeed=400;if(tSpeed)transitionSpeed=(parseInt(tSpeed,10));var take=0;var slideShowActive=false;var firstTime=true;var target='body';if(tLocation)target=tLocation;if(autoStart==true){slideShowActive=true;}
var countDuplicate=0;var galleryStructure='<table id="img-gallery"><tr><td><a class="img-hyp" href=""><img style="display:none"/></a></td></tr><tr><td><ul></ul></td></tr></table>';var started=false;$(gallery).each(function(i){$(this).hide();img[i]=[this.src,this.alt,$(this).attr('longdesc')];this.onload=function(){$(this).remove();}
gallery[gallery.length-1].onload=function(){$(this).remove();start();started=true;}
setTimeout(function(){if(!started)start();},2000)})
function start(){$('.gallery').remove();duplicate=$('#img-gallery').length;for(count_duplicate=0;count_duplicate<duplicate;count_duplicate){$('#img-gallery')[count_duplicate].hide();}
$(target).prepend(galleryStructure);if(showList==true){if(gallery.length>1){$('#img-gallery ul').append('<li><a href="#" id="playstop" title="Porneste/Opreste"> </a></li>');$(img).each(function(i){$('#img-gallery ul').append('<li><a href="#img'+(i+1)+'">'+(i+1)+'</a></li>');})}}
$('#img-gallery ul').hide();$('#img-gallery ul a:not(#playstop)').click(function(){var imgToLoad=$(this).attr('href');imgToLoad=imgToLoad.split('#');imgToLoad=parseInt(imgToLoad[1].substr(3))-1;changeImage(imgToLoad);currentImage=imgToLoad+1;if(slideShowActive==true)$('#img-gallery ul a#playstop').click();return false;})
$('#img-gallery ul a#playstop').toggle(function(){$(this).removeClass('stop');$(this).addClass('play');stopSlideShow();return false;},function(){$(this).removeClass('play');$(this).addClass('stop');startSlideShow();return false;});if(slideShowActive==true){if(gallery.length>1){$('#img-gallery ul a#playstop').addClass('stop');startSlideShow();}}else{$('#img-gallery ul a#playstop').addClass('play');changeImage(0);currentImage=1;$('#img-gallery ul a#playstop').click();}
function changeImage(n,callback){currentImage=n;if(firstTime==true){firstTime=false;switchOver();}else{fadeOutAll();}
function fadeOutAll(){$('#img-gallery img').fadeOut(transitionSpeed,switchOver);}
function switchOver(){$('#img-gallery ul a').removeClass('active');var originalWidth=$('#img-gallery img').width();var originalHeight=$('#img-gallery img').height();$('#img-gallery img').attr('src',img[n][0]).attr('alt',img[n][1]).attr('title',img[n][1]);$('#img-gallery a.img-hyp').attr('href',hypes[n]);var width=$('#img-gallery img').width();var height=$('#img-gallery img').height();if(originalWidth==width&&originalHeight==height){fadeInAll();}else{$('#img-gallery').animate({width:width,height:height},transitionSpeed,fadeInAll);}}
function fadeInAll(){$('#img-gallery img').fadeIn(transitionSpeed);$('#img-gallery ul').fadeIn(transitionSpeed);$('#img-gallery ul a:eq('+(n+1-take)+')').addClass('active');if(callback)callback();if(styling)styling();}}
function startSlideShow(){if(currentImage==gallery.length){currentImage=0;}
window['galleryTimeout']=setTimeout(function(){startSlideShow()},speed)
changeImage(currentImage,function(){eval(galleryTimeout);});currentImage++;slideShowActive=true;}
function stopSlideShow(){slideShowActive=false;clearTimeout(eval(galleryTimeout));}}}