/* Init stuff */
// Get window size
if (!is.ie) {
  winH = window.innerHeight;
}
function getMsWindowSize() {    //for IE only, call it after <body> tag
  if (is.ie) {
    if (is.ie7) winH = document.documentElement.offsetHeight-13
    else winH = document.body.offsetHeight-13;
  }
}

// Inits
function StartInit() {
  if (is.ie) getMsWindowSize();
  cdivH = winH-cdivOffset;
}

function EndInit() {
}


/* 'getElementsByClassName' if it isn't supported */
if (!document.getElementsByClassName) document.getElementsByClassName = function(className) {
  var allObj,retObj = new Array(),j=0,testStr;
  if (document.all) allObj = document.all;
  else if (document.getElementsByTagName && !document.all) allObj = document.getElementsByTagName("*");
  for (i=0;i<allObj.length;i++) {
    if (allObj[i].className.indexOf(className)!=-1) {
      testStr = ","+allObj[i].className.split(" ").join(",")+",";
      if (testStr.indexOf(","+className+",")!=-1) {
        retObj[j] = allObj[i];
        j++;
      }
    }
  }
  return retObj;
}


/* Set CSS classes for menus */
// For csc menus
function setCSSClasses(cols1,cols2,cols3) {
	// check parameters
	if (!cols2) cols2 = cols1;
	if (!cols3) cols3 = cols2;
	//get all lists
	alllists = document.getElementsByTagName("ul");
	// select only menu lists
	for (i=0;i<alllists.length;i++) {
		if (alllists[i].className.indexOf("menu-")>-1) {
			// check menu level
			if (alllists[i].className.indexOf("menu-1")>-1) cols = cols1;
			else if (alllists[i].className.indexOf("menu-2")>-1) cols = cols2;
			else  cols = cols3;
			// get all list items
			listitems = alllists[i].getElementsByTagName("li");
			if (listitems.length>0) {
				lastitem = (listitems[listitems.length-1].className=='more')? listitems.length-2 : listitems.length-1;
				// walk through all menu listitems and set CSS classes
				for (j=0;j<listitems.length;j++) {
					if (listitems[j].className!="more") {
						if ((j%cols)==0) {
							if (j==lastitem) {
								listitems[j].className = "firstlast" + listitems[j].className;
							} else {
								listitems[j].className = "first" + listitems[j].className;
							}
						}
						else if ((j%cols)==(cols-1) || j==lastitem) listitems[j].className = "last" + listitems[j].className;
					}
				}
			}
		}
	}
}

// For FAQ menus
function setFaqCSSClasses(cols) {
	//get menu
	allparagraphs = document.getElementsByTagName("p");
	// select only menu lists
	for (i=0;i<allparagraphs.length;i++) {
		if (allparagraphs[i].className.indexOf("category-selector")>-1) {
			// get all items
			allitems = allparagraphs[i].getElementsByTagName("a");
			lastitem = allitems.length-1;
			// walk through all menu items and set CSS classes
			for (j=0;j<allitems.length;j++) {
				if ((j%cols)==0) {
					if (j==lastitem) {
						allitems[j].className = "firstlast" + allitems[j].className;
					} else {
						allitems[j].className = "first" + allitems[j].className;
					}
				}
				else if ((j%cols)==(cols-1) || j==lastitem) allitems[j].className = "last" + allitems[j].className;
			}
		}
	}
}

