//================================================================
//Scripts for Tab panels (SR3.5)
//===============================================================
var tabCount = 1; //initialy only one tab

/*
* Changes the tab-button i to be aktive and the other tab-buttons
* to be inaktive. 0 < i < number of tab-buttons - 1
*/
function changeActiveTab(i) {
	for( j=0; j < tabCount; ++j ) {
		if( i==j ) { activateTab(j); }
		else { deactivateTab(j); }
	}
}

/*
* Activates the tab-button i and shows it's content panel.
*/
function activateTab(i) {
	var obj = document.getElementById( "tab-bg:"+i );
	if(obj) {obj.className="tab_on";}
	document.getElementById( "tab-body:"+i ).style.display='block';
}

/*
* Deactivates the tab-button i and hides it's content panel.
*/
function deactivateTab(i) {
	var obj = document.getElementById( "tab-bg:"+i );
	if(obj) {obj.className="tab_off";}
	document.getElementById( "tab-body:"+i ).style.display='none';
}

/*
* Call this function before calling any other function.
* Set parameter i to the number of tab-buttons when calling.
* Initialises the script.
*/
function initTabScript(i) {
	tabCount = i;
}


//=============================
//Scripts for Mainmenu-Popup
//=============================


function openWindow(url, target, width, height, centered) {
    var paramYY = "scrollbars=yes,resizable=1";
		var paramYN = "scrollbar=yes,resizable=0";
    var paramNN = "scrollbar=0;resizable=0";
		var parameter2 = "";
    if (centered == true && (navigator.appName.indexOf("Netscape") > -1 && parseInt(navigator.appVersion.substring(0,1)) >=4 )
        || (navigator.appName.indexOf("Microsoft Internet Explorer") > -1 && parseInt(navigator.appVersion.substring(0,1)) >=4 )) {
      var w = (screen.width/2)-(width/2);
      var h = (screen.height/2)-(height/2);

        if (width != 0) {
            parameter2 += ',width=' + width + ', screenX=' + w + ',left=' + w;
        }
        if (height != 0) {
            parameter2 += ',height=' + height + ', screenY=' + h + ',top=' + h;
        }
    } else {
        if (width != 0) {
            parameter2 += ',width=' + width;
        }
        if (height != 0) {
            parameter2 += ',height=' + height;
        }
    }
	// Originaler Aufruf:
    // var win = window.open(url, target, parameter);
	// Neu: Unterscheidung, ob CC5, www2.volkswagen.de
	if (url.indexOf("cc5.volkswagen.de") > 0) {
	    var win = window.open(url, "CC5", paramYY + parameter2);
	} else {
		// Die Movies (COM, Erlebnis->) sollen ohne scrollbar in fester Groesse geoeffnet werden
		// Genau wie die Emosites...
		if (    (url.indexOf("www2.volkswagen.de/volkswagen_com/popup_movie_") > 0)
			 || (url.indexOf("emosites.volkswagen.de") > 0)
			) {
			var win = window.open(url, target, paramNN + parameter2);
		} else {
	    	var win = window.open(url, target, paramYY + parameter2);
		}
	}
    if (win) {
        win.focus();
    }
}



//Variable for popup-timer
var zu;
var modindzu;
//Variable for active highlight
var activeImage;
var activeModelImage;
var activeBG;
//Variables for active gallery-Pic
var activeSmallPic;
var activeSmallPicObj;
zoomWin = null;


