// JavaScript Document
Portfolio = function () {
	
	this.portfolioIsOpen = false;
	this.portfolioOpenX = 0;
	this.portfolioCloseX = -350;
	this.portfolioX = this.portfolioCloseX;
	this.arDimensions;
	this.portfolioDiv = $('portfolio');

	this.opener = new Animator( this.portfolioCloseX, this.portfolioOpenX, this.setPosition, this.createContextFunction("show"));
	this.opener.setType(Animator.prototype.EASEOUT);
	this.opener.setStep(4);
	this.closer = new Animator( this.portfolioOpenX, this.portfolioCloseX, this.setPosition, this.createContextFunction("hide"));
	this.closer.setType(Animator.prototype.EASEOUT);
	this.closer.setStep(5);

	this.OPEN    = 0;
	this.OPENING = 1;
	this.CLOSED  = 2;
	this.CLOSING = 3;
	this.state = this.CLOSE;
}
Portfolio.prototype.toggle = function () {
	if (this.state == this.OPENING || this.state == this.OPEN) {
		if (this.state == this.OPENING) this.opener.stop();//cancel opening menu
		this.closer.start();
		this.state = this.CLOSING;
	} else {
		this.opener.start();
	}
}
Portfolio.prototype.enter = function () {
	if (this.entering) return;
	if (this.state != this.CLOSED) return;
	this.entering = setTimeout(this.createContextFunction("doEnter"),500);
}
Portfolio.prototype.doEnter = function () {
	this.entering = null;
	if (this.state == this.CLOSED) {
		setTimeout(this.createContextFunction("goEnter"), 300);
		this.state = this.OPENING;
	}
}
Portfolio.prototype.goEnter = function () {
	/* document.getElementById("dropdown").style.display = "block";
	document.getElementById("eventarea").style.display = "block"; */
	this.opener.start();
}
Portfolio.prototype.show = function() {
	this.state = this.OPEN;
}
Portfolio.prototype.leave = function () {
	if (this.entering) {
		clearTimeout(this.entering);
		this.entering = null;
	}
	if (this.state == this.OPENING || this.state == this.OPEN) {
		if (this.state == this.OPENING) this.opener.stop();//cancel opening menu
		this.closer.start();
		this.state = this.CLOSING;
	}
}
Portfolio.prototype.hide = function () {
	/* document.getElementById("eventarea").style.display = "none";
	document.getElementById("dropdown").style.display = "none";
	var menus = document.getElementById("navigation").menus;
	for (var i=0; i < menus.length; i++) {
		menus[i].submenu.className = "closed";
		menus[i].className = "";
	} */
	this.state = this.CLOSED;
}
Portfolio.prototype.setPosition = function (value) {
	$('portfolio').style.left = value + 'px';
}
Portfolio.prototype.resize = function() {
	this.arDimensions = getWindowsDimensions();
	this.setPosition( this.state == this.OPENING || this.state == this.OPEN ? this.portfolioOpenX : this.portfolioCloseX );
}
Portfolio.prototype.openItem = function( page, viewindex, row ) {
	var url = '/inlineSnippetView.cfm?page='+page+'&viewIndex='+viewindex+'&p='+row;
	if (viewindex > 0) {
		//ColdFusion.navigate( url ,'book_'+viewindex);
		ColdFusion.navigate( url ,'book_'+viewindex);
	}	
}
Portfolio.prototype.createContextFunction = function (method) {
	var context = this;
	return (function(){
		eval("context."+method+"()");
		return false;
    });
}
