			var imUrls = Array(
				'/new_header_images/header_3coupe.jpg',
				'/new_header_images/header_3series.jpg',
				'/new_header_images/header_5series.jpg',
				'/new_header_images/header_x3.jpg'
			);
			var imCurrent = 0;
			function cycleImHeaders() {
				document.getElementById('imHeader' + imCurrent).style.display = 'none';
				
				imCurrent++;
				
				if(imCurrent == imUrls.length)
					imCurrent = 0;
				
				document.getElementById('imHeader' + imCurrent).style.display = 'block';
			}
			function beginTheImshow() {
				
				/*
				for(i = 0; i < imUrls.length; i++) {
					imPlaceholder.innerHTML += '<img src="' + imUrls[i] + '" id="imHeader' + i + '" style="display: none;" />';
				}
				
				document.getElementById('imHeader' + imCurrent).style.display = 'block';
				setInterval(cycleImHeaders, 5000);
				*/
						var imPlaceholder = document.getElementById("ImagesPlaceholder");
						imPlaceholder.innerHTML = '<img src="public/images/wess_header2.jpg" width="1024" border="0" alt="" />';
						imPlaceholder.innerHTML += '<div onclick="window.location.href=\'1serija/Convertible/\';" style="position: absolute; width: 1024px; height: 191px; border: none; cursor: pointer; left: 0px; top: 100px;"><img src="public/images/spacer.gif" width="1024" height="191" border="0" alt="" /></div>';
			}


var browser_name = navigator.appName;

selected = '';
menu = new Array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '13');

/*
if (browser_name == "Microsoft Internet Explorer"){
    document.write('<link href="../scripts/ie.css" rel="stylesheet" />');
} else {
    document.write('<link href="../scripts/oth.css" rel="stylesheet" />');
} */
function NewWindow(locat,name,hght,wdth)
{ eval("window.open('"+name+"','"+locat+"','height="+hght+",width="+wdth+",status=no,location=no,toolbar=no,directories=no,menubar=no,scrollbars=yes');"); }



function toggle(id) {
    var o = document.getElementById(id);
    if (o) {
        if (document.getElementById(id).style.display == 'none') {
            document.getElementById(id).style.display = 'block';
        } else {
            document.getElementById(id).style.display = 'none';
        }
    }
}

function openPhoto(path, width, height) {
    var x = Math.floor((screen.width / 2) - (width / 2));
    var y = Math.floor((screen.height / 2) - (height * 0.6));
    var win = window.open('', 'photo', 'width='+width+',height='+height+',toolbar=no,directories=no,status=no,location=no,resizable=no,scrollbars=no,menubar=no,screenx='+x+',screeny='+y+',left='+x+',top='+y);
    win.document.write('<html><head><meta http-equiv="imagetoolbar" content="no" /><title> :: Wess-select :: </title></head><body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" style="overflow:hidden"><a href="#" onClick="self.close();return false" style="cursor:default"><img src="'+ path +'" width="'+width+'" height="'+height+'" border="0" /></a></body></html>');
    win.document.close();
}

function galleryChange(path, url) {
    document.getElementById('gallery').src = path;
    if (typeof(url) != 'undefined'   &&   url != '') {
        document.getElementById('galleryLink').href = "javascript:openPhoto('" + url + "', 1024, 768);";
        document.getElementById('galleryLink').style.cursor = 'pointer';
    } else {
        document.getElementById('galleryLink').href = '#';
        document.getElementById('galleryLink').style.cursor = 'default';
    }
}


function getRandom(min_random, max_random){
    max_random++;
    var range = max_random - min_random;
    var n = Math.floor(Math.random()*range) + min_random;
    return n;
}

/*

function inArray (value, array){
    var i;
    for (i = 0; i < array.length; i++){
        if (array[i] === value){
            return true;
        }
    }
    return false;
}

*/

function siteFiller(){
    document.getElementById('bigimg_link').href = bigImagesLinks[0];
    document.getElementById('bigimg').style.backgroundImage = "url('" + bigImages[0] + ".jpg')";
    document.getElementById('bigimg_over').src =  bigImages[0] + '.over.gif';
}


