// bbe 20080302 mod to match cms logic
// Rollover  v2.0.1
// documentation: http://www.dithered.com/javascript/rollover/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
/*document.getElementById('layerDhtml').style.visibility='hidden';*/
function isDefined(property) {
  return (typeof property != 'undefined');
}
var rolloverInitialized = false;
function rolloverInit() {

   if (!rolloverInitialized && isDefined(document.images)) {
      // get all images (including all <input type="image">s)
	  // bbe 20050607 - hover effect dont work for form-input images ..
      // use getElementsByTagName() if supported
      var images = new Array();
      if (isDefined(document.getElementsByTagName)) {
         images = document.getElementsByTagName('img');
         var inputs = document.getElementsByTagName('input');
         for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == 'image') {
               images[images.length] = inputs[i];
            }
         }
      }
      // otherwise, use document.images and document.forms collections
      // remove if not supporting IE4, Opera 4-5
      else {
         images = document.images;
         inputs = new Array();
         for (var formIndex = 0; formIndex < document.forms.length; formIndex++) {
            for (var elementIndex = 0; elementIndex < document.forms.elements.length; elementIndex++) {
               if (isDefined(document.forms.elements[i].src)) {
                  inputs[inputs.length] = document.forms.elements[i];
               }
            }
         }
      }
      // get all images with '_off.' in src value
      for (var i = 0; i < images.length; i++) {
         if (images[i].src.indexOf('navigation-inaktiv') != -1) {
            var image = images[i];
            // store the off state filename in a property of the image object
            image.offImage = new Image();
            image.offImage.src = image.src;
            // store the on state filename in a property of the image object
            // (also preloads the on state image)
            image.onImage = new Image();
            image.onImage.imageElement = image;
            // add onmouseover and onmouseout event handlers once the on state image has loaded
            // Safari's onload is screwed up for off-screen images; temporary fix
            if (navigator.userAgent.toLowerCase().indexOf('safari') != - 1) {
               image.onmouseover = function() {
                  this.src = this.onImage.src;
               };
               image.onmouseout = function() {
                  this.src = this.offImage.src;
               };
            }
            else {
               image.onImage.onload = function() {
                  this.imageElement.onmouseover = function() {
				  		/*alert("Changing to:"+this.onImage.src)*/
                     this.src = this.onImage.src;
                  };
                  this.imageElement.onmouseout = function() {
                     this.src = this.offImage.src;
                  };
               };
            }
            // set src of on state image after defining onload event handler
            // so cached images (that load instantly in IE) will trigger onload
			nameOfNav = new String(image.src.match(/name=.+$/));
			nameOfNav = nameOfNav.replace(/name=/, '');
			styleOfNav = new String(image.src.match(/style=[A-Za-z0-9-_]+/));
		/*	
			alert("styleOfNav: "+styleOfNav);*/
			
			/*alert(typeof(nameOfNav));*/
            if (nameOfNav == 'null'){
				image.onImage.src = image.src.replace(/navigation-inaktiv\.gif/, 'navigation-aktiv.gif');
				
			}else{
				image.onImage.src = image.src.replace(/text=.+&/, 'text='+nameOfNav+'&'+styleOfNav+'&');
			}
			
			
			/*document.write(image.offImage.src+"\n<br>"+image.onImage.src);*/
			
			/*<img border="0" src="{$fontrendererurl}?text=0{$foo}&style=navigation-inaktiv&name={$val_1.name}">*/
			
			
         }
      }
   }
   rolloverInitialized = true;
}

/*function manual_rollover(id){
	if (id.src.indexOf('_off.') != -1){
		id.src = id.src.replace(/_off\./, '_on.');
	}else{
		id.src = id.src.replace(/_on\./, '_off.');
	}
}*/

// call rolloverInit when document finishes loading
/*if (isDefined(window.addEventListener)) {
   window.addEventListener('load', rolloverInit, false);
   
}*/
/* Hide loading bar, show content and initialize mouse event listening after loading */
window.onload = function()
{
	if(document.getElementById(conf_imageflow))
	{
		// hide loading bar
		hide(conf_loading);
		
		// animation core
		refresh(true);
		
		show(conf_images);
		
		// show scrollbar
		show(conf_scrollbar);
		
		// controls initialisation
		initMouseWheel();
		initMouseDrag();
		
		/*alert("last_seen_logo: "+last_seen_logo+"\n last_seen_logo_x_pos: "+last_seen_logo_x_pos);*/
		if (last_seen_logo > 0 && last_seen_logo_x_pos != 0){
			
			glideTo(last_seen_logo_x_pos, last_seen_logo);
			
		}
		
		
		
	
	}
	rolloverInit();
}