/**
 * General triggered behaviour on document load
 */
var general_rules = {
    '.hilite_keywords' : function() {
    	
       var hiliter = new KeywordHiliter("ajax.php",this);
       hiliter.options.elementTag = 'SPAN';
       hiliter.options.elementClassName = 'intellilink';
       hiliter.options.useGetFunction = 'listKeywords';
       hiliter.options.elementClass = true;
       hiliter.options.useTitle = false;
       hiliter.options.useItemID = true;
       hiliter.fetchKeywords();
    },
    '.no_javascript' : function() {
      this.hide();
    },
    '.show_no_javascript' : function() {
      this.show();
    }
}
Event.addBehavior(general_rules);


var flash_rules = {
    '#selector_home' : function(el) {
        var params = Element.getClassParameters(el);
        var FOSelector = {
                movie:"/flash/selectorbanner.swf",
                width:"178",
                height:"89",
                menu:"false",
                flashvars: "pageID=" + params.pageID,
                wmode:"transparent",
                xi:"false",
                majorversion:"7",
                build:"0"
        };
        UFO.create(FOSelector,"selector_home");
    },
    '#aircoselector' : function(el) {
        var FOSelector = {
                movie:"/flash/selector.swf",
                width:"435",
                height:"400",
                menu:"false",
                wmode:"transparent",
                xi:"false",
                majorversion:"7",
                build:"0"
        };
        UFO.create(FOSelector,"aircoselector");
    },
    '#citymulti_vrf_r2' : function(el) {
        var FOSelector = {
                movie:"/flash/presentaties/citymulti_vrf_r2.swf",
                width:"775",
                height:"581",
                menu:"false",
                wmode:"transparent",
                xi:"false",
                majorversion:"7",
                build:"0"
        };
        UFO.create(FOSelector,"citymulti_vrf_r2");
    },
    '#citymulti_vrf_r2_short' : function(el) {
        var FOSelector = {
                movie:"/flash/presentaties/citymulti_vrf_r2_short.swf",
                width:"500",
                height:"415",
                menu:"false",
                wmode:"transparent",
                xi:"false",
                majorversion:"7",
                build:"0"
        };
        UFO.create(FOSelector,"citymulti_vrf_r2_short");
    },
    '#citymulti_vrf_y' : function(el) {
        var FOSelector = {
                movie:"/flash/presentaties/citymulti_vrf_y.swf",
                width:"775",
                height:"581",
                menu:"false",
                wmode:"transparent",
                xi:"false",
                majorversion:"7",
                build:"0"
        };
        UFO.create(FOSelector,"citymulti_vrf_y");
    },
    '#citymulti_vrf_y_short_koelen' : function(el) {
        var FOSelector = {
                movie:"/flash/presentaties/citymulti_vrf_y_short_koelen.swf",
                width:"500",
                height:"415",
                menu:"false",
                wmode:"transparent",
                xi:"false",
                majorversion:"7",
                build:"0"
        };
        UFO.create(FOSelector,"citymulti_vrf_y_short_koelen")
    },
    '#citymulti_vrf_y_short_koelen_verwarmen' : function(el) {
        var FOSelector = {
                movie:"/flash/presentaties/citymulti_vrf_y_short_koelen_verwarmen.swf",
                width:"500",
                height:"415",
                menu:"false",
                wmode:"transparent",
                xi:"false",
                majorversion:"7",
                build:"0"
        };
        UFO.create(FOSelector,"citymulti_vrf_y_short_koelen_verwarmen")
    },
    '#flash_header_home' : function(el) {
        var params = Element.getClassParameters(el);
        var flashvars = "skipIntro=" + params.skipIntro;
        if(params.roomID){
            flashvars += '&roomID='+ params.roomID;
        }
        var FOHeaderHome = {
                movie:"/flash/header_home.swf",
                width:"100%",
                height: "410",
                menu:"false",
                flashvars: flashvars,
                wmode:"opaque",
                xi:"false",
                majorversion:"9",
                build:"0"
        };
        UFO.create(FOHeaderHome,"flash_header_home");
    },
    '#flash_header' : function(el) {
        var params = Element.getClassParameters(el);
        var flashvars = params.roomID || 0;
        var FOHeader = {
                movie:"/flash/header_vervolg.swf",
                width:"100%",
                height:"211",
                menu:"false",
                flashvars: "roomID=" + flashvars,
                wmode:"opaque",
                xi:"false",
                majorversion:"9",
                build:"0"
        };
        UFO.create(FOHeader,"flash_header");
    },
    '#flash_videoplayer' : function() {
        var FOVideoPlayer = {
          movie:"/flash/videoplayer.swf",
          width: "435",
          height: "275",
          menu:"false",
          xi:"false",
          majorversion:"7",
          build:"0",
          wmode:"opaque",
      	  allowscriptaccess:"always",
  	      allowfullscreen:"true"
        }
        UFO.create(FOVideoPlayer,"flash_videoplayer");
    }
}
Behaviour.register(flash_rules);
/**
 * Rules for intellilinks
 */