function ChangeBigImg(){
    if (curBigImg == (bigImages.length - 1)){
        curBigImg = 0;
    } else {
        curBigImg++;
    }

    document.getElementById('bigimg').style.backgroundImage = "url('" + bigImages[curBigImg] + ".jpg')";
    document.getElementById('bigimg_over').src = bigImages[curBigImg] + '.over.gif';
    document.getElementById('bigimg_link').href = bigImagesLinks[curBigImg];
}


function preloadBigImages(){
    for(var i=0; i<bigImages.length; i++){
        var image = new Image();
        image.src = bigImages[i] + '.jpg';
        image.src = bigImages[i] + '.over.gif';
    }
}


function menuElswtch(id, ev, force){
    if (selected == '' || force){
        switch(ev){
            default:
                document.getElementById('menuEl' + id).style.color = '#fff'
            break;

            case('over'):
                document.getElementById('menuEl' + id).style.color = '#006';
            break;
        }
    }
}

function CloseMenu(id)
{
	document.getElementById('div' + id).style.visibility = 'hidden';
	document.getElementById('menuEl' + id).style.backgroundColor = 'transparent';
	document.getElementById('menuEl' + id).style.color = '#fff';	
}

function MenuDrop(id, dynamic){
  AllMenuClose();

	if (dynamic){
        if (selected != ''){

            var selection = selected;

            document.getElementById('div' + id).style.visibility = 'visible';
            document.getElementById('menuEl' + id).style.backgroundColor = '#fff';
            document.getElementById('menuEl' + id).style.color = '#039';

            selected = id;
        }
    } else {

        var selection = selected;

        if (selection != id){
            document.getElementById('div' + id).style.visibility = 'visible';
            document.getElementById('menuEl' + id).style.backgroundColor = '#fff';
            document.getElementById('menuEl' + id).style.color = '#039';

            selected = id;
        } else {
            menuElswtch(id, 'over');
        }

    }
}


