/**  Version       : 1.2
  *  Last modified : (K. Breynck) 20.02.2004
  *  Author        : BBDO InterOne Hamburg (K. Breynck)
  *  Copyright     : BMW Group 2002-2004
  *
  *  Unique scripting solutions that are provided for  BMW Group sites are for use exclusively
  *  within  BMW Group projects.  No other use of these solutions is permitted.
  *
  **/



var popupManager = {};
    popupManager.anonymus = [];

function centerPopup(popupName,popupUrl,popupWidth,popupHeight,myWidth,myHeight,myScrollbar) {
	if(!myWidth)     {myWidth = 10;}
	if(!myHeight)    {myHeight = 50;}
	if(!myScrollbar) {myScrollbar = 1;}

	var popupLeft = (window.screen.width/2)  - (popupWidth/2 + myWidth);
	var popupTop  = (window.screen.height/2) - (popupHeight/2 + myHeight);

  if (popupName !== "") {
    popupManager[popupName] = window.open(popupUrl,popupName,("toolbar=no,location=no,status=no,menubar=no,scrollbars=" + myScrollbar + ",resizable=no,width=" + popupWidth + ",height=" + popupHeight + ",left=" + popupLeft + ",top=" + popupTop + ",screenX=" + popupLeft + ",screenY=" + popupTop));
    popupManager[popupName].focus();
  } else {
    popupManager.anonymus[popupManager.anonymus.length] = window.open(popupUrl,popupName,("toolbar=no,location=no,status=no,menubar=no,scrollbars=" + myScrollbar + ",resizable=no,width=" + popupWidth + ",height=" + popupHeight + ",left=" + popupLeft + ",top=" + popupTop + ",screenX=" + popupLeft + ",screenY=" + popupTop));
    popupManager.anonymus[popupManager.anonymus.length-1].focus();
  }
}

function justifyPopup(popupName,popupUrl,popupWidth,popupHeight,myScrollbar,myLeft,myTop) {
  if(!myScrollbar) {myScrollbar = 0;}
  if(!myLeft)      {myLeft      = 0;}
  if(!myTop)       {myTop       = 0;}

  var popupLeft = ((document.all) ? window.screenLeft + myLeft : window.screenX);
  var popupTop  = ((document.all) ? window.screenTop  + myTop  : window.screenY);

  if (isString(popupName) && (popupName !== "")) {
    popupManager[popupName] = window.open(popupUrl,popupName,("toolbar=no,location=no,status=no,menubar=no,scrollbars=" + myScrollbar + ",resizable=no,width=" + popupWidth + ",height=" + popupHeight + ",left=" + popupLeft + ",top=" + popupTop + ",screenX=" + popupLeft + ",screenY=" + popupTop));
    popupManager[popupName].focus();
  } else {
    popupManager.anonymus[popupManager.anonymus.length] = window.open(popupUrl,popupName,("toolbar=no,location=no,status=no,menubar=no,scrollbars=" + myScrollbar + ",resizable=no,width=" + popupWidth + ",height=" + popupHeight + ",left=" + popupLeft + ",top=" + popupTop + ",screenX=" + popupLeft + ",screenY=" + popupTop));
    popupManager.anonymus[popupManager.anonymus.length-1].focus();
  }
}

function toolTipInit() { // Call this function to initialise the tool tips. The parameter must be a list of names(String) for all 'toolTipImageLayers'.
  toolTipImgLyr = new Array();

  for(var i=0; i<arguments.length; i++) {
    toolTipImgLyr[arguments[i]] = DynLayer.getInline(arguments[i]);
  }

  toolTipDynLayer      = DynLayer.getInline('toolTipLayer');
}

