	var nextlist = "";
  var prodsub = new Array();
  prodsub[0] = 0;
  prodsub[1] = -350;
  var curprodsub = 0;
	var margin = 0;
	var langid = 1;
	var products= new Array();
	var prodslist = new Array();	
	var viewall = true;
	var cur = 0;
	var curpage = 0;
	var pages = 5;
	var curprodid = 0;
	var scrolling = false;
	var scrolling2 = false;
	var prodopacity = 10;
	var prodopacity2 = 0; 
	var changinpsub = false;
	
	
window.onload=function() {	

	
	geturl();
	
}


function callfunc(str){
	
	if(!scrolling && !scrolling2){
	eval(str);
	}
	return false;
}
function geturl() {
	
	urlvars = window.location.hash.substring(1).split("&");
	
	if(urlvars.length > 0){
	for(i=0;i<urlvars.length;i++){
		
		var_ = urlvars[i].split("=")[0];
		param_  = urlvars[i].split("=")[1];
		
		if(var_=="aid"){
			
			cid_ = param_.split(",");
			
		} else if (var_=="page") {
			
			page_ = param_;
			
		}
		
		
	}
	
	if( typeof(cid_) != "undefined" ){
			
		id_ = ordfromid(cid_[1]);
		
		
		if(cid_.length > 2){
    	id2_ = 	cid_[2];
			curprodid = id2_;
			
			
		}
		
		
		if(id_ != -1 && cur !=  id_){
			
			curpage = page_;
			langid = cid_[0];
			
			jumptoprod(id_,true);
		 
			
		} else if (curpage !=  page_){
			
			curpage = page_;
			getProducts(products[cur].id,curpage);
			
		} else {
			
			openprod(curprodid);
			
		}

		
	
		
	
		
		
	}
	
	}
	 
	
}

function dyn(curr,dest,speed){
	
	if( typeof(speed) == "undefined" )
	speed = 10;
	speed = Math.abs(Math.abs(curr)-Math.abs(dest))/speed;
  
	
	if(	curr < dest -1){
		
		return curr += speed;	

		
	} else if(	curr > dest + 1) {
		return curr -= speed;	
	 
		
	} else {

    return dest;
  
	}	
	
	
}

function changeprodsub(id,num) {
	
	if(!changinpsub){
		
		if(id==1){
		document.getElementById("prodspeccont").style.height = (100)+"px";
		
		}
		else {
		document.getElementById("prodspeccont").style.height = "auto";	
		}
		document.getElementById("prodspeccont").style.overflow = "hidden";
		changinpsub = true;
	}
	
  speed = Math.abs(Math.abs(num) - Math.abs(prodsub[id]))/10;  
  obj = document.getElementById("selprodscroll2");
  
  
  num = dyn(num,prodsub[id],3)
  
  if( num != prodsub[id]){
  	
  	obj.style.marginLeft = num+"px";	
 		setTimeout("changeprodsub("+id+","+num+")",0);
 		document.getElementById("prodgalcont").style.width = (200-num)+"px";
 		document.getElementById("prodspeccont").style.width = (558+num)+"px";
 		
  } else {
  	
  	changinpsub = false;
		num = prodsub[id];
		curprodsub = id;
    obj.style.marginLeft = num+"px";	
    document.getElementById("prodgalcont").style.width = (200-num)+"px";
 		document.getElementById("prodspeccont").style.width = (558+num)+"px";
  	
  }
		
	
}

function nextpage() {
	
	if(curpage<pages-1){
		

		
		curpage++;
		if(curprodid>0){
		curprodid = -2;
		}
		getProducts(products[cur].id,curpage);
		
		
		
	}	
	return false;
}

function prevpage() {
	
	if(curpage>0){
		
		
		if(curprodid>0){
		curprodid = -1;
		}
		curpage--;

		getProducts(products[cur].id,curpage);
		
	}	
	return false;
}


function ordfromid(id) {
	
for(i=0;i<products.length;i++){
	
	if(products[i].id == id){
		
		return i;
		
	}
	
}
return -1;
}

function ordfromid2(id) {
	
for(i=0;i<prodslist.length;i++){
	
	if(prodslist[i] != null && prodslist[i].id == id){
		
		return i;
		
	}
	
}
return -1;
}




