function IsDefined(myVar) {
	var undefined;
	if (myVar != undefined) {
		return true;
	} else {
		return false;
	}
}

/**
* Adds an event handler to an element
*
* This method automatically decides the proper way to attach an event handler based on the browser's Javascript implementation
* @link http://www.quirksmode.org/js/events_order.html
* @param element target element
* @param eventType string event to listen for (example: 'click')
* @param function function to call when event occurs
* @param bool capture events (default: false)
*/
function addEventHandler(element, eventType, func, useCapture) {
  if (element){
     if (element.addEventListener) {
        element.addEventListener(eventType, func, useCapture);
        return true;
     } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, func);
        return r;
     } else {
        element['on' + eventType] = func;
     }
  }
}

/* USAGE EXAMPLE
addEventHandler(window, 'load', function(e){

});
*/

	function showYoutube(e){
	$.fancybox({
            'padding'           : 0,
            'autoScale'         : false,
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'title'             : this.title,
            'width'             : 680,
            'height'            : 495,
            'href'              : e.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'              : 'swf',
            'swf'               : {
                'wmode'             : 'transparent',
                'allowfullscreen'   : 'true'
            }
        });
	return false;
}

        function showFancybox(e){
	$.fancybox({
            'width'			: '75%',
            'height'                    : '75%',
            'autoScale'                 : false,
            'transitionIn'		: 'none',
            'transitionOut'		: 'none',
            'type'			: 'iframe'
            }
        );
	return false;
}



function emailCheck (obj,nomessage) {
	emailObj=obj;
	emailStr = emailObj.value;
	if(emailStr == "") {
		if (!nomessage) {  alert ( "U heeft geen email adres ingevuld." ); }
		    return false;
		}
		var checkTLD=0;
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		var emailPat=/^(.+)@(.+)$/;
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]";
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+';
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		var matchArray=emailStr.match(emailPat);
		if (matchArray==null) {
			if (!nomessage) {alert("Het ingevulde email adres is geen geldig email adres."); }
				return false;
		}
		var user=matchArray[1];
		var domain=matchArray[2];
		for (i=0; i<user.length; i++) {
			if (user.charCodeAt(i)>127) {
			if (!nomessage) {alert("Het emailadres bevat ongeldige tekens voor de @."); }
				return false;
			}
		}
		for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
				if (!nomessage) {alert("Het emailadres bevat ongeldige tekens na de @."); }
				return false;
			}
		}
		if (user.match(userPat)==null) {
			if (!nomessage) {alert("Het ingevulde email adres is geen geldig email adres."); }
			return false;
		}
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {
			if (domArr[i].search(atomPat)==-1) {
				if (!nomessage) {alert("Het ingevulde email adres is geen geldig email adres."); }
				return false;
			}
		}
		if (checkTLD && domArr[domArr.length-1].length!=2 &&
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		if (!nomessage) {alert("Het ingevulde email adres is geen geldig email adres."); }
			return false;
		}
		if (len<2) {
			if (!nomessage) {alert("Het ingevulde email adres is geen geldig email adres."); }
			return false;
		}
	return true
}

/**
*	jQuery version of the IE6 fix for :hover
*/
(function($){
    $.fn.nbHover = function(){
    	return this.each(function(){
		    var $e = $(this);
		    $e.hover(
				function(){
					$(this).addClass('sfhover');
				},
				function(){
					$(this).removeClass('sfhover');
				}
			);
		});
    };
})(jQuery);

$(document).ready(function(){

    // INIT HOVER
    $('.nav li').nbHover();


    // SCROLLABLE
    $(function() {
        $(".scrollable").scrollable().autoscroll({
            autoplay: true,
            interval: 5000
        });
    });


    // GALLERY
    $(".visual .desc").show();
    $(".visual .block").animate({ opacity: 0.85 }, 1 );

    $(".gallery-menu ul li:first").addClass('active');
    $(".gallery-menu ul li").click(function(){
            var imgAlt = $(this).find('img').attr("alt");
            var imgTitle = $(this).find('a').attr("href");
	    var imgUrl = $(this).find('.imgUrl').attr('href');
            var imgDesc = $(this).find('.block').html();
            var imgDescHeight = $(".visual").find('.block').height();
            if ($(this).is(".active")) {
                    return false;
            } else {
                $(".visual .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
                    $(".visual .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
		    $(".visual a").attr('href', imgUrl);
                    $(".visual img").attr({ src: imgTitle , alt: imgAlt});
                });
            }

            $(".gallery-menu ul li").removeClass('active');
            $(this).addClass('active');
            return false;

    }) .hover(function(){
            $(this).addClass('hover');
            }, function() {
            $(this).removeClass('hover');
    });

    $("a.collapse").click(function(){
            $(".main_image .block").slideToggle();
            $("a.collapse").toggleClass("show");
    });


	

    // SQUEEZEBOX
    $(function() {
        $("a.fancybox").fancybox();
        $("a.group").fancybox({
                'transitionIn'	:'elastic',
                'transitionOut'	:'elastic',
                'speedIn'	:600,
                'speedOut'	:200,
                'overlayShow'	:false
        });
    });
	

	
	
    $("a.youtube").click(function() {
        $.fancybox({
            'padding'           : 0,
            'autoScale'         : false,
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'title'             : this.title,
            'width'             : 680,
            'height'            : 495,
            'href'              : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'              : 'swf',
            'swf'               : {
                'wmode'             : 'transparent',
                'allowfullscreen'   : 'true'
            }
        });

        return false;
    });


});

