var request = null;
if (window.XMLHttpRequest) {
  // If IE7, Mozilla, Safari, and so on: Use native object.
  request = new XMLHttpRequest();
}
else
{
  if (window.ActiveXObject) {
     // ...otherwise, use the ActiveX control for IE5.x and IE6.
     request = new ActiveXObject('MSXML2.XMLHTTP.3.0');
  }
}


function addclass(el,ch)
{
$('#'+el.id+'').addClass(ch);
}

function removeclass(el)
{
$('#'+el.id+'').removeClass();
}

function galleryOn()
{
var sw = $('#paslepts1').length;
//alert(sw);
if(sw<1)
{
taimer("galleryOn()",500);
}
else
{
taimer("subgalleryOn()",100);
taimer("galleryShow()",200);
}
}


function galleryOn2()
{
var alrt = $('#paslepts2').length;
galleryhide();
if(alrt<1)
{
taimer("galleryOn2()",500);
}
else
{
taimer("loadGallery()",100);
taimer("galleryShow()",200);
}
}

function loadGallery()
{
$('#gallery a').lightBox();
}
function loadGallerydz()
{
$('#dzerieni_c a').lightBox();
}
function loadGalleryed()
{
$('#edieni_c a').lightBox();
}

function loadGallerysh()
{
$('#shodien_c a').lightBox();
$('#lit_pirmais').click();
}

function loadGalleryc()
{
$('#piejums a').lightBox();
}

function click_pirmais()
{
$('#lit_pirmais').click();
}


function galleryShow()
{
document.getElementById("gallery").style.display = "block";
}

function galleryhide()
{
document.getElementById("gallery").style.display = "none";
}

function imguploadShow()
{
$("#fadeinimgupload").show("slow");
}


function taimer(vertiba,laiks)
{
var t=setTimeout(vertiba,laiks);
}



function ajaxSwitch(content) {
var url = "swich.php?showit=" + content;
request.open("POST", url, true);
request.onreadystatechange = go;

request.send(null);

                    if(content == "galerija")
            {
                galleryOn(); 
            }  

}





function go() {
  if (request.readyState == 4) {
	  if (request.status == 200) {
		var response = request.responseText;
       // alert(response);
		//document.getElementById("content").innerHTML = response;          
		document.getElementById("gallery").innerHTML = response;          
	  }
  }
}


function ajaxSwitch2(content) {
var url = "center/galswich.php?galleryshow=" + escape(content);
request.open("POST", url, true);
request.onreadystatechange = go2;
request.send(null);
}

function go2() {
  if (request.readyState == 4) {
	  if (request.status == 200) {
		var response = request.responseText;
        //alert(response);
		document.getElementById("gallery").innerHTML = response;
	  }
  }
}

function subgalleryOn()
{
	var aTags=document.getElementById('galthumbs').getElementsByTagName('a');
	for (i=0; i<aTags.length; i++) {
		aTags[i].onclick=function() {
			var show=this.href.split('gallery=')[1];
            ajaxSwitch2(show);
            galleryOn2();

            return false;                      
                                    }
                                    }
}






