jQuery(document).ready(function(){
	//ie7 last 2 menu items
	jQuery('#mainMenu ul li:eq(6), #mainMenu ul li:last').css({"display":"none"});
	
	//preload all css images to prevent delays
	jQuery.preloadCssImages();
	
	// right last box
	jQuery('#rightContentContainer .rightBox:last').css({"background-image":"none"});
	
	// front news last item
	jQuery('#frontNews ul li:last').css({"background-image":"none"});
	
	// submenu last item
	jQuery('ul#subMenu li:last').css({"border-bottom":"none"});
	
	// first black box
	var rightColumnHeight = jQuery('#rightColumn').height();
	jQuery('#rightColumn .rightBoxBlack:first').css({"margin-top":"75px"}).parent().css({"height": rightColumnHeight + 45});
	
	// category item overlay
	jQuery('.categoryItemPicture').append('<div class="categoryItemPictureOverlay"></div>');
	
	// event last item
	jQuery('#eventContainer .eventItem:last').css({"background-image":"none"});
	
	// event item overlay
	jQuery('.eventPictureSingle').append('<div class="eventPictureSingleOverlay"></div>');
	jQuery('.eventPicture').append('<div class="eventPictureOverlay"></div>');
	
	jQuery(".eventPictureOverlay").hover(
		function () {
        	jQuery(this).addClass('hovered');
      	}, 
      	function () {
        	jQuery(this).removeClass('hovered');
      	}
    );
	
	jQuery(".eventPictureOverlay").click(function () {
		document.location = jQuery(this).parent().parent().find('h2 a').attr('href');
		return false;	 
    });
	
	// issue picture overlay
	jQuery('.issueItemPicture').append('<div class="issueItemPictureOverlay"></div>');
	
	jQuery(".issueItemPictureOverlay").hover(
		function () {
        	jQuery(this).addClass('hovered');
      	}, 
      	function () {
        	jQuery(this).removeClass('hovered');
      	}
    );
	
	jQuery(".issueItemPictureOverlay").click(function () { 
		document.location = jQuery(this).parent().parent().find('h2 a').attr('href');
		return false;
    });
	
	// related disciplines picture overlay
	jQuery('.relatedDisciplinePicture').append('<div class="relatedDisciplinePictureOverlay"></div>');
	
	// content picture overlay
	jQuery('.contentImage').append('<div class="contentImageOverlay"></div>');
	jQuery('.contentImageSingle').append('<div class="contentImageSingleOverlay"></div>');
	
	// member picture overlay
	jQuery('.memberPicture').append('<div class="memberPictureOverlay"></div>');
	
	// projects hover
	jQuery(".projectLine").hover(
		function () {
        	jQuery(this).addClass('hovered');
      	}, 
      	function () {
        	jQuery(this).removeClass('hovered');
      	}
    );
	
	// document info table first cells
	jQuery("table.docTable tr").each(function(){
		jQuery(this).children('th:first, td:first').addClass('firstCell');
		jQuery(this).children('th:last, td:last').addClass('lastCell');
	});
	
	//input hint
	if(jQuery('input')[0]){
		jQuery('input').hint();
	}
	
	//input searchterm in the other box too
	if(jQuery('#specialWords')[0]){
		jQuery('#specialWords').val(jQuery('#searchSwords').val());
	}
	
	// datatables
	if(jQuery('#expertsTable')[0]){
		$('#expertsTable').dataTable( {
			"bSort": true,
			"sPaginationType": "full_numbers",
			"aaSorting": [[ 1, "asc" ]],
			"iDisplayLength": 20,
			"oLanguage": {
				"sLengthMenu": "Toon _MENU_ artikelen per pagina",
				"sZeroRecords": "Geen resultaten - onze excuses",
				"sInfo": "<strong>_START_</strong> - <strong>_END_</strong> van <strong>_TOTAL_</strong>",
				"sInfoEmtpy": "Resultaat 0 tot 0 van 0 records",
				"sInfoFiltered": "(gefilterd _MAX_ total records)",
				"aoColumns": [ 
					{ "bSortable": false },
					null,
					null,
					{ "bSortable": false }
				]
			}
		});
	}
	
	jQuery('#expertsTable_paginate').prepend('<strong style="padding-right: 10px;">Resultaatpagina</strong>&nbsp;');
	jQuery('#expertsTable th').append('&nbsp;&nbsp;&nbsp;<span></span>');
	
	// project preview list tabs
	if(jQuery('#projectPreviewList')[0]){
		jQuery('#projectPreviewList').tabs();
		jQuery('#projectPreviewList a').click(function () {
			var projectImage = 'url(' + jQuery(this).attr('title') + ')';
			jQuery('#bigContainer').removeAttr('style').css("background-image", projectImage);
    	});

	}
	
	// project preview list custom scroll
	if(jQuery('#projectPreviewList')[0]){
		jQuery("#projectPreviewList").jScrollPane({scrollbarWidth: 21, showArrows: true});
	}
	
	jQuery('table#expertsTable tr:last td').css({"border-bottom":"none"});
	
	// cufon special fonts
	Cufon.replace('.rightBox h2, #leftContentContainer h1, .specialNote, #content h2, .categoryItemList h3, .projectPreviewDetailComplete h2, #expertsTable th, .searchFilter h1, .searchFilter h2, .searchFilter h3', { fontFamily: 'DTL Documenta ST', hover: true });
	Cufon.replace('#headerContainer h1, #mainMenu > ul > li > a, .eventDate, ul#subMenu li a', { fontFamily: 'NeueSans SemiBold', hover: true });
	
	if (jQuery.browser.msie && jQuery.browser.version == 6) { 
		$('#mainMenu > ul > li').hover(function(){ $(this).addClass('over')}, function(){ $(this).removeClass('over')})
	}
	
	// left container 100% height
	var bigheight = jQuery(document).height()
	var leftContainerHeight = jQuery('#leftContentContainer').height() + 255;
	if(bigheight > leftContainerHeight){
		jQuery('#leftContentContainer').css({"min-height": bigheight - 255});
	} 
	if(bigheight < leftContainerHeight){
		jQuery('#leftContentContainer').css({"height": "auto"});
	}
	
	//Validation
//  jQuery("#registrationForm").validate();
});

