var count=0;
var schleife=0;
var schleife2=0;
var newvehicle;
var oldvehicle="-";

var newvehiclesearch;
var oldvehiclesearch="-";
var newvideosearch;
var oldvideosearch="-";

var newvideonavigation;
var oldvideonavigation="-";


var newlast;
var oldlast="-";
var newvideo;
var oldvideo="-";

var newvideolast;
var oldvideolast="-";

var timer;
var tInterval;
var sInterval;
var suchtextinputrequest='';
var searchaktiv=0;
var keycodepressed;
var start=0;
var startd=0;
var order='';
var sort='';
var orderalt='';
var searchbuttonpressed=0;

var host = self.location.hostname;

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      }
    return xmlHttp;
}


function Tastendruck (Ereignis) {
	start=0;

    if (!Ereignis){
    	Ereignis = window.event;
    	keycodepressed=0;
	}else if (Ereignis.keyCode==13){
        keycodepressed=Ereignis.keyCode;
    }else{
    	keycodepressed=0;
    }
}






function autoSuggest(suchtextinput,sucheaktiviert){

    window.clearInterval(sInterval);
	if(sucheaktiviert==1){
		 searchaktiv=1;
		searchbuttonpressed=1;
	}else{
		searchbuttonpressed=0;
	}



	window.setTimeout("autoSuggestRequest();", 500);



}
document.onkeypress = Tastendruck;



function autoSuggestRequest(){


	suchtextinputrequest=document.getElementById("suchtext").value;
    if(document.getElementById("suggestBox") ){



        var xmlHttp1= GetXmlHttpObject();
        xmlHttp1.onreadystatechange=function(){
            if(xmlHttp1.readyState==4){
            	if(xmlHttp1.responseText.length>8){


                    var ergebnis = parseFloat(xmlHttp1.responseText.substr(0,8))-10000000;

                    if(ergebnis==1)
                        document.getElementById("searchbutton").value=ergebnis+" Autos anzeigen";
                    else
                        document.getElementById("searchbutton").value=ergebnis+" Autos anzeigen";
                }else{
                	document.getElementById("searchbutton").value="Fahrzeug - Suche";
                }
                document.getElementById("suggestBox").innerHTML=xmlHttp1.responseText.substr(8,xmlHttp1.responseText.length);

                ajaxFunction();
            }
        }

        xmlHttp1.open("GET","http://"+host+"/activeContent/autosuggest.php?st="+document.getElementById("suchtext").value+"",true);
        xmlHttp1.send(null);

    }

    //return false;
}



