
var TimeToFade = 300; // ms

var ISSAFARI4 = $.browser.safari && $.browser.version > 3;


// AnimatedBrowser.js
function DynamicBrowsePageContainer(id) {
	this.children=new Array();
	this.currentIndex=0;
	this.id=id;
}

DynamicBrowsePageContainer.prototype.id;
DynamicBrowsePageContainer.prototype.children;
DynamicBrowsePageContainer.prototype.currentIndex;

DynamicBrowsePageContainer.prototype.showCurrentOnly=function() {
	var i;
	for (i=0; i<this.children.length; i++) {
		if (i!=this.currentIndex) {
			this.children[i].close();
		}
	}
	this.displayCurrent();
};

DynamicBrowsePageContainer.prototype.displayCurrent=function() {
	this.children[this.currentIndex].open();
	
	var firstVisible=true;
	var lastVisible=true;
	var nextVisible=true;
	var previousVisible=true;
	
	if (this.currentIndex==0) {
		firstVisible=false;
		previousVisible=false;
	} else if (this.currentIndex==this.children.length-1) {
		lastVisible=false;
		nextVisible=false;
	}
	
	this.setVisibility(firstVisible,"browseToFirst_");
	this.setVisibility(lastVisible,"browseToLast_");
	this.setVisibility(nextVisible,"browseForward_");
	this.setVisibility(previousVisible,"browseBackward_");
}

DynamicBrowsePageContainer.prototype.setVisibility=function(status,prefix) {
	if (status==true) {
		showElementById(prefix+this.id);
	} else if (status==false) {
		hideElementById(prefix+this.id);
	}
}



DynamicBrowsePageContainer.prototype.addChild=function(c) {
	this.children.push(c);
	c.parent=this;
	
	if (this.children.length > 1) {
		$('#'+c.id).css({
		zoom: 1,
		top: 0,
		left: 0,
		display: 'none'
		});
	}

	// and make the 2*parent as tall as c...
	//alert(elem.parentNode.parentNode.clientHeight + " : " + elem.clientHeight);
	//if (this.clientHeight < elem.clientHeight) {
	//	this.height = elem.clientHeight;
	//}
};

DynamicBrowsePageContainer.prototype.displayLast=function() {
	this.children[this.currentIndex].close();
	this.currentIndex=this.children.length-1;
	this.displayCurrent();
};

DynamicBrowsePageContainer.prototype.displayFirst=function() {
	this.children[this.currentIndex].close();
	this.currentIndex=0;
	this.displayCurrent();
};

DynamicBrowsePageContainer.prototype.displayNext=function() {
	if (this.currentIndex<this.children.length-1) {
		this.children[this.currentIndex].close();
		this.currentIndex++;
		this.displayCurrent();
	}
};

DynamicBrowsePageContainer.prototype.displayPrevious=function() {
	if (this.currentIndex>0) {
		this.children[this.currentIndex].close();
		this.currentIndex--;
		this.displayCurrent();
	}
};

function DynamicBrowsePage(id) {
	this.id=id;
}

DynamicBrowsePage.prototype.parent;
DynamicBrowsePage.prototype.id;

DynamicBrowsePage.prototype.open=function() {
//	showElementById(this.id);

	if (ISSAFARI4)
		$('#'+this.id).show();
	else
		$('#'+this.id).css({position: 'static'}).fadeIn(TimeToFade);
};

DynamicBrowsePage.prototype.close=function() {
//	hideElementById(this.id);

	if (ISSAFARI4)
		$('#'+this.id).hide();
	else
		$('#'+this.id).css({position: 'absolute'}).fadeOut(TimeToFade);
};
