﻿var _animateDelay=600;
var _curObj=null;
var _curIdx=1;;
var _nextIdx;
var _switchFinished=true;
function switchToThis(nextObj,nextIdx){
if(_curObj==nextObj)return;
if(_switchFinished==false){
$($(".switch_banner")[_curIdx-1]).stop().addClass("hide").hide();;
$($(".switch_banner")[_nextIdx-1]).stop().removeClass("hide").show();
switchFinished();}
_switchFinished=false;
if(_curObj!=null){
$(_curObj).parent().removeClass("on");}else{
$(".switcher .on").removeClass("on");}
$(nextObj).parent().addClass("on");
nextObj.blur();_curObj=nextObj;
_nextIdx=nextIdx;
$($(".switch_banner")[_nextIdx-1]).fadeTo(0,0);
fadeOutCurBanner();}
function fadeOutCurBanner(){
$($(".switch_banner")[_curIdx-1]).fadeTo(_animateDelay,0,fadeInNextBanner);}
function fadeInNextBanner(){
$($(".switch_banner")[_curIdx-1]).addClass("hide").hide();
$($(".switch_banner")[_nextIdx-1]).stop().removeClass("hide").show();
$($(".switch_banner")[_nextIdx-1]).fadeTo(_animateDelay,.99,switchFinished);}
function switchFinished(){
_curIdx=_nextIdx;
$($(".switch_banner")[_nextIdx-1]).removeClass("hide");
_switchFinished=true;}
var _interval=2000;
var _curWordIdx=1;
var _nextWordIdx=1;
var _tId;
var _wordCount=5;
function swNext(){
$('#word'+_curWordIdx).stop().hide().fadeTo(0,0);
$('#word'+_nextWordIdx).stop().show().fadeTo(0,0.99);
if(_tId!=null){
clearTimeout(_tId);
_tId=null;}
switchWordFinished();}
function swPrev(){
if(_tId!=null){
clearTimeout(_tId);
_tId=null;}
var _temp=_curWordIdx-1;
if(_temp<1)_temp=_wordCount;
$('#word'+_curWordIdx).hide().stop().fadeTo(0,0);
$('#word'+_nextWordIdx).hide().stop().fadeTo(0,0);
$('#word'+_temp).css("opacity","0.99").show();
_nextWordIdx=_curWordIdx-1;
_curWordIdx=_temp-1;
if(_curWordIdx<1)_curWordIdx=_wordCount;
if(_nextWordIdx<1)_nextWordIdx=_wordCount;
switchWordFinished();}
function nextWord(nextObj,nextIdx){
if(nextIdx==undefined){
_nextWordIdx=_curWordIdx+1;}else{
_nextWordIdx=nextIdx;}
$('#word'+_nextWordIdx).fadeTo(0,0,fadeOutCurWord);}
function fadeOutCurWord(){
$('#word'+_curWordIdx).fadeTo(_animateDelay,0,fadeInNextWord);}
function fadeInNextWord(){
$('#word'+_curWordIdx).hide();
$('#word'+_nextWordIdx).show();
$('#word'+_nextWordIdx).fadeTo(_animateDelay,0.99,switchWordFinished);}
function switchWordFinished(){
var _temp=_nextWordIdx+1;
if(_temp>_wordCount){
_temp=1;}
_tId=setTimeout("nextWord(null,"+(_temp)+");",_interval);
if(_nextWordIdx!=null){
_curWordIdx=_nextWordIdx;
_nextWordIdx=_temp;}}
$(document).ready(function(){
$('#s1,#s2,#s3,#s4,#s5').click(function(){switchToThis($(this),$(this).text());});
$('#left_arrow').click(function(){swPrev();});
$('#right_arrow').click(function(){swNext();});
$('#left_arrow').focus(function(){this.blur();})
$('#right_arrow').focus(function(){this.blur();})
$('#word1').show()
switchWordFinished();});
