//----------------------------------------
// Skoda Top Menu ver. 2.0
// JScript source code for SkodaTopMenu
// S K O D A   A U T O   a . s .
//----------------------------------------

//Definition of menu styles in html file - style tag or css file

//Definition of menu items
//Item attributes : itemName, itemPosition[left,top], itemSize[height,width], itemOff[left,top], 
//					itemLevelOff[left,top], itemUrl, itemStyle, itemDescription

//default global value
defaultItemLevelOnePosition	= [];
defaultItemLevelOneSize = [];
defaultItemLevelOneItemOff = [];
defaultItemLevelOneStyle = [];
defaultItemLevelOneUrl = [];
defaultItemLevelSecondSize = [];
defaultItemLevelSecondItemOff = [];
defaultItemLevelSecondLevelOff = [];
defaultItemLevelSecondStyle = [];
defaultItemLevelSecondUrl = [];


//Main function
function SkodaMenu(menuItems)
{
	//default values for first item level
	defaultItemLevelOnePosition = menuItems[0].itemPosition;
	defaultItemLevelOneSize = menuItems[0].itemSize;
	defaultItemLevelOneItemOff = menuItems[0].itemOff;
	defaultItemLevelOneStyle = menuItems[0].itemStyle;
	defaultItemLevelOneUrl = menuItems[0].itemUrl;

	//defining actual position for first level
	actualPosition = [];
	actualPosition[0] = defaultItemLevelOnePosition[0];
	actualPosition[1] = defaultItemLevelOnePosition[1];
	
	//creating element for printing tags
	element = document.createElement("Span");
	element.id = "MainMenuSpan";

	//loop for menuItems.length items
	// : create new menuItem
	stringHtmlTags = "";
	i = 1;
//
	for (i; i < menuItems.length; i++) {
		//setting position for current item
		currentItemPosition = (menuItems[i].itemPosition == null) ? actualPosition : menuItems[i].itemPosition;
		//setting other values for current item
		currentItemName = (menuItems[i].itemName == null) ? "undefined" : menuItems[i].itemName;
		currentItemSize = [];
		currentItemSize[0] = (menuItems[i].itemSize == null) ? defaultItemLevelOneSize[0] : menuItems[i].itemSize[0];
		currentItemSize[1] = (menuItems[i].itemSize == null) ? defaultItemLevelOneSize[1] : menuItems[i].itemSize[1];
		currentItemStyle = (menuItems[i].itemStyle == null) ? defaultItemLevelOneStyle : menuItems[i].itemStyle;
		currentItemUrl = (menuItems[i].itemUrl == null) ? defaultItemLevelOneUrl : menuItems[i].itemUrl;
		currentItemDescription = (menuItems[i].itemDescription == null) ? "" : menuItems[i].itemDescription;
		currentItemOff = [];
		currentItemOff[0] = (menuItems[i].itemOff == null) ? defaultItemLevelOneItemOff[0] : menuItems[i].itemOff[0];
		currentItemOff[1] = (menuItems[i].itemOff == null) ? defaultItemLevelOneItemOff[1] : menuItems[i].itemOff[1];
		currentItemSubMenu = (menuItems[i].itemSubMenu == null) ? [] : menuItems[i].itemSubMenu;
		
		//string with html tags
		stringHtmlTags += SkodaMenuItem(i, currentItemName, currentItemPosition, currentItemSize, currentItemStyle, currentItemUrl, currentItemDescription, currentItemSubMenu);

		//setting actual position as enter for next item
		actualPosition[0] += currentItemOff[0];
		actualPosition[1] += currentItemOff[1];
	}

	//writing html tags into element and writing to document
	element.innerHTML = stringHtmlTags;
	//joining element with body element
	document.body.appendChild(element);
}

