// no conflict
// jQuery.noConflict();

/**
 *	custom IE Cleartype fixes
 */

$.fn.fadeIn = function(speed, callback) {
     return this.animate({
          opacity: 'show' }, speed, function() {
               if ($.browser.msie)
                    this.style.removeAttribute('filter');
               if (typeof callback == 'function')
                    callback();
     });
};

$.fn.fadeOut = function(speed, callback) {
     return this.animate({
           opacity: 'hide' }, speed, function() {
               if ($.browser.msie)
                    this.style.removeAttribute('filter');
               if (typeof callback == 'function') callback();
     });
};

$.fn.fadeTo = function(speed,to,callback) {
     return this.animate({opacity: to }, speed, function() {
          if (to == 1 && $.browser.msie)
               this.style.removeAttribute('filter');
          if (typeof callback == 'function') callback();
     });
}; 

/**
 *	checks if link is external 
 *	usage: a:external (only if element has href attr)
 */

$.extend($.expr[':'], {		
	external: function(a,i,m) {
		if(!a.href) {return false;}
		return a.hostname && a.hostname !== window.location.hostname;
	}
});

/**
 *	custom selector which determines if 
 *	images not resides in slideshow
 */

$.extend($.expr[':'], {			
	inSlideshow: function(e) {
		return $(e).parents("#slideshow").size();
	}
});


/**
 *	document load functions 
 */
$(document).ready(function() {
    
    $('html').css({overflowY: 'scroll'});
    
    // apply external behaviour at all external links
    $("body a:external").filter(function() { $(this).addClass("external").attr({title: this.href + ' (External link: opens in a new window)', target:'_blank'}); });

    // navigation fn
    $('#navigation > li').bind('mouseover', menu_open);
    $('#navigation > li').bind('mouseout',  menu_timer);
    
    var offset_width = $("#navigation > li:last-child ul").width() - $("#navigation > li:last-child").width();
    
    if(offset_width <= 0) offset_width = 0;
    
    $("#navigation > li:last-child ul").css({left: 0 - offset_width });

    // language fn
    $('#switch-anchor > a').bind('click', function() {
        lang.in_handle=true;
        lang_expand();
        return false;
    });
    $('#switch-anchor > a').bind('mouseout',  function() {
        lang.in_handle=false;
        lang_timer();
    });
    $('#languages-list > ul').bind('mouseover', function() {
        lang.in_menu=true;
        lang_expand();
    });
    $('#languages-list > ul').bind('mouseout', function() {
        lang.in_menu=false;
        lang_timer();
    });

    // Gallery
    if ($('#thumbs').length) {
        $().slideshow();
        $('.image > div > a').each(function(i, elt) {
            var href = $(elt).attr('href');
            var url = href.match(/&(amp;)?file=([^&]+)&/).pop().replace(/%2(F|f)/g,'/');
            $(elt).attr('href', url);
            $(elt).attr('rel','superbox[gallery][my]');
        });
    }

    if ($('#thumbs').length || $('#organogram').length || $('#locations').length) $.superbox();

    // content pages cufon replace (kan uitgezet worden voor Typo3 methode
    Cufon.replace($('#page-slogans'));
    Cufon.replace($('#container h2')); 

    // Clear search box on standard click, but only first time
    $('#search-input').bind('click', function(ev) {
        $(ev.target).attr('value','');
        $(ev.target).unbind('click');
    });
});
