// ALFA MASCHINEN JavaScript Document Basic JS in combination with jQuery

//function open window not used jet
function openNewWindow(URLtoOpen, windowName, windowFeatures)
{ newWindow=window.open (URLtoOpen, windowName, windowFeatures);}


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		mAlfaMaschinen_o = newImage("../mImages/mAlfaMaschinenOver.png");
		mService_o = newImage("../mImages/mServiceOver.png");
		mTechniken_o = newImage("../mImages/mTechnikenOver.png");
		mBranchen_o = newImage("../mImages/mBranchenOver.png");
		preloadFlag = true;
	}
}


// for flickerfree dropdown, since IE can only :hover on an <a> element; other elements not!
// So for IE we have to use onmouseover/onmouseout events
// start IE check with <body onLoad="init('droplist')">
// if there are more 'droplists', name them differently, else it won't work for those!

var g_bH = false;

  function init(p_strId) {
    g_bH = false;
    var l_E = document.getElementById(p_strId);
    if(l_E && document.defaultView) {
if(document.defaultView.getComputedStyle(l_E, 'hover')) {
  g_bH = true;
}
    }
    l_E = null;
  }

  
  //	Browsercheck (needed)
	function lib_bwcheck() {
		this.ver=navigator.appVersion;
		this.agent=navigator.userAgent;
		this.dom=document.getElementById?1:0;
		this.opera5=this.agent.indexOf("Opera 5")>-1;
		this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
		this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
		this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
		this.ie=this.ie4||this.ie5||this.ie6;
		this.mac=this.agent.indexOf("Mac")>-1;
		this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
		this.ns4=(document.layers && !this.dom)?1:0;
		this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);
		return this;
	}
	
//	replace image
	var bw = new lib_bwcheck();
	
	function set_image(name, url) {
		var img = document.images[name];
		if(img){
		  img.src = url;
		}
	}
	
	
