var isExtended = 0;
var height = 155;
var width = 200;
var slideDuration = 150;
var opacityDuration = 150;
var undefined;
var timer2 = new Array();
var timer = new Array();
var currentsidebartab;
var isExtended = new Array();
isExtended["sideBarTab1"] = 0;
isExtended["sideBarTab2"] = 0;

function getstyledimension(styleproperty) {
	pxposition = styleproperty.indexOf('px');
	if (styleproperty == '' || styleproperty == null) {
		//no or blank style dimension
		dimension = 0;
	}
	else if (pxposition == -1) {
		//no px probably an old browser
		dimension = styleproperty;
	}
	else {
		//strip dimension
		dimension = styleproperty.slice(0,pxposition);
	}
	return dimension;
}


function mouseover(sidebartab, sidebarcontents, vheight) {
	 if (vheight == null){
	   vheight = height;
	 }
	if (currentsidebartab == sidebartab) {
	clearTimeout(timer[sidebartab]);
	//isExtended[sidebartab] = 1;
	}
	currentsidebartab = sidebartab;
	//if(isExtended[sidebartab] == 0){
	//if ($(sidebarcontents).style.height.indexOf('20')>=0 || $(sidebarcontents).style.height == ''){
	//if ($(sidebarcontents).style.height.indexOf('20')>=0 || $(sidebarcontents).style.height == ''){
	//window.alert(getstyledimension($(sidebarcontents).style.height));
	if (getstyledimension($(sidebarcontents).style.width) == 20 || getstyledimension($(sidebarcontents).style.width) == 0){
		//expand(sidebartab, sidebarcontents);
		timer2[sidebartab] = setTimeout("expand(" + sidebartab + ", " + sidebarcontents + ", " + vheight + ")", 100);
	}
}

function mouseout(sidebartab, sidebarcontents) {
	if (currentsidebartab == sidebartab) {
	clearTimeout(timer2[sidebartab]);
	//isExtended[sidebartab] = 1;
	}
	currentsidebartab = sidebartab;
	//window.alert($(sidebarcontents).style.height.indexOf('100'));
	//if ($(sidebarcontents).style.height.indexOf('100')>=0){
	//if ($(sidebarcontents).style.height.indexOf('20')==-1 || $(sidebarcontents).style.height != ''){
	if (getstyledimension($(sidebarcontents).style.width) > 20){
	//if(isExtended[sidebartab] == 1){
	timer[sidebartab] = setTimeout("contract(" + sidebartab + ", " + sidebarcontents + ")", 175);
	isExtended[sidebartab] = 0;
	//window.alert($(sidebarcontents).style.height);
	}
}




function expand(sidebartab, sidebarcontents, vheight) {
		sideBarSlide(vheight, vheight, 0, width, sidebartab, sidebarcontents);
		
		sideBarOpacity(0, .9, sidebartab, sidebarcontents);
	
		isExtended[sidebartab] = 1;
		
		// make expand tab arrow image face left (inwards) but check to make sure that it hasn't already been done
		// $(sidebartab).childNodes[0].src = $(sidebartab).childNodes[0].src.replace(/(\.[^.]+)$/, '-active$1');

}

function contract(sidebartab, sidebarcontents) {
		sideBarSlide(height, height, width, 0, sidebartab, sidebarcontents);
		
		sideBarOpacity(1, 0, sidebartab, sidebarcontents);
		
		isExtended[sidebartab] = 0;
		currentsidebartab = "";
		
		// make expand tab arrow image face right (outwards)
		//$(sidebartab).childNodes[0].src = $(sidebartab).childNodes[0].src.replace(/-active(\.[^.]+)$/, '$1');

}




/*
function extendContract(sidebartab, sidebarcontents){
	if(isExtended[sidebartab] == 0){
		sideBarSlide(0, height, 0, width, sidebartab, sidebarcontents);
		
		sideBarOpacity(0, 1, sidebartab, sidebarcontents);
	
		isExtended[sidebartab] = 1;
		
		// make expand tab arrow image face left (inwards)
		$(sidebartab).childNodes[0].src = $(sidebartab).childNodes[0].src.replace(/(\.[^.]+)$/, '-active$1');
		
	}
	else{
		
		sideBarSlide(height, 20, width, 0, sidebartab, sidebarcontents);
		
		sideBarOpacity(1, 0, sidebartab, sidebarcontents);
		
		isExtended[sidebartab] = 0;
		window.alert(isExtended[sidebartab]);
		// make expand tab arrow image face right (outwards)
		
		$(sidebartab).childNodes[0].src = $(sidebartab).childNodes[0].src.replace(/-active(\.[^.]+)$/, '$1');
	}

}
*/

function sideBarSlide(fromHeight, toHeight, fromWidth, toWidth, sidebartab, sidebarcontents){
		var myEffects = new Fx.Styles(sidebarcontents, {duration: slideDuration, transition: Fx.Transitions.linear});
		myEffects.custom({
			 'height': [fromHeight, toHeight],
			 'width': [fromWidth, toWidth]
		});
}

function sideBarOpacity(from, to, sidebartab, sidebarcontents){
		var myEffects = new Fx.Styles(sidebarcontents, {duration: opacityDuration, transition: Fx.Transitions.linear});
		myEffects.custom({
			 'opacity': [from, to]
		});
}

function init(){
	//$('sideBarTab').addEvent('click', function(){extendContract()});
	window.alert=("ddd");
}

window.addEvent('load', function(){init()});