//Definition for one first level item
function SkodaMenuItem(itemLevelOneId, itemName, itemPosition, itemSize, itemStyle, itemUrl, itemDescription, itemSubMenu)
{
	//number of members menu second level
	subMenuItemLength = itemSubMenu.length;
	//event onClick ( go on url or nothing)
	actionOnClick = (itemUrl == "none") ? '' : ' onclick="location.href=\'' + itemUrl + '\';"';
	//text in status bar
	actionStatusBar = (itemDescription == "") ? '' : ' self.status = \'' + itemDescription + '\';';
	//creating output string
	outputStringHtmlTags = "";
	outputStringHtmlTags += '<table height="' + itemSize[0] + '" width="' + itemSize[1] + '" cellspacing="0" cellpadding="0" border="0" style="position: absolute; z-index: 100; left: ' + itemPosition[0] + 'px; top: ' + itemPosition[1] + 'px">';
	outputStringHtmlTags += '<tr><td id="levelOne_' + itemLevelOneId + '" width="100%" height="100%" class="' + itemStyle[0] + '" onmouseover="ShowHideSubMenu(\'visible\',' +  itemLevelOneId + '); this.className=\'' + itemStyle[1] + '\'; ' + actionStatusBar + '" onmouseout="this.className=\'' + itemStyle[0] + '\'; ShowHideSubMenu(\'hidden\',' +  itemLevelOneId + ');"' + actionOnClick + '>' + itemName + '</td></tr></table>';
	outputStringHtmlTags += SkodaSubMenuItem(itemLevelOneId, itemPosition, itemStyle, itemSubMenu);
	return outputStringHtmlTags;
}

//Definition for second level items
function SkodaSubMenuItem(itemLevelOneId, itemLevelOnePosition, itemLevelOneStyle, subMenuItems)
{
	//default values for second item level
	defaultItemLevelSecondSize[0] = subMenuItems[0].itemSize[0];
	defaultItemLevelSecondSize[1] = subMenuItems[0].itemSize[1];
	defaultItemLevelSecondItemOff[0] = subMenuItems[0].itemOff[0];
	defaultItemLevelSecondItemOff[1] = subMenuItems[0].itemOff[1];
	defaultItemLevelSecondLevelOff[0] = subMenuItems[0].itemLevelOff[0];
	defaultItemLevelSecondLevelOff[1] = subMenuItems[0].itemLevelOff[1];
	defaultItemLevelSecondStyle = subMenuItems[0].itemStyle;
	defaultItemLevelSecondUrl = subMenuItems[0].itemUrl;
	//enter position for sub menu
	itemSubMenuActualPosition = [];
	itemSubMenuActualPosition[0] = itemLevelOnePosition[0];
	itemSubMenuActualPosition[1] = itemLevelOnePosition[1];
	//setting position for table
	itemSubMenuPosition = [];
	itemSubMenuPosition[0] = itemSubMenuActualPosition[0] + defaultItemLevelSecondLevelOff[0] -1;
	itemSubMenuPosition[1] = itemSubMenuActualPosition[1] + defaultItemLevelSecondLevelOff[1] -1;
	//creating table
	stringSubMenuHtmlTags = "";
	stringSubMenuHtmlTags += '<table id="levelSecond_' + itemLevelOneId + '" height="' + defaultItemLevelSecondSize[0] + '" width="' + defaultItemLevelSecondSize[1] + '" cellspacing="0" cellpadding="0" border="0" style="visibility: hidden; position: absolute; z-index: 100; left: ' + itemSubMenuPosition[0] + 'px; top: ' + itemSubMenuPosition[1] + 'px">';

	//creating string with html tags
	j = 1;
	for (j; j < subMenuItems.length; j++)
	{
		if (subMenuItems[j]) {
		//setting other values for current item
		itemSubMenuName = (subMenuItems[j].itemName == null) ? "undefined" : subMenuItems[j].itemName;
		itemSubMenuStyle = (subMenuItems[j].itemStyle == null) ? defaultItemLevelSecondStyle : subMenuItems[j].itemStyle;
		itemSubMenuUrl = (subMenuItems[j].itemUrl == null) ? defaultItemLevelSecondUrl : subMenuItems[j].itemUrl;
		itemSubMenuDescription = (subMenuItems[j].itemDescription == null) ? "" : subMenuItems[j].itemDescription;
		
		//event onClick ( go on url or nothing)
		actionSubMenuOnClick = (itemSubMenuUrl == "none") ? '' : ' onclick="location.href=\'' + itemSubMenuUrl + '\';"';
		//text in status bar
		actionSubMenuStatusBar = (itemSubMenuDescription == "") ? '' : ' self.status = \'' + itemSubMenuDescription + '\';';

		//string with html tags
		stringSubMenuHtmlTags += '<tr><td width="100%" height="' + defaultItemLevelSecondItemOff[1] + '" class="' + itemSubMenuStyle[0] + '" onmouseover="this.className=\'' + itemSubMenuStyle[1] + '\'; ShowHideSubMenu(\'visible\',' +  itemLevelOneId + '); document.getElementById(\'levelOne_' + itemLevelOneId + '\').className = \'' + itemLevelOneStyle[1] + '\';' + actionSubMenuStatusBar + '" onmouseout="this.className=\'' + itemSubMenuStyle[0] + '\'; ShowHideSubMenu(\'hidden\',' +  itemLevelOneId + '); document.getElementById(\'levelOne_' + itemLevelOneId + '\').className = \'' + itemLevelOneStyle[0] + '\';"' + actionSubMenuOnClick + '>' + itemSubMenuName + '</td></tr>';
		}
	}

	stringSubMenuHtmlTags += '</table>';
	return stringSubMenuHtmlTags;
}