var intellilink_rules = {
    'span.intellilink:mouseover': function(e) {
        /**
         * Event:  mouseover
         * Action: show the intellilink DIV and fill with title text
         */
        var container = $('tooltip');
        
        
        var params = Element.getClassParameters(this);
        var containerItemID = Element.getClassParameter(container,'itemID');
        /*
         * If already loaded, just show in the right place...
         */
        container.setStyle({'top': (Position.cumulativeOffset(this)[1] + 20) + 'px','left': (Position.cumulativeOffset(this)[0] + 15) + 'px'});
        if (containerItemID == params.itemID) {
          container.show();
        } else {
          container.removeClassName('param-itemID=' + containerItemID);
          container.innerHTML = '<p>laden...</p>';
          container.show();
          var updater = new Ajax.Updater(
            container,
            'ajax.php',
            {
              parameters: {
                action: 'getTooltip',
                itemID: params.itemID
              },
              onSuccess: (function(transport) {
                Element.addClassName(this,'param-itemID=' + params.itemID);
              }).bind(container)
            }
          );
        }
        return false;
    },
    'span.intellilink:mouseout': function(e) {
        /**
         * Event:  mouseover
         * Action: show the intellilink DIV and fill with title text
         */
        $('tooltip').hide();
    }
}
Event.addBehavior(intellilink_rules);


var rollover_rules = {
    'img.rollover' : function(el) {
        el.onmouseover = function() {
            parts = this.src.match(/^(.+)\.(\w+)$/);
            if (parts[1] != null && parts[1].match(/_ro/) == null ) {
                this.src = parts[1] + "_ro." + parts[2];
            }
        };
        el.onmouseout = function() {
            parts = this.src.match(/^(.+)_ro\.(\w+)$/);
            if (parts != null ) {
                this.src = parts[1] + "." + parts[2];
            }
        }
    },
    'ul.nav li' : function(el) {
        el.onmouseover = function() {
            this.className = 'MenuItemOver';
        };
        el.onmouseout = function() {
            this.className = 'MenuItem';
        };
    },
    'img.hover' : function(el) {
        el.onmouseover = function () {
            this.src = this.src.replace('normal','hover');
        };
        el.onmouseout = function() {
            this.src = this.src.replace('hover','normal');
        };
    },
    '#menu a img' : function(el) {
        el.onmouseover = function () {
            if (this.parentNode.className != "selected") {
                this.src = this.src.replace('normal','hover');
            }
        };
        el.onmouseout = function() {
            if (this.parentNode.className != "selected") {
                this.src = this.src.replace('hover','normal');
            }
        };
        el.onclick = function() {
            this.parentNode.className = "selected";
        };
    },
    'a.switch' : function(el) {
        el.onclick = function() {
            content = $(this.id.replace('_switch',''));
            if (content) {
                if (content.style.display != 'none') {
                    content.style.display = 'none';
                } else {
                    content.style.display = 'block';
                }
            }
            return false;
        }
    }
}
Behaviour.register(rollover_rules);

