var check;
var allchecked;
var temp = true;
var lastcat = null;
var childImgCount;
var accord;
var mySliders;

window.onDomReady(function(){
	var acc_tds = document.getElementsByClassName('acc_td');
	var stretchers = document.getElementsByClassName('stretcher');
	
	var childNodes; // All Divs under the containing element
	childImgCount = 0;
	var strContainer = "div.Accordion";
	// Get all Divs within the container
	childNodes = $$(strContainer).getElementsByTagName("img");
	
	for (i = 0; i < childNodes.length; i++)
	{
		// Add the Img to the childDivs array only if it's a shiftDivCell
		if(childNodes[i].tagName.toLowerCase() == "img" && childNodes[i].className.toLowerCase().indexOf("togs") != -1)
		{
			childImgCount++;
		}
	}
	check = new Array(childImgCount);
	mySliders = new Array(childImgCount);
	for(var i = 0; i < childImgCount; i++)
	{
		mySliders[i] = new Fx.Slide("stretcher["+i+"]",{duration: 700, transition: Fx.Transitions.expoOut}).hide();
		check[i] = true;
	}
	allchecked = true;
	
});

function stay_on(cat) {

	if(cat != lastcat || allchecked)
	{
		for(var p = 1; p <= childImgCount; p++)
		{
		
			if(cat == ("cat" + p))
			{
				if(check[p - 1] == false) {
					$('tog'+ p).src=$('tog'+ p).src.replace("plus-", "minus-");
					document.getElementById('text_' + p).style.color = "#6b685f";
				}
				else{
					for(var x = 1; x <= childImgCount; x++)
					{
						if(x == p)
						{
							mySliders[x-1].slideIn();
							check[x-1] = false;
							$('tog'+ x).src=$('tog'+ x).src.replace("plus-", "minus-");
							document.getElementById('text_' + x).style.color = "#51504d";

						}
						else
						{
			 				mySliders[x-1].slideOut();
							check[x-1] = true;
							$('tog'+ x).src=$('tog'+ x).src.replace("minus-", "plus-");
							document.getElementById('text_' + x).style.color= "#6b685f";
						}
					}
					allchecked = false;
				}
			}
		}
	lastcat = cat;		
	}
	else
	{	
		for(var p = 1; p <= childImgCount; p++)
		{
			mySliders[p-1].slideOut();
			$('tog'+ p).src=$('tog'+ p).src.replace("minus-", "plus-");
			document.getElementById('text_'+p).style.color= "#6b685f";
			check[p-1] = true;
		}
		allchecked = true;
		lastcat = null;

	}
}

function openDrawer(index) {
	index = Number(index);
	var temp = index-1;
	document.getElementById("block_"+index).style.display='block'; 
	document.location = "#block_"+index;
 	check[temp]=true;
	stay_on('cat' + index);
}

function checkOpen(cindex)
{
	var temp = check[cindex];
	check[cindex] = false;
	return temp;
}

function stopEvent(e) {
    if (!e) e = window.event;
    if (e.stopPropagation) {
        e.stopPropagation();
    }else{
        e.cancelBubble = true;

    }
}