//function for show and hide submenu items
function ShowHideSubMenu(action, itemLevelOneId)
{
	if (document.getElementById('levelSecond_' + itemLevelOneId) != null) {
		if (thebrowser == 'safari') {
			document.getElementById('levelSecond_' + itemLevelOneId).style.Opacity = 0.8;
			document.getElementById('MainMenuSpan').style.Opacity = 0.999;
			document.getElementById('levelOne_' + itemLevelOneId).style.Opacity = 0.999;
		}
		document.getElementById('levelSecond_' + itemLevelOneId).style.visibility = action;
	}
}

//--------------------------------------
// end of navi script
//--------------------------------------

//--------------------------------------
// start of fade script
//--------------------------------------
agent = navigator.userAgent;
var thebrowser;
if (agent.toLowerCase().indexOf('safari')>-1) {
	thebrowser = 'safari';
} else if ((agent.toLowerCase().indexOf('msie')>-1) && (agent.toLowerCase().indexOf('mac')>-1)) {
	thebrowser = 'ms';
} else if (agent.toLowerCase().indexOf('gecko')>-1) {
	thebrowser = 'moz';
}

var currentOpacity = new Array();
var lastPhoto = "";

var FADE_STEP = 15;
//var FADE_STEP = 100;
var FADE_INTERVAL = 2;
var pause = false;
var running = false;

var mInterval = false;

function init() {
	currentOpacity[currentPhoto]=100;
	if(document.all) {
		document.getElementById('photo'+currentPhoto).style.filter="alpha(opacity=100)";
	} else if (thebrowser == 'moz') {
		document.getElementById('photo'+currentPhoto).style.MozOpacity = 1;
	} else if (thebrowser == 'safari') {
		document.getElementById('photo'+currentPhoto).style.Opacity = 1;
	} else {
		document.getElementById('photo'+currentPhoto).style.Opacity = 1;
	}
	for (i=1;i<imageArray.length;i++) {
		currentOpacity[i]=0;
		if(document.all) {
			document.getElementById('photo'+i).style.filter="alpha(opacity=0)";
		} else if (thebrowser == 'moz') {
			document.getElementById('photo'+i).style.MozOpacity = 0;
		} else if (thebrowser == 'safari') {
			document.getElementById('photo'+i).style.Opacity = 0;
		}
	}
	if (document.getElementById('linx1')) {
		document.getElementById('linx1').style.Opacity = 0.999;
	}
	if (document.getElementById('txt0')) {
		document.getElementById('txt0').style.Opacity = 0.999;
	}
}

