$(function(){
  
  /* get language */
  lang = $.url().param('lang');
  lang = (lang=='') ? 'de' : lang;
  
  /* set anim pars */
  aTime = 400;  // fade in/out time
  aPause= 1500; // pause between images
  aStopI= 0;    // index of image BEFORE the animation stops
  aStop = 5000; // length of the stop
   
  /* control animation */
  /*
  $('.topPics').attr('title','play / stop').css('cursor','pointer').click(function(){
    if (aPlay) {
      aPlay = false;
    } else {
      aPlay = true;
      $('.topPics img[name="img'+xIndex+'"]').fadeOut(aTime, function () {
        aFadeIn(topIndex);
      });
    }
  });
  */
  
});

// load image and pause
function aLoad() {
  if (topIndex<(topImages.length-1)) {
    topIndex++; 
    if (!topLoaded) {
      $('.topPics').append('<img src="images/intro/'+topImages[topIndex]+'" name="img'+topIndex+'">');
      $('.topPics img[name="img'+topIndex+'"]').load(function() {
        fadeOut(topIndex);
      });
    } else {
      fadeOut(topIndex);
    }
  } else {
    topIndex = 0;
    topLoaded= true;
    fadeOut(topIndex);
  }
}

/* cycle animation: fade in - load - pause - fade out */
// hide image
function fadeOut(topIndex) {
  if (topIndex==0) {
    xIndex = topImages.length-1;
    xPause = (aStopI==0) ? aStop : aPause;
  } else {
    xIndex = topIndex - 1;
    xPause = (aStopI==topIndex && topLoaded) ? aStop : aPause;
  } 
  setTimeout(function() {
    $('.topPics img[name="img'+xIndex+'"]').fadeOut(aTime, function () {
      aFadeIn(topIndex);
    });
  },xPause); // stop time
}

// show new image
function aFadeIn(topIndex) {
  $('.topPics img[name="img'+topIndex+'"]').fadeIn(aTime, function () {
    aLoad();
  });
}



/* switch display */
function switchDisplay(element) {
	if (document.getElementById(element).style.display=='') document.getElementById(element).style.display='none';
	else document.getElementById(element).style.display=''
}



/* redir */
function gotoPage(page){
   location=page;
}



/* menus*/
function hideMenu() {
	document.getElementById('subMenu3').style.display='none';
	document.getElementById('subMenu4').style.display='none';
	document.getElementById('subMenu5').style.display='none';
	document.getElementById('subMenu6').style.display='none';
	document.getElementById('subMenu7').style.display='none';
	document.getElementById('subMenu8').style.display='none';
}

function showMenu(element) {
	for (var i=2;i<=8;i++) {
		if (i!=element) {
			eval ('document.getElementById(\'subMenu' + i+'\').style.display=\'none\'');
		}
	}
	eval ('document.getElementById(\'subMenu' + element+'\').style.display=\'\'')
}

function showShopMenuLeft(menu) {

	var menuLeftItems = document.getElementsByName("menuLeft"+menu);
	
	for (i=0;i<menuLeftItems.length;i++ ) {
		menuLeftItems[i].style.display = "";
	}
	
}



/* images */
function MM_preloadImages() { //v3.0
  var d=document;if(d.images){if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;if(!d) d=document;if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n];for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n);return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc) x.oSrc=x.src;x.src=a[i+2];}
}



/* popup functions*/
function GetCenterHeight (tarHeight) {
	return Math.round((screen.availHeight - tarHeight)/2);
}

function GetCenterWidth (tarWidth) {
	return Math.round((screen.availWidth - tarWidth)/2);
}

function CheckAvalWidth (tarWidth) {
	if(screen.availWidth < (tarWidth+20)) return (screen.availWidth-20); else return (tarWidth+20);
}

function CheckAvalHeight (tarHeight) {
	if(screen.availHeight < (tarHeight+40)) return (screen.availHeight-20); else return (tarHeight+20);
}

function CheckScrollbars (tarWidth,tarHeight) {
	if(screen.availHeight < tarHeight || screen.availWidth < tarWidth) return "yes"; else return "no";
}



