/* Webmobil24-IFRAME: Domainname kürzen */
if(document.domain)
{
	var str_hostname = window.location.hostname;
	var array_hostname = str_hostname.split(".");
	var str_domain = "";
	
	if(array_hostname.length >= 3)
	{
		str_domain = array_hostname[(array_hostname.length-2)] + "." + array_hostname[(array_hostname.length-1)];
		document.domain = str_domain;
	}
	
	delete str_hostname;
	delete array_hostname;
	delete str_domain;
	
}
/* "try" gibt's erst ab JS1.5, document.domain jedoch seit JS1.1 */
/*
try {
	document.domain = 'porsche-stadt.de';
} catch (e) {
	
}
*/
/* END Webmobil24-IFRAME */

var g_timeout = -1;
var g_timeoutTime = 500;
var g_openZoom = 0;
var g_openKnowledgeBase = 0;
var g_imageNr = 1;
var g_req;

/* fuer statische version */
var root="http://www.porsche-muenchen.de/portal";
//var root="http://www.mosaiq-media.de/kunden/porsche_stadt_2005/portal";

var g_currentModelLink = '';
var g_echoCount = 0;
var g_is_opera = false;
var g_is_ie = false;
var g_is_ie5 = false;
var g_is_ie5_5 = false;
var g_is_safari = false;
var g_is_mac = true;
window.onload = function ()
{
    positionFooter();
};

// pkg 06.12.2005
window.onload = function ()
{
    initAll();
};


function initAll()
{
    var sClass = "";
    if (document.body.className) {
        sClass = document.body.className;
    }
    else {
        sClass = document.body.getAttribute("class");
    }
    if (sClass != undefined) {
        g_is_home = sClass.indexOf("home") >= 1;
    }
    else {
        g_is_home = false;
    }
    
    positionFooter();    

    var noteConflict = false;
    sniffAll();
    if (document.getElementById) {
        g_canHandleTransparency = !g_is_ie5;
    }
    else if (noteConflict) {
        gotoUrl("/browser.htm");
    }
    if (g_is_home) {
        initHome();
    }


}






/*
 * Erzeugt JavaScript E-Mail-Links
 */
 function js_email_javascript(prefix, user, host, suffix, suffix2)
 	{
 	document.write(prefix+user+'@'+host+suffix+user+'@'+host+suffix2);
 	}

function positionFooter()
{
    var footer = document.getElementById("footer");
    if (footer) { footer.style.bottom = "-1px"; }
    var search = document.getElementById("search");
    if (search) { search.style.bottom = "-1px"; }
}

function overHome()
{
    if (g_timeout != -1) { clearTimeout(g_timeout); }
    showNavHomeSub();
}

function outHome()
{
    g_timeout = setTimeout("hideNavHomeSub()", g_timeoutTime);
}

function overNavHomeSub()
{
    if (g_timeout != -1) { clearTimeout(g_timeout); }
}

function outNavHomeSub()
{
    if (g_timeout != -1) { clearTimeout(g_timeout); }
    g_timeout = setTimeout("hideNavHomeSub()", g_timeoutTime);
}

function showNavHomeSub()
{
    showLr("navigationHomeSub");
    showLr("navigationShade");
    setBackground("navigationHome", "rgb(242,242,242)");
}

function hideNavHomeSub()
{
    hideLr("navigationHomeSub");
    hideLr("navigationShade");
    setBackground("navigationHome", "rgb(255,255,255)");
}

function setBackground(id, sBack)
{
    var elm = document.getElementById(id);
    elm.style.backgroundColor = sBack;
}

function clickKnowledgebase(sUrl)
{
    if (g_openKnowledgeBase == 0)
    {
        var pageWidth = 839;
        var shadeborder = 8;

        imgWidth = 646;
        imgHeight = 535;

        var elmShade = document.getElementById("knowledgeBaseShade");
        var elmKB = document.getElementById("knowledgeBase");

        var imgX = pageWidth / 2 - imgWidth / 2;
        var imgY = Math.round( (viewportGetHeight() - imgHeight)/2 ) + viewportGetScrollY();

        if (imgY < 0) { imgY = 0; }
        if (imgX < 0) { imgX = 0; }

        elmShade.style.left = (imgX - shadeborder) + "px";
        elmShade.style.top = (imgY - shadeborder) + "px";

        elmKB.style.left = imgX + "px";
        elmKB.style.top = imgY + "px";

        var elmCloseButton = document.getElementById("closeButtonKbase");
        if (elmCloseButton) {
            elmCloseButton.style.left = (imgWidth - 19) + "px";
        }

        elmKB.style.display = "block";
        elmShade.style.display = "block";

        g_openKnowledgeBase = sUrl;

        prepareFillKbase(sUrl);
    }
}

function closeKnowledgebase()
{
    hideLr("knowledgeBaseShade");
    hideLr("knowledgeBase");
    g_openKnowledgeBase = 0;
}