function crossFade(secondPhoto) {
	document.getElementById('photo'+secondPhoto).style.visibility = 'visible';
	document.getElementById('linx1').style.Opacity = 0.999;

	currentOpacity[currentPhoto]-= FADE_STEP;
	currentOpacity[secondPhoto] += FADE_STEP;

	if(document.all) {
		document.getElementById('photo'+currentPhoto).style.filter = "alpha(opacity=" + currentOpacity[currentPhoto] + ")";
		document.getElementById('photo'+secondPhoto).style.filter = "alpha(opacity=" + currentOpacity[secondPhoto] + ")";
	} else if (thebrowser == 'moz') {
		document.getElementById('photo'+currentPhoto).style.MozOpacity = currentOpacity[currentPhoto]/100;
		document.getElementById('photo'+secondPhoto).style.MozOpacity = currentOpacity[secondPhoto]/100;
	} else if (thebrowser == 'safari') {
		document.getElementById('photo'+currentPhoto).style.Opacity = currentOpacity[currentPhoto]/100;
		document.getElementById('photo'+secondPhoto).style.Opacity = currentOpacity[secondPhoto]/100;
	}

	if (currentPhoto == secondPhoto) {
			clearInterval(mInterval)
			running = false;
			mInterval = false;
	} else {
		if(currentOpacity[currentPhoto]<=0) {
			document.getElementById('photo'+currentPhoto).style.visibility = 'hidden';
			if (document.getElementById('txt'+secondPhoto)) {
				document.getElementById('txt'+secondPhoto).style.Opacity = 0.999;
			} else if (document.getElementById('txt0')) {
				document.getElementById('txt0').style.Opacity = 0.999;
			}

			currentPhoto = secondPhoto;
			clearInterval(mInterval)
			running = false;
			mInterval = false;
			currentOpacity[currentPhoto] = 100
			currentOpacity[0] = 0
			currentOpacity[secondPhoto] = 100
		} else if (!mInterval) {
			thesecondPhoto = secondPhoto;
			running = true;
			mInterval = setInterval("crossFade(thesecondPhoto)",FADE_INTERVAL);
		}
	}
}

function boxover(box) {
	if (running) {
			clearInterval(mInterval)
			running = false;
			mInterval = false;
			currentPhoto = 0;
			secondPhoto = '';
		init();
		crossFade(box)
	} else {
		crossFade(box)
	}
	if (document.getElementById('box'+box)) {
		if(document.all) {
			document.getElementById('box'+box).style.filter="alpha(opacity=80)";
		} else if (thebrowser == 'moz') {
			document.getElementById('box'+box).style.MozOpacity = 0.8;
		} else if (thebrowser == 'safari') {
			document.getElementById('box'+box).style.Opacity = 0.8;
		} else {
			return;
		}
		if (obj = document.getElementById('box'+box)) {
			document.getElementById('linx'+box).style.visibility = 'hidden';
			obj.style.visibility = 'visible';
		}
	} else {
		document.getElementById('linx'+box).style.fontWeight = 'bold';
	}
	for (i=1;i<imageArray.length;i++) {
		if (i != box) {
			if (obj = document.getElementById('box'+i)) {
				document.getElementById('linx'+i).style.visibility = 'visible';
				obj.style.visibility = 'hidden';
				if (thebrowser == 'safari') {
					document.getElementById('linx'+box).style.Opacity = 0.999;
				}
			} else {
				document.getElementById('linx'+i).style.fontWeight = 'normal';
			}
		}
	}
}

function boxout() {
	if (!running) {
		crossFade(0)
	}
	for (i=1;i<imageArray.length;i++) {
		if (document.getElementById('box'+i)) {
			if (obj = document.getElementById('box'+i)) {
				document.getElementById('linx'+i).style.visibility = 'visible';
				obj.style.visibility = 'hidden';
			}
		} else {
			document.getElementById('linx'+i).style.fontWeight = 'normal';
		}
	}
}

//--------------------------------------
// end of fade script
//--------------------------------------

function checkvals() {
	if (document.forms['leadform'].nachname.value == '' || document.forms['leadform'].adresse.value == '' || document.forms['leadform'].email.value == '') {
		alert('Tragen Sie bitte Name, Adresse und E-Mail ein.');
	} else {
		if (checkAge()) {
			document.forms['leadform'].submit();
		}
	}
}
function findObj(theObj, theDoc)
{
  var p, i, foundObj;

  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++)
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

  return foundObj;
}