function ajaxFunction(){


	if(searchaktiv==1)
		ajaxFunction2();
	else{


        if(document.getElementById("newVehicles")){
            var xmlHttp= GetXmlHttpObject();
            xmlHttp.onreadystatechange=function(){

                if(xmlHttp.readyState==4){

                    newvehicle=xmlHttp.responseText;

                    if(newvehicle!=oldvehicle){
                        oldvehicle=newvehicle;
                        var xmlHttp1= GetXmlHttpObject();
                        xmlHttp1.onreadystatechange=function(){
                            if(xmlHttp1.readyState==4){
                                document.getElementById("newVehicles").innerHTML=xmlHttp1.responseText;


                                return true;

                            }
                        }
                        xmlHttp1.open("GET","http://"+host+"/activeContent/autos.php?st="+suchtextinputrequest+"",true);
                        xmlHttp1.send(null);
                    }
                }

            }
            xmlHttp.open("GET","http://"+host+"/activeContent/autos.php?check=1&st="+suchtextinputrequest+"",true);
            xmlHttp.send(null);
        }

        if(document.getElementById("lastView")){
            var xmlHttpLV= GetXmlHttpObject();
            xmlHttpLV.onreadystatechange=function(){

                if(xmlHttpLV.readyState==4){

                    newlast=xmlHttpLV.responseText;

                    if(newlast!=oldlast){


                        oldlast=newlast;
                        var xmlHttpLV2= GetXmlHttpObject();
                        xmlHttpLV2.onreadystatechange=function(){
                            if(xmlHttpLV2.readyState==4){
                                document.getElementById("lastView").innerHTML=xmlHttpLV2.responseText;
                                return true;
                            }
                        }
                        xmlHttpLV2.open("GET","http://"+host+"/activeContent/autos.php?lastview=1&st="+suchtextinputrequest+"",true);
                        xmlHttpLV2.send(null);
                    }
                }
            }
            xmlHttpLV.open("GET","http://"+host+"/activeContent/autos.php?lastviewcheck=1&st="+suchtextinputrequest+"",true);
            xmlHttpLV.send(null);
        }
        if(document.getElementById("videoCars")){
            var xmlHttpVC= GetXmlHttpObject();
            xmlHttpVC.onreadystatechange=function(){

                if(xmlHttpVC.readyState==4){

                    newvideo=xmlHttpVC.responseText;

                    if(newvideo!=oldvideo){
                        oldvideo=newvideo;
                        var xmlHttpVC2= GetXmlHttpObject();
                        xmlHttpVC2.onreadystatechange=function(){
                            if(xmlHttpVC2.readyState==4){
                                document.getElementById("videoCars").innerHTML=xmlHttpVC2.responseText;
                                return true;
                            }
                        }
                        xmlHttpVC2.open("GET","http://"+host+"/activeContent/autos.php?videocars=1&st="+suchtextinputrequest+"",true);
                        xmlHttpVC2.send(null);
                    }
                }
            }

            xmlHttpVC.open("GET","http://"+host+"/activeContent/autos.php?videocarscheck=1&st="+suchtextinputrequest+"",true);
            xmlHttpVC.send(null);
        }
        if(document.getElementById("lastVideoView")){
            var xmlHttpLVV= GetXmlHttpObject();
            xmlHttpLVV.onreadystatechange=function(){

                if(xmlHttpLVV.readyState==4){

                    newvideolast=xmlHttpLVV.responseText;

                    if(newvideolast!=oldvideolast){
                        oldvideolast=newvideolast;
                        var xmlHttpLVV2= GetXmlHttpObject();
                        xmlHttpLVV2.onreadystatechange=function(){
                            if(xmlHttpLVV2.readyState==4){
                                document.getElementById("lastVideoView").innerHTML=xmlHttpLVV2.responseText;
                                return true;
                            }
                        }
                        xmlHttpLVV2.open("GET","http://"+host+"/activeContent/autos.php?lastvideoview=1&st="+suchtextinputrequest+"",true);
                        xmlHttpLVV2.send(null);
                    }
                }
            }
            xmlHttpLVV.open("GET","http://"+host+"/activeContent/autos.php?lastvideoviewcheck=1&st="+suchtextinputrequest+"",true);
            xmlHttpLVV.send(null);
        }
        if(document.getElementById("videoNavigation")){
        	if(document.getElementById('videoKat')){
                var videokattext=document.getElementById('videoKat').value;
            }
        	if(document.getElementById('videoBestand')){
                var videobestandtext=document.getElementById('videoBestand').value;
            }

            document.getElementById("videoNavigation").style.visibility='visible';
            var xmlHttpVN= GetXmlHttpObject();
            xmlHttpVN.onreadystatechange=function(){

                if(xmlHttpVN.readyState==4){

                    newvideonavigation=xmlHttpVN.responseText;

                    if(newvideonavigation!=oldvideonavigation){
                        oldvideonavigation=newvideonavigation;

                        var videoanzarray = newvideonavigation.split("-");
                        videoanz=videoanzarray[0];
                        document.getElementById("videoanztext").innerHTML="Anzahl AutoVideos: "+videoanz;
                        var xmlHttpVN2= GetXmlHttpObject();
                        xmlHttpVN2.onreadystatechange=function(){
                            if(xmlHttpVN2.readyState==4){
                                document.getElementById("videoNavigation").innerHTML=xmlHttpVN2.responseText;
                                return true;
                            }
                        }
          	xmlHttpVN2.open("GET","http://"+host+"/activeContent/videos.php?videonavigation=1&start="+start+"&kat="+videokattext+"&bestand="+videobestandtext,true);
                        xmlHttpVN2.send(null);
                    }
                }
            }

            xmlHttpVN.open("GET","http://"+host+"/activeContent/videos.php?videonavigationcheck=1&start="+start+"&kat="+videokattext+"&bestand="+videobestandtext,true);
            xmlHttpVN.send(null);
        }


        if(schleife==0){
            schleife=1;
            callAjaxFunction();
        }
    }

}