function prepareFillKbase(sUrl)
{
    sUrl += getCachePrevent();
    if (window.XMLHttpRequest) {
        g_req = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        g_req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    g_req.onreadystatechange = fillKbase;
    g_req.open("GET", sUrl, true);
    g_req.send(null);
}

function getCachePrevent()
{
    return "?rand=" + escape( Math.round( Math.random() * 10000 ) );
}

function fillKbase() /* wenns nicht mehr funktioniert, liegt es an dem zusammengebauten s-string mit root */
{
    if (g_req.readyState == 4)
    {
        if (g_req.status == 200)
        {
            var s = "";
        
            var elmKB = document.getElementById("knowledgeBase");
            var s = "";

            s += "";
            s += "<div class=\"closeButton\" id=\"closeButtonKbase\" onclick=\"closeKnowledgebase()\"><img src=\"";
            s += root+"/pics/layout/close-button.gif\" alt=\"[X]\" title=\"Close\" /></div>";
            s += g_req.responseText;
            s = replStr(s, "<?xml version=\"1.0\"?>", "");

            elmKB.innerHTML = s;     
        }
        else
        {
            alert("Can't retrieve XML: " + g_req.statusText);
        }
    }
}

function replStr(str,oldStr,newStr)
{ var strPos=str.indexOf(oldStr);
  return (strPos>=0) ?
    str.substring(0,strPos) + newStr +
       replStr( str.substring(strPos +
       oldStr.length), oldStr, newStr ) :
    str
}

function clickZoomable(id, imgWidth, imgHeight)
{
    if (g_openZoom == 0)
    {
        var pageWidth = 840;
        var shadeborder = 8;

        var elmShade = document.getElementById("zoomImageShade");
        var elmImage = document.getElementById("zoomImage" + id);
        var elmCloseButton = document.getElementById("closeButton" + id);

        var imgX = pageWidth / 2 - imgWidth / 2;
        var imgY = Math.round( (viewportGetHeight() - imgHeight)/2 ) + viewportGetScrollY();

        if (imgY < 0) { imgY = 0; }
        // if (imgX < 0) { imgX = 0; }
				
				
         elmShade.style.left = (imgX - shadeborder) + "px";
        // *1 damit es wirklich ein  int ist. sonst wird nur string-concateniert!
       	elmShade.style.width = (imgWidth*1+(shadeborder*1*2))+ "px";
        elmShade.style.top = (imgY - shadeborder) + "px";
        elmShade.style.height = (imgHeight*1 + shadeborder*1*2) + "px";

        elmImage.style.left = imgX + "px";
        elmImage.style.top = imgY + "px";
        if (elmCloseButton) {
            elmCloseButton.style.left = (imgWidth - 19) + "px";
        }

        elmImage.style.display = "block";
        elmShade.style.display = "block";

        g_openZoom = id;
    }
}

function clickZoomed()
{
    hideLr("zoomImageShade");
    hideLr("zoomImage" + g_openZoom);
    g_openZoom = 0;
}

function showLr(id)
{
    var elm = document.getElementById(id);
    if (elm) {
        elm.style.display = "block";
    }
}

function hideLr(id)
{
    var elm = document.getElementById(id);
    if (elm) {
        elm.style.display = "none";
    }
}


/* Expandable module */

function expandCollapse(id)
{
    var elm = document.getElementById("expandable_" + id);

    if (elm)
    {
        /* Hack alert -- footer will be hidden temporarily
        to recalculate bottom position correctly.
        */

        var footer = document.getElementById("footer");
        footer.style.display = "none";

        if (elm.style.height != "auto")
        {
            elm.style.height = "auto";
        
            var h3 = document.getElementById("expandableHead_" + id);
            if (h3) {
                h3.style.backgroundColor = "rgb(102,102,102)";
                h3.style.color = "rgb(255,255,255)";
                /* vorher: h3.style.backgroundImage = "url(images/arrow-lightgrey-down.gif)";*/
                h3.style.backgroundImage = "url("+root+"/pics/layout/arrow-lightgrey-down.gif)";
                h3.style.backgroundPosition = "9px 9px";
            }
        }
        else
        {
            elm.style.height = "19px";

            var h3 = document.getElementById("expandableHead_" + id);
            if (h3) {
                h3.style.backgroundColor = "rgb(204,204,204)";
                h3.style.color = "rgb(0,0,0)";
                /* vorher: h3.style.backgroundImage = "url(pics/layout/arrow-grey.gif)";*/
                h3.style.backgroundImage = "url("+root+"/pics/layout/arrow-grey.gif)";
                h3.style.backgroundPosition = "11px 7px";
            }
        }

        footer.style.display = "block";
        footer.style.bottom = "-1px";

    }
}

function viewportGetHeight()
{
    var retval = 0;

    if (window.innerHeight)
        retval = window.innerHeight - 18;
    else if (document.documentElement && document.documentElement.clientHeight) 
        retval = document.documentElement.clientHeight;
    else if (document.body && document.body.clientHeight) 
        retval = document.body.clientHeight;

    return retval;    
}

function viewportGetScrollY()
{
    var retval = 0;

    if (typeof window.pageYOffset == "number")
        retval = window.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop)
        retval = document.documentElement.scrollTop;
    else if (document.body && document.body.scrollTop) 
        retval = document.body.scrollTop; 
    else if (window.scrollY)
        retval = window.scrollY;

    return retval;
}

function playMovie(id)
{
    // todo: play Flash
    alert("Coming soon");
}


/* Gallery module */

var g_lastNumber = 1;

function setImage(elm, n)
{
    if (g_lastNumber != n)
    {
        var lastElm = document.getElementById("thumbnail" + g_lastNumber);
        lastElm.className = "";
        lastElm.style.border = "1px solid #ccc";

        var thisElm = document.getElementById("thumbnail" + n);
        thisElm.className = "selected";
        thisElm.style.border = "1px solid rgb(204,0,0)";

        g_lastNumber = n;

        sHref = elm.href;
        document.getElementById("galleryImage").src = sHref;
    }

    return false;
}

function setThumbnail(elm, n)
{
    if (g_lastNumber != n)
    {
        var lastElm = document.getElementById("thumbnail" + g_lastNumber);
        lastElm.className = "";
        lastElm.style.border = "1px solid #ccc";

        var thisElm = document.getElementById("thumbnail" + n);
        thisElm.className = "selected";
        thisElm.style.border = "1px solid rgb(204,0,0)";

        g_lastNumber = n;
    }

    return false;
}

