//********************
//GENERAL INFO
//------------
//The Shelf v1.1
//By Digital Pen
//LICENSE STATEMENT
//-----------------
//The following code is made available free of cost for non-commercial use and is governed by a GPL license which can be viewed at http://www.gnu.org/licenses/gpl.txt.
//********************

//GLOBAL VARIABLES
var shelf_status = "collapsed"

//GENERAL FUNCTIONS
function curr_top(e) {
	var the_top = parseInt(e.offsetTop);
	
	return the_top;
	}			

function curr_height(e) {
	var the_height = parseInt(e.offsetHeight);
	
	return the_height;
	}

//SHELF FUNCTION
function activate_shelf(action) {
	if (action) {
		if (action == "expand") {
			expand_shelf();
			}
		else if (action == "collapse") {
			collapse_shelf();
			}
		}
	else {
		if (shelf_status == "collapsed") {
			expand_shelf();
			}
		else if (shelf_status == "expanded") {
			collapse_shelf();
			}
		}
	}

//EXPANSION FUNCTION
function expand_shelf() {
	//Establish object variables
	var object_shelf = document.getElementById('shelf');
	var object_shelf_contents = document.getElementById('shelf_contents');
	
	//Shelf calculations
	var curr_height_without_padding = curr_height(object_shelf) - 10; //Do not include the padding calculations.
	var height_to_set = curr_height_without_padding + 20;
	var height_to_set_string = height_to_set + "px;";
	
	var height_limit = curr_top(object_shelf_contents) + curr_height(object_shelf_contents) + 10;
	
	//The shelf loop: continue expansion until all the shelf content is displayed.
	if (height_to_set < height_limit) {
		//Implement height change
		if (navigator.appName == "Microsoft Internet Explorer") {
			object_shelf.style.pixelHeight = height_to_set;
			}
		else {
			object_shelf.style.height = height_to_set_string;
			}
	
		setTimeout('expand_shelf()', 1);
		}
	else {
		shelf_status = "expanded";
		}
	}

//COLLAPSING FUNCTION
function collapse_shelf() {
	//Establish object variables
	var object_shelf = document.getElementById('shelf');
	var object_control_link = document.getElementById('control_link');
	
	//Shelf calculations		
	var curr_height_without_padding = curr_height(object_shelf) - 10; //Do not include the padding in calculations.
	var height_to_set = curr_height_without_padding - 20;
	var height_to_set_string = height_to_set + "px;"
	
	var height_limit = curr_top(object_control_link) + curr_height(object_control_link) - 10;
	
	//The shelf loop: continue expansion until all the shelf content is displayed.
	if (height_to_set > height_limit) {
		//Implement height change
		if (navigator.appName == "Microsoft Internet Explorer") {
			object_shelf.style.pixelHeight = height_to_set;
			}
		else {
			object_shelf.style.height = height_to_set_string;
			}
	
		setTimeout('collapse_shelf()', 1);
		}
	else {
		shelf_status = "collapsed";
		}
	}