function writeToolTip(myToolTipImageLayer, myToolTipText, myTooltipMaxWidth, myTooltipModes) {

  if(typeof(toolTipDynLayer) != "undefined") {

  

    var myOffset       = 0;             // Offset of the tool tip layer to the mouse sensitive tool tip image.

    var myBgSpanH      = 5;             // Horizontal span between the the tool tip text to its background border.

    var myBgSpanV      = 5;             // Vertical span between the tool tip text to its background border.

  

    var toolTipTimeOut = 250;

    var activateToolTipLyr;             // Variable for the timeout handling

  

    var newToolTipDynLayerPosX;         // New horizontal position of the tool tip.

    var rightToolTipDynLayerPosX;       // Standard horizontal position of the tool tip, if the browser window is not wide enough.

    var leftToolTipDynLayerPosX;        // Alternative horizontal position of the tool tip, if the browser window is not wide enough.

    var newToolTipDynLayerPosY;         // New vertical position of the tool tip.

    var upToolTipDynLayerPosY;          // Standard vertical position of the tool tip, if the browser window is not wide enough.

    var downToolTipDynLayerPosY;        // Alternative vertical position of the tool tip, if the browser window is not wide enough.

    var toolTipBottomPos;               // Vertical position of the right border of the tool tip.

  

    var toolTipRightPos;                // Hirizontal position of the right border of the tool tip.

  

    var newToolTipContent;

  

    var toolTipDynLayerHeight;

    var toolTipDynLayerWidth  = ((myTooltipMaxWidth) ? myTooltipMaxWidth : 202);

  

    var toolTipImageDynLayer  = toolTipImgLyr[myToolTipImageLayer];

  

    toolTipDynLayer.setVisible(0);

  

    if (myToolTipText) {

  

        newToolTipContent  = '<table cellpadding="0" cellspacing="0" width="' + (toolTipDynLayerWidth) + '" border="0">';

        newToolTipContent += '  <tr>';

        newToolTipContent += '    <td valign="top" width="' + (toolTipDynLayerWidth) + '" colspan="3" bgcolor="#000000"><img src="'+ rootpath + '/images/common/1x1_trans.gif" width="1" height="1" /></td>';

        newToolTipContent += '  </tr>';

        newToolTipContent += '  <tr>';

        newToolTipContent += '    <td valign="top" width="1" bgcolor="#000000"><img src="'+ rootpath + '/images/common/1x1_trans.gif" width="1" height="1" /></td>';

        newToolTipContent += '    <td valign="top" width="' + (toolTipDynLayerWidth-2) + '">';

  

        newToolTipContent += '      <table cellpadding="0" cellspacing="0" width="' + (toolTipDynLayerWidth-2) + '" border="0" bgcolor="#ffffe1">';

        newToolTipContent += '        <tr>';

        newToolTipContent += '          <td valign="top" width="' + (toolTipDynLayerWidth-2) + '" colspan="3"><img src="'+ rootpath + '/images/common/1x1_trans.gif" width="' + (toolTipDynLayerWidth-2) + '" height="' + (myBgSpanV-2) + '" /></td>';

        newToolTipContent += '        </tr>';

        newToolTipContent += '        <tr>';

        newToolTipContent += '          <td valign="top" width="' + myBgSpanH + '"  ><img src="'+ rootpath + '/images/common/1x1_trans.gif" width="' + myBgSpanH + '" height="1" /></td>';

        newToolTipContent += '          <td valign="top" width="' + (toolTipDynLayerWidth-(2*myBgSpanH)-2) + '" class="color000000"><span class="font11line13">' + myToolTipText + '</span></td>';

        newToolTipContent += '          <td valign="top" width="' + myBgSpanH + '"  ><img src="'+ rootpath + '/images/common/1x1_trans.gif" width="' + myBgSpanH + '" height="1" /></td>';

        newToolTipContent += '        </tr>';

        newToolTipContent += '        <tr>';

        newToolTipContent += '          <td valign="top" colspan="3"><img src="'+ rootpath + '/images/common/1x1_trans.gif" width="' + (toolTipDynLayerWidth-2) +  '" height="' + (myBgSpanV-2) + '" /></td>';

        newToolTipContent += '        </tr>';

        newToolTipContent += '      </table>';

  

        newToolTipContent += '    </td>';

        newToolTipContent += '    <td valign="top" width="1" bgcolor="#000000"><img src="'+ rootpath + '/images/common/1x1_trans.gif" width="1" height="1" /></td>';

        newToolTipContent += '  </tr>';

        newToolTipContent += '  <tr>';

        newToolTipContent += '    <td valign="top" colspan="3" bgcolor="#000000"><img src="'+ rootpath + '/images/common/1x1_trans.gif" width="1" height="1" /></td>';

        newToolTipContent += '  </tr>';

        newToolTipContent += '</table>';

  

      toolTipDynLayer.setHTML(newToolTipContent);

      toolTipDynLayerHeight = toolTipDynLayer.getContentHeight();

  

      toolTipRightPos  = toolTipImageDynLayer.getX() + toolTipImageDynLayer.getWidth()  + toolTipDynLayerWidth  + myOffset;

      toolTipBottomPos = toolTipImageDynLayer.getY() + toolTipImageDynLayer.getHeight() + toolTipDynLayerHeight + myOffset;

  

      rightToolTipDynLayerPosX = toolTipRightPos  - toolTipDynLayerWidth;

      downToolTipDynLayerPosY  = toolTipBottomPos - toolTipDynLayerHeight;

      leftToolTipDynLayerPosX  = toolTipImageDynLayer.getX() - toolTipDynLayerWidth  - myOffset;

      upToolTipDynLayerPosY    = toolTipImageDynLayer.getY() - toolTipDynLayerHeight - myOffset;

  

      switch (myTooltipModes) {

      case "1": // down right (if possible)

        newToolTipDynLayerPosX = (((toolTipRightPos)  < dynapi.document.getWidth()) ? rightToolTipDynLayerPosX   : ((leftToolTipDynLayerPosX < 0) ? 0 : leftToolTipDynLayerPosX ));

        newToolTipDynLayerPosY = (((toolTipBottomPos) < dynapi.document.getHeight())  ? downToolTipDynLayerPosY  : ((upToolTipDynLayerPosY < 0)   ? 0 : upToolTipDynLayerPosY ));

        break;

      case "2": // down left (if possible)

        newToolTipDynLayerPosX = ((leftToolTipDynLayerPosX < 0) ? 0 : leftToolTipDynLayerPosX);

        newToolTipDynLayerPosY = ((toolTipBottomPos < dynapi.document.getHeight())  ? downToolTipDynLayerPosY  : ((upToolTipDynLayerPosY < 0) ? 0 : upToolTipDynLayerPosY ));

        break;

      case "3": // top left (if possible)

        newToolTipDynLayerPosX = ((leftToolTipDynLayerPosX < 0) ? 0 : leftToolTipDynLayerPosX);

        newToolTipDynLayerPosY = ((upToolTipDynLayerPosY < 0) ? 0 : upToolTipDynLayerPosY);

        break;

      case "4": // top right align to image top (if possible)

        newToolTipDynLayerPosX = ((toolTipRightPos < dynapi.document.getWidth()) ? rightToolTipDynLayerPosX : ((leftToolTipDynLayerPosX < 0) ? 0 : leftToolTipDynLayerPosX ));

        newToolTipDynLayerPosY = ((upToolTipDynLayerPosY < 0) ? 0 : upToolTipDynLayerPosY);

        newToolTipDynLayerPosY += toolTipDynLayerHeight + 4;

        break;

      case "MINIOpenNights": // Special case for the module "MINI Open Nights" 

        newToolTipDynLayerPosX = ((toolTipRightPos < dynapi.document.getWidth()) ? rightToolTipDynLayerPosX : ((leftToolTipDynLayerPosX < 0) ? 0 : leftToolTipDynLayerPosX ));

        newToolTipDynLayerPosY = ((upToolTipDynLayerPosY < 0) ? 0 : upToolTipDynLayerPosY);

        newToolTipDynLayerPosY += toolTipDynLayerHeight + 44;

        break;

      default: // top right (if possible)

        newToolTipDynLayerPosX = ((toolTipRightPos < dynapi.document.getWidth()) ? rightToolTipDynLayerPosX : ((leftToolTipDynLayerPosX < 0) ? 0 : leftToolTipDynLayerPosX ));

        newToolTipDynLayerPosY = ((upToolTipDynLayerPosY < 0) ? 0 : upToolTipDynLayerPosY);

        break;

      }

  

      toolTipDynLayer.setX(newToolTipDynLayerPosX);

      toolTipDynLayer.setY(newToolTipDynLayerPosY);

  

      activateToolTipLyr   = window.setTimeout("toolTipDynLayer.setVisible(1)",toolTipTimeOut);

  

    } else {

      clearTimeout(activateToolTipLyr);

      toolTipDynLayer.setHTML('');

      toolTipDynLayer.setX(-1000);

      toolTipDynLayer.setY(-1000);

      toolTipDynLayer.setVisible(0);

    }

  }

}

function loadMainImage(imgPath, imageName) {
  var preload = new Image();
  preload.src = imgPath;
  document.images[imageName].src = preload.src;
}