/**
 * Creator: khastie
 * Date: Jan 28, 2009
 * Time: 11:54:44 AM
 * Contents are property of Cappex.com LLC, and strictly confidential.
 */
 
/** 
 * CLASS: Scattergram
 * DESCR: 
 * USAGE: 
 * EXMPL: 
 */
var Scattergram = new Class({
	
	options : {
		thisURL : null,
		ajaxUrl : null,
		ajaxData : {
			collegeID : null,
			applicationYear : null
		}
	},

	layerIDs : null,
	pointElems : new Array(),
	ajax : Class.empty(),

	initialize : function (options) {

		this.setOptions(options);

		window.addEvent('domready', function () {
			this.domReady();

		}.bind(this));

		this.ajax = new AjaxCpx(this.options.ajaxUrl, {
			evalScripts : true,
			update : 'scattergramArea'
		});

	},

	domReady : function () {

		/* PROD-PATCH 2009-02-06: disable animation
		this.layerIDs = ['pointsStudent', 'pointsOther', 'pointsWaitlisted', 'pointsDenied', 'pointsAccepted', 'pointsAcceptedWillAttend'];

		// load points
		for (var i = 0; i < this.layerIDs.length; i++) {

			this.pointElems.merge($ES('img', this.layerIDs[i]));
		}

		this.renderPoints();
		*/

		// not currently working: this.ajax.buildIndicator('scattergramArea');

		if (this.options.ajaxData.collegeID != null && this.options.ajaxData.collegeID != '') {
			this.loadChart();
		}

		if ($('selectCollege')) {
			$('selectCollege').addEvent('change', function () {
				this.changeCollege($('selectCollege').value);
			}.bind(this));
		}

	},

	loadChart : function () {
		this.ajax.request(this.options.ajaxData);
	},

	renderPoints : function () {

		for (var j = 0; j < this.pointElems.length; j++) {

			var delayMs = j*1678/this.pointElems.length;

			this.revealPoint.delay(delayMs, this, this.pointElems[j]);

		}
		
	},

	revealPoint : function (pointElem) {
		pointElem.style.visibility = 'visible';
	},

	changeCollege : function (collegeID) {

        // update collegeID and force applicationYear to -1
		window.location.href = this.options.thisURL.replace(/collegeID=[0-9]*/g, 'collegeID=' + collegeID).replace(/applicationYear=[\-0-9]*/g, 'applicationYear=-1');

		// old way, via ajax:
		// this.options.ajaxData.collegeID = collegeID;
		// this.loadChart();
	},

	test : function () {

	}
});

Scattergram.implement(new Options);