/* open popups */
var Pop43;
function OpenPop43(lang){
	u = 'hofer_43g.php?lang=' + lang;
	id = 'Pop43';
	f = 'top='+GetCenterHeight(802)+',left='+GetCenterWidth(650)+',width=802,height=650,scrollbars=no';
	df = 1;
	if(eval(id)==null||eval(id+".closed")){
	eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
	else{eval(id+".close()");eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
}

var HWap;
function OpenPop52(id,lang){
	u = 'hofer_52g.php?prodid=' + id + '&lang=' + lang;
	id = 'HWap';
	f = 'top='+GetCenterHeight(650)+',left='+GetCenterWidth(802)+',width=802,height=650,scrollbars=no';
	df = 1;
	if(eval(id)==null||eval(id+".closed")){
	eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
	else{eval(id+".close()");eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
}

var Pop52h;
function OpenPop52h(id,iid,lang, tarWidth, tarHeight){
	u = 'hofer_52gh.php?prodid=' + id + '&imageid=' + iid + '&lang=' + lang + '&tarWidth=' + tarWidth + '&tarHeight=' + tarHeight;
	id = 'Pop52h';
	f = 'left='+(GetCenterWidth(CheckAvalWidth(tarWidth)))+',top='+(GetCenterHeight(CheckAvalHeight(tarHeight))-30)+',width='+CheckAvalWidth(tarWidth)+',height='+CheckAvalHeight(tarHeight)+',menubar=no,scrollbars=yes';
	df = 1;
	if(eval(id)==null||eval(id+".closed")){
	eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
	else{eval(id+".close()");eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
}

var Pop53d;
function OpenPop53d(id,lang){
	tarWidth = 818;
	tarHeight = 750;
	u = 'hofer_53d.php?id='+id+'&lang='+lang;
	id = 'Pop53d';
	f = 'left='+GetCenterWidth(tarWidth)+',top='+GetCenterHeight(tarHeight)+',width='+CheckAvalWidth(tarWidth)+',height='+CheckAvalHeight(tarHeight)+',menubar=no,scrollbars=yes';
	df = 1;
	if(eval(id)==null||eval(id+".closed")){
	eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
	else{eval(id+".close()");eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
}

var PopSV;
function OpenPopSV(id,lang){
	tarWidth = 818;
	tarHeight = 750;
	u = 'hofer_53p.php?id=' + id + '&lang='+lang+'&ref=sv';
	id = 'PopSV';
	f = 'left='+GetCenterWidth(tarWidth)+',top='+GetCenterHeight(tarHeight)+',width='+CheckAvalWidth(tarWidth)+',height='+CheckAvalHeight(tarHeight)+',scrollbars=yes,menubar=no';
	df = 1;
	if(eval(id)==null||eval(id+".closed")){
	eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
	else{eval(id+".close()");eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
}

var Pop9;
function OpenPop9(id,lang){
	u = 'hofer_9g.php?id=' + id + '&lang=' + lang;
	id = 'Pop9';
	f = 'top='+GetCenterHeight(802)+',left='+GetCenterWidth(650)+',width=802,height=650,scrollbars=no';
	df = 1;
	if(eval(id)==null||eval(id+".closed")){
	eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
	else{eval(id+".close()");eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
}

var HWap;
function OpenPop53(id){ // old gallery hofer_53_old.php
	u = 'hofer_53p.php?id=' + id;
	id = 'HWap';
	f = 'left='+GetCenterWidth(802)+',top='+GetCenterHeight(700)+',width=802,height=700,scrollbars=no';
	df = 1;
	if(eval(id)==null||eval(id+".closed")){
	eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
	else{eval(id+".close()");eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
}

var Pop53i; // old gallery hofer_53_old.php
function OpenPop53i(lang){
	tarWidth = 818;
	tarHeight = 750;
	u = 'hofer_53i.php?lang='+lang;
	id = 'Pop53i';
	f = 'left='+GetCenterWidth(tarWidth)+',top='+GetCenterHeight(tarHeight)+',width='+CheckAvalWidth(tarWidth)+',height='+CheckAvalHeight(tarHeight)+',menubar=no,scrollbars=yes';
	df = 1;
	if(eval(id)==null||eval(id+".closed")){
	eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
	else{eval(id+".close()");eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
}


function OpenPop54(id){ // old hofer_54g.php
	u = 'hofer_54p.php?id=' + id;
	id = 'HWap';
	f = 'width=940,height=1009,scrollbars=no';
	df = 1;
	if(eval(id)==null||eval(id+".closed")){
	eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
	else{eval(id+".close()");eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
}



/* ie flash correction */

function RunMusic() {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100" height="20">\n');
    document.write('<param name="movie" value="images/intro/music.swf?sectionFull='+sectionFull+'">\n');
    document.write('<param name="quality" value="high"><param name="menu" value="false"><param name="bgcolor" value="#000000">\n');
    document.write('<embed src="images/intro/music.swf?sectionFull='+sectionFull+'" width="100" height="20" bgcolor="#000000" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false"></embed>\n');
    document.write('</object>\n');
}

function RunIntroHoriz() {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="792" height="300">\n');
    document.write('<param name="movie" value="images/intro/intro_big.swf?idSec='+sectionFull+'&lang='+langAct+'">\n');
    document.write('<param name="quality" value="high"><param name="menu" value="false">\n');
    document.write('<embed src="images/intro/intro_big.swf?idSec='+sectionFull+'&lang='+langAct+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" menu="false" type="application/x-shockwave-flash" width="792" height="300"></embed>\n');
    document.write('</object>\n');
}

function RunIntroVert() {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="347" height="673">\n');
    document.write('<param name="movie" value="images/intro/intro_vert.swf?idSec='+sectionFull+'">\n');
    document.write('<param name="quality" value="high"><param name="menu" value="false">\n');
    document.write('<embed src="images/intro/intro_vert.swf?idSec='+sectionFull+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="347" height="673" menu="false"></embed>\n');
    document.write('</object>\n');
}

function RunIntroSplash() {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="792" height="362">\n');
    document.write('<param name="movie" value="images/intro/index_intro.swf">');
    document.write('<param name="quality" value="high"><param name="menu" value="false">\n');
    document.write('<embed src="images/intro/index_intro.swf" width="792" height="362" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false"></embed>\n');
    document.write('</object>\n');
}

