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

//Variable for popup-timer
var vwcms_common_menu_close;
var vwcms_common_menu_modindclose;
//Variable for active highlight 
var vwcms_common_activeImage;
//Variables for active gallery-Pic
var vwcms_common_activeSmallPic; 

var isMac = (navigator.platform == "MacPPC");
	

//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>";
}


//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 && isMac != true){
		document.getElementById("main_sub_container").style.width = 500 + "px";
		}
	else{
		document.getElementById("main_sub_container").style.width = "auto";
	}
	
	//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(vwcms_common_menu_close);
	
}

function dropdown_mouseEnter() {
	window.clearTimeout(vwcms_common_menu_close);
	if(vwcms_common_menu_modindclose) clearTimeout(vwcms_common_menu_modindclose);
}

function dropdown_mouseLeave(whichMenu) {
	switch (whichMenu) {
		case 'main':
			vwcms_common_menu_close = window.setTimeout("menuCollapse()",50);
			break;
		case 'sr35_sub':
			vwcms_common_menu_close = window.setTimeout("sr35_submenuCollapse()",50);
			break;
	}			
}

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

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

function menuCollapse(){
	//reset highlight;
	resetHighlight();
	//hide popup-menu
	window.clearTimeout(vwcms_common_menu_close);
	document.getElementById("main_sub_container").style.visibility="hidden";
	document.getElementById("main_sub_container").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 && vwcms_common_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();
	if (typeof offsrc!="undefined" && offsrc.length!=0) {
    	this.offimg.src = offsrc;
    }
	this.onimg = new Image();
	if (typeof onsrc!="undefined" && onsrc.length!=0) {
		this.onimg.src = onsrc;
	}
	this.hiliteimg = new Image();
	if (typeof hisrc!="undefined" && hisrc.length!=0) {
		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;
	}	


//=========================================
// image popup
//=========================================

function showImagePopupSimple(pImageURL, pWidth, pHeight, pTitle) {
  if (!pImageURL) {
    return;
  }
  var windowFeatures = "toolbar=no,directories=no,location=no,status=no,menubar=no,resizable=no,scrollbars=no,"
    + "width=" + pWidth + ",height=" + pHeight;
  if (!pTitle || pTitle=='') {
    pTitle = 'Volkswagen';
  }
  var popup = window.open('', 'imagePopup', windowFeatures);
  if (popup) {
    popup.document.clear();
    popup.focus();
    popup.document.writeln('<html><head><title>' + pTitle + '</title></head>');
    popup.document.writeln('<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" style="margin:0px">');
    popup.document.writeln('<center><img src="' + pImageURL + '" border="0" alt=""></center>');
    popup.document.writeln('</body>');
    popup.document.writeln('</html>');
    popup.document.close();
    popup.focus();
  }
}

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();
  }
}


// open.window method used by AbstractLinkHelper
function cms_openWindow(pLinkUrl, pLinkTarget, pLinkWindowAttributes) {
  if (pLinkTarget==null || pLinkTarget=="_self") {
    document.location = pLinkUrl;
  }
  else if(pLinkTarget!="layer"){
    window.open(pLinkUrl, pLinkTarget, pLinkWindowAttributes);
  }
}

// deprecated - not used by AbstractLinkHelper any longer
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();
  }
}

