var intTotalSlides;
var intIndexCurrent = 0;
var intIndexNext;
var intSlideDelay = 100;
var intOpacityLevel = 100;
var imgCurrent;
var imgCurrent2;
var imgNext;
var headCurrent;
var headNext;
var textCurrent;
var textNext;
var ulCurrent;
var ulNext;
var blnSliding = false;
var blnSliding2 = false;
var blnShowingInternal = true;
var timerSlide;
var timeoutLoop;



/* ***** HOME SLIDESHOW ***** */
function slideHome()
{
if (!blnSliding)
    {
    blnSliding = true;

    intIndexNext = (intIndexCurrent + 1 == intTotalSlides) ? 0 : intIndexCurrent + 1;

    imgCurrent = document.getElementById("topImage").getElementsByTagName("img")[intIndexCurrent];
    imgCurrent.style.filter = "alpha(opacity=100)";
    imgCurrent.style.opacity = "1";
    imgCurrent.style.display = "block";

    imgNext = document.getElementById("topImage").getElementsByTagName("img")[intIndexNext];
    imgNext.style.filter = "alpha(opacity=0)";
    imgNext.style.opacity = "0.0";
    imgNext.style.display = "block";

    headCurrent = document.getElementById("topImageText").getElementsByTagName("div")[intIndexCurrent];
    headCurrent.style.filter = "alpha(opacity=100)";
    headCurrent.style.opacity = "1";
    headCurrent.style.display = "block";

    headNext = document.getElementById("topImageText").getElementsByTagName("div")[intIndexNext];
    headNext.style.filter = "alpha(opacity=0)";
    headNext.style.opacity = "0.0";
    headNext.style.display = "block";

    timerSlide = setInterval(startSlideHome, intSlideDelay);
    }
}



function startSlideHome()
{
if (intOpacityLevel != 0)
    {
    intOpacityLevel = intOpacityLevel - 10;

    imgCurrent.style.filter = "alpha(opacity=" + intOpacityLevel + ")";
    imgCurrent.style.opacity = intOpacityLevel / 100;

    imgNext.style.filter = "alpha(opacity=" + (100 - intOpacityLevel) + ")";
    imgNext.style.opacity = (100 - intOpacityLevel) / 100;

    headCurrent.style.filter = "alpha(opacity=" + intOpacityLevel + ")";
    headCurrent.style.opacity = intOpacityLevel / 100;

    headNext.style.filter = "alpha(opacity=" + (100 - intOpacityLevel) + ")";
    headNext.style.opacity = (100 - intOpacityLevel) / 100;
    }
else 
    {
    clearInterval(timerSlide);

    headCurrent.style.display = "none";

    intIndexCurrent = intIndexNext;
    intOpacityLevel = 100;

    imgCurrent.style.display = "none";
    headCurrent.style.display = "none";

    blnSliding = false;

    timeoutLoop = setTimeout(slideHome,5000);
    }
}
/* ***** HOME SLIDESHOW ***** */



/* ***** VEHICLE SLIDESHOW ***** */
var intOpacityExternal = 100;
var intOpacityInternal = 0;