function AllMenuClose(){
	var d = document.getElementsByTagName("div");
	for (i = 0; i < d.length; i++) {
		if (d[i].className == 'menuEl') {
			d[i].style.backgroundColor = 'transparent';
			d[i].style.color = '#fff';
		} // if menuEl
		else {
			if (d[i].className == 'dropDMenu') {
				d[i].style.visibility = 'hidden';
			} // if dropDMenu
		} // not menuEl
	} // for all divs
}


    var menuDropState = true;
    var menuDropMaxHeight = 280;
    var menuDropMaxHeight320 = 343;    
    var menuDropMinHeight = 0;
    var menuDropStep = 30; // 30
    var startState = true;
    var finish = false;
    var menuDropSpeed = 1; // ms
    var difference = -1;

    function menuChangeState() {
        var id = 'dropdown';
		var id2 = 'dropdown2';
		var id3 = 'dropdowncontent';
		
        var height = parseInt(document.getElementById(id).style.height);

		//alert(document.getElementById(id).style.height);
		
        if (startState != menuDropState){
            finish = false;
            id = '';
            return ;
        }

        if (menuDropState) {
            // Going UP
            height = height - menuDropStep;
            if (height <= menuDropMinHeight) {
                document.getElementById('dropdownarea').style.display = 'block';
                menuDropState = false;
                finish = true;
                if (difference < 0){
                    difference = parseInt(document.getElementById(id).style.height) - 10;
                }
                document.getElementById(id).style.height = '10px';
				document.getElementById(id2).style.height = '10px';
				document.getElementById(id3).style.height = '10px';				
            } else {
                document.getElementById(id).style.height = height + 'px';
				document.getElementById(id2).style.height = height + 'px';
				document.getElementById(id3).style.height = height + 'px';	
            }
            setTimeout("menuChangeState()", menuDropSpeed);
        } else {
            // Going DOWN
            height = height + menuDropStep;
            if (height >= menuDropMaxHeight) {
                document.getElementById('dropdownarea').style.display = 'none';
                menuDropState = true;
                finish = true;
                document.getElementById(id).style.height = parseInt(document.getElementById(id).style.height) + difference + 'px';
                document.getElementById(id2).style.height = parseInt(document.getElementById(id2).style.height) + difference + 'px';
                document.getElementById(id3).style.height = parseInt(document.getElementById(id3).style.height) + difference + 'px';				
            } else {
                document.getElementById(id).style.height = height + 'px';
				document.getElementById(id2).style.height = height + 'px';
				document.getElementById(id3).style.height = height + 'px';	
            }
            setTimeout("menuChangeState()", menuDropSpeed);
        }
    }
    

    function menuChangeState320() {
        var id = 'dropdown';
		var id2 = 'dropdown2';
		var id3 = 'dropdowncontent';
		
        var height = parseInt(document.getElementById(id).style.height);

		//alert(document.getElementById(id).style.height);
		
        if (startState != menuDropState){
            finish = false;
            id = '';
            return ;
        }

        if (menuDropState) {
            // Going UP
            height = height - menuDropStep;
            if (height <= menuDropMinHeight) {
                document.getElementById('dropdownarea').style.display = 'block';
                menuDropState = false;
                finish = true;
                if (difference < 0){
                    difference = parseInt(document.getElementById(id).style.height) - 10;
                }
                document.getElementById(id).style.height = '10px';
				document.getElementById(id2).style.height = '10px';
				document.getElementById(id3).style.height = '10px';				
            } else {
                document.getElementById(id).style.height = height + 'px';
				document.getElementById(id2).style.height = height + 'px';
				document.getElementById(id3).style.height = height + 'px';	
            }
            setTimeout("menuChangeState320()", menuDropSpeed);
        } else {
            // Going DOWN
            height = height + menuDropStep;
            if (height >= menuDropMaxHeight320) {
                document.getElementById('dropdownarea').style.display = 'none';
                menuDropState = true;
                finish = true;
                document.getElementById(id).style.height = parseInt(document.getElementById(id).style.height) + difference + 'px';
                document.getElementById(id2).style.height = parseInt(document.getElementById(id2).style.height) + difference + 'px';
                document.getElementById(id3).style.height = parseInt(document.getElementById(id3).style.height) + difference + 'px';				
            } else {
                document.getElementById(id).style.height = height + 'px';
				document.getElementById(id2).style.height = height + 'px';
				document.getElementById(id3).style.height = height + 'px';	
            }
            setTimeout("menuChangeState320()", menuDropSpeed);
        }
    }
    
    

    function menuHide() {
        var id = 'dropdown';
        var height = parseInt(document.getElementById(id).style.height);

        if (startState != menuDropState){
            finish = false;
            id = '';
            return ;
        }

        // Going UP
        height = height - menuDropStep;
        if (height <= menuDropMinHeight) {
            document.getElementById('dropdownarea').style.display = 'block';
            menuDropState = false;
            finish = true;
            if (difference < 0){
                difference = parseInt(document.getElementById(id).style.height) - 10;
            }
            document.getElementById(id).style.height = '10px';
        } else {
            document.getElementById(id).style.height = height + 'px';
        }
        setTimeout("menuHide()", menuDropSpeed);
    }


function divToggle(id){
    if (document.getElementById(id).style.display == 'none'){
        document.getElementById(id).style.display = 'block';
    } else {
        document.getElementById(id).style.display = 'none';
    }
}

function divToggleRequest(img)
{
	divToggle('RequestDiv');
	var sc = 0;
	if (document.documentElement.scrollTop)
		sc = document.documentElement.scrollTop;
	else if (document.body.scrollTop)
		sc = document.documentElement.scrollTop;
	document.getElementById('RequestDiv').style.top = (sc + 200) + "px"
	document.getElementById('CarName').value = img;
}

function divToggleHide()
{
	divToggle('RequestDiv');
	document.getElementById('CarName').value = '';
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}