function removeprods(){
	
	obj = document.getElementById("productslist");
	ul  = obj.getElementsByTagName("ul")[0];
	list = obj.getElementsByTagName("li");
	
	if(list.length > 0) {
		
		prodopacity-=1.1;
		setOpacity2(prodopacity,list[list.length-1])
		
		if(prodopacity < 0){
			
		ul.removeChild(list[list.length-1]);
		prodopacity = 10;
		}
		scrolling2 = true;
		setTimeout('removeprods()',0);	
	} else {
		
		addprods(0);
		scrolling2 = false;
		
	}
	
	
}

function addprods(num) {
	
	
	obj = document.getElementById("productslist").getElementsByTagName("ul")[0];	

	list = nextlist.getElementsByTagName("product");
	
	if(num == 0){
		
		
		pages = nextlist.attributes.getNamedItem("pages").value;
		curpage = nextlist.attributes.getNamedItem("curpage").value;
		str2 = "";
		
	  
		
		
		for(i=0;i<prodslist.length;i++){
			
			prodslist[i] = null;		
			
		}
		
		
		for(i=0;i<pages;i++){
			
			
			if( curpage == i ){
			str2 += '<li><p class="active" >'+(i+1)+'</p></li>';
			} else {
								
			str2 += '<li><p>'+(i+1)+'</p></li>';		
					
			}
			
		}
		
		document.getElementById("prodpagelist").innerHTML = str2;
	
		
		
		if(curpage< pages-1){
		setOpacity2(10,document.getElementById("prodnextpage"));
		} else {
			setOpacity2(5,document.getElementById("prodnextpage"));
		}

		if(curpage>0){
		setOpacity2(10,document.getElementById("prodprevpage"));
		} else {
			setOpacity2(5,document.getElementById("prodprevpage"));
		}
		
	
		
		
	}
	if( num < list.length ){	
		
	scrolling2 = true;
	if(prodopacity2 == 0 ){
	
		
	str = '<li style="opacity:0" ><img src="'+list[num].attributes.getNamedItem("src").value+'" />';
	str += '<div><h2>'+list[num].attributes.getNamedItem("title").value+'</h2>';	
	str += '<p>'+list[num].firstChild.nodeValue+'<a onClick="openprod('+list[num].attributes.getNamedItem("id").value+');return false;" href="?cid=1,7,4" class="morelink">mė shumė</a></p></div></li>';	
	
	
	
	
	obj.innerHTML += str;
	

	}
	
	
	if(prodopacity2 < 10){
		
		obj2 = document.getElementById("productslist").getElementsByTagName("li")[num]; 
		prodopacity2+=1.1;
		setOpacity2(prodopacity2,obj2);
	
		
	} else {
		
		prodslist[num] = new Object();
	  prodslist[num].title = list[num].attributes.getNamedItem("title").value;
	  prodslist[num].id = list[num].attributes.getNamedItem("id").value;
		
		num++;
		prodopacity2 = 0;		
  
      	
	}
	
	


	setTimeout('addprods('+num+')',0);	

	
} else {
	
	scrolling2 = false;
	if( curprodid == -2){
		
		
		curprodid = prodslist[0].id;
		openprod(curprodid);
		
		
	}else if( curprodid == -1){
		
		
		curprodid = prodslist[prodslist.length-1].id;
		openprod(curprodid);
		
		
	} else if(curprodid != 0){
		

		openprod(curprodid);
		
		
	}
}


		
	

	
}

function openprevprod() { 
			openprod(prodslist[ord_-1].id);
			return false;
		}
		
		
