﻿var blnSliderMoving = false;
var blnAllSnippetsExpanded = true;
var arrExpandDivs = new Array();

function runDivSliderSetup() {
	var arrDivs = document.getElementsByTagName("div");
	for(var i = 0, len = arrDivs.length; i < len; i++) {
		if(arrDivs[i].className.indexOf("snippet") > -1) {
			arrExpandDivs[arrExpandDivs.length] = arrDivs[i];
			arrDivs[i].setAttribute("orgHeight", (arrDivs[i].offsetHeight + 20));
			arrDivs[i].style.visibility = "visible";
			arrDivs[i].style.height = "0px";
			arrDivs[i].style.overflow = "hidden";
		}
	}
}
	function toggleAllSnippets() {
		if(blnSliderMoving) 
			return;
		for(var i = 0, len = arrExpandDivs.length; i < len; i++) {
			if(blnAllSnippetsExpanded) {
				tmpTo = arrExpandDivs[i].getAttribute("orgHeight");
				height_scroller(arrExpandDivs[i].id, (tmpTo == 0 ? arrExpandDivs[i].getAttribute("orgHeight") : 0), tmpTo, (parseInt(arrExpandDivs[i].getAttribute("orgHeight")) / 12), 6);
			} else {
				tmpTo = 0;
				height_scroller(arrExpandDivs[i].id, (tmpTo == 0 ? arrExpandDivs[i].getAttribute("orgHeight") : 0), tmpTo, (parseInt(arrExpandDivs[i].getAttribute("orgHeight")) / 12), 6);
			}
		}
		blnAllSnippetsExpanded = !blnAllSnippetsExpanded;
	}
	
	function toggleDivSlide(strId, blnIgnoreSliderMoving) {
		if(blnSliderMoving&&!blnIgnoreSliderMoving) { return; }
		tmpTo = (p(g(strId).style.height) == 0 ? g(strId).getAttribute("orgHeight") : 0);
		height_scroller(strId, (tmpTo == 0 ? g(strId).getAttribute("orgHeight") : 0), tmpTo, (parseInt(g(strId).getAttribute("orgHeight")) / 12), 6);
	}
	
	function expandCornerBox(strBoxId, intEndWidth) {
		if(blnSliderMoving) { 
			return; 
		}
		var table = (ns6 ? g(strBoxId).childNodes[1] : g(strBoxId).childNodes[0]);
		var intStart = 0;
		var intEnd = intEndWidth;
		
		if(table.rows[0].cells[1].getAttribute("orgwidth") == table.rows[0].cells[1].offsetWidth) {
			intStart = table.rows[0].cells[1].getAttribute("orgwidth");
		} else {
			intStart = table.rows[0].cells[1].offsetWidth;
			intEnd = table.rows[0].cells[1].getAttribute("orgwidth");
		}
		blnSliderMoving = true;
		
		expandCB(strBoxId, intStart, intEnd, 20, 10);
	}
	