//mainMenuConstructor
function mainMenu(whichMenu,whichImg,offsrc,onsrc){
	//creating mouseover-Images
	this.imgname = new Object(whichImg);
	this.imgname.createHiliteImages = createImgObjs;
	this.imgname.createHiliteImages(offsrc,onsrc,'');
	//reading arrays, writing four menus
	this.activeMenu = eval(whichMenu);
	this.imgPosChecked = 0;
	this.menuPos = 0;
	this.menuTop = 0;
	this.imgHeight = 0;
	this.menuWidth = 0;
	this.menuItemsListOne = "";
	this.menuItemsListTwo = "";
	this.menuItemsListThree = "";
	this.menuItemsListFour = "";
	this.completeMenuHTML = "";
	for(var i = 0; i < this.activeMenu.length; i++) {
		if(i <= 6){
		this.menuItemsListOne += this.activeMenu[i + 1] + this.activeMenu[i] + "</a><br>";
		i = i + 1;
		}
		else if(i >= 8 && i <= 15){
		this.menuItemsListTwo +=  this.activeMenu[i + 1] + this.activeMenu[i] + "</a><br>";
		i = i + 1;
		}
		else if(i >= 16 && i <= 23){
		this.menuItemsListThree += this.activeMenu[i + 1] + this.activeMenu[i] + "</a><br>";
		i = i + 1;
		}
		else if(i >= 24 && i <= 31){
		this.menuItemsListFour += this.activeMenu[i + 1] + this.activeMenu[i] + "</a><br>";
		i = i + 1;
		}
	}
	if (this.menuItemsListOne) this.menuItemsListOne = "<td class='main_sub'>" + this.menuItemsListOne + "</td>";
	if (this.menuItemsListTwo) this.menuItemsListTwo = "<td class='main_sub'>" + this.menuItemsListTwo + "</td>";
	if (this.menuItemsListThree) this.menuItemsListThree = "<td class='main_sub'>" + this.menuItemsListThree + "</td>";
	if (this.menuItemsListFour) this.menuItemsListFour = "<td class='main_sub'>" + this.menuItemsListFour + "</td>";
	this.completeMenuHTML = "<table id='main_sub_list'><tr>" + this.menuItemsListOne + this.menuItemsListTwo + this.menuItemsListThree + this.menuItemsListFour + "</tr></table>";
	//alert(this.completeMenuHTML);
}


//hilite-image method
function createHiliteObj(picsrc){
	this.offimg = new Image();
	this.offimg.src = picsrc;
	var picsrc_replaced  = 'a';
	picsrc_replaced = picsrc.replace(/a\./i,".");	
	var picsrc_end = picsrc.substr((picsrc.length - 4),picsrc.length);

	var picsrc_highimg =  picsrc_replaced.substr(0,(picsrc_replaced.length - 4)) + "a" + picsrc_end;
	//var picsrc_highimg = picsrc.substr(0,(picsrc.length - 4)) + picsrc_end;
	this.onimg = new Image();
	this.onimg.src = picsrc_highimg;
}


//show-function for mainmenu
//args = name of menuset,Hilite-Toggle (1 = Hilite on, 0 = hilite off)

function showMenu(whichMenu,whichPic) {
	//show new hilite
	resetHighlight();
	if(whichPic == 0) showHighlight(whichMenu.imgname);
	//workaround mozilla menuwidth bug
	/*if(navigator.appVersion.indexOf("MSIE") != -1){
		document.getElementById("main_sub_container").style.width = 500 + "px";
		}
	else{
		document.getElementById("main_sub_container").style.width = "auto";
	}*/
	document.getElementById("main_sub_container").style.width = 500 + "px";
	//writing HTML content
	document.getElementById("main_sub_container").innerHTML = whichMenu.completeMenuHTML;
	document.getElementById("main_sub_container").style.display = "block";

	//check img-position to get menu position
	if(whichMenu.imgPosChecked == 0) {
		whichMenu.menuPos = eval("document." + whichMenu.imgname + ".offsetLeft");
		whichMenu.menuWidth = document.getElementById("main_sub_list").offsetWidth;
		var currWidth = whichMenu.menuPos + whichMenu.menuWidth;
		if(currWidth >= 780){
	 	whichMenu.menuPos = (780 - whichMenu.menuWidth + 10);
		}
		else{
			//left indent
			whichMenu.menuPos = whichMenu.menuPos + 6;
		}
		whichMenu.imgPosChecked = 1;
	}

	//positioning of menu
	document.getElementById("main_sub_container").style.width = whichMenu.menuWidth + "px";
	document.getElementById("main_sub_container").style.left = whichMenu.menuPos + "px";
	document.getElementById("main_sub_container").style.visibility = "visible";

	//disable timeout
	window.clearTimeout(zu);

}

function dropdown_mouseEnter() {
	window.clearTimeout(zu);
	if(modindzu) clearTimeout(modindzu);
	}

function dropdown_mouseLeave(whichMenu) {
	switch (whichMenu) {
			case 'main':
			zu = window.setTimeout("menuCollaps()",50);
			break;
			case 'sub':
			zu = window.setTimeout("submenuCollaps()",50);
			break;
			case 'modelSub':
			modindzu = window.setTimeout("submenuModelCollaps()",50);
			break;
			}
	}

