
var noticeList = new Array();


//noticeList[0] = ["Faculty Pool Hours","The Franklin Academy Pool is open for all MCSD faculty and staff on Monday, Wednesday, and Friday from 2:45 - 3:45.  Lanes will be put in for lap swim and a free swim area is available for faculty and staff who would like to swim with their small children. A $2 donation for the lifeguard is appreciated.  Please call Jennifer Massaro at Franklin Academy with questions.  See you at the pool!!"];



function ticker () {
    this.state = 'collapse';
    this.holdPattern = false;
    this.position = {};
    this.width = 0;
    this.height = 0;
    return true;
}

ticker.prototype = {
    constructor : ticker,
    toggleState : function (event) {
	var thisRef = event.data.contextObj;
	$('#tickerContainer').clearQueue();
	if (thisRef.state == 'collapse') {	    
	    thisRef.position = $('#tickerWrap').offset();
	    thisRef.width = $('#tickerWrap').width();
	    thisRef.height = $('#tickerWrap').height();
	    $('#tickerWrap').width(thisRef.width);
	    $('#tickerWrap').css('position','absolute');
	    $('#tickerWrap').css('top',thisRef.position.top);
	    $('#tickerWrap').css('left',thisRef.position.left);
	    $('#tickerWrap~img:first').before($("<div class='tSpacer'>&nbsp;</div>"));
	    $('.tSpacer').height(thisRef.height);
	    thisRef.state = 'expand';
	    thisRef.holdPattern = true;
	    var pelem = $('<p id="tickerExtra">' + event.data.text + '</p>');
	    $('#tickerContainer').append(pelem);
	    var finalHeight = pelem.height() + 60;
	    $('#tickerContainer').animate({ height: finalHeight},1250);
	    $('#moreLink').empty().append('Click to Close');
	} else {
	    thisRef.holdPattern = 'RESET';
	    thisRef.state = 'collapse';
	    $('#tickerContainer').animate({height:40},1250, null, function() {
		    $("#tickerExtra").remove();
		    $(".tSpacer").remove();
		    $('#tickerWrap').css('position','relative');
		    $('#tickerWrap').css('top',0);
		    $('#tickerWrap').css('left',0);
		});
	    $('#moreLink').empty().append('Click to Read More');
	    
	}
    },
    populateNotice : function(noticeText) {
	$('.popper').effect('puff');
	var elem = $('<div class="popper"><span id="tickerTitle">' + noticeText[0] + '</span></div>');
	$('#tickerContainer').empty();
	$('#tickerContainer').append(elem);
	$('.popper').show('fast',function () {
		$('#tickerContainer').effect('highlight',{color:'#ff0000'},2500);
	    });
	$("#moreLink").unbind('click');
	$("#moreLink").bind('click',{text:noticeText[1],contextObj:this},this.toggleState);
    },
    spinGears : function () {
	if (this.holdPattern == false && this.state != 'expand') {
	    if (this.noticeIndex == undefined) {
		this.noticeIndex = 0;
	    }
	    if (this.noticeIndex >= noticeList.length) {
		this.noticeIndex = 0;
	    }
	    this.populateNotice(noticeList[this.noticeIndex]);
	    this.noticeIndex ++;	
	} else if (this.holdPattern == 'RESET') {
		this.holdPattern = false;
	}
    }
}

var statTicker;

    var tickerEnable = false;

$(document).ready(function() {
	if (tickerEnable == true) {
	    statTicker = new ticker();
	    if (noticeList.length > 1) {
		statTicker.timer = setInterval("statTicker.spinGears()",10000);
	    }
	    statTicker.noticeIndex = 1;
	    statTicker.populateNotice(noticeList[0]);
	} else {
	    $('#tickerWrap').hide();
	}
    });