function height_scroller(theelement, startheight, endheight, maxspeed, softness) {
  	var el=document.getElementById(theelement);
  	if (el.offsetHeight != endheight) {
    	var distanceend=Math.abs((endheight - el.offsetHeight) / softness);
    	var distancestart=Math.abs((startheight - el.offsetHeight) / softness);                    
    	var distance=Math.min(distancestart, distanceend);
    	var multiplier;
    	if (distance<1) {
    		multiplier=Math.abs(distance-1)+1;
    	}
    	else { 
    		multiplier=1; 
    	}
    	
    	distance = Math.ceil(distance);
    	
    	if (distance==0) {
    		distance=1; 
    	}
    	if (distance>maxspeed) {
    			distance=maxspeed;
    		}
    	if (startheight > endheight) {
    		distance=-distance;
    	}
    	var tempscrolltop = el.offsetHeight;
    	
    	if (startheight > endheight) {
    		el.style.height = p(el.style.height) + distance + "px";
    	}
    	else {
    		el.style.height = tempscrolltop + distance + "px";
    	}
	    
	    if ((startheight>endheight ? p(el.style.height) > 0 : p(el.style.height) + distance < endheight)) {
	      t=setTimeout('height_scroller(\''+theelement+'\','+startheight+','+endheight+','+maxspeed+','+softness+')',Math.round(20 * multiplier));
	      blnSliderMoving = true;
	    }
	    else {
	    	el.style.height = endheight + "px";
	    	t=null;
	    	//alert(endheight);
	    	blnSliderMoving = false;
	    }
  	} 
  	else {
  		t=null;
  	}
	}
	
	function expandCB(theelement, startheight, endheight, maxspeed, softness) {
		var parentObj = document.getElementById(theelement);
  	var el = (ns6 ? parentObj.childNodes[1] : parentObj.childNodes[0]);
  	el = el.rows[0].cells[1];
  	el = parentObj;
  	
  	if (el.offsetWidth!= endheight) {
    	var distancestart=Math.abs((endheight - el.offsetWidth) / softness);
    	var distanceend=Math.abs((startheight - el.offsetWidth) / softness);  
    	var distance=Math.min(distancestart, distanceend);
    	var multiplier;
    	if (distance<1) {
    		multiplier=Math.abs(distance-1)+1;
    	}
    	else { 
    		multiplier=1; 
    	}
    	
    	distance = Math.ceil(distance);
    	
    	if (distance==0) {
    		distance=1; 
    	}
    	if (distance>maxspeed) {
    		distance=maxspeed;
    	}
    	if (startheight > endheight) {
				distance=-distance;
    	}
    	var tempscrolltop = el.offsetWidth;
    	var xpos = rxposObj(el) - distance;
    	
    	el.style.left = xpos + "px";
    	
    	if (startheight > endheight) {
    		el.style.width = p(el.offsetWidth) + distance + "px";
    	}
    	else {
    		el.style.width = tempscrolltop + distance + "px";
    	}
    	
	    if ((startheight>endheight ? p(el.offsetWidth) > 0 : p(el.offsetWidth) + distance < endheight)) {
	      t=setTimeout('expandCB(\''+theelement+'\','+startheight+','+endheight+','+maxspeed+','+softness+')',Math.round(20 * multiplier));
	    }
	    else {
	    	el.style.width = endheight + "px";
	    	t=null;
	    	blnSliderMoving = false;
	    }
  	} 
  	else {
  		t=null;
  		blnSliderMoving = false;
  	}
	}
	
	function xy_scroller(theelement, startheight, endheight, maxspeed, softness) {
		blnSliderMoving = false;
  	var el=document.getElementById(theelement);
  	if (p(el.style.left) != endheight) {
    	var distanceend=Math.abs((endheight - p(el.style.left)) / softness);
    	var distancestart=Math.abs((startheight - p(el.style.left)) / softness);                    
    	var distance=Math.min(distancestart, distanceend);
    	var multiplier;
    	
    	if(distance<1) {
    		multiplier=Math.abs(distance-1)+1;
    	} else { 
    		multiplier=1; 
    	}
    	
    	distance = Math.ceil(distance);
    	
    	if(distance==0) {
    		distance=1; 
    	}
    	if(distance>maxspeed) {
    			distance=maxspeed;
    		}
    	if(startheight > endheight) {
    		distance=-distance;
    	}
    	
    	var tempscrolltop = p(el.style.left);
    	
    	if(startheight > endheight) {
    		el.style.left = p(el.style.left) + distance + "px";
    	} else {
    		el.style.left = tempscrolltop + distance + "px";
    	}
	    
	    if((startheight < endheight ? p(el.style.left) < 0 : (p(el.style.left) + distance) > endheight)) {
	      t = setTimeout('xy_scroller(\''+theelement+'\','+startheight+','+endheight+','+maxspeed+','+softness+')',Math.round(20 * multiplier));
	      blnSliderMoving = true;
	    }
	    else {
	    	el.style.left = endheight + "px";
	    	t=null;
	    }
  	} 
  	else {
  		t=null;
  	}
	}