function slideVehicle(blnGoForward)
{
clearInterval(timerSlide);
clearTimeout(timeoutLoop);

if (!blnSliding)
    {
    blnSliding = true;
    blnSliding2 = false;
    blnShowingInternal = true;

    if (blnGoForward)
        {
        intIndexNext = (intIndexCurrent + 1 == intTotalSlides) ? 0 : intIndexCurrent + 1;
        }
    else
        {
        intIndexNext = (intIndexCurrent - 1 < 0) ? (intTotalSlides - 1) : intIndexCurrent - 1;
        }

    imgCurrent = document.getElementById("vehiclesFirst").getElementsByTagName("img")[intIndexCurrent];
    imgCurrent.style.filter = "alpha(opacity=" + intOpacityExternal + ")";
    imgCurrent.style.opacity = intOpacityExternal / 100;

    imgCurrent2 = document.getElementById("vehiclesSecond").getElementsByTagName("img")[intIndexCurrent];
    imgCurrent2.style.filter = "alpha(opacity=" + intOpacityInternal + ")";
    imgCurrent2.style.opacity = intOpacityInternal / 100;

    imgNext = document.getElementById("vehiclesFirst").getElementsByTagName("img")[intIndexNext];
    imgNext.style.filter = "alpha(opacity=0)";
    imgNext.style.opacity = "0.0";
    imgNext.style.display = "block";

    headCurrent = document.getElementById("vehiclesRight").getElementsByTagName("div")[intIndexCurrent];
    headCurrent.style.filter = "alpha(opacity=100)";
    headCurrent.style.opacity = "1";

    headNext = document.getElementById("vehiclesRight").getElementsByTagName("div")[intIndexNext];
    headNext.style.filter = "alpha(opacity=0)";
    headNext.style.opacity = "0.0";
    headNext.style.display = "block";

    textCurrent = document.getElementById("holdVehicleText").getElementsByTagName("div")[intIndexCurrent];
    textCurrent.style.filter = "alpha(opacity=100)";
    textCurrent.style.opacity = "1";

    textNext = document.getElementById("holdVehicleText").getElementsByTagName("div")[intIndexNext];
    textNext.style.filter = "alpha(opacity=0)";
    textNext.style.opacity = "0.0";
    textNext.style.display = "block";

    ulCurrent = document.getElementById("carSpec").getElementsByTagName("ul")[intIndexCurrent];
    ulCurrent.style.filter = "alpha(opacity=100)";
    ulCurrent.style.opacity = "1";

    ulNext = document.getElementById("carSpec").getElementsByTagName("ul")[intIndexNext];
    ulNext.style.filter = "alpha(opacity=0)";
    ulNext.style.opacity = "0.0";
    ulNext.style.display = "block";

    timerSlide = setInterval(startSlideVehicle, intSlideDelay);
    }
}



function startSlideVehicle()
{
if (intOpacityLevel != 0)
    {
    intOpacityLevel = intOpacityLevel - 10;
    intOpacityExternal = intOpacityExternal - 10;
    intOpacityInternal = intOpacityInternal - 10;

    imgCurrent.style.filter = "alpha(opacity=" + intOpacityExternal + ")";
    imgCurrent.style.opacity = intOpacityExternal / 100;

    imgCurrent2.style.filter = "alpha(opacity=" + intOpacityInternal + ")";
    imgCurrent2.style.opacity = intOpacityInternal / 100;

    imgNext.style.filter = "alpha(opacity=" + (100 - intOpacityLevel) + ")";
    imgNext.style.opacity = (100 - intOpacityLevel) / 100;

    headCurrent.style.filter = "alpha(opacity=" + intOpacityLevel + ")";
    headCurrent.style.opacity = intOpacityLevel / 100;

    headNext.style.filter = "alpha(opacity=" + (100 - intOpacityLevel) + ")";
    headNext.style.opacity = (100 - intOpacityLevel) / 100;

    textCurrent.style.filter = "alpha(opacity=" + intOpacityLevel + ")";
    textCurrent.style.opacity = intOpacityLevel / 100;

    textNext.style.filter = "alpha(opacity=" + (100 - intOpacityLevel) + ")";
    textNext.style.opacity = (100 - intOpacityLevel) / 100;

    ulCurrent.style.filter = "alpha(opacity=" + intOpacityLevel + ")";
    ulCurrent.style.opacity = intOpacityLevel / 100;

    ulNext.style.filter = "alpha(opacity=" + (100 - intOpacityLevel) + ")";
    ulNext.style.opacity = (100 - intOpacityLevel) / 100;
    }
else 
    {
    clearInterval(timerSlide);

    intIndexCurrent = intIndexNext;
    intOpacityLevel = 100;
    intOpacityExternal = 100;
    intOpacityInternal = 0;

    imgCurrent.style.filter = "alpha(opacity=0)";
    imgCurrent.style.opacity = "0.0";

    imgCurrent2.style.filter = "alpha(opacity=0)";
    imgCurrent2.style.opacity = "0.0";

    imgCurrent.style.display = "none";
    imgCurrent2.style.display = "none";
    headCurrent.style.display = "none";
    textCurrent.style.display = "none";
    ulCurrent.style.display = "none";

    blnSliding = false;

    timeoutLoop = setTimeout(slideVehicleInternal,5000);
    }
}