function nextgalleryImage()
{
    var lastElm = document.getElementById("thumbnail" + g_lastNumber);
    lastElm.className = "";
    lastElm.style.border = "1px solid #ccc";

    var n = ++g_lastNumber;
    var max = getMaxNumberGallery();
    if (n > max) { n = 1; }

    var thisElm = document.getElementById("thumbnail" + n);
    thisElm.className = "selected";
    thisElm.style.border = "1px solid rgb(204,0,0)";

    var elm = document.getElementById("href" + n);
    sHref = elm.href;
    document.getElementById("galleryImage").src = sHref;

    g_lastNumber = n;

    return false;
}

function getMaxNumberGallery()
{
    var max = 0;
    for (var i = 15; i >= 5 && max == 0; i--) {
        var testElm = document.getElementById("thumbnail" + i);
        if (testElm) {
            max = i;
            break;
        }
    }

    return max;
}

function showWallpaper(img, iWidth, iHeight)
{
		/* vorher: var imageUrl = "images/" + img + "/" + iWidth + "-" + iHeight + "/" + g_imageNr + ".jpg"; */
    var imageUrl = root+"/pics/" + img + "/" + iWidth + "-" + iHeight + "/" + g_imageNr + ".jpg";
    gotoUrlNewWin(imageUrl);
}


/* Windows module */

function gotoUrlNewWinSimple(s)
{
    newWin = window.open(s, "newWin" + getRandomInt(10000));
}

function gotoUrlNewWin(s)
{
    sWidth = 826;
    sHeight = 610;

    sWidth += 20;
    sHeight += 25;
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function gotoUrlNewWinSize(s, sWidth, sHeight)
{
    sWidth += 20;
    sHeight += 25;
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function gotoUrlNewWinSizeCentered(s, iWidth, iHeight)
{
    iWidth += 20;
    iHeight += 25;	
    iLeft = Math.round((screen.width - iWidth) / 2);
    iTop = Math.round((screen.height - iHeight) / 2);
    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + iWidth + ",height=" + iHeight + ",left=" + iLeft + ",top=" + iTop + ",dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function gotoUrlNewWinSizeByName(s, sWidth, sHeight, sName)
{
    sWidth += 20;
    sHeight += 25;
    newWin = window.open(s, sName, "width=" + sWidth + ",height=" + sHeight + ",left=40,top=40,dependent=yes,location=no,resizable=no,scrollbars=no,status=no");
}

function openLeanWin(sUrl, sWidth, sHeight)
{
    sWidth += 20;
    sHeight += 25;
    newWin = window.open(sUrl, "newWin" + getRandomInt(10000), "width=" + sWidth + ",height=" + sHeight + ",left=140,top=140,dependent=yes,location=no,resizable=no,scrollbars=no,status=no,menubar=no,toolbar=no");
}


// pkg 06.12.2005 //
function gotoUrl(s)
{
    g_psyma_navi_clicked = true;
    document.location.href = s;
}

function gotoUrlTimeout(s, timeout)
{
  setTimeout("gotoUrl('" + s + "')", timeout)
}
function nogo()
{
    //
}


function getRandomInt(max)
{
    return Math.round( Math.random() * (max-1) );
}


/* Ad-Tracker module */

function getAdTrackerNumber()
{
    var axel = Math.random() + "";
    var a = axel * 10000000000000;
    return a;
}



/* Home module */

var g_initHome = false;
var g_timeoutHide1 = 0;
var g_timeoutHide2 = 0;
var g_timeoutHide3 = 0;
var g_timeoutHide4 = 0;
var g_timeoutTime = 80;
var g_currentNav1 = "";
var g_currentNav2 = "";
var g_currentNav3 = "";
var g_currentNav4 = "";

var g_currentHi1 = "";
var g_currentHi2 = "";
var g_currentHi3 = "";
var g_currentHi4 = "";

var g_blackValue = 0;
var g_blackTimeout = 0;
var g_navShadeMax = .35;

var g_currentModelLink = '';
var g_echoCount = 0;
var g_is_opera = false;
var g_is_ie5 = false;
var g_is_ie5_5 = false;
var g_is_safari = false;
var g_is_mac = true;


function initHome()
{
    sniffAll();
    
    if (document.getElementById)
    {
        g_canHandleTransparency = !g_is_ie5;
        g_initHome = true;
    }
    else if (noteConflict)
    {
        gotoUrl("/browser.htm");
    }
}

function bannerLinkToHi(sId)
{
    if (!g_initHome) { initHome(); }
    if (g_initHome)
    {
        var elm = document.getElementById(sId);
        if (elm)
        {
            elm.style.color = "#c00";
            /* vorher:  elm.style.backgroundImage = "url(pics/layout/arrow-red.gif)"; */
            elm.style.backgroundImage = "url("+root+"pics/layout/arrow-red.gif)";
        }
    }

}

function bannerLinkToLo(sId)
{
    if (!g_initHome) { initHome(); }
    if (g_initHome)
    {
        var elm = document.getElementById(sId);
        if (elm)
        {
            elm.style.color = "rgb(102,102,102)";
            /* vorher:  elm.style.backgroundImage = "url(images/arrow-grey.gif)";*/
            elm.style.backgroundImage = "url("+root+"/pics/layout/arrow-grey.gif)";
        }
    }
}

function navShadeIn(level)
{
    if (!g_initHome) { initHome(); }
    if (g_initHome)
    {
        if (level == 1)
        {
            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }
        }
        else if (level == 2)
        {
            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }
            if (g_timeoutHide2 != 0) { clearTimeout(g_timeoutHide2); }
        }
        else if (level == 3)
        {
            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }
            if (g_timeoutHide2 != 0) { clearTimeout(g_timeoutHide2); }
            if (g_timeoutHide3 != 0) { clearTimeout(g_timeoutHide3); }
        }
    }
}