function sendOrderForm() {
	var err1 = 0;
	var err2 = 0;
	var err3 = 0;
	var err4 = 0;
	var err5 = 0;
	var err6 = 0;
	var err7 = 0;
	var err8 = 0;
	var err = 0;
	
	document.getElementById('error1_txt').style.display = 'none';
	document.getElementById('error1').style.color = '#000000';
	document.getElementById('error1').style.fontWeight = 'normal';
	document.getElementById('error2_txt').style.display = 'none';
	document.getElementById('error2').style.color = '#000000';
	document.getElementById('error2').style.fontWeight = 'normal';
	document.getElementById('error3_txt').style.display = 'none';
	document.getElementById('error3').style.color = '#000000';
	document.getElementById('error3').style.fontWeight = 'normal';
	document.getElementById('error4_txt').style.display = 'none';
	document.getElementById('error6_txt').style.display = 'none';
	document.getElementById('error7_txt').style.display = 'none';
	document.getElementById('error_price').style.display = 'none';

	if (document.getElementById('firstname').value=='' || document.getElementById('firstname').value=='Voornaam') err1=1;
	if (document.getElementById('lastname').value=='' || document.getElementById('lastname').value=='Achternaam') err1=1;
	if (document.getElementById('street').value=='' || document.getElementById('street').value=='Straatnaam') err2=1;
	if (document.getElementById('streetno').value=='' || document.getElementById('streetno').value=='Nr.') err2=1;
	if (document.getElementById('zip').value=='' || document.getElementById('zip').value=='Postcode') err2=1;
	if (document.getElementById('city').value=='' || document.getElementById('city').value=='Plaatsnaam') err2=1;
	if (document.getElementById('email').value=='' || document.getElementById('email').value=='e-mail@adres.nl') err3=1;
		if (document.getElementById('city').value=='' || document.getElementById('city').value=='Plaatsnaam') err2=1;
	//alert($('invoiceno').val());
	if ($('input[name="invoiceno"]').val()=='Rekeningnummer') err6=1;
	if ($('input[name="invoiinvoicenameceno"]').val()=='Op naam van') err7=1;
	if ($('input[name="factur"]').val()=='Kenmerk op factuur (eventueel)') err8=1;
	
 if (jQuery("#accord:checked").val() == null) err4=1;
	if ( (parseInt(document.getElementById('qtynormal').value) < 1) &&  (parseInt(document.getElementById('qtyprint').value) < 1) ) err5=1;

	if (err1==1) {
		document.getElementById('error1_txt').style.display = 'block';
		document.getElementById('error1').style.color = '#f00';
		document.getElementById('error1').style.fontWeight = 'bold';
		err = 1;
	}
	if (err2==1) {
		document.getElementById('error2_txt').style.display = 'block';
		document.getElementById('error2').style.color = '#f00';
		document.getElementById('error2').style.fontWeight = 'bold';
		err = 1;
	}
	if (err3==1) {
		document.getElementById('error3_txt').style.display = 'block';
		document.getElementById('error3').style.color = '#f00';
		document.getElementById('error3').style.fontWeight = 'bold';
		err = 1;
	}
	
	if (err4==1) {
		document.getElementById('error4_txt').style.display = 'block';

		err = 1;
	}
	
	if (err5==1) {
		document.getElementById('error_price').style.display = 'block';

		err = 1;
	}

		if (err6==1) {
			document.getElementById('error6_txt').style.display = 'block';
			err=1;
		}
		
		if (err7==1) {
			 document.getElementById('error7_txt').style.display = 'block';
			 err=1;
		}


		
	if (err==0) { 


		if (err8==1) $('input[name="factur"]').val('Niet ingevuld');
		document.getElementById('orderForm').submit();
	}
}


/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/*
 * Accordion
 * Author: Andrei Eftimie
 */
jQuery(function($) {

  var $list = $('ul.pages');
  $('.submenu', $list).each(function(i){
    if ($.cookie('submenu-'+i) == 'hide') $(this).hide(); 
  });
  
  $list.bind('click', function(event){
    if ($(event.target).is('.lvl1')){
      $submenu = $(event.target).siblings('.submenu');
      $submenu.slideToggle('fast', function(){
        $.cookie('submenu-'+$submenu.parent().index(), ($submenu.is(':visible'))?'show':'hide');
      });           
    }
  });
  
});