function slideVehicleInternal()
{
if (!blnSliding2)
    {
    blnSliding2 = true;

    if (blnShowingInternal)
        {
        imgCurrent = document.getElementById("vehiclesFirst").getElementsByTagName("img")[intIndexCurrent];
        imgCurrent2 = document.getElementById("vehiclesSecond").getElementsByTagName("img")[intIndexCurrent];

        blnShowingInternal = false;
        }
    else
        {
        imgCurrent = document.getElementById("vehiclesSecond").getElementsByTagName("img")[intIndexCurrent];
        imgCurrent2 = document.getElementById("vehiclesFirst").getElementsByTagName("img")[intIndexCurrent];

        blnShowingInternal = true;
        }

    imgCurrent.style.filter = "alpha(opacity=100)";
    imgCurrent.style.opacity = "1";

    imgCurrent2.style.filter = "alpha(opacity=0)";
    imgCurrent2.style.opacity = "0.0";
    imgCurrent2.style.display = "block";

    timerSlide = setInterval(startSlideVehicleInternal, intSlideDelay);
    }
}



function startSlideVehicleInternal()
{
if (intOpacityLevel != 0)
    {
    intOpacityLevel = intOpacityLevel - 10;

    imgCurrent.style.filter = "alpha(opacity=" + intOpacityLevel + ")";
    imgCurrent.style.opacity = intOpacityLevel / 100;

    imgCurrent2.style.filter = "alpha(opacity=" + (100 - intOpacityLevel) + ")";
    imgCurrent2.style.opacity = (100 - intOpacityLevel) / 100;

    if (blnShowingInternal)
        {
        intOpacityExternal = (100 - intOpacityLevel);
        intOpacityInternal = intOpacityLevel;
        }
    else
        {
        intOpacityExternal = intOpacityLevel;
        intOpacityInternal = (100 - intOpacityLevel);
        }
    }
else 
    {
    clearInterval(timerSlide);

    intOpacityLevel = 100;
    blnSliding2 = false;

    timeoutLoop = setTimeout(slideVehicleInternal,5000);
    }
}
/* ***** VEHICLE SLIDESHOW ***** */



/* ***** GALLERY SLIDESHOW ***** */
var intCurrentGallerySet;
var intGalleryWidth = 432;
var intNextPosition;
var blnSlideLeft;
var blnChangeNext = false;
var paraCaption;


function setupGallery(intCurrentGallery, strGalleryHead)
{
clearTimeout(timeoutLoop);
clearInterval(timerSlide);

intIndexCurrent = 0;

var arrThumbDivs = document.getElementById("galleryThumbs").getElementsByTagName("div");
var arrGalleryNavLinks = document.getElementById("galleryNav").getElementsByTagName("li");
var arrGallerySets = document.getElementById("gallerySlideShow").getElementsByTagName("div");
var arrCurrentGallerySet;

for (var intLoopDivThumbs = 0; intLoopDivThumbs < arrThumbDivs.length; intLoopDivThumbs++)
    {
    if (intCurrentGallery == intLoopDivThumbs)
        {
        arrThumbDivs[intLoopDivThumbs].style.display = "block";
        arrGalleryNavLinks[intLoopDivThumbs].className = "gallSubOn";
        arrGallerySets[intLoopDivThumbs].style.display = "block";

        arrCurrentGallerySet = arrGallerySets[intLoopDivThumbs].getElementsByTagName("img");
        }
    else
        {
        arrThumbDivs[intLoopDivThumbs].style.display = "none";
        arrGalleryNavLinks[intLoopDivThumbs].className = "";
        arrGallerySets[intLoopDivThumbs].style.display = "none";
        }
    }

for (var intLoopLargeImages = 0; intLoopLargeImages < arrCurrentGallerySet.length; intLoopLargeImages++)
    {
    arrCurrentGallerySet[intLoopLargeImages].style.display = (intLoopLargeImages == 0) ? "block" : "none";
    arrCurrentGallerySet[intLoopLargeImages].style.left = "0px";
    }

intTotalSlides = arrThumbDivs[intCurrentGallery].getElementsByTagName("img").length;
intSlideDelay = 30;

document.getElementById("galleryThumbs").getElementsByTagName("h1")[0].innerHTML = strGalleryHead;

paraCaption = document.getElementById("gallerySlideShow").getElementsByTagName("p")[0];
paraCaption.innerHTML = "1 of " + intTotalSlides;

intCurrentGallerySet = intCurrentGallery;

timeoutLoop = setTimeout("startGallery(true)", 4200);
}