function navShadeOut(level)
{
    if (!g_initHome) { initHome(); }
    if (g_initHome)
    {
        if (level == 1)
        {
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);
        }
        else if (level == 2)
        {
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);
            g_timeoutHide2 = setTimeout("hideNav(2,\"" + g_currentNav2 + "\",\"" + g_currentHi2 + "\")", g_timeoutTime);
        }
        else if (level == 3)
        {
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);
            g_timeoutHide2 = setTimeout("hideNav(2,\"" + g_currentNav2 + "\",\"" + g_currentHi2 + "\")", g_timeoutTime);
            g_timeoutHide3 = setTimeout("hideNav(3,\"" + g_currentNav3 + "\",\"" + g_currentHi3 + "\")", g_timeoutTime);
        }
    }
}

function overNav(level, sName, sSelf)
/**
* Zeigt bei einem Mouseover über das Hauptmenue auf Startseite das 
* dazugehoerige Submenue an.
* @param level: ebene des menues
* @param sName: name des elements, welches durch den mouseover angezeigt werden soll. 
* die id dieses elements setzt sich zusammen aus "nav_sName_i". fuer i wird aufsteigend eine zahl ab 1 eingesetzt. 
* das element wurde bisher durch die eigenschaft display:none ausgeblendet, welche durch javascript dann 
* auf display:block geaendert wird.
* @param sSelf: der name des elements, welches diese funktion ausgeloest hat. ist gleichzeitig die id des elements.
*
*/
{
    if (!g_initHome) { initHome(); }
    if (g_initHome)
    {
        if (level == 0 || level == "0")
        {
            echo("level in 0");

            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }

            hideSubLayers(g_currentNav1);
            loliteLr(level, g_currentHi1);

            if (g_currentNav1 != "") { hideSubLayers(g_currentNav1); }
            if (g_currentHi1 != "") { loliteLr(level, g_currentHi1); }

            showNav(level + 1, sName, sSelf);
            g_currentNav1 = sName;
            g_currentHi1 = sSelf;
        }
        else if (level == 1 || level == "1")
        {
            echo("level in 1");

            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }
            if (g_timeoutHide2 != 0) { clearTimeout(g_timeoutHide2); }

            if (g_currentNav2 != "") { hideSubLayers(g_currentNav2); }
            if (g_currentHi2 != "") { loliteLr(level, g_currentHi2); }

            showNav(level + 1, sName, sSelf);
            g_currentNav2 = sName;
            g_currentHi2 = sSelf;
        }
        else if (level == 2 || level == "2")
        {
            echo("level in 2");

            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }
            if (g_timeoutHide2 != 0) { clearTimeout(g_timeoutHide2); }
            if (g_timeoutHide3 != 0) { clearTimeout(g_timeoutHide3); }

            if (g_currentNav3 != "") { hideSubLayers(g_currentNav3); }
            if (g_currentHi3 != "") { loliteLr(level, g_currentHi3); }

            showNav(level + 1, sName, sSelf);
            g_currentNav3 = sName;
            g_currentHi3 = sSelf;
            loadImage(sName);
        }
        else if (level == 3 || level == "3")
        {
            echo("level in 3");

            if (g_timeoutHide1 != 0) { clearTimeout(g_timeoutHide1); }
            if (g_timeoutHide2 != 0) { clearTimeout(g_timeoutHide2); }
            if (g_timeoutHide3 != 0) { clearTimeout(g_timeoutHide3); }
            if (g_timeoutHide4 != 0) { clearTimeout(g_timeoutHide4); }

            if (g_currentNav4 != "") { hideSubLayers(g_currentNav4); }

            showNav(level + 1, sName, sSelf);
            g_currentNav4 = sName;
        }
    }
}


function loadImage(sName)
/**
* laedt das bild fuer ein informations-fenster, welches im hauptmenue auf startseite erscheinen kann
* (menue 4. ebene). der bildname wurde der funktion overNav als 2. parameter uebergeben, hier wird er 
* zu einem dateinamen zusammengesetzt
*/
{
    sName = "nav_" + sName + "_1"; 
   /* vorher: */
    /*var elem = document.getElementById(sName).childNodes[1];//.childNodes[1].childNodes[1];*/
    /* ziemlich hart reinprogrammiert.. vielleicht besser so: */
    var elem = document.getElementById(sName+"_image");
    
    if (elem)
    {
    	//document.write("/PorscheWebsite/all/home/image/info/" + sName + "_image.jpg");
      /* vorher: */ // elem.src = "/PorscheWebsite/all/home/image/info/" + sName + "_image.jpg";
      /* nochmal vorher, aber nach dem vorigen vorher: elem.src = "images/info/" + sName + "_image.jpg"; */
       	elem.src = root+"/pics/info/" + sName + "_image.jpg";
    }
}

function outNav(level)
{
    if (!g_initHome) { initHome(); }
    if (g_initHome)
    {
        if (level == 0 || level == "0")
        {
            echo("level out 0");
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);
        }
        else if (level == 1 || level == "1")
        {
            echo("level out 1");
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);
            g_timeoutHide2 = setTimeout("hideNav(2,\"" + g_currentNav2 + "\",\"" + g_currentHi2 + "\")", g_timeoutTime);
        }
        else if (level == 2 || level == "2")
        {
            echo("level out 2");
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);
            g_timeoutHide2 = setTimeout("hideNav(2,\"" + g_currentNav2 + "\",\"" + g_currentHi2 + "\")", g_timeoutTime);
            g_timeoutHide3 = setTimeout("hideNav(3,\"" + g_currentNav3 + "\",\"" + g_currentHi3 + "\")", g_timeoutTime);
        }
        else if (level == 3 || level == "3")
        {
            echo("level out 3");
            g_timeoutHide1 = setTimeout("hideNav(1,\"" + g_currentNav1 + "\",\"" + g_currentHi1 + "\")", g_timeoutTime);
            g_timeoutHide2 = setTimeout("hideNav(2,\"" + g_currentNav2 + "\",\"" + g_currentHi2 + "\")", g_timeoutTime);
            g_timeoutHide3 = setTimeout("hideNav(3,\"" + g_currentNav3 + "\",\"" + g_currentHi3 + "\")", g_timeoutTime);
            g_timeoutHide4 = setTimeout("hideNav(4,\"" + g_currentNav4 + "\",\"" + g_currentHi4 + "\")", g_timeoutTime);
        }
        else
        {
            echo("level out is else: " + level);
        }
    }
}

