$(function() {
	/**
	 * IE check
	 */
	if ($.browser.msie){
		$('html').addClass('ie');
	
		if($.browser.version.substr(0,1)<7) {
	        $("div#container").before('<div id="IE6check" style="width: 100%; display: block; color: #000000; background-color: #FFFFCC; font-size: 12px; font-family: Arial, Helvetica, sans-serif; padding-bottom: 5px; border-bottom: 1px solid #141414; "><span class="close"><img src="http://static.comsi.nl/img/ie6-warning.gif" width="20" height="20" alt="Sluiten" /></span>U gebruikt momenteel Internet Explorer 6. Wij raden u aan zo spoedig mogelijk de browser te updaten naar een moderne browser omdat wij de functionaliteit in uw sterk verouderde browser niet kunnen garanderen. Download <a href="http://www.google.nl/chrome" target="_blank">Google Chrome &raquo;</a>, <a href="http://www.getfirefox.com" target="_blank">Firefox &raquo;</a>, of update naar de laatste versie van <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx" target="_blank">Internet Explorer &raquo;</a>.</div>');
	        $("div#IE6check").click(function () { 
	            $(this).slideUp('slow'); 
	        });
		}
	}
	// INLINE labels in form 
	$( 'input[title]' ).each( function() {
		var $this = $(this);
		
		if( $this.val() === '' ) $this.val( $this.attr( 'title' ) ).addClass( 'inactive' );    
		
		$this.focus( function() {
			if( $this.val() == $this.attr( 'title' ) ) $this.val( '' ).removeClass( 'inactive' );  
		});
		
		$this.blur( function() {
			if( $this.val() === '' ) $this.val( $this.attr( 'title' ) ).addClass( 'inactive' );    
		});
		
		$this.trigger( 'labelready' );
	});

	//ANTI-SPAM
	$('.emailReplacement')
		.html(AppConfig['email'])
		.bind( 'click', function(){
			window.location.href = "mailto:"+AppConfig['email'];
		});
	// MESSAGES (with animation)
	$('.msg').slideDown();
	
	/**
	 * Disable fancybox for the following dom elements
	 * Array is defined in main.js ( config.js for older versions )
	 */
	if ( disableFancybox != 'undefined' ) {
		for ( i = 0; i < disableFancybox.length; i++ ) {
			$(disableFancybox[i]).find('a.fancybox').removeClass('fancybox').removeAttr('href');		
		}
	}
	
	/**
	 *	FancyBox voor afbeeldingen
	 **/
	if ( typeof($.fn.fancybox) != 'undefined' )
		$('a.fancybox:has(> img)').fancybox( { overlayColor: '#333' } );

	/**
	 *	ShadowBox voor afbeeldingen
	 **/
	if ( typeof($.fn.shadowbox) != 'undefined' ){
		Shadowbox.init();
		Shadowbox.setup("a.fancybox:has(> img)");
	}

	/**
	 * SuperBgImage
	 */
	$('#superbgimage').superbgimage();

	/**
	 * SUBMENU
	 */
	var $submenu 	 = $('#navigation').find('li.active-parent').find('> ul');

	if ( $submenu.length > 0 ) {

		// width menu container 725px
		var submenuWidth = $submenu.outerWidth(),
			parentPos = $submenu.parent().position().left;

		if ( ( parentPos + submenuWidth ) > 725 )
			var leftPos = (parentPos - submenuWidth ) + 100;
			
			if ( leftPos < 1 ) leftPos = 0;
			
		else
			var leftPos = parentPos - 90;

		/* animate submenu */
		$submenu.fadeIn(200)
			.animate({
				left: leftPos
			}, 400);
	}
});