function changeGallery(intImageNumber)
{
if (!blnSliding)
    {
    clearTimeout(timeoutLoop);

    blnChangeNext = true;

    intIndexNext = (intImageNumber - 1);

    if ((intImageNumber - 1) > intIndexCurrent)
        {
        startGallery(true);
        }
    else
        {
        startGallery(false);
        }
    }
}



function startGallery(blnGoForward)
{
if (!blnSliding)
    {
    clearTimeout(timeoutLoop);

    blnSliding = true;
    blnSlideLeft = blnGoForward;

    if (!blnChangeNext)
        {
        if (blnGoForward)
            {
            intIndexNext = (intIndexCurrent + 1 >= intTotalSlides) ? 0 : intIndexCurrent + 1;
            }
        else
            {
            intIndexNext = (intIndexCurrent - 1 < 0) ? (intTotalSlides - 1) : intIndexCurrent - 1;
            }
        }

    blnChangeNext = false;

    intNextPosition = (blnSlideLeft) ? intGalleryWidth : -intGalleryWidth;

    imgCurrent = document.getElementById("gallerySlideShow").getElementsByTagName("div")[intCurrentGallerySet].getElementsByTagName("img")[intIndexCurrent];
    imgCurrent.style.left = "0px";

    imgNext = document.getElementById("gallerySlideShow").getElementsByTagName("div")[intCurrentGallerySet].getElementsByTagName("img")[intIndexNext];
    imgNext.style.left = intNextPosition + "px";
    imgNext.style.display = "block";

    timerSlide = setInterval(runGallery, intSlideDelay);
    }
}



function runGallery()
{
if (blnSlideLeft)
    {
    intNextPosition = (intNextPosition - 10 < 0) ? 0 : intNextPosition - 10;
    imgCurrent.style.left = (intNextPosition - intGalleryWidth) + "px";
    }
else
    {
    intNextPosition = (intNextPosition + 10 > 0) ? 0 : intNextPosition + 10;
    imgCurrent.style.left = (intNextPosition + intGalleryWidth) + "px";
    }

imgNext.style.left = intNextPosition + "px";
imgNext.style.borderLeftColor = "#ffffff";

if (intNextPosition == 0)
    {
    clearInterval(timerSlide);

    imgNext.style.borderLeftColor = "#7e7d81";

    intIndexCurrent = intIndexNext;
    intLeftPosition = 0;
    blnSliding = false;

    paraCaption.innerHTML = (intIndexNext + 1) + " of " + intTotalSlides;

    timeoutLoop = setTimeout("startGallery(true)",4200);
    }
}
/* ***** GALLERY SLIDESHOW ***** */



/* ********** SUB MENUS ********** */
var timeoutMenu;


function showSubMenu(intSubMenu)
{
hideSubMenus();

document.getElementById("subMenu" + intSubMenu).style.display = "block";
}



function hideSubMenus()
{
var arrSubMenus = document.getElementById("topSubMenu").getElementsByTagName("ul");

for (var intLoopSubMenus = 0; intLoopSubMenus < arrSubMenus.length; intLoopSubMenus++)
    {
    arrSubMenus[intLoopSubMenus].style.display = "none";
    }
}