function showHighlight(menupic){
	document.images[menupic].src = menupic.onimg.src;
	activeImage = menupic;
}

function resetHighlight(){
	if(activeImage) document.images[activeImage].src = activeImage.offimg.src;
}

function menuCollaps(){
		//reset highlight;
		resetHighlight();
		//hide popup-menu
		window.clearTimeout(zu);
		document.getElementById("main_sub_container").style.visibility="hidden";
		document.getElementById("main_sub_container").style.display="none";
	}

//================================================================
//Scripts for Subnav-Menu
//===============================================================

//creating Subnav-Menu
function subMenu(whichMenu,whichImg,picsrc){
	//creating mouseover-Images
	this.imgname = new Object(whichImg);
	this.imgname.createHiliteImages = createHiliteObj;
	this.imgname.createHiliteImages(picsrc);
	//props for checking img-position
	this.imgPosChecked = 0;
	//alert(picsrc);
	this.menuPos = 0;
	this.menuTop = 0;
	this.imgHeight = 0;
	this.menuWidth = 0;
	//reading Menu-Array, writing HTML-Codes
	this.activeMenu = eval(whichMenu);
	this.subMenuItemsList = "";
	if(this.activeMenu != 0) {
		for(var i = 0; i < this.activeMenu.length; i++) {
			this.subMenuItemsList += "<a class='subnav_sub_link' href='" + this.activeMenu[i+1] + "'>" + this.activeMenu[i] + "</a>";
			//alert(this.activeMenu[i]);
			i++;
		}
	}
}

//function for subnav-popup
//args = name of menuset,Hilite-Toggle (1 = Hilite on, 0 = hilite off)

function showSubMenu(whichMenu,whichPic) {

	//reset old hilite and show new
	resetHighlight();
	if(whichPic == 0) showHighlight(whichMenu.imgname);
	//check img-position to get menu position
	if(whichMenu.imgPosChecked == 0) {
	whichMenu.menuPos = eval("document." + whichMenu.imgname + ".offsetLeft");
//	whichMenu.menuTop = document.getElementById("subnav").offsetTop;
	whichMenu.menuTop = findPosY(subnav);
	whichMenu.imgHeight = eval("document." + whichMenu.imgname + ".offsetHeight");
	whichMenu.menuTop = whichMenu.menuTop + whichMenu.imgHeight;
	whichMenu.menuWidth = eval("document." + whichMenu.imgname + ".offsetWidth");
	whichMenu.imgPosChecked = 1;
	}
	//writing html-strings, positioning menu-layers
	if(whichMenu.activeMenu != 0) {
		document.getElementById("subnav_submenu").innerHTML = whichMenu.subMenuItemsList;
		document.getElementById("subnav_submenu").style.left= whichMenu.menuPos + "px";
		document.getElementById("subnav_submenu").style.top = whichMenu.menuTop + 0 + "px";
		document.getElementById("subnav_submenu").style.width = whichMenu.menuWidth + 125 + "px";
		document.getElementById("subnav_submenu").style.visibility = "visible";
		document.getElementById("subnav_submenu").style.display = "block";
	}
	//if there is no submenu
	else if(whichMenu.activeMenu == 0) {
		document.getElementById("subnav_submenu").style.visibility = "hidden";
		document.getElementById("subnav_submenu").style.display = "none";
		}
	//reset timeout
	window.clearTimeout(zu);
}

function submenuCollaps(){
		//reset hilite
		resetHighlight();
		//hide popup-menu
		window.clearTimeout(zu);
		document.getElementById("subnav_submenu").style.visibility="hidden";
		document.getElementById("subnav_submenu").style.display="none";
}

//===============================
//image hilite without submenu-popup
//==============================
function subButton(whichImg,offsrc,onsrc){
	this.imgname = new Object(whichImg);
	this.imgname.createHiliteImages = createImgObjs;
	this.imgname.createHiliteImages(offsrc,onsrc,'');

}

function showHigh(whichButton,whichPic){
	if(whichPic == 0) document.images[whichButton.imgname].src = whichButton.imgname.onimg.src;
}