function dimHeadline(doOn)
{         
    var elem = document.getElementById("heading_home");
    
    if (elem) {
            
                if (doOn)
                {	
                    elem.style.MozOpacity = ".99";
                    elem.style.filter = "alpha(opacity=100)";
                }
                else
                {
                    elem.style.MozOpacity = ".40";
                    elem.style.filter = "alpha(opacity=40)";
                }
    }
}

function showNav(level, sName, sSelf)
{
    dimHeadline(false);

    hiliteLr(level - 1, sSelf);
    var foundOne = showSubLayers(sName);
    if (foundOne)
    {
        if (g_canHandleTransparency)
        {
            var elm = document.getElementById("navshade" + level);
            showLr("navshade" + level);
        }
        else
        {
            var elm = document.getElementById("navshadeSimple" + level);
            showLr("navshadeSimple" + level);
        }
    }
    else
    {
        if (g_canHandleTransparency)
        {
            hideLr("navshade" + level);
        }
        else
        {
            hideLr("navshadeSimple" + level);
        }
    }
}

function hideNav(level, sName, sSelf)
{
    if (level == 1) { g_timeoutHide1 = 0; g_currentNav1 = ""; g_currentSelf1 = ""; dimHeadline(true); }
    if (level == 2) { g_timeoutHide2 = 0; g_currentNav2 = ""; g_currentSelf2 = ""; }
    if (level == 3) { g_timeoutHide3 = 0; g_currentNav3 = ""; g_currentSelf3 = ""; }
    if (level == 4) { g_timeoutHide4 = 0; g_currentNav4 = ""; }

    loliteLr(level - 1, sSelf);


    if (g_canHandleTransparency)
    {
        hideLr("navshade" + level);
    }
    else
    {
        hideLr("navshadeSimple" + level);
    }

    hideSubLayers(sName);
}

function hiliteLr(level, sName)
{
    var elem = document.getElementById(sName);
    if (elem)
    {
        if (level == 0 || level == "0")
        {
            elem.style.color = "rgb(204, 0, 0)";
            elem.style.backgroundColor = "rgb(255,255,255)";
            if (! (elem.className.indexOf("final") >= 0) )
            {		// hintergrundbild fuer hauptmenue auf startseite bei mouseover: roter pfeil nach rechts
            	/* vorher:    elem.style.backgroundImage = "url(pics/layout/arrow-red.gif)";*/
                elem.style.backgroundImage = "url("+root+"/pics/layout/arrow-red.gif)";
            }
        }
        else
        {
            elem.style.color = "rgb(204, 0, 0)";

            if (! (elem.className.indexOf("final") >= 0) )
            {
            		// hintergrundbild fuer submenue eines hauptmenuepunktes auf startseite bei mouseover: roter pfeil nach rechts
            		// url muss hier ausgehend von html-datei angegeben werden!!
            		/* vorher:    elem.style.backgroundImage = "url(images/arrow-red.gif)"; */
                elem.style.backgroundImage = "url("+root+"/pics/layout/arrow-red.gif)";
            }

            elem.style.MozOpacity = ".99"; // hack around weeeiiird bug which causes "1" to break NS7.02
            elem.style.filter = "alpha(opacity=100)";
        }
    }
}

function loliteLr(level, sName)
{
    var elem = document.getElementById(sName);
  
    if (elem)
    {
        if (level == 0 || level == "0")
        {
            elem.style.color = "rgb(255,255,255)";
            elem.style.backgroundColor = "transparent";
            if (! (elem.className.indexOf("final") >= 0) )
            {
            		/* vorher: elem.style.backgroundImage = "url(images/arrow-white.gif)";*/
                elem.style.backgroundImage = "url("+root+"/pics/layout/arrow-white.gif)";
            }
        }
        else
        {
            elem.style.color = "rgb(0, 0, 0)";
            if (! (elem.className.indexOf("final") >= 0) )
            {
            		/* vorher: elem.style.backgroundImage = "url(images/arrow-grey.gif)"; */
                elem.style.backgroundImage = "url("+root+"/pics/layout/arrow-grey.gif)";
            }

            elem.style.MozOpacity = ".86";
            elem.style.filter = "alpha(opacity=86)";
        }
    }
}

/* zeigt submenue des mouse-over menues auf startseite an zu dem menuepunkt sName */
function showSubLayers(sName)
{
    var i = 0;
    var foundOne = false;

    for (i = 1; i <= 13; i++)
    {
        var s = "nav_" + sName + "_" + i; 
        var elem = document.getElementById(s); /* sucht element im html-dokument mit id "nav_xxx_i" */
        if (elem)
        {
            foundOne = true;
        }
        else
        {
            break;
        }

        showLr(s);
    }

    return foundOne;
}

function hideSubLayers(sName)
{
    var i = 0;
    var foundOne = false;

    for (i = 1; i <= 13; i++)
    {
        var s = "nav_" + sName + "_" + i;
        var elem = document.getElementById(s);
        if (elem)
        {
            foundOne = true;
        }
        else
        {
            break;
        }

        hideLr(s);
    }

    return foundOne;
}

function echo(s)
{
    /*
    var elDebug = document.getElementById("debug");
    elDebug.innerHTML = "<div><span>" + (++g_echoCount) + ".</span> " + s + "</div>" + elDebug.innerHTML;
    */
}

function setModel(s)
{
    if (!g_initHome) { initHome(); }
    if (g_initHome)
    {
        g_currentModelLink = s;
    }
}

