$(document).ready(function(){
    $("a.menu-item").mouseover(function(){
		var imgsrc = $(this).children("img").attr("src");
        // Fail if no image found
        if (typeof(imgsrc) != 'undefined') {
            // Replace OFF with ON
            imgsrcON = imgsrc.replace('.gif', '_o.gif');
            // Now change the src to the 'ON' value
            $(this).children("img").attr("src", imgsrcON);
        }
    })
    $("a.menu-item").mouseout(function(){
        var imgsrcON = $(this).children("img").attr("src");
        // trap for 'undefined' errors again
        if (typeof(imgsrcON) != 'undefined') {
            imgsrc = imgsrcON.replace('_o.gif', '.gif');
            $(this).children("img").attr("src", imgsrc);
        }
	})
    $("li.menu-item").mouseover(function(){
    	$(this).children("ul").addClass('show');
    })
    $("li.menu-item").mouseout(function(){
        $(this).children("ul").removeClass('show');
    })

    //fancybox
    $("a.fancybox").fancybox({
        'titlePosition' : 'over',
        'onComplete'	:	function() {
            $("#fancybox-wrap").hover(function() {
                $("#fancybox-title").show();
            }, function() {
                $("#fancybox-title").hide();
            });
        }
    });
    
    //youtube videos
    $("a.fancytube").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;
        });

			$("a.fancyvimeo").click(function() {
			        $.fancybox({
			            'padding'       : 0,
			            'autoScale'     : false,
			            'transitionIn'  : 'none',
			            'transitionOut' : 'none',
			            'title'         : this.title,
			            'width'         : 640,
			            'height'        : 390,
			            'href'          : this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'),
			            'type'          : 'swf'
			        });

			        return false;
			    });
			
			$("a.fancygallery").attr('rel','gallery').fancybox();


    //magnifying glass on zoomable images
    $("a.fancybox").wrap('<div class="fi" />');    
    if(typeof document.body.style.maxHeight === "undefined") {
        //IE6 heeft geen idee
        $(".fi > a > img.floatLeft").each(function() {
          h = $(this).height() - 15;
          w = $(this).width() + 5;
          $(this).after('<div class="magnify" style="top: ' + h + 'px; left: -' + w + 'px;">&nbsp;</div>');
        });
        $(".fi > a > img.floatRight").each(function() {
          h = $(this).height() - 15;
          w = $(this).width();
          $(this).after('<div class="magnify" style="top: ' + h + 'px; right: ' + w + 'px;">&nbsp;</div>');
        });
    } else {
        //een normale(re) browser
        $(".fi > a > img.floatLeft").each(function() {
          h = $(this).height() - 15;
          $(this).after('<div class="magnify" style="top: ' + h + 'px; left: 0px;">&nbsp;</div>');
        });
        
        $(".fi > a > img.floatRight").each(function() {
          h = $(this).height() - 15;
          w = $(this).width() -15;
          $(this).after('<div class="magnify" style="top: ' + h + 'px; right: ' + w + 'px;">&nbsp;</div>');
        });
    }

		//tipsy hover tooltip
			$('.tipsy-hover').tipsy({gravity: 'sw'});
			
			
});
