var vCarousel = new Class({
	initialize: function(pEl, up, dn, options) {
		this.container = pEl;
		this.options = options;
		this.subelems = $(pEl).getChildren();
		this.intelems = this.subelems.getChildren();
		this.itemHeight = parseInt(this.intelems[0].getStyle('height')) + parseInt(this.intelems[0].getStyle('margin-bottom'));
		this.fx = new Fx.Morph(pEl,{duration: 1500, unit: 'px'});
		this.many = 4;
		this.position = 0;
		this.total = (this.subelems.length - 1);
		
		//Grab, set click and style of up button
		this.btn_up = $(up);
		this.btn_up.addEvent('click', function() {
			this.goUp();
		}.bind(this));
		this.btn_up.setStyles({'cursor': 'default','opacity':.1,'filter':'alpha(opacity=10)'})
		
		//Grab, set click and style of down button
		this.btn_dn = $(dn);
		this.btn_dn.addEvent('click', function() {
			this.goDn();
		}.bind(this));
		this.btn_dn.setStyles({'cursor': 'pointer','opacity':1,'filter':'alpha(opacity=100)'})
	},
	goUp: function() {
		if(this.position == 4) {
			this.position = 0;
			this.fx.start({'margin-top':[-(this.itemHeight * this.many),0]}).chain(function() {
				this.btn_up.setStyles({'cursor': 'default','opacity':.1,'filter':'alpha(opacity=10)'})
				this.btn_dn.setStyles({'cursor': 'pointer','opacity':1,'filter':'alpha(opacity=100)'})
			}.bind(this));
		}
	},
	goDn: function() {
		if(this.position == 0) {
			this.position = 4;
			this.fx.start({'margin-top':[0,-(this.itemHeight * this.many)]}).chain(function() {
				this.btn_dn.setStyles({'cursor': 'default','opacity':.1,'filter':'alpha(opacity=10)'})
				this.btn_up.setStyles({'cursor': 'pointer','opacity':1,'filter':'alpha(opacity=100)'})
			}.bind(this));
		}
	}
});

var NewsTick = new Class({
    initialize: function(elem) {
        this.cur = 0;
        this.fx = [];
        this.container = $(elem);
        this.articles = $$('#'+elem+' p');
        this.articles.each(function(el,i) {
            this.fx[i] = new Fx.Morph(el,{duration: 1500, wait: true});
        }.bind(this));
        this.fx[this.cur].start({'opacity': [0,1]});
        setInterval(function() { this.rotate(); }.bind(this), 7500);
    },
    rotate: function() {
        this.fx[this.cur].start({'opacity':[1,0]});
        if(this.cur == (this.articles.length - 1))
            this.cur = 0;
        else
            this.cur++;
        setTimeout(function() { this.fx[this.cur].start({'opacity':[0,1]}); }.bind(this), 1500);
    }
});


var validate = function(frmID) {
	var req_fields = $$('#'+frmID+' .required');
	var frmError = false;
	req_fields.each(function(el,i) {
		if(el.value == '') {
			el.setStyles({
				'background-color':'#F79239',
				'color': '#000'
			});
			frmError = true;
		} else {
			el.setStyles({
				'background-color':'#FFF',
				'color': '#000'
			});
		}
	});
	
	if(frmError) {
		$('frmErrors').set('html','Unable to send application.  Please correct the required fields marked in <span style="background-color: #F79239; color: #000;">orange</span>.');
	} else {
		if($('applicant_signature').checked == false) {
			$('frmErrors').set('html','Please check the Applicant Signature box above before sending application.');
		} else {
			new Request({
				url: '/php/apply_submission.php',
				method: 'post',
				onRequest: function() {
					$('frmErrors').set('html','<img src="/img/loader.gif" />');
				},
				onSuccess: function(tr) {
					$('frmApplyComp').submit();
				}
			}).send($('frmApply').toQueryString());
		}
	}
}