function gotoModel()
{
    if (!g_initHome) { initHome(); }
    if (g_initHome)
    {
        if (g_currentModelLink != '')
        {
            gotoUrl(g_currentModelLink);
        }
    }
}

function gotoUrl(s)
{
    document.location.href = s;
}

function nogo()
{
    //
}

function getRandomInt(max)
{
    return Math.round( Math.random() * (max-1) );
}

function selectAllInput(elm)
{
    if (elm)
    {
        elm.focus();
        elm.select();
    }
}

function changedCountry(elmThis)
{
    if (document.getElementById)
    {
        var sUrl = elmThis.value;

        if (sUrl != "")
        {
            document.location.href = sUrl;
        }
    }
}

function sniffAll()
{
    /* JavaScript Browser Sniffer
       Eric Krok, Andy King, Michel Plungjan Jan. 31, 2002
       see http://www.webreference.com/ for more information
       This program is free software */

    var agt=navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();

    var is_minor = parseFloat(appVer);
    var is_major = parseInt(is_minor);

    var is_opera = (agt.indexOf("opera") != -1);

    /*
    var is_opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1);
    var is_opera7 = (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1);
    var is_opera6up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5);
    var is_opera7up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5 && !is_opera6);
    */

    var iePos  = appVer.indexOf('msie');
    if (iePos !=-1) {
       is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
       is_major = parseInt(is_minor);
    }

    var is_konq = false;
    var kqPos   = agt.indexOf('konqueror');
    if (kqPos !=-1) {                 
       is_konq  = true;
       is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
       is_major = parseInt(is_minor);
    }

    var is_getElementById   = (document.getElementById) ? "true" : "false";
    var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
    var is_documentElement = (document.documentElement) ? "true" : "false";

    var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
    var is_khtml  = (is_safari || is_konq);

    var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
    var is_gver  = 0;
    if (is_gecko) is_gver=navigator.productSub;

    var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                    (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                    (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                    (is_gecko) && 
                    ((navigator.vendor=="")||(navigator.vendor=="Mozilla")));


    if (is_moz) {
       var is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
       if(!(is_moz_ver)) {
           is_moz_ver = agt.indexOf('rv:');
           is_moz_ver = agt.substring(is_moz_ver+3);
           is_paren   = is_moz_ver.indexOf(')');
           is_moz_ver = is_moz_ver.substring(0,is_paren);
       }
       is_minor = is_moz_ver;
       is_major = parseInt(is_moz_ver);
    }

    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
                && (!is_khtml) && (!(is_moz)));

    if ((navigator.vendor)&&
        ((navigator.vendor=="Netscape6")||(navigator.vendor=="Netscape"))&&
        (is_nav)) {
       is_major = parseInt(navigator.vendorSub);
       is_minor = parseFloat(navigator.vendorSub);
    }

    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && is_minor >= 4); 
    var is_navonly  = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );

    var is_nav6   = (is_nav && is_major==6);
    var is_nav6up = (is_nav && is_minor >= 6);

    var is_nav5   = (is_nav && is_major == 5 && !is_nav6);
    var is_nav5up = (is_nav && is_minor >= 5);

    var is_nav7   = (is_nav && is_major == 7);
    var is_nav7up = (is_nav && is_minor >= 7);

    var is_ie   = ((iePos!=-1) && (!is_opera) && (!is_khtml));
    var is_ie3  = (is_ie && (is_major < 4));

    var is_ie4   = (is_ie && is_major == 4);
    var is_ie4up = (is_ie && is_minor >= 4);
    var is_ie5   = (is_ie && is_major == 5);
    var is_ie5up = (is_ie && is_minor >= 5);
    
    var is_ie5_5  = (is_ie && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5_5up =(is_ie && is_minor >= 5.5);
	
    var is_ie6   = (is_ie && is_major == 6);
    var is_ie6up = (is_ie && is_minor >= 6);

// pkg 06.12.2005 //
    g_is_ie = is_ie;
    g_is_opera = is_opera;
    g_is_ie5 = is_ie5;
    g_is_ie5_5 = is_ie5_5;
    g_is_safari = is_safari;
}



/* Module Motorschaubild */

function showDetail(item) {
    getDiagramDetail(item).style.display = "block";
}
	
function hideDetail(item) {
    getDiagramDetail(item).style.display = "none";
}	
	
function getDiagramDetail(item) {
    return document.getElementById("engineDiagramDetail" + item.getAttribute("id").substr(17,2));
}

/* zusaetzliche funktionen */
function link(URL)
{
window.opener.location.href=URL;
}

// pkg 12.2005 //
   // Eine Liste aller geöffneten Popups
   var PopupList = new Array();
   
   //
   // Öffnen eines Fensters.
   //
	function js_popup(str_url, str_name, str_window, int_width, int_height, int_x, int_y, str_features)
	   	{
	    str_features = str_features + ',width=' + int_width + ',height=' + int_height;
	   
		if (int_x=='false')
	   	  str_features = str_features + ',left=' + (screen.width/2 - int_width/2) + ',top=' + (screen.height/2 - int_height/2);
	    else
	   	  str_features = str_features + ',left=' + int_x + ',top=' + int_y;
	    
		if (PopupList[str_window] && PopupList[str_window].closed == false)
			{
			obj_window = PopupList[str_window];
			obj_window.location.href = str_url;
			obj_window.resizeTo(int_width, int_height);
			}
		else
			{
			obj_window = window.open(str_url, str_window, str_features);
			PopupList[str_window] = obj_window;
			}
		obj_window.focus();
		}
		