// * Dependencies *
// this function requires the following snippets:
// JavaScript/readable_MM_functions/findObj
//
// Accepts a variable number of arguments, in triplets as follows:
// arg 1: simple name of a layer object, such as "Layer1"
// arg 2: ignored (for backward compatibility)
// arg 3: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'','show',Layer2,'','hide');
function showHideLayers()
{
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
    if ((obj = findObj(args[i])) != null)
    {
      visStr = args[i+2];
      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }
  }
}


// Example:
// onMouseOver="toolTip('tool tip text here')";
// onMouseOut="toolTip()";
// -or-
// onMouseOver="toolTip('more good stuff', '#FFFF00', 'orange')";
// onMouseOut="toolTip()"; 
/*
MOVE this to the <body>:
<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
<script language="JavaScript"><!-- initToolTips(); //--></script>
*/
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
offsetX = 0;
offsetY = 20;
//var tool_message="Für mehr Informationen klicken Sie..";
var tool_message="";
var toolTipSTYLE="";
var blaTip ="";

function initToolTips()
{
  if(ns4||ns6||ie4)
  {
    if(ns4) toolTipSTYLE = document.toolTipLayer;
    else if(ns6) {
    	toolTipSTYLE = document.getElementById("toolTipLayer").style;
    	document.onmousemove = moveToMouseLoc;
    }
    else if(ie4){
    	toolTipSTYLE = document.all.toolTipLayer.style;
    	//document.onmousemove = moveToMouseLoc;
    }
    if(ns4) document.captureEvents(Event.MOUSEMOVE);
    else
    {
      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";
    }
  
  //blaTip.onmousemove = moveToMouseLoc;
  }
}
function toolTip(msg, fg, bg, cl)
{
  if(toolTip.arguments.length < 1) // hide
  {
    if(ns4) toolTipSTYLE.visibility = "hidden";
    else toolTipSTYLE.display = "none";
  }
  else // show
  {
    if(!fg) fg = "";
    if(!bg) bg = "";
    if(!cl) cl = "";
   
    var content =
    '<table border="1" bordercolor="#FFFFFF" class='+cl+' cellspacing="0" cellpadding="0" bgcolor="' + fg + '"><tr><td>' +
    '<table border="0" class='+cl+' cellspacing="0" cellpadding="0" bgcolor="' + bg + 
    '"><tr><td align="left"><font face="Arial, Helvetica, sans-serif" color="' + fg +
    '" size="-2">' + msg +
    '&nbsp\;</font></td></tr><tr><td><font face="Arial, Helvetica, sans-serif" color="' + fg +
    '" size="-2"><br>'+tool_message+
    '&nbsp\;</font></td></tr></table></td></tr></table>';
    if(ns4)
    {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }
    if(ns6)
    {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block'
    }
    if(ie4)
    {
    	moveToMouseLoc()
      document.all("toolTipLayer").innerHTML=content;
      toolTipSTYLE.display='block'
    }
  }
 // alert("top"+toolTipSTYLE.top+" left"+toolTipSTYLE.left)
}
function moveToMouseLoc(e)
{
  if(ns4||ns6)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else
  {
  
    x = event.x + document.body.scrollLeft;
    y = event.y + document.body.scrollTop;
  }
 
  toolTipSTYLE.left = (x+offsetX)+"px";
  toolTipSTYLE.top = (y + offsetY)+"px";

//status = "x="+x+" y="+y
  return true;
}
function checkAge() {
	/* the minumum age you want to allow in */
	var min_age = 18;

	/* change "age_form" to whatever your form has for a name="..." */
	var year = parseInt(document.forms["leadform"]["year"].value);
	var month = parseInt(document.forms["leadform"]["month"].value) - 1;
	var day = parseInt(document.forms["leadform"]["day"].value);

	var theirDate = new Date((year + min_age), month, day);
	var today = new Date;

	if ( (today.getTime() - theirDate.getTime()) < 0) {
		//alert("Sie sind zu jung um an einer Probefahrt teilzunehmen!");
		return true;
	} else {
		return true;
	}
}
