//funkcja przekirowujaca na strony ocen poszczegolnych marek i/lub modeli
function findMakeGalery(fid){
var xf=document.getElementById(fid);
var loc = "http://www.autocentrum.pl/galerie/";
if(xf.s1.selectedIndex>0)loc+=xf.s1.options[xf.s1.selectedIndex].value+"/";
if(xf.s2.selectedIndex>0)loc+="#"+xf.s2.options[xf.s2.selectedIndex].value;
document.location = loc;
}

//funkcja pobierajaca modele do podanej marki
function getModels(x,node_id,sel_name,class_name){
 plik = "http://"+location.host+"/scripts/gallery/gallery.php?q="+x.getAttribute("makeid");
 el = document.getElementById(node_id);
 xml = null;
 
 try{ 
   xml = new ActiveXObject("Microsoft.XMLHTTP"); // IE
 }catch(e){
  try {
   xml = new XMLHttpRequest(); // Mozilla/FireFox/Opera
  }catch(e){
   xml = null;
  }
 }
 if(xml != null){
  xml.onreadystatechange = function(){
   if(xml.readyState==4){
	  el.innerHTML = "";
		dis="";
		if(!xml.responseText.length) dis = "disabled=\"\"";
    el.innerHTML = "<select name=\""+sel_name+"\" "+dis+" class=\""+class_name+"\"><option value=\"-1\">wybierz</option>"+xml.responseText+"</select>";
   }
  }
  xml.open("GET", plik, true);
  xml.send(null);
 }
 return false;
}



//------------ OBSŁUGA GALERII -----------------------------------------------
var begin = 1;
var end = 1;
var mainpic = 1;
var allthumbs = 0
var base_dir = '';
var thumbs = null;
var noleft = true;
var noright = false;
function moveImg(direction){
  var img1 = document.getElementById('img1');
  var img2 = document.getElementById('img2');
  var img3 = document.getElementById('img3');
  var img4 = document.getElementById('img4');
  if(direction=='up'){
	  if(noright) return false;
	  begin++;
		end++;
  	img1.src = img2.src;
	  img2.src = img3.src;
	  img3.src = img4.src;
	  img4.src = base_dir+thumbs[end]+"_tn.jpg";
  	img1.style.backgroundColor = img2.style.backgroundColor;
	  img2.style.backgroundColor = img3.style.backgroundColor;
	  img3.style.backgroundColor = img4.style.backgroundColor;
		if(mainpic==end) img4.style.backgroundColor = "#265183"; else img4.style.backgroundColor = "";
	}
  if(direction=='down'){
	  if(noleft) return false;
	  begin--;
		end--;
  	img4.src = img3.src;
	  img3.src = img2.src;
	  img2.src = img1.src;
	  img1.src = base_dir+thumbs[begin]+"_tn.jpg";
  	img4.style.backgroundColor = img3.style.backgroundColor;
	  img3.style.backgroundColor = img2.style.backgroundColor;
	  img2.style.backgroundColor = img1.style.backgroundColor;
		if(mainpic==begin) img1.style.backgroundColor = "#265183"; else img1.style.backgroundColor = "";
	}
	if(end==allthumbs) noright = true; else noright = false;//document.getElementById('arrow_right').style.visibility="hidden"; else document.getElementById('arrow_right').style.visibility="";
  if(begin==1) noleft = true; else noleft = false;//document.getElementById('arrow_left').style.visibility="hidden"; else document.getElementById('arrow_left').style.visibility="";
	return false;
}

function loadPhotos(x){
  begin = x;
  document.getElementById('img1').src = base_dir+thumbs[x++]+"_tn.jpg";
  document.getElementById('img2').src = base_dir+thumbs[x++]+"_tn.jpg";
  document.getElementById('img3').src = base_dir+thumbs[x++]+"_tn.jpg";
  document.getElementById('img4').src = base_dir+thumbs[x]+"_tn.jpg";
	end = x;
}

function showImg(x){
  mainpic = begin+x;
  document.getElementById('mainimg').src = base_dir+thumbs[mainpic]+".jpg";
  document.getElementById('img1').style.backgroundColor = "";
  document.getElementById('img2').style.backgroundColor = "";
  document.getElementById('img3').style.backgroundColor = "";
  document.getElementById('img4').style.backgroundColor = "";
	x++;
  document.getElementById('img'+x).style.backgroundColor = "#265183";
  return false;
}

function moveMainPic(direction){
  var img1 = document.getElementById('img1');
  var img2 = document.getElementById('img2');
  var img3 = document.getElementById('img3');
  var img4 = document.getElementById('img4');
  if(direction=='up'){
	  begin++;
		end++;
  	img1.src = img2.src;
	  img2.src = img3.src;
	  img3.src = img4.src;
	  img4.src = base_dir+thumbs[end]+"_tn.jpg";
  	img1.style.backgroundColor = img2.style.backgroundColor;
	  img2.style.backgroundColor = img3.style.backgroundColor;
	  img3.style.backgroundColor = img4.style.backgroundColor;
		if(mainpic==end) img4.style.backgroundColor = "#265183"; else img4.style.backgroundColor = "";
	}
  if(direction=='down'){
	  begin--;
		end--;
  	img4.src = img3.src;
	  img3.src = img2.src;
	  img2.src = img1.src;
	  img1.src = base_dir+thumbs[begin]+"_tn.jpg";
  	img4.style.backgroundColor = img3.style.backgroundColor;
	  img3.style.backgroundColor = img2.style.backgroundColor;
	  img2.style.backgroundColor = img1.style.backgroundColor;
		if(mainpic==begin) img1.style.backgroundColor = "#265183"; else img1.style.backgroundColor = "";
	}
	if(end==allthumbs) document.getElementById('arrow_right').style.visibility="hidden"; else document.getElementById('arrow_right').style.visibility="";
  if(begin==1) document.getElementById('arrow_left').style.visibility="hidden"; else document.getElementById('arrow_left').style.visibility="";
  return false;
}
//------------ OBSŁUGA GALERII -----------------------------------------------















