/* Class to animate properties of elements */

function ResizeLayer(id) {
  this.objectId = id;
  this.object = null;
  this.maxHeight = 220;
  this.minHeight = 32;
  this.divisor = 3;
  this.interval = null;
  this.listeners = new Array();
}
ResizeLayer.prototype.init = function(){
	var element = null;
	
	this.setHeight(this.minHeight);
	
	element = document.getElementById('LoginExposeButton');
	
	if(element) {	
		element.style.cursor = "pointer";
	}

	if(session.isLoggedIn()){
		//document.getElementById('LoginExposeButtonHint').innerHTML = 'Account Centre';
	} else {
		element = document.getElementById('LoginExposeButtonHint');
		
		if(element) {
			element.innerHTML = 'MyViamonde Login';
		}
	}

}
ResizeLayer.prototype.setHeight = function(val){
	this.object = document.getElementById('LoginContainer');

	if(this.object) {
		this.object.style.height = val + 'px';
	}
}
ResizeLayer.prototype.getHeight = function(){
	this.object = document.getElementById('LoginContainer');
	return (this.object) ? this.object.clientHeight : null; 
}
ResizeLayer.prototype.resize = function(){
	var ref = this;
	if(this.getHeight() == this.maxHeight){
		clearInterval(this.interval);
		this.interval = setInterval(function(){ref.animate('close')}, 50);
	} else if(this.getHeight() == this.minHeight){
		clearInterval(this.interval);
		this.interval = setInterval(function(){ref.animate('open')}, 50);
	} 
}
ResizeLayer.prototype.onAnimationComplete = function(process){
	for(var i=0; i<this.listeners.length; i++){
		if(process == 'close'){
			this.listeners[i].onResizeClosed();
		} else {
			this.listeners[i].onResizeOpened();
		}
	}
}
ResizeLayer.prototype.addListener = function(val){
	this.listeners[this.listeners.length] = val;
}
ResizeLayer.prototype.animate = function(process){
	var targetHeight = (process=='close')?this.minHeight:this.maxHeight;
	var currentHeight = this.getHeight();
	
	var jumpBy = (targetHeight - currentHeight) / this.divisor;
	jumpBy = Math.round(jumpBy);
	
	if(jumpBy == 0){
		this.setHeight(targetHeight);
		clearInterval(this.interval);
		this.onAnimationComplete(process);
	} else {
		this.setHeight(currentHeight + jumpBy);
	}
}


/*
	To get over the problem of saved password on load
*/
var CheckSavedPasswords = new (function(){
	this.fields = new Array('LoginUsername', 'LoginPassword');								
	Interface.addListener(this);
	
	this.init = function(){
		for(var i=0; i < this.fields.length; i++){
			var temp = document.getElementById(this.fields[i]);
			if(temp && temp.value != ''){
				temp.style.backgroundImage = 'none';
			}
		}
	}
});