var popup_rules = {
    'a.popup' : function(el) {
        el.onclick = function() {
            window.open(this.href,
                'PopUp',
                'width=684,height=350,top=200,left=50%,scrollbars=0,status=no,resizable=0,toolbar=0,titlebar=0,menubar=0,location=0');
            return false;
        }
    },
    'a.popup_flash' : function(el) {
        el.onclick = function() {
            window.open(this.href,
                'PopUp',
                'width=775,height=581,top=200,left=50%,scrollbars=0,status=no,resizable=0,toolbar=0,titlebar=0,menubar=0,location=0');
            return false;
        }
    },
    'a.status' : function(el) {
        el.onmouseover = function() {
            window.status=this.title;
            return true;
        };
        el.onmouseout = function() {
            window.status='';
            return true;
        }
    }
}
Behaviour.register(popup_rules);
var form_rules = {
    'input.auto_upper' : function(el) {
        el.onblur = function() {
            this.value = this.value.toUpperCase();
        };
        el.onchange = function() {
            this.value = this.value.toUpperCase();
        };
    },
    'input.error' : function(el) {
        el.onfocus = function() {
            this.value = '';
            this.onfocus = null;
        }
    },
    '#contact_adviseur_form' : function(el) {
        el.onsubmit = function() {
            var submit = true;
            /*
            if (this.name.value == '') {
                this.name.label.className += " red";
                setError("name","Vul uw naam in.");
                submit = false;
            } else {
                this.name.className = this.name.className.replace("red","");
                unsetError("name");
            }
            if (/^[\w-.]+@[\w-.]+\.\w{2,}$/.test(this.email.value) == false) {
                this.email.label.className += " red";
                setError("email","Vul uw e-mail adres in.");
                submit = false;
            } else {
                unsetError("email");
            }
            if (/^[\+\-\(\)\s\d]+$/.test(this.phone.value) == false) {
                this.name.className += " red";
                setError("phone","Vul uw telefoonnummer in.");
                submit = false;
            } else {
                unsetError("phone");
            }
            */
            return submit;
        }
    },
   '#contact' : function(el) {
        el.onsubmit = function() {
             var submit = true;
            if (this.organisation.value == '') {
                setError("organisation","Vul uw organisatie in.");
                submit = false;
            } else {
                unsetError("organisation");
            }
            if (this.name.value == '') {
                setError("name","Vul uw naam in.");
                submit = false;
            } else {
                unsetError("name");
            }
            if (this.address.value == '') {
                setError("address","Vul uw adres in.");
                submit = false;
            } else {
                unsetError("address");
            }
            if (/^\d{4}\s?[a-zA-Z]{2}$/.test(this.postcode.value) == false) {
                setError("postcode","Vul uw postcode in.");
                submit = false;
            } else {
                unsetError("postcode");
            }
            if (this.city.value == '') {
                setError("city","Vul uw stad in.");
                submit = false;
            } else {
                unsetError("city");
            }
            if (/^[\w-.]+@[\w-.]+\.\w{2,}$/.test(this.email.value) == false) {
                setError("email","Vul uw e-mail adres in.");
                submit = false;
            } else {
                unsetError("email");
            }
            if (/^[\+\-\(\)\s\d]+$/.test(this.phone.value) == false) {
                setError("phone","Vul uw telefoonnummer in.");
                submit = false;
            } else {
                unsetError("phone");
            }
            if (this.question.value == '') {
                setError("question","Vul uw vraag in.");
                submit = false;
            } else {
                unsetError("question");
            }
            return submit;
        }
    },
   '#docrequest' : function(el) {
        el.onsubmit = function() {
             var submit = true;
            if (this.organisation.value == '') {
                setError("organisation","Vul uw organisatie in.");
                submit = false;
            } else {
                unsetError("organisation");
            }
            if (this.name.value == '') {
                setError("name","Vul uw naam in.");
                submit = false;
            } else {
                unsetError("name");
            }
            if (this.address.value == '') {
                setError("address","Vul uw adres in.");
                submit = false;
            } else {
                unsetError("address");
            }
            if (/^\d{4}\s?[a-zA-Z]{2}$/.test(this.postcode.value) == false) {
                setError("postcode","Vul uw postcode in.");
                submit = false;
            } else {
                unsetError("postcode");
            }
            if (this.city.value == '') {
                setError("city","Vul uw stad in.");
                submit = false;
            } else {
                unsetError("city");
            }
            if (/^[\w-.]+@[\w-.]+\.\w{2,}$/.test(this.email.value) == false) {
                setError("email","Vul uw e-mail adres in.");
                submit = false;
            } else {
                unsetError("email");
            }
            if (/^[\+\-\(\)\s\d]+$/.test(this.phone.value) == false) {
                setError("phone","Vul uw telefoonnummer in.");
                submit = false;
            } else {
                unsetError("phone");
            }
            return submit;
        }
    }
}

var ajax_rules = {
    '#producten a' : function(el) {
        el.onclick = function() {
            var params = this.href.toQueryParams();
            getProducten(params["serie"],params["uitvoering"],params["type"],params["set"]);
            return false;
        };
    }
}

var google_analytics_rules = {
	'#analytics_placeholder' : function(el){
		var sid= Element.getClassParameter(el, 'sid');
		pageTracker = _gat._getTracker(sid);
		pageTracker._trackPageview();
	}
}

Behaviour.register(google_analytics_rules);