function callAjaxFunction(){

sInterval=setInterval("if(ajaxFunction());",20000);

}

function setStart(startvalue){
	start=startvalue;
	ajaxFunction2();
}
function setStartD(startvalue){
	startd=startvalue;
	ajaxFunction3();
}
function setOrder(ordervalue){
	if(orderalt!=ordervalue)
		sort=' ASC';
	else if(orderalt==ordervalue && sort==' ASC')
        sort=' DESC';
    else
		sort=' ASC';


	orderalt=ordervalue;
	order=ordervalue;



	ajaxFunction3();
}
function setVideoKat(videokat){
	start=0;
	document.getElementById("videoKat").value=videokat;
	ajaxFunction();
}
function setVideoBestand(videobestand){
	start=0;
	document.getElementById("videoBestand").value=videobestand;
	var btnColor= new Array();

	btnColor[0]="#3366cc";
	btnColor[1]="#00CC00";
	btnColor[2]="#FF0000";


	for(var i=0;i<3;i++){
		if(videobestand==i){
			document.getElementById("bestandbtn"+i).style.color=btnColor[i];
        	document.getElementById("bestandbtn"+i).style.borderColor=btnColor[i];
		}else{
			document.getElementById("bestandbtn"+i).style.color='#999999';
        	document.getElementById("bestandbtn"+i).style.borderColor='#999999';
		}

	}


	ajaxFunction();
}


function setOrder2(ordervalue){
	if(orderalt!=ordervalue)
		sort=' ASC';
	else if(orderalt==ordervalue && sort==' ASC')
        sort=' DESC';
    else
		sort=' ASC';


	orderalt=ordervalue;
	order=ordervalue;



	ajaxFunction2();
}

var videospernavi=6;
function setStartVideo(navigation){

	start=start+(videospernavi*navigation);



	if(start>=videoanz)
        start=0

	if(start<0){

		start=videoanz-(videoanz%videospernavi);

        if(start==videoanz)
            start=videoanz-videospernavi;

	}





	ajaxFunction();
}