/* --DEPRECATED-- car configurator aufruf */
function configureCar(marketId)
{
    var newMarketId = "";
    switch (marketId)
    {
        case "usa": newMarketId = "us"; break;
        case "germany": newMarketId = "de"; break;
    }
    gotoUrlNewWinSizeByName("http://cc.porsche.com/pva/ui/pva/index.jsp?sprache=" + marketId + "&modelrange=null", 960, 652, "PVA")
}

/* --NEU (15.01.2007)-- car configurator aufruf */
function startPVA(param, lang, user, pfad)
{
	bV = new BrowserDescription();
	bV.init();

	gotoUrlNewWinSizeByName("http://cc.porsche.com/" + pfad + "/ui/pva/pva.jsp?RT=" + new Date().getTime() + "&PARAM=" + param + "&LANG=" + lang + "&USER=" + user + "&BOS=" + bV.OS + "&BV=" + bV.version + "&BF=" + bV.family + "&BORG=" + bV.org +"", 960, 655, "PVA");
}
function BrowserDescription()
{
	this.OS	= null;
	this.version = 0;
	this.org = null;
	this.family	= null;

	this.init = detectBrowser;
}
function detectBrowser()
{
	var	platform = null;

	if (typeof(window.navigator.platform) != 'undefined')
	{
		platform = window.navigator.platform.toLowerCase();
		if (platform.indexOf('win') != -1)
			this.OS = 'win';
		else if (platform.indexOf('mac') != -1)
			this.OS = 'mac';
		else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
			this.OS = 'nix';
	}

	var i = 0;
	var ua = window.navigator.userAgent.toLowerCase();

	var foundKHTML = false;
	try
	{
		var _testStr = window+"";
	}
	catch (e)
	{
		foundKHTML = true;
	}
	if (foundKHTML)
	{
		this.family = 'khtml';
		this.org = 'khtml';
		// 20050701; tsc; fixed version detection for safari; begin
		if (ua.indexOf('safari')!=-1)
		{
			this.org = 'apple';
			this.version = parseFloat(ua.replace(/^.*safari\/(\d+)\.(\d+).*$/, "$1.$2"), 10);
		}
		// 20050701; tsc; fixed version detection for safari; end
	}
	else if (ua.indexOf('opera') != -1)
	{
		i = ua.indexOf('opera');
		this.family	= 'opera';
		this.org		= 'opera';
		this.version	= parseFloat('0' + ua.substr(i+6), 10);
	}
	else if ((i = ua.indexOf('msie')) != -1)
	{
		this.org		= 'microsoft';
		this.version	= parseFloat('0' + ua.substr(i+5), 10);

		if (this.version < 4)
			this.family = 'ie3';
		else
			this.family = 'ie4'
	}
	else if (typeof(window.controllers) != 'undefined' && typeof(window.locationbar) != 'undefined')
	{
		i = ua.lastIndexOf('/')
		this.version = parseFloat('0' + ua.substr(i+1), 10);
		this.family = 'gecko';

		// 20050701; tsc; fixed version detection for firefox; begin
		if (ua.indexOf('firefox') != -1)
		{
			if (isNaN(this.version = parseFloat(ua.replace(/^.*firefox\/(\d+)\.(\d+)\.(\d+).*$/, "$1.$2$3"), 10)))
				this.version = parseFloat(ua.replace(/^.*firefox\/(\d+)\.(\d+).*$/, "$1.$2"), 10);

			this.org = 'firefox';
		}
		// 20050701; tsc; fixed version detection for firefox; end
		else if (ua.indexOf('netscape') != -1)
			this.org = 'netscape';
		else if (ua.indexOf('compuserve') != -1)
			this.org = 'compuserve';
		else
		{
			this.org = 'mozilla';
			// 20050701; tsc; better version detection for mozilla; begin
			if (ua.match(/rv:\d+\.\d+\.\d+\)/)!=null)
				this.version = parseFloat(ua.replace(/^.*rv:(\d+)\.(\d+)\.(\d+)\).*$/, "$1.$2$3"), 10);
			// 20050701; tsc; better version detection for mozilla; end;
		}
	}
	else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)&& (ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
	{
	    var is_major = parseFloat(this.appVersion);

		if (is_major < 4)
			this.version = is_major;
		else
		{
			i = ua.lastIndexOf('/')
			this.version = parseFloat('0' + ua.substr(i+1), 10);
		}
		this.org = 'netscape';
		this.family = 'nn' + parseInt(this.appVersion);
	}
	else if ((i = ua.indexOf('aol')) != -1 )
	{
		// aol
		this.family	= 'aol';
		this.org		= 'aol';
		this.version	= parseFloat('0' + ua.substr(i+4), 10);
	}

	this.DOMCORE1	= (typeof(document.getElementsByTagName) != 'undefined' && typeof(document.createElement) != 'undefined');
	this.DOMCORE2	= (this.DOMCORE1 && typeof(document.getElementById) != 'undefined' && typeof(document.createElementNS) != 'undefined');
	this.DOMHTML	= (this.DOMCORE1 && typeof(document.getElementById) != 'undefined');
	this.DOMCSS1	= ( (this.family == 'gecko') || (this.family == 'ie4') );

	this.DOMCSS2   = false;
	if (this.DOMCORE1)
	{
		element = document.createElement('p');
		this.DOMCSS2 = (typeof(element.style) == 'object');
	}

	this.DOMEVENTS	= (typeof(document.createEvent) != 'undefined');
}
/* END car configurator aufruf */


/* JSL anzeigen eines bestimmten elements by id */
function showElementByID(id, active)
{
    var elem = document.getElementById(id);
		var elemActive = document.getElementById(active);
		//window.alert(id);

    if (elem && elemActive)
    {	
    	elem.style.display = "inline";
    	elemActive.style.display = "none";
    }
    	
}

/* JSL: 20060116 : hintergrundfarbe eines uebergebenen elements aendern 
id : die id des elements
colour: die neue hintergrundfarbe */
function changeBackgroundByID(id, colour)
{
	var elem = document.getElementById(id);
	
	if (elem)
		elem.style.background = colour;
			
}


