window.rotatorContentDefault = {};

window.addEvent('domready', function(){
    window.rotatorContentDefault.pages = $$("div.rotatorDefaultPage");
    window.rotatorContentDefault.naviOne = $$("div.rotatorDefaultNavi a");

    window.rotatorContentDefault.naviOne.addEvent('click', function(){
    	j4s.ivwReload();
        var id = window.rotatorContentDefault.naviOne.indexOf( this );
        window.rotatorContentDefault.goTo( id );
    });

    $$('.rotatorDefault').addEvent('mouseover', function(){
        window.rotatorContentDefault.go = false;
    });

    $$('.rotatorDefault').addEvent('mouseout', function(){
        window.rotatorContentDefault.go = true;
        window.rotatorContentDefault.lastD = window.rotatorContentDefault.next.delay( 2500 );
    });

    window.rotatorContentDefault.pages.setStyles({
        opacity: 0,
        display: 'block'
    });
    window.rotatorContentDefault.goTo(0);
    window.rotatorContentDefault.current = -1;
    window.rotatorContentDefault.go = true;
    window.rotatorContentDefault.next();
});

window.rotatorContentDefault.next = function(){
    window.rotatorContentDefault.current++;

    if( window.rotatorContentDefault.lastD )
        $clear( window.rotatorContentDefault.lastD );

    if( !window.rotatorContentDefault.go ) return;

    if( window.rotatorContentDefault.pages[ window.rotatorContentDefault.current ]  ){
        window.rotatorContentDefault.goTo( window.rotatorContentDefault.current );
        window.rotatorContentDefault.lastD = window.rotatorContentDefault.next.delay( 2500 );
    } else {
        window.rotatorContentDefault.current = -1;
        window.rotatorContentDefault.next();
    }
}

window.rotatorContentDefault.goTo = function( pNewId ){
    if( window.rotatorContentDefault.last ){
        window.rotatorContentDefault.last.tween('opacity', 0);
        window.rotatorContentDefault.lastBtn.set('class', '');
    }
    
    window.rotatorContentDefault.pages[ pNewId ].tween('opacity', 1);
    window.rotatorContentDefault.naviOne[ pNewId ].set('class', 'active');
    window.rotatorContentDefault.last = window.rotatorContentDefault.pages[ pNewId ];
    window.rotatorContentDefault.lastBtn = window.rotatorContentDefault.naviOne[ pNewId ];

}