var durchlauf=1;
function ajaxFunction2(){

   // document.getElementById("contentBox").innerHTML="<div class='leftbox2'><div class='boxtitle2'>Ihr Suchergebnis</div><div id='newVehicles'></div></div><div class='leftbox'><div class='boxtitle'>Davon mit Videos</div><div id='videoCars' ></div></div>";

	if(searchbuttonpressed==1){

        if (document.getElementById("lastViewBox")){
            var Knoten = document.getElementById("lastViewBox");
            document.getElementById("contentBox").removeChild(Knoten);
        }
        if(document.getElementById("lastVideoViewBox")){
            var Knoten = document.getElementById("lastVideoViewBox");
            document.getElementById("contentBox").removeChild(Knoten);
        }
        if (document.getElementById("newVehiclesBox")){
            var Knoten = document.getElementById("newVehiclesBox");
            document.getElementById("contentBox").removeChild(Knoten);
        }
        if(document.getElementById("videoCarsBox")){
            var Knoten = document.getElementById("videoCarsBox");
            document.getElementById("contentBox").removeChild(Knoten);
        }
        //document.getElementById("lastVideoViewBox").outerHTML="";
        //document.getElementById("newVehiclesBox").className="leftbox2";
        //document.getElementById("videoCarsBox").class="";





        if(document.getElementById("newVehiclesBoxSuche")){
            document.getElementById("newVehiclesBoxSuche").style.visibility='visible';
            var xmlHttp= GetXmlHttpObject();
            xmlHttp.onreadystatechange=function(){

                if(xmlHttp.readyState==4){

                    newvehiclesearch=xmlHttp.responseText;
                    if(newvehiclesearch!=oldvehiclesearch){
                        oldvehiclesearch=newvehiclesearch;
                        var xmlHttp1= GetXmlHttpObject();
                        xmlHttp1.onreadystatechange=function(){
                            if(xmlHttp1.readyState==4){
                                document.getElementById("newVehiclesBoxSuche").innerHTML=xmlHttp1.responseText;
                                return true;

                            }
                        }
                        xmlHttp1.open("GET","http://"+host+"/activeContent/suche.php?order="+order+"&sort="+sort+"&newvehicles=1&st="+suchtextinputrequest+"&start="+start,true);
                        xmlHttp1.send(null);
                    }
                }

            }
            xmlHttp.open("GET","http://"+host+"/activeContent/suche.php?order="+order+"&sort="+sort+"&check=1&newvehicles=1&st="+suchtextinputrequest+"&start="+start,true);
            xmlHttp.send(null);
        }
        if(document.getElementById("videoCarsBoxSuche")){
            document.getElementById("videoCarsBoxSuche").style.visibility='visible';
            var xmlHttpVC= GetXmlHttpObject();
            xmlHttpVC.onreadystatechange=function(){

                if(xmlHttpVC.readyState==4){

                    newvideosearch=xmlHttpVC.responseText;

                    if(newvideosearch!=oldvideosearch){
                        oldvideosearch=newvideosearch;
                        var xmlHttpVC2= GetXmlHttpObject();
                        xmlHttpVC2.onreadystatechange=function(){
                            if(xmlHttpVC2.readyState==4){
                                document.getElementById("videoCarsBoxSuche").innerHTML=xmlHttpVC2.responseText;
                                return true;
                            }
                        }
                        xmlHttpVC2.open("GET","http://"+host+"/activeContent/suche.php?order="+order+"&sort="+sort+"&videocars=1&st="+suchtextinputrequest+"&start="+start,true);
                        xmlHttpVC2.send(null);
                    }
                }
            }

            xmlHttpVC.open("GET","http://"+host+"/activeContent/suche.php?order="+order+"&sort="+sort+"&videocarscheck=1&st="+suchtextinputrequest+"&start="+start,true);
            xmlHttpVC.send(null);
        }

    }
//    if(schleife2==0){
//        schleife2=1;
//        callAjaxFunction2();
//    }

}






function callAjaxFunction2(){

sInterval=setInterval("if(ajaxFunction2());",20000);

}
function confirmSuggest(suchtextsuggest,anzahl){
	 searchbuttonpressed=0;
    if(anzahl==1)
        document.getElementById("searchbutton").value=anzahl+" Auto anzeigen";
    else
        document.getElementById("searchbutton").value=anzahl+" Autos anzeigen";


	document.getElementById('suchtext').value=suchtextsuggest;
	document.getElementById("suggestBox").innerHTML="";
	suchtextinputrequest=suchtextsuggest;
	ajaxFunction();


}
function startplayer(videoidnavi,linktext,datum,filmlaenge,clickgesamt,bild,haendler,fahrzeug){


	document.getElementById("linktexttext").innerHTML=linktext;
	document.getElementById("moviedatum").innerHTML=datum;
	document.getElementById("movielaenge").innerHTML=filmlaenge;
	document.getElementById("movieclicks").innerHTML=clickgesamt;
	document.getElementById("movielink").innerHTML='<a href="videoarchiv.php?id='+videoidnavi+'">Link zu diesem Video</a>';
	document.getElementById("movielinktext").value='http://www.autopod.de/videoarchiv.php?id='+videoidnavi



	window.document.title="Auto Video "+linktext+" autopod.de Fahrzeugvideo";

	player.location.href='videonojs.php?id='+videoidnavi+'&bildm='+bild;
    dealer.location.href='dealer.php?dealer='+haendler+'&fahrzeug='+fahrzeug;

	var typetext = linktext.split(" ");
	videobestandtext=document.getElementById('videoBestand').value;

	if(typetext[0]!=''){
		related.location.href='relatedvideos.php?bestand='+videobestandtext+'&dealer='+haendler+'&fahrzeug='+fahrzeug+'&type='+typetext[0]+'&type2='+typetext[1];
	}



//window.setTimeout("player.location.href='videonojs.php?id="+videoidnavi+"&play=1'",500);
}
function startplayerparent(videoidnavi,linktext,datum,filmlaenge,clickgesamt,bild,haendler,fahrzeug){


	parent.document.getElementById("linktexttext").innerHTML=linktext;
	parent.document.getElementById("moviedatum").innerHTML=datum;
	parent.document.getElementById("movielaenge").innerHTML=filmlaenge;
	parent.document.getElementById("movieclicks").innerHTML=clickgesamt;
	parent.document.getElementById("movielink").innerHTML='<a href="videoarchiv.php?id='+videoidnavi+'">Link zu diesem Video</a>';
	parent.document.getElementById("movielinktext").value='http://www.autopod.de/videoarchiv.php?id='+videoidnavi



	parent.document.title="Auto Video "+linktext+" autopod.de Fahrzeugvideo";

	parent.player.location.href='videonojs.php?id='+videoidnavi+'&bildm='+bild;
	parent.dealer.location.href='dealer.php?dealer='+haendler+'&fahrzeug='+fahrzeug;




//window.setTimeout("player.location.href='videonojs.php?id="+videoidnavi+"&play=1'",500);
}
function ajaxFunction3(){



    if(document.getElementById("newVehiclesBoxDealer")){




        var xmlHttpVD= GetXmlHttpObject();
        xmlHttpVD.onreadystatechange=function(){
            if(xmlHttpVD.readyState==4){
                document.getElementById("newVehiclesBoxDealer").innerHTML=xmlHttpVD.responseText;
                return true;
            }
        }

        xmlHttpVD.open("GET","http://"+host+"/activeContent/dealer.php?order="+order+"&sort="+sort+"&start="+startd+"&dealer="+dealer,true);
        xmlHttpVD.send(null);

    }


}