// pkg 06.12.2005 //  
// 19.04.06 fgr/jsl ueberarbeitet
/* 
Die Funktion oeffnet eine url in dem angegebenen 
Ziel. Einige Elemente sind so verlinkt, dass 
der IE diesen Link nicht mehr versteht. Deshalb 
diese Funktion, allerdings wird sie in allen 
Browsern verwendet. 
*/
function gotoUrlHelper(url, target, element)
{

	
    if (target == "_blank") {
    	//alert("blank!");
    	window.open(url, 'newWindow');
    }
 	else if (target == "_self") {
    	
    	window.location.href = url;
    }
    else if (target == "_parent") {
    	parent.location.href = url;
    }
    else if (target == "_popup(450,300)") {
    	//alert("popup 450, 350");
    	js_popup(url, 'newWindow', 'newWindow', 450, 350, 200, 200, 'scrollbars=no,toolbar=no,location=no,status=no,menubar=no,directories=no')
    	//window.open(url, this, "width=450, height=300");
    }
    else if (target == "_popup(615,550)") {
    	//alert("popup 615, 550");
    	js_popup(url, 'newWindow', 'newWindow', 615, 550, 200, 200, 'scrollbars=no,toolbar=no,location=no,status=no,menubar=no,directories=no')
    }
/*	if (g_is_ie)
	{ 
	element.setAttribute("target", "");
	element.setAttribute("href", "#");
	    if (target == "_blank") {
	    	window.open(url, 'newWindow');
	    }
	 	else if (target == "_self") {
	    	
	    	//window.location.replace(url);
	    	window.location.href = url;
	    
	    }
	    else if (target == "_parent") {
	    	parent.location.href = url;
	    }
	    else if (target == "_popup(450,300)") {
	    	js_popup(url, 'newWindow', 'newWindow', 450, 350, 200, 200, 'scrollbars=no,toolbar=no,location=no,status=no,menubar=no,directories=no');
	    }
	    else if (target == "_popup(615,550)") {
	    	js_popup(url, 'newWindow', 'newWindow', 615, 550, 200, 200, 'scrollbars=no,toolbar=no,location=no,status=no,menubar=no,directories=no');
	    }
	}
	else
	{
	// fuer den firefox die popup-abwicklung:
	
	    if (target == "_popup(450,300)") {
	    	element.setAttribute("target", "");
		element.setAttribute("href", "#");
	    	js_popup(url, 'newWindow', 'newWindow', 450, 350, 200, 200, 'scrollbars=no,toolbar=no,location=no,status=no,menubar=no,directories=no');
	    }
	    else if (target == "_popup(615,550)") {
	    	element.setAttribute("target", "");
		element.setAttribute("href", "#");
	    	js_popup(url, 'newWindow', 'newWindow', 615, 550, 200, 200, 'scrollbars=no,toolbar=no,location=no,status=no,menubar=no,directories=no');
	    }
	}
    */
}


// pkg 07.12.2005 JS-für Film-Element//

function showGalleryFlash(pool, movieFolder, bandwidth, flashParams)
{
    var elmImg = document.getElementById("galleryImage");
    if (elmImg) {
        g_fallbackImage = elmImg.src;
    }
	
    var url = "pics/hauptdomain/filme/swf/videoplayer.swf";
    showFlash(url, "galleryContent", "615", "351", "7", "#FFFFFF",
            "loop=true,menu=true,quality=high,wmode=opaque",
            "pool=" + pool + ",flashfolder=" + movieFolder + ",id=" +  "test/" + ",bandwidth=" + bandwidth + ",eventhandler=flashEnded," + flashParams);
}

function flashEnded()
{
    if (g_fallbackImage != "") {
        var elmContent = document.getElementById("galleryContent");
        elmContent.innerHTML = "<img src=\"" + g_fallbackImage + "\" alt=\"\" id=\"galleryImage\" />";
    }
}

function showFlash(url, id, width, height, version, bgcolor, playerparamstr, flashparamstr) {

    if (! (g_is_home && g_is_safari) ) {
        var fo = new FlashObject(url, id, width, height, version, bgcolor);
        
        if (playerparamstr != undefined) {    
            var playerparams = playerparamstr.split(",");
            for (var i=0; i < playerparams.length; i++ ){
                var param = playerparams[i].split("=");
                fo.addParam(param[0], param[1]);
            }
        }
        
        if (flashparamstr != undefined) {
            var flashparams = flashparamstr.split(",");
            for (var i=0; i < flashparams.length; i++ ){
                var param = flashparams[i].split("=");
                fo.addVariable(param[0], param[1]); 
            }
        }
  
        fo.write(id);
    }
}



//Bookmarks
jQuery(document).ready(function () {
    jQuery(".sharelayer").hide();
    
    jQuery(".sharing").hover(
    function () {
        jQuery(".sharelayer").fadeIn(100);

    },
    function () {
        jQuery(".sharelayer").fadeOut(100);
    }
    );

});

//Wiredminds tracking
function click_track(value) {
    // trackt einen Besucher Klick
    if (g_is_home) {   // wm_cd1= value;
        try {
            wiredminds.count(value);
        }
        catch (e) {
            log("wiredminds tracking gescheitert! Value: " + value);
        }

    }
}


function sharethis(href, encoding) {
    var link;
    if (encoding == null)
        link = href.replace('URL', encodeURIComponent(document.location.toString()));
    else
        link = href.replace('URL', document.location.toString());

    link = link.replace('TITEL', document.title);

    window.open(link, 'share');
}



/**
 * Hinzufügen der Klasse last des letzten li-Elements für die Formatierung
 * der Blue-Box-Navigation
 */
$(document).ready(function(){
	$("ul.navigation-bluebox li.blueboxitem a").last().addClass('last');
});