// BROWSER DETECTION //
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
var menu_arr = new Array();

function menu_button( button ){
	document.getElementById( 'menu_container' ).innerHTML += document.getElementById( button ).innerHTML;
	document.getElementById( button ).innerHTML = '';
}
function collapseAll( item ){
	
	if( $( item + "-child" ) ) {
//		$( item + "-child" ).setStyles({  'top': '516' });
		document.getElementById( item + "-child" ).style.top = '516px';
	}
}

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
// END BROWSER DETECTION //

// PNG //
if(OS == 'Windows' && browser=='Internet Explorer') {
  var pngAlpha = true;
} else {
  var pngNormal = true;
}

function od_displayImage(strId, strPath, intWidth, intHeight, strClass, strAlt) {

 if (pngAlpha) {
  document.write('<div onClick="klikergens()" style="width:'+intHeight+';height:'+intWidth+';filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+strPath+'.png\', sizingMethod=\'scale\')" id="'+strId+'" class="'+strClass+'"></div>');

 } else if (pngNormal) {
  document.write('<img onClick="klikergens()" style="top:'+intWidth+';height:'+strAlt+';width:'+intHeight+'" src="'+strPath+'.png" width="'+intHeight+'" height="'+strAlt+'" id="'+strId+'" border="0" class="'+strClass+'"/>');

 } else {
  // doorzichtige layer //
  document.write('<img onClick="klikergens()" src="'+strPath+'.gif" width="'+intWidth+'"  height="'+intHeight+'" id="'+strId+'" border="0" class="'+strClass+'" alt="'+strAlt+'" />');

 }
 
 
}

// EINDE PNG //

function preload_afbeeldingen(){
  if(!document.afbeeldingen) document.afbeeldingen=new Array();
  var i;
  var j=document.afbeeldingen.length;
  var bestandsnamen=preload_afbeeldingen.arguments; 
  for(i=0; i<bestandsnamen.length; i++){
	if (bestandsnamen[i].indexOf("#")!=0){ 
	  document.afbeeldingen[j]=new Image; 
	  document.afbeeldingen[j++].src=bestandsnamen[i];
	}
  }
}

var Timer;
var menu_direct_sluiten=0;      // 0 = neen, 1 = ja

if(browser=='Safari' || browser=='Opera' || browser=='Netscape Navigator') {
  var schuifsnelheid=5;          // (1-10)
  //specify speed of scroll (greater=faster)
  var speed=5;
} else {
  var schuifsnelheid=25;
  //specify speed of scroll (greater=faster)
  var speed=1;
}

function inuit(item){
	
	menu_arr.each( collapseAll );
	
	var laag = item + '-button';
	var menus = item + '-child';
//  console.log( laag );
  if(document.getElementById(laag).style.zIndex != '4'){
     inschuiven(menus); document.getElementById(laag).style.zIndex = '4';
  }
  
//  document.getElementById('bedrijf_menu').style.top = '486';document.getElementById('bedrijf_menu_achtergrond').style.top = '486';document.getElementById('bedrijf').style.zIndex = '4';
  	document.getElementById(menus).style.top = '486'; 
//  	console.log( $( laag ).getPosition().y  );

   iens6=document.all||document.getElementById
	ns4=document.layers

	//alert($( laag ).getPosition().x);
	//document.getElementById(menus).style.left = $( laag ).getPosition().x - 280;//210IE6 //280IE7 //315FF
	/*document.getElementById(menus).style.left = $( laag ).getPosition().x - 317;
	
	// Zorgt ervoor dat het menu in IE een pixel meer naar rechts wordt gezet
	if (browser=='Internet Explorer')
		document.getElementById(menus).style.left = $( laag ).getPosition().x - 316;*/
		var itemId = item + "-button";
		var itemPos = $(itemId).getPosition().x;
		var contPos = $('container').getPosition().x;
		//var itemPos = $(itemId).getPosition().x;
		
		//alert(itemPos);
		//document.getElementById(menus).style.left = itemPos - (itemPos / 3); // 302
		//document.getElementById(menus).style.left = $("blauw_vlak").getStyle('left');
		
		//$(menus).setStyle('left', $("blauw_vlak").getStyle('left'));
		$(menus).setStyle('left', itemPos - contPos);

		//alert($(menus).getParent().getPosition().x);
		//$(menus).css('left' , $("#menu_container").css('left'));
	
  	document.getElementById(laag).style.zIndex = '4';
  	
//  document.getElementById('locaties_menu').style.top = '486';document.getElementById('locaties_menu_achtergrond').style.top = '486';document.getElementById('locaties').style.zIndex = '4';
//  document.getElementById('energie_menu').style.top = '486';document.getElementById('energie_menu_achtergrond').style.top = '486';document.getElementById('energie').style.zIndex = '4';
//  document.getElementById('teelt_menu').style.top = '486';document.getElementById('teelt_menu_achtergrond').style.top = '486';document.getElementById('teelt').style.zIndex = '4';
//  document.getElementById('gewassen_menu').style.top = '486';document.getElementById('gewassen_menu_achtergrond').style.top = '486';document.getElementById('gewassen').style.zIndex = '4';
//  document.getElementById('afzet_menu').style.top = '486';document.getElementById('afzet_menu_achtergrond').style.top = '486';document.getElementById('afzet').style.zIndex = '4';
//  document.getElementById('nieuws_menu').style.top = '486';document.getElementById('nieuws_menu_achtergrond').style.top = '486';document.getElementById('nieuws').style.zIndex = '4';
//  document.getElementById('links_menu').style.top = '486';document.getElementById('links_menu_achtergrond').style.top = '486';document.getElementById('links').style.zIndex = '4';
//  document.getElementById('contact_menu').style.top = '486';document.getElementById('contact_menu_achtergrond').style.top = '486';document.getElementById('contact').style.zIndex = '4';
  uitschuiven(menus); document.getElementById(laag).style.zIndex = '5';
}

