var bannerRotator=(function(){function BannerRotator(){this.init=function(rotator,images,links,animation,navigation){rotator.pic=[];for(var i in images){rotator.pic[i]=new Image();rotator.pic[i].src=images[i];}
rotator.randImgNo=Math.round(Math.random()*i);rotatorContainer=$('<div>');rotatorContainer.css({'background-image':'url("'+rotator.pic[rotator.randImgNo].src+'")','background-position':'right center','width':rotator.width(),'height':rotator.height(),'float':'left'});rotator.append(rotatorContainer);rotator.href=$('<a href="'+links[rotator.randImgNo]+'"></a>');rotator.href.css({'display':'block','position':'relative','border':0});if(navigation==="arrows"){rotator.leftButton=$('<div>');rotator.leftButton.addClass('cl_RotatorLeftButton');rotator.leftButton.attr('id','leftButton');rotator.leftButton.append('<img src="images/rotatorLeftButton.png">')
rotator.leftButton.css({'opacity':'0.5'});rotator.leftButton.stop();rotator.leftButton.mouseover(function(){$(this).stop();$(this).fadeTo(300,1);});rotator.leftButton.mouseout(function(){$(this).stop();$(this).fadeTo(300,0.5);});rotator.leftButton.click(function(){bannerRotator.imageTransation(rotator,animation,'right',1000);rotator.href.attr('href',links[rotator.randImgNo]);rotator.append(rotator.href);});rotator.rightButton=$('<div>');rotator.rightButton.addClass('cl_RotatorRightButton');rotator.rightButton.attr('id','rightButton');rotator.rightButton.append('<img src="images/rotatorRightButton.png">')
rotator.rightButton.css({'opacity':'0.5'});rotator.rightButton.mouseover(function(){$(this).stop();$(this).fadeTo(300,1);});rotator.rightButton.mouseout(function(){$(this).stop();$(this).fadeTo(300,0.5);});rotator.rightButton.click(function(){bannerRotator.imageTransation(rotator,animation,'left',1000);rotator.href.attr('href',links[rotator.randImgNo]);rotator.append(rotator.href);});rotator.href.css({'width':rotator.width()-54*2,'height':rotator.height(),'margin-left':'54px','margin-right':'54px','margin-top':(parseInt(($.browser.version))<8)&&($.browser.msie)?-rotator.height():0});rotator.append(rotator.leftButton);rotator.append(rotator.rightButton);rotator.append(rotator.href);}
if(navigation==="dots"){var dot;rotator.dotsContainer=$('<div>');rotator.dotsContainer.css({'width':rotator.width(),'height':rotator.height(),'margin-top':(parseInt(($.browser.version))<8)&&($.browser.msie)?-rotator.height():0});rotator.dotsContainer.addClass('cl_RotatorDots');rotator.href.css({'width':rotator.width(),'height':rotator.height()-30,'top':-rotator.height()});for(var i in rotator.pic){var dot=$('<img src="images/rotatorDot.png" id="'+i+'">');dot.index=i;if((parseInt(($.browser.version))<8)&&($.browser.msie))dot.css('top',rotator.height()-24);if(rotator.randImgNo!=i){dot.css({'opacity':'0.15','cursor':'pointer'});dot.mouseover(function(){$(this).stop();$(this).fadeTo(300,1);});dot.mouseout(function(){$(this).stop();$(this).fadeTo(300,0.15);});dot.click(function(){dotClickInit(this);});}
rotator.dotsContainer.append(dot);}
rotator.append(rotator.dotsContainer);rotator.append(rotator.href);}
rotator.append(rotator.href);function dotClickInit(obj){var active=$(rotator.selector+" .cl_RotatorDots").children('img#'+rotator.randImgNo);active.mouseover(function(){$(this).stop();$(this).fadeTo(300,1);});active.mouseout(function(){$(this).stop();$(this).fadeTo(300,0.15);});active.fadeTo(300,0.15);active.css({'cursor':'pointer'});active.click(function(){dotClickInit(this);});bannerRotator.imageTransation(rotator,animation,obj.id,1000);$(obj).unbind('mouseover');$(obj).unbind('mouseout');$(obj).unbind('click');$(obj).css({'cursor':'default'});rotator.href.attr('href',links[rotator.randImgNo]);rotator.append(rotator.href);}}
this.imageTransation=function(rotator,type,direction,speed){if(rotator.leftButton)rotator.leftButton.detach();if(rotator.rightButton)rotator.rightButton.detach();if(rotator.dotsContainer)rotator.dotsContainer.detach();rotator.empty();var oldTr=$('<div>'),newTr=$('<div>'),rotatorContainer=$('<div>');var currSrc='',nextSrc='';if(direction==='left'){currSrc=rotator.pic[rotator.randImgNo].src;nextSrc=(rotator.randImgNo+1===rotator.pic.length)?rotator.pic[0].src:rotator.pic[rotator.randImgNo+1].src;rotator.randImgNo++;if(rotator.randImgNo===rotator.pic.length)rotator.randImgNo=0;}else if(direction==='right'){currSrc=rotator.pic[rotator.randImgNo].src;nextSrc=(rotator.randImgNo-1<0)?rotator.pic[rotator.pic.length-1].src:rotator.pic[rotator.randImgNo-1].src;rotator.randImgNo--;if(rotator.randImgNo<0)rotator.randImgNo=rotator.pic.length-1;}else if(parseInt(direction)==direction){currSrc=rotator.pic[rotator.randImgNo].src;nextSrc=rotator.pic[direction].src;rotator.randImgNo=direction;}
if(type==='move'){oldTr.css({'background-image':'url("'+currSrc+'")','background-position':'right center','width':rotator.width(),'height':rotator.height(),'float':'left'});newTr.css({'background-image':'url("'+nextSrc+'")','width':rotator.width(),'height':rotator.height(),'float':'left'});if(direction==='left'){oldTr.animate({'width':'0px'},speed,'easeInOutCubic');}
if(direction==='right'){oldTr.css({'width':'0px','background-image':'url("'+nextSrc+'")'});newTr.css({'background-image':'url("'+currSrc+'")'});oldTr.css({'width':'0px'});oldTr.animate({'width':rotator.width()},speed,'easeInOutCubic');}}else if(type==='fade'){rotatorContainer.css({'background-image':'url("'+currSrc+'")','background-position':'right center','width':rotator.width(),'height':rotator.height()});newTr.css({'opacity':'0','background-image':'url("'+nextSrc+'")','width':rotator.width(),'height':rotator.height(),'float':'left'});newTr.animate({'opacity':'1'},speed,'easeInOutCubic');}
rotatorContainer.css({'width':rotator.width()*2,'height':rotator.height(),'float':'left'});rotatorContainer.append(oldTr);rotatorContainer.append(newTr);rotator.append(rotatorContainer);rotator.append(rotator.leftButton);rotator.append(rotator.rightButton);rotator.append(rotator.dotsContainer);}}
return new BannerRotator();}());