function keepHighlighted(blnOn, intMenuNumber)
{
clearTimeout(timeoutMenu);
document.getElementById("topMenu").getElementsByTagName("li")[intMenuNumber].className = (blnOn == 1) ? "highlightMenu" : "";
}



function hideSubMenuTimed()
{
timeoutMenu = setTimeout(hideSubMenus,50);
}
/* ********** SUB MENUS ********** */



/* ***** NEWSLETTER SUBSCRIPTION ***** */
function clearSubscribe(txtEmail)
{
txtEmail.value = (txtEmail.value == "Enter your email address") ? "" : txtEmail.value
}



function checkSubscription()
{
var blnSubscibe = true;
var arrInputs = document.getElementsByTagName("input");
var txtEmail;

for (var intLooper = 0; intLooper < arrInputs.length; intLooper++)
    {
    if (arrInputs[intLooper].id.indexOf("txtEmail") != -1)
        {
        txtEmail = arrInputs[intLooper];
        break;
        }
    }

if (txtEmail.value == "Enter your email address" || txtEmail.value == "")
    {
    alert("Please enter your email address");
    blnSubscibe = false;
    }

return blnSubscibe;
}
/* ***** NEWSLETTER SUBSCRIPTION ***** */



/* ***** STAFF POPUPS ***** */
function Trans_Popup()
{
var blnIsNonTransparent = false;
var arrStaffText = document.getElementById("topStaffText").getElementsByTagName("div");
var intCountStaff = 0;
var arrStaffTextPosTop = new Array(42,42,42,42,42,42,42,130,130,130,130,130,130);
var arrStaffTextPosLeft = new Array(44,119,194,249,334,400,450,44,120,184,250,330,400);

blnIsNonTransparent = ((navigator.appVersion.indexOf("MSIE 5.") != -1) || (navigator.appVersion.indexOf("MSIE 6.") !=-1)) ? true : false;

for (var intLoopStaff = 0; intLoopStaff < arrStaffText.length; intLoopStaff++)
    {
    if (arrStaffText[intLoopStaff].id.indexOf("staffText") != -1)
        {
        arrStaffText[intLoopStaff].className = (blnIsNonTransparent) ? "nonTransparent" : "";
        arrStaffText[intLoopStaff].style.top = arrStaffTextPosTop[intCountStaff] + "px";
        arrStaffText[intLoopStaff].style.left = arrStaffTextPosLeft[intCountStaff] + "px";

        intCountStaff++;
        }
    }
}



function showStaff(intStaffNum)
{
var arrStaffTexts = document.getElementById("topStaffText").getElementsByTagName("div");
var intCountStaff = 0;

for (var intLoopStaff = 0; intLoopStaff < arrStaffTexts.length; intLoopStaff++)
    {
    if (arrStaffTexts[intLoopStaff].id.indexOf("staffText") != -1)
        {
        intCountStaff++;
        arrStaffTexts[intLoopStaff].style.display = (intCountStaff == intStaffNum) ? "block" : "none";
        }
    }
}
/* ***** STAFF POPUPS ***** */



/* ***** POP UP CONTENT ***** */
var popContentUnder;
var intPageHeight;
var intPageWidth;
var intPopContentHeightHalf = 300;
var intPopContentWidthHalf = 300;



function showPopContent(strPopUpDivID)
{
getPageSizes();

popContentUnder = document.getElementById("popContentUnder");
popContentUnder.style.display = (popContentUnder.style.display == "none") ? "block" : "none";
popContentUnder.style.height = intPageHeight + 'px';
popContentUnder.style.width = "100%";
popContentUnder.style.filter = "alpha(opacity=65)";
popContentUnder.style.opacity = "0.65";

var popWindow = document.getElementById(strPopUpDivID);
popWindow.style.display = (popWindow.style.display == "none") ? "block" : "none";
//popWindow.style.top = intPageHeight / 2 - intPopContentHeightHalf + 'px';
popWindow.style.top = "680px";
popWindow.style.left = intPageWidth / 2 - intPopContentWidthHalf + 'px';
}