function opennextprod() { 
	openprod(prodslist[ord_+1].id);
	return false;
}
		
		
function openprod(id,num){	 

	 if(typeof(num) == "undefined" ){
	 	num = viewall? 0:-140;
		array1 = document.getElementById("selprodpath1").getElementsByTagName("a");
		array2 = document.getElementById("selprodpath2").getElementsByTagName("a");

	 curprodid = id;
	 
	 	
   
	
	 array1[0].innerHTML = products[cur].title+" ( "+viewall_lbl+" ) ";
	 array2[0].innerHTML = products[cur].title+" ( "+viewall_lbl+" ) ";
	

	ord_ = ordfromid2(id);	 
	
	if( ord_ > -1 && prodslist[ord_] != null ) {
		
	array1[2].innerHTML = prodslist[ord_].title;	
	array2[2].innerHTML = prodslist[ord_].title;	
	}
	
	array1[1].style.display= "inline";
		array2[1].style.display= "inline";
		
	if( ord_ > 0) {
		
		array1[1].innerHTML = prodslist[ord_-1].title;
		array1[1].onclick = openprevprod;		
		array2[1].innerHTML = prodslist[ord_-1].title;
		array2[1].onclick = openprevprod;
		
		
	} else if (curpage > 0){
		
		array1[1].innerHTML = '( prev page )';
		array1[1].onclick = prevpage;		
		array2[1].innerHTML = '( prev page )';
		array2[1].onclick = prevpage;
		
	}else {
		
		array1[1].innerHTML = '';
		array2[1].innerHTML = '';
		
		array1[1].style.display= "none";
		array2[1].style.display= "none";
	}
	
	if( ord_+1 < prodslist.length && prodslist[ord_+1] != null) {
		
		array1[3].innerHTML = prodslist[ord_+1].title;
		array1[3].onclick = opennextprod;				
		array2[3].innerHTML = prodslist[ord_+1].title;
		array2[3].onclick = opennextprod;		

		
	} else if(curpage<pages-1){
		
		array1[3].innerHTML = '( next page )';
		array1[3].onclick = nextpage;		
		array2[3].innerHTML = '( next page )';
		array2[3].onclick = nextpage;		
		
	}
	else {
		
		array1[3].innerHTML = '';
		array2[3].innerHTML = '';
	}
	
	if(id>0){
	getProdCont(id);
	}
		
	 	
	 }
	 
	 
	 if( id==0){
	 dest =  0;
	   	document.getElementById("productslist").style.display="block";
	 	  	document.getElementById("selprodcontent").style.display="none";
	 	  	
	 } else {
	 	
	 	dest =  -140;
	 }
	
	 obj = document.getElementById("viewall");
	 obj2 = document.getElementById("productscat2");
	 obj3 = document.getElementById("productscat");
	 
	 
	
	 num = dyn(num,dest,3);
	 
	 
	 if( num != dest){
	 	
	 	  obj.style.marginTop = num+"px";
	 	  if(num>-105){
	 	  obj3.style.height = (140+num)+"px";
	 	  obj2.style.height = (140+num)+"px";
	 	  } else {
	 	  	
	 	  	obj3.style.height = 40+"px";
	 	    obj2.style.height = 40+"px";
	 	  }
	 	  setTimeout('openprod('+id+','+num+')',0);
	 	  
	 }	else {
	 	  if(id == 0 ){
	 	  	viewall = true;
	 	  } else {
	 	  	viewall = false;
	 	  }
	 	  
	 	  obj.style.marginTop = dest+"px";
	 	  if(viewall){
	 	  	height_ = 140;
	 	  	document.getElementById("productslist").style.display="block";
	 	  	document.getElementById("selprodcontent").style.display="none";

	 	  } else {
	 	  	height_ = 40;
	 	  	 document.getElementById("productslist").style.display="none";
	 	  	document.getElementById("selprodcontent").style.display="block";
	 	  	
	 	  }
      obj3.style.height = height_+"px";
	 	  obj2.style.height = height_+"px";
	 	  
	 	  if(id==0){
	 	  window.location.hash = "aid="+langid+","+products[cur].id+"&page="+curpage;
	 		} else {
	 			window.location.hash = "aid="+langid+","+products[cur].id+","+id+"&page="+curpage;
	 			
	 		}
	 	  
	 	  
	 	  
	 	  
	 	  
	 }
		

	 
	
	
	
}

	function setOpacity2(value,obj) {
					
			obj.style.opacity = value/10.0;
			obj.style.filter = 'alpha(opacity=' + value*10 + ')';

		}

