var inter = "";
var inter2 = '';

var mainSpeed = 4000;
var sentenceSpeed = 10000;

var verdana = {src: '/swf/verdana.swf'};
sIFR.activate(verdana);

function replaceSifr() {
      sIFR.replace(verdana, {wmode:'transparent',selector: 'h3.sifred',css: ['.sIFR-root { font-weight: normal;color:#273577;line-height:10px;padding:0;margin:0}']});
}
replaceSifr();

function theRotator() {
    $('div#rotator .rot_photo').css('display', 'none');
    $('div#rotator .rot_photo:first').css('display', 'block');
    inter = setInterval('rotate()',mainSpeed);
    $('div.opinion').css('display', 'none');
    $('div.opinion:first').css('display', 'block');
    inter2 = setInterval( 'rotateSeeTo()', sentenceSpeed );
}

function rotate() {
	var current = ($('div#rotator .rot_photo.show') ?  $('div#rotator .rot_photo.show') : $('div#rotator .rot_photo:first'));
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator .rot_photo:first') :current.next()) : $('div#rotator .rot_photo:first'));
        current.css( 'display', 'block' ).removeClass( 'show' );
	next.css('display','none')
	.addClass('show')
        .fadeIn( 1500, function() {
            current.css('display','none');
            current.removeClass('show');
        })
        
        //replaceSifr();
};

function rotateBack() {
	var current = ($('div#rotator .rot.show') ?  $('div#rotator .rot.show') : $('div#rotator .rot:first'));
	var prev = ((current.prev().length) ? ((current.prev().hasClass('show')) ? $('div#rotator .rot:last') :current.prev()) : $('div#rotator .rot:last'));
	prev.css('display','none')
	.addClass('show')
	.css('display','block')
        current.css('display','none')
	.removeClass('show');
}

function nextRotate() {
    resetRotator();
    rotate();
}

function prevRotate() {
    resetRotator();
    rotateBack();
}

function stopRotator() {
    clearInterval( inter );
}

function resetRotator() {
    stopRotator();
    inter = "";
    inter = setInterval('rotate()',mainSpeed);
}

function rotateSeeTo() {
	var current = ( $('div.opinion.show').find('strong').html() != null ) ?  $('div.opinion.show') : $('div.opinion:first');
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.opinion:first') :current.next()) : $('div.opinion:first'));
	next.css('display','none')
	.addClass('show')
	.css('display','block');
        current.css('display','none')
	.removeClass('show');
}

function rotateBackSeeTo() {
	var current = ( $( 'div.opinion.show' ).find( 'strong' ).html() != null ) ? $( 'div.opinion.show' ) : $( 'div.opinion:first' );
	var prev = null;
	var caser = '';
	if( current.prev().length ) {
	    if( current.prev().hasClass( 'show' ) ) {
		prev = $( 'div.opinion:last' );
		caser = '1';
	    } else {
		prev = current.prev();
		caser = '2';
	    }
	} else {
	    prev = $('div.opinion:last');
	    caser = '3';
	}
	var currStr = current.find( '.position' ).html();
	var prevStr = prev.find( '.position' ).html();
	//alert( caser+"\n" + currStr+"\n"+prevStr);
	//var prev = ((current.prev().length) ? ((current.prev().hasClass('show')) ? $('div.opinion:last') :current.prev()) : $('div.opinion:last'));
	//prev.addClass('show').css('display','block');
	prev.css('display','none').addClass('show').css('display','block');
        current.css('display','none').removeClass('show');
}
function stopRotatorSeeTo() {
    $('#pauseRotator').css('display','none');
    $('#resumeRotator').css('display','inline');
    clearInterval( inter2 );
}
function nextRotateSeeTo() {
    resetRotatorSeeTo();
    rotateSeeTo();
}
function prevRotateSeeTo() {
    resetRotatorSeeTo();
    rotateBackSeeTo();
}
function resetRotatorSeeTo() {
    clearInterval( inter2 );
    $('#pauseRotator').css('display','inline');
    $('#resumeRotator').css('display','none');    
    inter2 = "";
    inter2 = setInterval('rotateSeeTo()',sentenceSpeed);
}