function resetHigh(whichButton,whichPic){
	if(whichPic == 0 && activeSmallPic != whichButton.imgname ) document.images[whichButton.imgname].src = whichButton.imgname.offimg.src;
}






//hilite-image method
function createImgObjs(offsrc,onsrc,hisrc,midsrc,big800,big1024,big1280){
	this.offimg = new Image();
    this.offimg.src = offsrc;
	this.onimg = new Image();
	this.onimg.src = onsrc;
	this.hiliteimg = new Image();
	this.hiliteimg.src = hisrc;
	if(arguments.length > 3) {
		this.midimg = midsrc;
		this.big800 = big800;
		if(big1024) this.big1024 = big1024;
		if(big1280) this.big1280 = big1280;
		}
	}

//===============================
//image object constructor submenu model index
//==============================
function createModelImgObjs(offsrc,onsrc){
	this.offimg = new Image();
    this.offimg.src = offsrc;
	this.onimg = new Image();
	this.onimg.src = onsrc;
	//if(hgoffsrc){
	//this.hgoffimg = new Image();
	//this.hgoffimg.src = hgoffsrc;
	//}
	//if(hgonsrc){
	//this.hgonimg = new Image();
	//this.hgonimg.src = hgonsrc;
	//}
	}

//================================================================
//Scripts for Model Index Subnav-Menu
//===============================================================

//creating Subnav-Menu
function subModelMenu(whichMenu,whichImg,offsrc,onsrc,whichHGImg,hgoffsrc,hgonsrc){
	//creating mouseover-Images
	this.imgname = new Object(whichImg);
	this.imgname.createHiliteImages = createModelImgObjs;
	this.imgname.createHiliteImages(offsrc,onsrc);
	this.hgimgname = '';
	if(whichHGImg){
		this.hgimgname = new Object(whichHGImg);
		this.hgimgname.createHiliteImages = createModelImgObjs;
		this.hgimgname.createHiliteImages(hgoffsrc,hgonsrc);
		}
	//props for checking img-position
	this.menuPos = 0;
	this.menuBottom = 0;
	this.menuTop = 0;
	this.imgHeight = 0;
	this.menuWidth = 0;
	//reading Menu-Array, writing HTML-Codes
	this.activeMenu = eval(whichMenu);
	this.subMenuItemsList = "";
	if(this.activeMenu != 0) {
		for(var i = 0; i < this.activeMenu.length; i++) {
			this.subMenuItemsList += this.activeMenu[i+1] + this.activeMenu[i] + "</a>";
			i++;;
		}
	}

}

//function for subnav-popup
//args = name of menuset,Hilite-Toggle (1 = Hilite on, 0 = hilite off)

function showModelSubMenu(whichMenu,whichPic,whichMouseover,whichHeight) {
	//reset main nav
	if(zu) zu = window.setTimeout("menuCollaps()",0);
	//reset old hilite and show new
	resetModelHighlight();
	if(whichPic == 0) showModelHighlight(whichMenu.imgname,whichMenu.hgimgname);
	//check img-position to get menu position
	whichMenu.menuPos = findPosX(whichMouseover);
	whichMenu.menuBottom = findPosY(whichMouseover);
	whichMenu.imgHeight = eval(whichHeight);
	switch (whichMenu.imgHeight) {
			case 20:
			whichMenu.menuBottom = 450 - whichMenu.menuBottom;
			break;
			case 70:
			whichMenu.menuBottom = 450 - (whichMenu.menuBottom + whichMenu.imgHeight);
			break;
			case 80:
			whichMenu.menuBottom = 450 - (whichMenu.menuBottom + whichMenu.imgHeight);
			break;
			}
	whichMenu.menuWidth = eval("document." + whichMenu.imgname + ".offsetWidth");

	//writing html-strings, positioning menu-layers
	if(whichMenu.activeMenu != 0) {
		document.getElementById("modelSubnav_list").innerHTML = whichMenu.subMenuItemsList;
		document.getElementById("modelSubnav_list").style.bottom = 1;
		document.getElementById("modelSubnav_submenu").style.left= whichMenu.menuPos + "px";
		document.getElementById("modelSubnav_submenu").style.bottom = whichMenu.menuBottom + "px";
		document.getElementById("modelSubnav_submenu").style.width = whichMenu.menuWidth + "px";
		document.getElementById("modelSubnav_submenu").style.visibility = "visible";
		document.getElementById("modelSubnav_submenu").style.display = "block";
	}
	//if there is no submenu
	else if(whichMenu.activeMenu == 0) {
		document.getElementById("modelSubnav_submenu").style.visibility = "hidden";
		document.getElementById("modelSubnav_submenu").style.display = "none";
		}
	//reset timeout
	window.clearTimeout(modindzu);
}