function getPageSizes()
{
var intScreenHeight = (typeof window.innerWidth != 'undefined') ? window.innerHeight : document.documentElement.clientHeight;

if ((intScreenHeight > document.body.parentNode.scrollHeight) && (intScreenHeight > document.body.parentNode.clientHeight))
    {
    intPageHeight = intScreenHeight;
    }
else
    {
    intPageHeight = (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) ? document.body.parentNode.clientHeight : document.body.parentNode.scrollHeight;
    }


var intScreenWidth = (typeof window.innerWidth != 'undefined') ? window.innerHeight : document.documentElement.clientHeight;

if ((intScreenWidth > document.body.parentNode.scrollWidth) && (intScreenWidth > document.body.parentNode.clientWidth))
    {
    intPageWidth = intScreenWidth;
    }
else
    {
    intPageWidth = (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) ? document.body.parentNode.clientWidth : document.body.parentNode.scrollWidth;
    }
}
/* ***** POP UP CONTENT ***** */



/* ***** CONTACT FORM ***** */
function getFormElement(arrFormElements, strFormPartID)
{
var objOutput;

for (var intLooper = 0; intLooper < arrFormElements.length; intLooper++)
    {
    if (arrFormElements[intLooper].id.indexOf(strFormPartID) != -1)
        {
        objOutput = arrFormElements[intLooper];
        break;
        }
    }

return objOutput;
}



function validateContact()
{
var blnForm_Validated = true;
var strMessage = "Please fill in the highlighted form fields.\n";

var arrInputs = document.getElementById("contactForm").getElementsByTagName("input");
var arrTextareas = document.getElementById("contactForm").getElementsByTagName("textarea");

var txtCompanyName = getFormElement(arrInputs, "txtCompanyName");
var txtFirst_Name = getFormElement(arrInputs, "txtFirstName");
var txtSurname = getFormElement(arrInputs, "txtSurname");
var txtEmail = getFormElement(arrInputs, "txtEmail");
var txtEnquiry = getFormElement(arrTextareas, "txtEnquiry");

txtCompanyName.className = "";
txtFirst_Name.className = "";
txtSurname.className = "";
txtEmail.className = "";
txtEnquiry.className = "";

if (txtCompanyName.value == "")
    {
    blnForm_Validated = false;
    txtCompanyName.className = "fillForm";
    }

if (txtFirst_Name.value == "")
    {
    blnForm_Validated = false;
    txtFirst_Name.className = "fillForm";
    }

if (txtSurname.value == "")
    {
    blnForm_Validated = false;
    txtSurname.className = "fillForm";
    }

if (txtEmail.value == "")
    {
    blnForm_Validated = false;
    txtEmail.className = "fillForm";
    }

if (txtEnquiry.value == "")
    {
    blnForm_Validated = false;
    txtEnquiry.className = "fillForm";
    }

if (!blnForm_Validated)
    {
    alert(strMessage);
    }

return blnForm_Validated;
}
/* ***** CONTACT FORM ***** */



function showLogo(intImgIndex)
{
var arrLogoLinks = document.getElementById("clientList").getElementsByTagName("li");
var arrLogoImages = document.getElementById("clientList").getElementsByTagName("img");

for (var intLoopLogos = 0; intLoopLogos < arrLogoImages.length; intLoopLogos++)
    {
    arrLogoLinks[intLoopLogos].className = (intLoopLogos == intImgIndex) ? "clientLinkOn" : "";
    arrLogoImages[intLoopLogos].style.display = (intLoopLogos == intImgIndex) ? "block" : "none";
    }

}



function goURL(strURL)
{
window.location.href = strURL;
}



function doWebsiteBy(blnOnOff, strPath)
{
if (blnOnOff == 1)
    {
    document.getElementById("websiteByNames").style.display = "block";
    //document.getElementById("seraphim").src = strPath + "images/seraphim1.gif";
    document.getElementById("demonDesign").src = strPath + "images/demond1.gif";
    }
else
    {
    document.getElementById("websiteByNames").style.display = "none";
    //document.getElementById("seraphim").src = strPath + "images/seraphim.gif";
    document.getElementById("demonDesign").src = strPath + "images/demond.gif";
    }
}