$(document).ready(function() {
  
    /* sample function for animation; now in use*/
 $('#mainWrapper').css('display','none');					   
  var mainAnimation = function() {
	  var $mainWrapperHeight = $('#mainWrapper').css('height'); //var not used jet	  
	  //alert($mainWrapperHeight);
	  $('#mainWrapper').fadeIn('slow'); 
	 // $('#mainWrapper').show(1000); 
	 //  $('#mainWrapper').animate({height: 'show'}, 'slow'); 
	  // $('#mainWrapper').animate({width: 'show'}, 'slow'); 
		
  };	
  mainAnimation();
  
 /* $('#dropdown4a h4').hover(function() {
	 $('table.tableOverwiew').find('td').addClass('highlighted');
	var column = 1;
   }, function() {
	$('table.tableOverwiew').find('td').removeClass('highlighted');
  }); */
  
 /* var $totalColumns = $('table.tableOverwiew').each(function (column) {
		$('table.tableOverwiew').get('td');
		alert(column);
	}); */ //not working as expected
  
  
  //var $totalColumns = $('table.tableOverwiew').find('tr:first td').length;
	var $totalColumns = $('table.tableService').find('tr:first td').length;
  //alert($totalColumns);

/* SERVICE overview table column hightlighting*/
 $('#droplist3 h4').hover(function () {
		//alert($('#droplist3 h4').length);		
		//alert($('#droplist3 h4').eq);	
		//alert(event.target);	
		var index = $('#droplist3 h4').index(this);
		//alert('That was #droplist3 h4 index #' + index);
      var $tableService = $('table.tableService tr');
	  $tableService.each(function (i) {
		// $tableService.find('td:first').addClass('highlighted');
		// if (index == $('#droplist3 h4') [0]) {
		//	 alert(this.index);
        if (index == '0') {
		//	if (this == [0]) {
          $tableService.find('td:first').addClass('highlighted');
      	} else if (index == '1') {
          $tableService.find('td:first').next().addClass('highlighted');
         } else if (index == '2') {
          $tableService.find('td:first').next().next().addClass('highlighted');
        } else if (index == '3') {
          $tableService.find('td:first').next().next().next().addClass('highlighted');
        } else if (index == '4') {
          $tableService.find('td:first').next().next().next().next().addClass('highlighted');
        } 
		
      });
	  }, function() {
		 $('table.tableService').find('td').removeClass('highlighted');
    });
 
  /* SERVICE overview table row hightlighting*/
  $('#menuSet h4').hover(function () {
	  var serviceRowIndex = $('#menuSet h4').index(this);
	  //alert('That was #menuSet h4 index #' + serviceRowIndex);
	  serviceRowIndex++; // prepare rowIndex for 1 based child selector
	  //alert(rowIndex);
	 // use filter to hightlight the correct row; using find would hightlight column!!
	  $('table.tableService tr').filter(':nth-child(' + (serviceRowIndex) + ')').addClass('highlighted');
	  //$('table.tableOverwiew tr:nth-child(5)').addClass('highlighted');
	  }, function() {
		 $('table.tableService').find('tr').removeClass('highlighted');
    });
 
 /* TECHNIK table overview column hightlighting*/
 $('h4').hover(function () {
		var index4 = $('#droplist4 h4').index(this);
		//alert('That was #droplist3 h4 index #' + index);
      var $table = $('table.tableOverwiew tr');
	  $table.each(function (i) {
        if (index4 == '0') {
          $table.find('td:first').addClass('highlighted');
      	} else if (index4 == '1') {
          $table.find('td:first').next().addClass('highlighted');
         } else if (index4 == '2') {
          $table.find('td:first').next().next().addClass('highlighted');
        } else if (index4 == '3') {
          $table.find('td:first').next().next().next().addClass('highlighted');
        } else if (index4 == '4') {
          $table.find('td:first').next().next().next().next().addClass('highlighted');
        } else if (index4 == '5') {
          $table.find('td:first').next().next().next().next().next().addClass('highlighted');
        } 
		
      });
	  }, function() {
		 //  $table.find('td').removeClass('highlighted'); fault: $table not defined?
		 $('table.tableOverwiew').find('td').removeClass('highlighted');
    });
 
  /* TECHNIK overview table row hightlighting*/
  $('#menuSet h4').hover(function () {
	  var rowIndex = $('#menuSet h4').index(this);
	  //alert('That was #menuSet h4 index #' + rowIndex);
      var $tableRows = $('table.tableOverwiew tr');
	  rowIndex++; // prepare rowIndex for 1 based child selector
	  //alert(rowIndex);
	 // use filter to hightlight the correct row; using find would hightlight column!!
	  $('table.tableOverwiew tr').filter(':nth-child(' + (rowIndex) + ')').addClass('highlighted');
	  //$('table.tableOverwiew tr:nth-child(5)').addClass('highlighted');
	  }, function() {
		 $('table.tableOverwiew').find('tr').removeClass('highlighted');
    });
  
  
 /* AUFBEREITUNG table overview column hightlighting*/
$('thead th').hover(function () {
		//var index4 = $('#droplist4 h4').index(this);
		var index4 = $('thead th').index(this);
		//alert('That was #droplist3 h4 index4 #' + index4);
      var $table = $('table.tableAufbereitung tr');
	  $table.each(function (i) {
        if (index4 == '0') {
          $table.find('td:first').addClass('highlighted');
      	} else if (index4 == '1') {
          $table.find('td:first').next().addClass('highlighted');
         } else if (index4 == '2') {
          $table.find('td:first').next().next().addClass('highlighted');
        } else if (index4 == '3') {
          $table.find('td:first').next().next().next().addClass('highlighted');
        } else if (index4 == '4') {
          $table.find('td:first').next().next().next().next().addClass('highlighted');
        } else if (index4 == '5') {
          $table.find('td:first').next().next().next().next().next().addClass('highlighted');
        } 
		
      });
	  }, function() {
		 $('table.tableAufbereitung').find('td').removeClass('highlighted');
    });
 
   /* AUFBEREITUNG overview table row hightlighting*/
  $('#menuSetTechnik2 h4').hover(function () {
	  var rowIndex = $('#menuSetTechnik2 h4').index(this);
	  //alert('That was #menuSet h4 index #' + rowIndex);
      var $tableRows = $('table.tableAufbereitung tbody tr');
	  rowIndex++; // prepare rowIndex for 1 based child selector
	  //alert(rowIndex);
	 // use filter to hightlight the correct row; using find would hightlight column!!
	  $('table.tableAufbereitung tbody tr').filter(':nth-child(' + (rowIndex) + ')').addClass('highlighted');
	  //$('table.tableOverwiew tr:nth-child(5)').addClass('highlighted');
	  }, function() {
		 $('table.tableAufbereitung').find('tr').removeClass('highlighted');
    });
  

/* ZERKLEINERUNGSTECHNIK/PALETTE table overview column hightlighting*/
 $('thead th').hover(function () {
	//alert('hover list item');
		var index4b = $('thead th').index(this);
		//alert('That was thead th li index #' + index4b);
      var $tableSub = $('table.tableSub tr');
	  $tableSub.each(function (i) {
        if (index4b == '1') {
          $tableSub.find('td:first').addClass('highlighted');
      	} else if (index4b == '2') {
          $tableSub.find('td:first').next().addClass('highlighted');
         } else if (index4b == '3') {
          $tableSub.find('td:first').next().next().addClass('highlighted');
        } else if (index4b == '4') {
          $tableSub.find('td:first').next().next().next().addClass('highlighted');
        } else if (index4b == '5') {
          $tableSub.find('td:first').next().next().next().next().addClass('highlighted');
        } 
		
      });
	  }, function() {
		 $('table.tableSub').find('td').removeClass('highlighted');
    });
 
   /* ZERKLEINERUNGSTECHNIK/PALETTE overview table row hightlighting*/
 // $('table.tableSub tbody tr:not([td])').hover(function () {
 // $('table.tableSub tbody tr[th]').hover(function () {
 // $('table.tableSub tbody tr:nth-child(1)').hover(function () { // highlights only firist row!!
  $('table.tableSub tbody tr').hover(function () { // this version acts when hovering on ANY CELL in that row	
	//alert('hovering');
	  var tableRowIndex = $('table.tableSub tbody tr').index(this);
	 // alert('That was table.tableSub tbody tr index #' + tableRowIndex);
	  tableRowIndex++;
	 // alert(tableRowIndex);
	 // use filter to hightlight the correct row; using find would hightlight column!!
	  $('table.tableSub tbody tr').filter(':nth-child(' + (tableRowIndex) + ')').addClass('highlighted');
	//  $('table.tableSub:not([thead]) tr').filter(':nth-child(' + (tableRowIndex) + ')').addClass('highlighted'); // this doesn't work
	   $('table.tableSub thead').find(':first').css('background-color', 'transparent'); // don't highlight thead	
	  }, function() {
		 $('table.tableSub').find('tr').removeClass('highlighted');
    });


/* FÖRDERTECHNIK table overview column hightlighting*/
 $('thead th').hover(function () {
	//alert('hover list item');
		var index4c = $('thead th').index(this);
		//alert('That was #droplist4c li index #' + index4c);
      var $tableFoerder = $('table.tableFoerdertechnik tr');
	  $tableFoerder.each(function (i) {
        if (index4c == '0') {
          $tableFoerder.find('td:first').addClass('highlighted');
      	} else if (index4c == '1') {
          $tableFoerder.find('td:first').next().addClass('highlighted');
        } else if (index4c == '2') {
          $tableFoerder.find('td:first').next().next().addClass('highlighted');
        } else if (index4c == '3') {
          $tableFoerder.find('td:first').next().next().next().addClass('highlighted');
        } 
		
      });
	  }, function() {
		 $('table.tableFoerdertechnik').find('td').removeClass('highlighted');
    });
 
  /* FÖRDERTECHNIK overview table row hightlighting*/
  $('#menuSetTechnik h4').hover(function () {
	  var foerderRowIndex = $('#menuSetTechnik h4').index(this);
	  foerderRowIndex++; // prepare rowIndex for 1 based child selector
	  //alert(foerderRowIndex);
	 // use filter to hightlight the correct row; using find would hightlight column!!
	  $('table.tableFoerdertechnik tbody tr').filter(':nth-child(' + (foerderRowIndex) + ')').addClass('highlighted');
	  //$('table.tableOverwiew tr:nth-child(5)').addClass('highlighted');
	  }, function() {
		 $('table.tableFoerdertechnik').find('tr').removeClass('highlighted');
    });
  
  
 
/* SIEBTECHNIK table overview column hightlighting*/
 $('#droplist4d li').hover(function () {
	//alert('hover list item');
		var index4d = $('#droplist4d li').index(this);
		//alert('That was #droplist4d li index #' + index4d);
      var $tableSieb = $('table.tableSiebtechnik tr');
	  $tableSieb.each(function (i) {
        if (index4d == '0') {
          $tableSieb.find('td:first').addClass('highlighted');
      	} else if (index4d == '1') {
          $tableSieb.find('td:first').next().addClass('highlighted');
         } else if (index4d == '2') {
          $tableSieb.find('td:first').next().next().addClass('highlighted');
        } 
		
      });
	  }, function() {
		 $('table.tableSiebtechnik').find('td').removeClass('highlighted');
    });
 
  /* SIEBTECHNIK overview table row hightlighting*/
  $('#menuSet h4').hover(function () {
	  var siebRowIndex = $('#menuSet h4').index(this);
	  siebRowIndex++; // prepare rowIndex for 1 based child selector
	  //alert(siebRowIndex);
	 // use filter to hightlight the correct row; using find would hightlight column!!
	  $('table.tableSiebtechnik tr').filter(':nth-child(' + (siebRowIndex) + ')').addClass('highlighted');
	  //$('table.tableOverwiew tr:nth-child(5)').addClass('highlighted');
	  }, function() {
		 $('table.tableSiebtechnik').find('tr').removeClass('highlighted');
    });
  
  
  /* assignment: .subnav img buttons functionality like in mr.mister stallentmister */
  	$('#image1').css('display','none'); // hide film
   $('.subImg').css('display','inline');
   $('.subImg img:eq(0)').addClass('active');
   $('.subImg img:eq(0)').attr('id', 'current');				   
   $('.subImg img').hover(function() {
     if (this.id != 'current') {
	 	var $image = $(this);	
		$(this).fadeTo("slow", 0.5);
		var imagePath = $image.attr('src');
		var imageTitle = $image.attr('alt');
		//alert("imagePath: " + imagePath);
		//alert("imageTitle: " + imageTitle);
		var imageLargePath = imagePath.slice(0,-6);
		var imageEnding = imagePath.slice(-4);
		var imageLarge = imageLargePath + imageEnding;

		var $imgLg = $('#image0');
		var imgLgCurrentPath = $imgLg.attr('src');
		//alert("imageLarge: " + imageLarge + "imgLgCurrentPath: " + imgLgCurrentPath);
		$(this).click(function() {
		  // alert('click');
		  //if (imageLarge !=  imgLgCurrentPath) {
		  if (imagePath !=  imgLgCurrentPath) {
			  $('.subImg img').removeClass('active');
			  $('.subImg img').attr('id', '');
			  $(this).addClass('active').attr('id', 'current');
			  //$('#image0').fadeTo('slow', 0.2, function() {
			  $($imgLg).fadeTo('slow', 0.2, function() {
	    		 //$('#image0').attr('src',imageLarge).fadeTo('slow', 0.99);
				 //$('#image0').attr('src',imagePath).fadeTo('slow', 0.99);
				 $($imgLg).attr('src',imagePath).fadeTo('slow', 0.99);
				 $('.mainImgTitle').text(imageTitle).fadeTo('slow', 0.99);
	   	 	  });
	  	   }
		});
	
	
	 }
  }, function() {
	 // for Safari we need to set opacitiy to 0.99, else imgage disapears
	$(this).fadeTo("fast", 0.99);
  });	
	

	/* just hover effect for pages with movies */
   $('.subLink img').hover(function() {
     if (this.id != 'current') {
	 	var $image = $(this);	
		$(this).fadeTo("slow", 0.5);
	 }
  }, function() {
	 // for Safari we need to set opacitiy to 0.99, else imgage disapears
	$(this).fadeTo("fast", 0.99);
  });	
		
		
 /* assignment: for movies */
    $('.subMov img').hover(function() {
     if (this.id != 'current') {
	 	var $image = $(this);	
		$(this).fadeTo("slow", 0.5);
		var imagePath = $image.attr('src');
		var imageTitle = $image.attr('alt');
		//alert("imagePath: " + imagePath);
		//alert("imageTitle: " + imageTitle);
		var imageLargePath = imagePath.slice(0,-6);
		var imageEnding = imagePath.slice(-4);
		var imageLarge = imageLargePath + imageEnding;
		
		//var $imgLg = $('#image0');
		var $imgLg = $('#image1');
		var $imgFade = $('#image0');
		var imgLgCurrentPath = $imgLg.attr('src');
		//alert("imageLarge: " + imageLarge + "imgLgCurrentPath: " + imgLgCurrentPath);
		//alert("imagePath: " + imagePath + "imgLgCurrentPath: " + imgLgCurrentPath);
		$(this).click(function() {
		  // alert('click');
		  //alert("this: " + this);
		  //if (imageLarge !=  imgLgCurrentPath) {
		// test  $('#image1').css('display','inline');
		  if (imagePath !=  imgLgCurrentPath) {
			  $('.subImg img').removeClass('active');
			  $('.subImg img').attr('id', '');
			  $(this).addClass('active').attr('id', 'current');

			  //$('#image0').fadeTo('slow', 0.2, function() {
			$('#image1').css('display','inline');
			  $($imgLg).fadeTo('slow', 0.2, function() {
	    		 //$('#image0').attr('src',imageLarge).fadeTo('slow', 0.99);
				 //$('#image0').attr('src',imagePath).fadeTo('slow', 0.99);
				 $($imgLg).attr('src',imagePath).fadeTo('slow', 0.99);
				 $($imgFade).fadeTo('slow', 0.2);
				 $('.mainImgTitle').text(imageTitle).fadeTo('slow', 0.99);
	   	 	  });
	  	   }
		});
	
	
	 }
  }, function() {
	 // for Safari we need to set opacitiy to 0.99, else imgage disapears
	$(this).fadeTo("fast", 0.99);
  });	
	
});