function jumptoprod(nextid,force){
		
	num = products.length;	

		
		prod_prev = document.getElementById("prodprev");
		prod_next = document.getElementById("prodnext");
		
		if(!scrolling) {
		
		if(!force){
		openprod(0);
		}
		
		if(nextid  > 0 ) {
			setOpacity2(10,prod_prev);
			prod_prev.innerHTML = products[nextid -1].title;
		
		} else {
			setOpacity2(8,prod_prev);
			prod_prev.innerHTML = "";
		}
		

		
		if(products.length >  nextid + 1 ) {
			setOpacity2(10,prod_next);
			prod_next.innerHTML = products[nextid +1].title;
		
		} else {
			setOpacity2(8,prod_next);
			prod_next.innerHTML = "";
		}
		
		document.getElementById("sub"+products[cur].id).className = "";
		
		document.getElementById("sub"+products[nextid].id).className = "active";
		
		getProducts(products[nextid].id,curpage);

		//document.getElementById("productslist").innerHTML = "";
		}
		scrolling = true;
  obj = document.getElementById("scroll");
  dest = -(nextid*570);
	
	margin = dyn(margin,dest);
	if( margin != dest){
		
		obj.style.marginLeft = margin+"px";
		setTimeout('jumptoprod('+nextid+')',0);
		
	} else {
		
		obj.style.marginLeft = margin+"px";
		cur=nextid;		
		scrolling = false;
		

		
	}
	
	
}	

function nextprod(){
curpage = 0;
num = products.length;
if(cur < num-1){
jumptoprod(cur+1);
}

}
function prevprod(){
	curpage = 0;
if(cur > 0){
jumptoprod(cur-1);
}

}	


function getProdCont(id)
{
	
var xmlHttp2;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp2=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp2.onreadystatechange=function()
    {
    	 
    	
    if(xmlHttp2.readyState==4)
      {
      	

  	window.location.hash = "aid="+langid+","+products[cur].id+","+id+"&page="+curpage;
  	var xml = xmlHttp2.responseXML.documentElement;
 		
 	
		document.getElementById("prodspeccont").innerHTML = "";
		document.getElementById("pageno").innerHTML = "";
		document.getElementById("gallery").innerHTML = "";
		
		var gallery = '';
		hastext = false;
		countimg = 0;
		
		
		xmla = xml.childNodes;
		
		for(i=0;i<xmla.length;i++){
		if(xmla[i].nodeName == "img"){
			
				if(countimg>0){
					gallery += '<img style="display:none;width:100%;" id="img'+(countimg+1)+'" src="'+xmla[i].attributes.getNamedItem("src").value+'" />';
				} else {
					gallery += '<img style="width:100%;" id="img'+(countimg+1)+'" src="'+xmla[i].attributes.getNamedItem("src").value+'" />';
				} 
			countimg++;
		}
		if(xmla[i].nodeType == 4){
	
		document.getElementById("prodspeccont").innerHTML = xmla[i].nodeValue;	
		
		}	
		}
		
		
		
			
			
	
		document.getElementById("gallery").innerHTML = gallery;
		var pageno = "";
		
		if(countimg > 0){
		
		pageno	+= '<a id="prevg" style="cursor:pointer" onclick="prevg();return false;" >prev</a>';
		for(i=1;i<=countimg;i++){
				pageno	+=  '<a id="b'+i+'" style="cursor:pointer" onclick="openid('+i+');return false;" >'+i+'</a>';
		}						
		pageno	+= '<a id="nextg" style="cursor:pointer" onclick="nextg();return false;" >next</a>';
		
		document.getElementById("pageno").innerHTML = pageno;
		
		totalgpages = countimg;		
		prevheight = 1;
		curentgpage = 1;
		
			element2 = document.getElementById("b1");
			element2.className = "active";
		}
			
			
		
		
  
      		
      
      
      }
    }
   rand = 6*Math.random();
   xmlHttp2.open("GET","inc/getproducts.php?trip="+rand+"&cid="+langid+","+products[cur].id+","+id,"allAccess");
  

  xmlHttp2.send(null);
  
  }
  
function getProducts(id,page)
{
	
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    	 
    if(xmlHttp.readyState==4)
      {
      	

  	window.location.hash = "aid="+langid+","+id+"&page="+page;
     nextlist = xmlHttp.responseXML.documentElement;
      	removeprods();
      		
    
 
      		
      
      
      }
    }
   rand = 6*Math.random();
  xmlHttp.open("GET","inc/getproducts.php?trip="+rand+"&cid="+langid+","+id+"&page="+page,true);

  xmlHttp.send(null);
  
  }
