;(function($){$.fn.slidy=function(settings){if(this.length==0){debug('selector invalid or missing!');return;}else if(this.length>1){return this.each(function(){$.fn.slidy.apply($(this),[settings]);});}
var opt=$.extend({},$.fn.slidy.defaults,settings),$this=$(this),id=this.attr('id'),elements=$this.children(opt.children),quantity=elements.length,images=(opt.children=='img')?elements:elements.find('img'),timer=0,isanimate=false;stopidx=0;if(id===undefined){id='slidy-'+$this.index();$this.attr('id',id);}
$this.data('options',opt).css({'cursor':opt.cursor,'overflow':'hidden','position':'relative'});elements.each(function(i){$(this).css({'position':'absolute','z-index':quantity-i}).attr('id',$this.attr('id')+'-'+(i+1));});if(opt.children=='a'&&opt.target!=''){elements.attr('target',opt.target);}
elements.hide().first().show();if(opt.menu){$menu=$('
',{id:id+'-slidy-menu','class':'slidy-menu'}).insertafter($this);}
var stop=function(){isanimate=false;cleartimeout(timer);},overbanner=function(){stop();},overmenu=function(thiz){stop();var $this=$(this),index=$this.index(),$current=$this.parent().children('.slidy-link-selected'),last=$current.index();stopidx=index;if(index!=last){$current.removeclass('slidy-link-selected');$this.addclass('slidy-link-selected');change(last,index);}},outbanner=function(thiz){go(stopidx);},outmenu=function(){var $this=$(this),index=$this.index(),$current=$this.parent().children('.slidy-link-selected'),last=$current.index();go(last);},clickmenu=function(thiz){stop();var $this=$(this),index=$this.index(),$current=$this.parent().children('.slidy-link-selected'),last=$current.index();if(index!=last){$current.removeclass('slidy-link-selected');$this.addclass('slidy-link-selected');change(last,index);}};if(opt.menu){var target=(opt.target!='')?'target="'+opt.target+'"':'',menu='',parent,img;images.each(function(){img=$(this);parent=img.parent(opt.children);menu+='';});$menu.html(menu);var space=parseint((opt.width/quantity)+(quantity-1)),diff=opt.width-(space*quantity),links=$menu.children('li');if(opt.action=='mouseenter'){links.mouseenter(overmenu).mouseleave(outmenu);}else if(opt.action=='click'){links.click(clickmenu);}else{debug('action attribute must to be "click" or "mouseenter"!');return;}
links.css('width',space).first().addclass('slidy-link-selected').end().last().css({'border-right':'0','width':(space+diff)-(quantity-1)});if(opt.animation=='slide'||opt.animation=='fade'){links.mousemove(function(){var $this=$(this);if(!$this.hasclass('slidy-link-selected')){$this.mouseenter();}});}}
go(0);if(opt.pause){$this.mouseenter(overbanner).mouseleave(outbanner);}
function go(index){var total=quantity-1
if(index>total){index=0;last=total;}else if(index<=0){index=0;last=total;}else{last=index-1;}
change(last,index);timer=settimeout(function(){go(++index);},opt.time);}
function change(last,index){if(!isanimate){isanimate=true;if(opt.animation=='fade'){elements.eq(last).fadeout(opt.speed).end().eq(index).fadein(opt.speed,function(){selectmenu(index);isanimate=false;});}else if(opt.animation=='slide'){elements.css('z-index',0).eq(index).css('z-index',quantity).slidedown(opt.speed,function(){elements.eq(last).hide();selectmenu(index);isanimate=false;});}else{elements.eq(last).hide().end().eq(index).show(0,function(){selectmenu(index);isanimate=false;});}}};function selectmenu(index){if(opt.menu){$this.next('ul.slidy-menu').children().removeclass('slidy-link-selected').eq(index).addclass('slidy-link-selected');stopidx=index;}};return $this;};function debug(message){if(window.console&&window.console.log){window.console.log(message);}};$.fn.slidy.defaults={action:'mouseenter',animation:'normal',children:'img',cursor:'default',menu:false,pause:false,speed:600,target:'',time:3600};})(jquery);