function ValidateRequestForm()
{
	if(document.getElementById('FormName').value == '')
	{
		alert('Obligats lauks!');
		document.getElementById('FormName').value = ''
		document.getElementById('FormName').focus();
		return false;
	}
	
	if(document.getElementById('FormSurname').value == '')
	{
		alert('Obligats lauks!');
		document.getElementById('FormSurname').value = ''
		document.getElementById('FormSurname').focus();		
		return false;
	}

	if(document.getElementById('FormMail').value == '' || /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(document.getElementById('FormMail').value) == false )
	{
		alert('Obligats lauks!');
		document.getElementById('FormMail').value = ''
		document.getElementById('FormMail').focus();		
		return false;
	}

	if(document.getElementById('FormTel').value == '' || !IsNumeric(document.getElementById('FormTel').value) || document.getElementById('FormTel').value.length < 8)
	{
		alert('Obligats lauks!');
		document.getElementById('FormTel').value = ''
		document.getElementById('FormTel').focus();		
		return false;
	}	
	alert('Paldies par pieteikumu!');
	return true;
}

function ValidateRequestFormWC()
{
    if(document.getElementById('FormName').value == '')
    {
        alert('Obligats lauks!');
        document.getElementById('FormName').value = ''
        document.getElementById('FormName').focus();
        return false;
    }
    
    if(document.getElementById('FormSurname').value == '')
    {
        alert('Obligats lauks!');
        document.getElementById('FormSurname').value = ''
        document.getElementById('FormSurname').focus();        
        return false;
    }
   
    if(document.getElementById('FormMail').value == '' || /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(document.getElementById('FormMail').value) == false )
    {
        alert('Obligats lauks!');
        document.getElementById('FormMail').value = ''
        document.getElementById('FormMail').focus();        
        return false;
    }

    if(document.getElementById('FormTel').value == '' || !IsNumeric(document.getElementById('FormTel').value) || document.getElementById('FormTel').value.length < 8)
    {
        alert('Obligats lauks!');
        document.getElementById('FormTel').value = ''
        document.getElementById('FormTel').focus();        
        return false;
    }    
    
    if(document.getElementById('Captcha').value == '')
    {
        alert('Obligats lauks!');
        document.getElementById('Captcha').value = ''
        document.getElementById('Captcha').focus();        
        return false;
    }
        
    alert('Paldies par pieteikumu!');
    return true;
}
function switchTechImage(){
    var image_div = document.getElementById("techBigImg");
    if(image_div.style.display=="none"){
        image_div.style.display = "block";
        document.getElementById("techMain").style.display = "none";
    }
    else {
        image_div.style.display = "none";
        document.getElementById("techMain").style.display = "block";
    }
}

var active_car_popup = "";
function closeCarPopups(){
     var active_popup = document.getElementById(active_car_popup);
    if(active_popup){
        active_popup.style.display = "none";
    }
}

function popupCarDescription(id){
    closeCarPopups();
    var popup = document.getElementById("car_description_"+id);
    if(popup){
        popup.style.display = "block";
    }
    active_car_popup = "car_description_"+id;
    return false;
}


function popupModelTypes(){
    closeCarPopups();
    document.getElementById("iChoiceWindow").style.display = "block";
    active_car_popup = "iChoiceWindow";
}

active_model_type = "model_type_none";
function switchModelType(type){
    var active_type = document.getElementById(active_model_type);
    if(active_type) active_type.style.display = "none";

    var type_panel = document.getElementById("model_type_" + type);
    if(type_panel) type_panel.style.display = "block";

    active_model_type = "model_type_"+type;
}


function popupModelSeries(){
    closeCarPopups();
    document.getElementById("model_series_popup").style.display = "block";
    active_car_popup = "model_series_popup";
}


active_model_series = "model_series_none";
function switchModelSeries(series){
    var active_series = document.getElementById(active_model_series);
    if(active_series) active_series.style.display = "none";

    var series_panel = document.getElementById("model_series_" + series);
    if(series_panel) series_panel.style.display = "block";

    active_model_series = "model_series_"+series;
}

function ShowImage(img) {
        var url = PATH;
        
		var NewWin=window.open(url+'public/map.html','','height=467,width=835,status=no,location=no,toolbar=no,directories=no,menubar=no,scrollbars=no');
		NewWin.document.onclick=function() {
								//alert('close');
								NewWin.close();
								}
	}


function PopupFoto(ID)
{
	if(document.getElementById('p_'+ID).style.display == 'none')
		$('#p_'+ID).fadeIn('fast')
	else
		$('#p_'+ID).fadeOut('fast')
}