  var xmlhttp = false;

	try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}

	function switchTab(tabId, frameId){
	  var current = document.getElementById('tab_' + currentTab[frameId]);
	  var next = document.getElementById('tab_' + tabId);
	  if(current.className.match('mtab-first')){
	    current.className = 'mbmid mtab-first';
	  }else{
	    current.className = 'mbmid';
	  }
	  if(next.className.match('mtab-first')){
	    next.className = 'mwmid mtab-first';
	  }else{
	    next.className = 'mwmid';
	  }
	  cChildren = current.getElementsByTagName('span');
	  nChildren = next.getElementsByTagName('span');
	  cChildren[0].className = 'mbleft';
	  cChildren[1].className = 'mbright';
	  nChildren[0].className = 'mwleft';
	  nChildren[1].className = 'mwright';
	  currentTab[frameId] = tabId;
	  return false;
	}
	
/*	function replaceContent(tabId, frameId){
		xmlhttp.open("GET", "?ajax=1&tabid=" + tabId);
		xmlhttp.onreadystatechange=function(){
			//alert(xmlhttp.readyState + " " + xmlhttp.status);
			if(xmlhttp.readyState == 4) {
				if(xmlhttp.status == 200 || xmlhttp.status == 302){ // HTTP 302 - Found; in case of Apache response on URL rewrite;
					document.getElementById('frm_' + frameId).innerHTML = xmlhttp.responseText;
				}
			}
		}
		xmlhttp.send(null);
	}*/

	function replaceContent(tabId, frameId){
		var response = null;
		xmlhttp.open("GET", "?ajax=1&tabid=" + tabId);
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200 || xmlhttp.status == 302){
					if(xmlhttp.getResponseHeader("Content-Type") == 'text/xml'){
						response = xmlhttp.responseXML;
					}else{
						alert('Invalid response data!');
						return false;
					}
					//alert(response.childNodes[0].childNodes.length);
					//alert(response.getElementsByTagName('title')[0].childNodes[0].nodeValue);
					document.title = response.getElementsByTagName('title')[0].childNodes[0].nodeValue;
					document.getElementById('frm_' + frameId).innerHTML = response.getElementsByTagName('body')[0].childNodes[0].nodeValue;
				}
			}
		}
		xmlhttp.send(null);
	}
	
	function showConfirm(redirectUri){
	  var conf = document.getElementById('confirm');
	  var confWin = document.getElementById('conf-win');
	  var anchors = confWin.getElementsByTagName('a');
	  conf.style.display = "block";
	  conf.style.width = document.body.scrollWidth + 'px'; // IE returns only window visible width in offsetWidth;
	  conf.style.height = document.body.scrollHeight + 'px'; // IE returns only window visible height in offsetHeight;
	  if (confWin.pageYOffset) {
			confWin.style.top = confWin.pageYOffset + 150 + 'px' ;
	  }else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			confWin.style.top = document.documentElement.scrollTop + 150 + 'px';
	  }else if (document.body) {// all other Explorers
			confWin.style.top = document.body.scrollTop + 150 + 'px';
	  }
	  anchors[0].href = redirectUri;
	}
	
	function hideConfirm(){
	  var conf = document.getElementById('confirm');
	  conf.style.display = "none";
	}

	
	// getPageSize adopted from LyteBox script - http://www.dolem.com/lytebox/
	function getPageSize(){	
		var xScroll, yScroll, windowWidth, windowHeight;
		if (window.innerHeight && window.scrollMaxY) {
			xScroll = document.scrollWidth;
			yScroll = self.innerHeight + self.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else {
			xScroll = document.getElementsByTagName("html").item(0).offsetWidth;
			yScroll = document.getElementsByTagName("html").item(0).offsetHeight;
			xScroll = (xScroll < document.body.offsetWidth) ? document.body.offsetWidth : xScroll;
			yScroll = (yScroll < document.body.offsetHeight) ? document.body.offsetHeight : yScroll;
		}
		if (self.innerHeight) {
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.getElementsByTagName("html").item(0).clientWidth;
			windowHeight = document.getElementsByTagName("html").item(0).clientHeight;
			windowWidth = (windowWidth == 0) ? document.body.clientWidth : windowWidth;
			windowHeight = (windowHeight == 0) ? document.body.clientHeight : windowHeight;
		}
		var pageHeight = (yScroll < windowHeight) ? windowHeight : yScroll;
		var pageWidth = (xScroll < windowWidth) ? windowWidth : xScroll;
		return new Array(pageWidth, pageHeight);
}
	
	
	var first = true;
	var last = false;
	var imgSrc = '';
	var imgAlt = '';
	var cur = -1;
	var catId = 0;
	var catPath = '/slide.php';

	
	function closeSlide(){
		cur = -1;
		document.getElementById('semi-tr-bg').style.display = 'none';
		document.getElementById('slide-bg').style.display = 'none';
		document.getElementById('slide-content').style.display = 'none';
		document.getElementById('close').style.display = 'none';
	}
	
	function showSlide(id){
		var pgSize = getPageSize();
		var trBg = document.getElementById('semi-tr-bg');
		trBg.style.display = 'block';
		trBg.style.width = pgSize[0] + 'px';
		trBg.style.height = pgSize[1] + 'px';
		document.getElementById('slide-bg').style.display = 'block';
		document.getElementById('slide-content').style.display = 'block';
		document.getElementById('close').style.display = 'block';
		catId = id;
		requestXml(catPath + '?catid=' + catId + '&cur=' + cur + '&next=true');
	}
	
	function retrieveContent(){
		var response = null;

		if(xmlhttp.readyState == 4) {
			if(xmlhttp.status == 200 || xmlhttp.status == 302){ // HTTP 302 - Found; in case of Apache response on URL rewrite;
				if(xmlhttp.getResponseHeader("Content-Type") == 'text/xml'){
					response = xmlhttp.responseXML;
				}else{
					alert('Invalid response data!');
					return false;
				}
				first = response.getElementsByTagName('queuestate')[0].getElementsByTagName('first')[0].childNodes[0].nodeValue;
				last = response.getElementsByTagName('queuestate')[0].getElementsByTagName('last')[0].childNodes[0].nodeValue;
				cur = response.getElementsByTagName('image')[0].getElementsByTagName('id')[0].childNodes[0].nodeValue;
				imgSrc = response.getElementsByTagName('image')[0].getElementsByTagName('src')[0].childNodes[0].nodeValue;
				imgAlt = response.getElementsByTagName('image')[0].getElementsByTagName('alt')[0].childNodes[0].nodeValue;
				
				var imgHldr = document.getElementById('img-holder');
				var img = imgHldr.getElementsByTagName('img')[0];
				img.src = imgSrc;
				img.alt = imgAlt;
				if(last == 'true'){
					document.getElementById('forward').style.visibility = 'hidden'; // using visibility, because it remains previous dimensions and image do not slide up;
					imgHldr.getElementsByTagName('a')[0].onclick = emptyEvent;
				}else{
					document.getElementById('forward').style.visibility = 'visible';
					imgHldr.getElementsByTagName('a')[0].onclick = fetchNext;
				}
				if(first == 'true'){
					document.getElementById('back').style.visibility = 'hidden';
				}else{
					document.getElementById('back').style.visibility = 'visible';
				}
			}
		}
	}
	
	function emptyEvent(){
		return false;
	}
	
	function fetchNext(){
		reqUri = catPath + '?catid=' + catId + '&cur=' + cur + '&next=true';
		requestXml(reqUri);
	}
	
	function requestXml(reqStr){
		xmlhttp.open("GET", reqStr);
		
		
		xmlhttp.onreadystatechange=retrieveContent;
		xmlhttp.send(null);
	}