function advertshow(){


	adfenster=window.open("videoadvert.php?videofile=mittevoiceover.mp4","nix","width=520,height=288,left=300,top=200,scrollbars=no,resizable=no,menubar=no, status=no,toolbar=no");

	window.setTimeout("if(!adfenster){advertshow2()}",500);
}

function advertshow2(){

	document.getElementById("advertshow").innerHTML="<div style='width:520px;background-color:#ffffff'><div style='width:520px;text-align:right;cursor:pointer;' onclick='document.getElementById(\"advertshow\").innerHTML=\"\"'>X SCHLIESSEN</div><div style='width:520px'><iframe src='videoadvert.php?videofile=mittevoiceover.mp4' marginheight='0' marginwidth='0' scrolling='no' frameborder='0' width='520' height='288'></iframe></div></div>";


}



// Anzeigedauer der Bilder (milliseconds)
var slideShowSpeed = 6000

// Dauer der Überblendung (seconds)
var crossFadeDuration = 6

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below
Pic[0]= 'banner/pixelrot.gif'

// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = Pic[i]
}



//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}


function blendimage(divid, imageid, imagefile, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //set the current image as background
   // document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";

    //make image transparent
    changeOpac(0, imageid);

    //make new image
    document.getElementById(imageid).src = imagefile;

    //fade in image
    for(i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
        timer++;
    }

    j = j + 1
    if (j > (p-1))
        j=0;
 //   t = setTimeout("blendimage('blenddiv', 'blendimage', '"+preLoad[j].src+"', "+(crossFadeDuration*100)+")", slideShowSpeed)
 	return ;
}


function runSlideShow(){
    if (document.all){
        document.images.SlideShow.style.filter="blendTrans(duration=3)";
        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);

   }else{

        blendimage("blenddiv", "blendimage", preLoad[j].src, (crossFadeDuration*100));


   }
}



function adzeigen (id) {

    if (document.getElementById("blenddiv").style.visibility == "hidden" && id!='X')
    {
        document.getElementById("blenddiv").style.visibility = "visible";
        setTimeout("runSlideShow();",1500);
        setTimeout(" document.getElementById('adpic').style.visibility = 'visible'; document.getElementById('closead').style.visibility = 'visible'; ", 3000)

        return;
    }
    else
    {	document.getElementById("adlayer").style.visibility = "hidden";
        document.getElementById("closead").style.visibility = "hidden";
        document.getElementById("adpic").style.visibility = "hidden";
        document.getElementById("blenddiv").style.visibility = "hidden";
        return;
    }

}

