var currentBGIndex=0;var slideshowInterval=8000;var slideshowTimer=null;function swap(event){clearTimeout(slideshowTimer);$("div#bg-switcher a").removeClass("on");$(this).addClass("on");if($(this).hasClass('first')){goFirst();}
if($(this).hasClass('second')){goSecond();}
if($(this).hasClass('third')){goThird();}
if($(this).hasClass('fourth')){goFourth();}
event.preventDefault();}
function goFirst(){$("div#bg-switcher a").removeClass("on");$("div#bg-switcher a.first").addClass("on");fadeSlide(1,currentBGIndex);$('p.btns-read-more a img').attr('src','images/btn_read_more.png');$('div#message img').attr('src','images/title_01.png');}
function goSecond(){$("div#bg-switcher a").removeClass("on");$("div#bg-switcher a.second").addClass("on");fadeSlide(2,currentBGIndex);$('p.btns-read-more a img').attr('src','images/btn_read_more.png');$('div#message img').attr('src','images/title_02.png');}
function goThird(){$("div#bg-switcher a").removeClass("on");$("div#bg-switcher a.third").addClass("on");fadeSlide(3,currentBGIndex);$('p.btns-read-more a img').attr('src','images/btn_read_more.png');$('div#message img').attr('src','images/title_03.png');}
function goFourth(){$("div#bg-switcher a").removeClass("on");$("div#bg-switcher a.fourth").addClass("on");fadeSlide(4,currentBGIndex);$('p.btns-read-more a img').attr('src','images/btn_read_more.png');$('div#message img').attr('src','images/title_04.png');}
function fadeSlide(currentIndex,previousIndex){for(var i=1;i<=4;i++){if((i!=currentIndex)&&(i!=previousIndex)){$('#background-img-'+i.toString()).animate({opacity:0.0},50);}}
$('#background-img-'+currentIndex.toString()).css({opacity:0.0}).animate({opacity:1.0},1000);if(currentIndex!=previousIndex){$('#background-img-'+previousIndex.toString()).animate({opacity:0.0},1000);}
currentBGIndex=currentIndex;}
function slideShowUpdate(){var continueTimer=true;switch(currentBGIndex){case 1:goSecond();break;case 2:goThird();break;case 3:goFourth();break;case 4:goFirst();continueTimer=false;break;default:goFirst();break;}
if(continueTimer){slideshowTimer=setTimeout("slideShowUpdate()",slideshowInterval);}}
$(document).ready(function(){switch(currentBGIndex){case 1:goSecond();break;case 2:goThird();break;case 3:goFourth();break;case 4:goFirst();break;default:goFirst();break;}
$("div#bg-switcher a").click(swap);slideshowTimer=setTimeout("slideShowUpdate()",slideshowInterval);});
