var companyCode = '';
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 5000;

// Duration of crossfade (seconds)
var crossFadeDuration = 3;

// Specify the image files
var Pic = new Array();
var SlideShowRunning = false;
var t;
var j = 0;

function startSlideShow() {
	document.getElementById("imageholder").style.visibility = 'hidden';
	document.getElementById("slideShowDiv").style.display='block';
	SlideShowRunning = true;
	runSlideShow();
}

function stopSlideShow() {
	document.getElementById("imageholder").style.visibility = 'visible';
	document.getElementById("slideShowDiv").style.display='none';
	SlideShowRunning = false;
	clearTimeout(t);
}

function runSlideShow() {
   if (document.all){
      document.images.SlideShow.style.filter="blendTrans(duration=2)"
      document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
      document.images.SlideShow.filters.blendTrans.Apply()
   }
   document.images.SlideShow.src = preLoad[j].src
   if (document.all){
      document.images.SlideShow.filters.blendTrans.Play()
   }
   j = j + 1
   if (j > (p-1)) j=0
   t = setTimeout('runSlideShow()', slideShowSpeed)
}

var tabArray = new Array();
tabArray[0] = "advertentie";
tabArray[1] = "fotos";
tabArray[2] = "route";
tabArray[3] = "taxatie";
//tabArray[4] = "history";
tabArray[4] = "reviews";
tabArray[5] = "lease";

function paginateDetails(mode, limit, limitstart) {
	var carId = '';
	if (mode == 'previous') {
		carId = document.advanceSearch.previousCarId.value;
	} else {
		carId = document.advanceSearch.nextCarId.value;
	}
	document.advanceSearch.action= '/index.php?option=com_carsearch&task=car_details&carId=' + carId;
	document.advanceSearch.detailsLimitstart.value = limitstart;
	document.advanceSearch.submit();
}

function changeImage(url, overlayId, totalImages) {
	if(SlideShowRunning){return;}
	if(url.indexOf("youtube")>-1){
		document.getElementById("imageholder").innerHTML="<iframe width='640' height='480' src='"+url+"' frameborder='0'></iframe>";
	}
	else
	{
		document.getElementById("imageholder").innerHTML="<img src='"+url+"'name='imageObj' width='640' height='480' border='0' >";
	}
	for (var i=0; i < totalImages; i++) {
		document.getElementById("overlay" + i).style.display="none";
	}
	document.getElementById("overlay" + overlayId).style.display="inline";
	
}

function sendAfriend(carId) {
	var w = window.open('/index2.php?option=com_content&task=view&id=33&Itemid=&action=show_form&carId=' + carId, 'sendAfried','width=630,height=350,left=0,top=0,menubar=no,resizable=no,toolbar=no,status=no,location=no');
	w.focus();
}

function showTab(tabNumber) {
	var activeTab = tabArray[tabNumber-1];
	document.getElementById(activeTab).style.display="block";
	document.getElementById(activeTab + "_tab").className="tab_active";

	if (tabNumber == 3) {
		var companyCodeuse = companyCode;
		if(companyCodeuse == 4438) {
				companyCodeuse = 4435;
			}
    		document.getElementById('routeInternalFrame').src = 'http://www.smeeing.nl/_planners/' + companyCodeuse + '.html?location=' + companyCodeuse + '&host=4435';
	}

	for (var i=0; i < tabArray.length; i++) {
		if (tabArray[i] != activeTab) {
			document.getElementById(tabArray[i]).style.display="none";
			document.getElementById(tabArray[i] + "_tab").className="tab_inactive";
		}
	}

}

var scrollStep=2

var timerLeft=""
var timerRight=""

function toLeft(id){
  document.getElementById(id).scrollLeft=0
}

function scrollDivLeft(id){
  clearTimeout(timerRight)
  document.getElementById(id).scrollLeft+=scrollStep
  timerRight=setTimeout("scrollDivLeft('"+id+"')",10)
}

function scrollDivRight(id){
  clearTimeout(timerLeft)
  document.getElementById(id).scrollLeft-=scrollStep
  timerLeft=setTimeout("scrollDivRight('"+id+"')",10)
}

function toRight(id){
  document.getElementById(id).scrollLeft=document.getElementById(id).scrollWidth
}

function stopMe(){
  clearTimeout(timerRight)
  clearTimeout(timerLeft)
}

function toSearchResults() {
	document.advanceSearch.action = document.advanceSearch.fromURL.value;
	document.advanceSearch.submit();
}