function klikergens(){
//  if(document.getElementById('bedrijf').style.zIndex == '5' || document.getElementById('medewerkers').style.zIndex == '5' || document.getElementById('locaties').style.zIndex == '5' || document.getElementById('energie').style.zIndex == '5' || document.getElementById('teelt').style.zIndex == '5' || document.getElementById('gewassen').style.zIndex == '5' || document.getElementById('afzet').style.zIndex == '5' || document.getElementById('nieuws').style.zIndex == '5' || document.getElementById('links').style.zIndex == '5' || document.getElementById('contact').style.zIndex == '5') klik();
}


function klik(){
  var laag;
//  if(document.getElementById('bedrijf').style.zIndex == '5') laag = 'bedrijf';
  	if(document.getElementById(laag).style.zIndex == '5');
//  if(document.getElementById('locaties').style.zIndex == '5') laag = 'locaties';
//  if(document.getElementById('energie').style.zIndex == '5') laag = 'energie';
//  if(document.getElementById('teelt').style.zIndex == '5') laag = 'teelt';
//  if(document.getElementById('gewassen').style.zIndex == '5') laag = 'gewassen';
//  if(document.getElementById('afzet').style.zIndex == '5') laag = 'afzet';
//  if(document.getElementById('nieuws').style.zIndex == '5') laag = 'nieuws';
//  if(document.getElementById('links').style.zIndex == '5') laag = 'links';
//  if(document.getElementById('contact').style.zIndex == '5') laag = 'contact';
//  var menus = laag + '_menu';

  inschuiven(menus); document.getElementById(laag).style.zIndex = '4';
}

function inschuiven(menus){
//	console.log( menus);
  if(window.stijgen) clearInterval(stijgen);
  if(window.dalen) clearInterval(dalen);
  var daal = "naar_beneden('" + menus + "')";
  dalen=setInterval(daal,schuifsnelheid);
}

function uitschuiven(menus){
  if(window.stijgen) clearInterval(stijgen);
  if(window.dalen) clearInterval(dalen);
  var stijg = "naar_boven('" + menus + "')";
  stijgen=setInterval(stijg,schuifsnelheid);
}
	
function naar_boven(menua) {
//	console.log( document.getElementById(menua).style.top);
  var startpositie = parseInt(document.getElementById(menua).style.top);
  var menub = menua + "-button";

  var hh = 470 - $( menua ).getStyle('height').toInt();
  if(startpositie > hh) {
//	 console.log('yes naar_boven');
    document.getElementById(menua).style.top = startpositie - 10;
//    document.getElementById(menub).style.top = startpositie - 10;
  } else if (window.stijgen){
    clearInterval(stijgen);
  }
}

function naar_beneden(menua) {
  var startpositie = parseInt(document.getElementById(menua).style.top);
  if(startpositie < 486) {
    if(menu_direct_sluiten==1){
      document.getElementById(menua).style.top = 486;
    } else if(menu_direct_sluiten==0){
      document.getElementById(menua).style.top = startpositie + 10;
//      document.getElementById(menub).style.top = startpositie + 10;
    }
  } else if (window.dalen){
    clearInterval(dalen);
  }
}

   // SCROLL PART 1 //
   var movedownvar;
   var moveupvar;



   iens6=document.all||document.getElementById
   ns4=document.layers


   function movedown(){
     if (iens6&&parseInt(crossobj.style.top)>=(contentheight*(-1)+370)) 
       crossobj.style.top=parseInt(crossobj.style.top)-speed+"px"
     else if (ns4&&crossobj.top>=(contentheight*(-1)+370))
       crossobj.top-=speed
     movedownvar=setTimeout("movedown()",20)
   }

   function moveup(){
     if (iens6&&parseInt(crossobj.style.top)<=0)
       crossobj.style.top=parseInt(crossobj.style.top)+speed+"px"
     else if (ns4&&crossobj.top<=0)
       crossobj.top+=speed
       moveupvar=setTimeout("moveup()",20)
   }

   function moveto(where){
     if (iens6&&parseInt(crossobj.style.top)>=(contentheight*(-1)+370)) 
       crossobj.style.top=parseInt(crossobj.style.top)-where+"px"
     else if (ns4&&crossobj.top>=(contentheight*(-1)+370))
       crossobj.top+=where
       moveupvar=setTimeout("moveto(where)",20)
   }

   function getcontent_height(){
     if (iens6)
     contentheight=crossobj.offsetHeight
     else if (ns4)
     document.nscontainer.document.nscontent.visibility="show"
   }