function submenuModelCollaps(){
		//reset hilite
		resetModelHighlight();
		//hide popup-menu
		window.clearTimeout(modindzu);
		document.getElementById("modelSubnav_submenu").style.visibility="hidden";
		document.getElementById("modelSubnav_submenu").style.display="none";
}

function showModelHighlight(menupic,bgpic){
	document.images[menupic].src = menupic.onimg.src;
	if(bgpic) document.images[bgpic].src = bgpic.onimg.src;
	activeModelImage = menupic;
	activeBG = bgpic;
}

function resetModelHighlight(){
	if(activeModelImage) document.images[activeModelImage].src = activeModelImage.offimg.src;
	if(activeBG) document.images[activeBG].src = activeBG.offimg.src;
}

//detect mouse-over image position for correct layer positioning

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function showImagePopupUrl(pURL, pWidth, pHeight, pAltText) {
  if (!pURL) {
    return;
  }
  var offsetWidth = 30;
  var offsetHeight = 60;
  if (pAltText) {
    if (pAltText.length!=0) {
      offsetHeight += 30;
    }
  }
  var windowFeatures = "toolbar=no,directories=no,location=no,status=no,menubar=no,resizable=no,scrollbars=no,"
    + "width=" + (pWidth + offsetWidth) + ",height=" + (pHeight + offsetHeight);
  var popup = window.open(pURL, 'imagePopup', windowFeatures);
  if (popup) {
    popup.focus();
  }
}


function ShowImagePopup1(img_src,img_popup_src,popup_alt,header,footer,scrol,param)
{
	var h=0;
	var w=0;  
	var popup= new Image();
	popup.src=img_popup_src;
	//alert(popup.src);
	h=popup.height;
	w=popup.width
	//alert(h+'-----'+w);
	var src_popup="/popup.php?src="+img_popup_src+"&alt="+popup_alt+"&popup=Y";
	if(header)
	{
		src_popup=src_popup+"&header=Y";
		h=h+162;
		w=w+40;	
	}
	if(footer)
	{
		src_popup=src_popup+"&footer=Y"; 
		h=h+26;
	}			
	//document.write('<a href="javascript: void(0)" onclick="window.open(\''+src_popup+'\',\'Volkswagen\',\'width='+w+',height='+h+',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars='+scrol+'\'); alert('+ h+')"><img src='+img_src+' '+param+'></a>');
	document.write('<a href="javascript: void(0)" onclick="window.open(\''+src_popup+'\',\'Volkswagen\',\'width='+w+',height='+h+',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars='+scrol+'\');"><img src='+img_src+' '+param+'></a>');	
	
}

function ShowImagePopup(img_src, img_popup_src,popup_alt,header,footer,scrol,param)
{
	var h=0;
	var w=0;  
	var popup= new Image();
	popup.src=img_popup_src;
	//alert(popup.src);
	h=popup.height;
	w=popup.width
	//alert(h+'-----'+w);
	var src_popup="/popup.php?src="+img_popup_src+"&alt="+popup_alt+"&popup=Y";
	if(header)
	{
		src_popup=src_popup+"&header=Y";
		h=h+162;
		w=w+40;	
	}
	if(footer)
	{
		src_popup=src_popup+"&footer=Y"; 
		h=h+26;
	}			
	document.write('<a href="javascript: void(0)" onclick="window.open(\''+src_popup+'\',\'\',\'width='+w+',height='+h+',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars='+scrol+'\');"><img src='+img_src+' '+param+'></a>');
	
}

//================================================================
//Konfigurator box
//===============================================================

function konfigurator_execute() {
  var link = document.frmKonfigurator.cboKonfigurator.options[document.frmKonfigurator.cboKonfigurator.selectedIndex].value;
  if (link!=null && link.length!='') {
    window.setTimeout(link,1);
  }
}



