/*
 * General DOM READY events
 */
jQuery(function($){
	
	//Text resize
//	$('body').textResize({
//		plus: '#adjust-font-size .plus',
//		minus: '#adjust-font-size .minus'
//	});
	
	//IE
	if ($.browser.msie){
		//IE6
		if ($.browser.version <= 6){
			$('input:submit').addClass('input-submit');
			$('input:text, input:password').addClass('input-text');
			
			//Hover fix
			$('#overview li, .program-logos img, .overview li, .news-col li, #faq dt').hover(
				function(){$(this).addClass('hover'); },
				function(){$(this).removeClass('hover'); }
			);
			
			$('.more').hover(
			    function(){this.id = 'more-hover';},
			    function(){this.id = '';}
			);
			
			$('#meta-nav-secondary li:first-child, #breadcrumbs li:first-child, .pager a:first-child, .browsebox li:first-child').addClass('first-child');
		}
		
		//Pager fix
		$('.browseLinksWrap span:first-child').addClass('first-child');
		
	}	
	
	//EmptyOnFocus
	$('#search, #search-page .form-item').emptyOnFocus();
	
	//Overview
	$('.overview li, .news-col li, #home #column .csc-textpic').each(function(){
		$(this).find('a:first').clone().empty().addClass('overlay').appendTo($(this));
	});
	
	//Homepage tabs
	$('#tabs').tabs();
	$('#tabs').tabs('select', 3);
	$('#tabs li').each(function(i){
		$(this).mouseover(function(){
			$('#tabs').tabs('select', i);
		});
		$(this).mouseout(function(){
		        $('#tabs').tabs('select', 3);
		});
		$(this).focus(function(){
			$('#tabs').tabs('select', i);
		});
		$(this).blur(function(){
		        $('#tabs').tabs('select', 3);
		});
	});
	
	$('#tabs li:last-child').hide().css({
	'position': 'absolute',
	'left': '-9999px'
	});
	
	$('#home-projecten').tabs({
		fx: { opacity: 'toggle', height: 'toggle' }
	});
	
	//Tell a friend
	if (!$('#tell-a-friend .tell-error').is('div')) {
		$('#tell-a-friend')
		.find('fieldset').hide().end()
		.find('.email a').click(function(){
			$(this).parent().siblings('fieldset').toggle('slow');
		});
	}
	
	
	//Height fix for tell a friend
	//if ($('#nav-secondary').outerHeight() < $('#content').outerHeight()){
	//	$('#nav-secondary').height($('#content').outerHeight()+40);
	//}
	
	//FAQ
	$('#faq')
		.find('dd').hide().end()
		.find('dt').click(function(){
			dd = $(this).next('dd');
			if ($(this).is('.on')) {
				dd.fadeOut('fast');
				$(this).removeClass('on');
			}
			else {
				dd.fadeIn('fast');
				$(this).addClass('on');
			}
		});
		
	$('#faq-on').click(function(){
		$('#faq dt').addClass('on');
		$('#faq dd').show();
		return false;
	});
	$('#faq-off').click(function(){
		$('#faq dt').removeClass('on');
		$('#faq dd').hide();
		return false;
	});
	
	//Height fix for tell a friend
	if ($('#nav-secondary').outerHeight() < $('#content').outerHeight()){
	    $('#nav-secondary').height($('#content').outerHeight()+40);
	}
	
	//Column links fix
	$('#column ul li').parent().addClass('on');
		
	
	//Documenten Fix
	$('#column .csc-uploads')
		.after('<ul class="docs"></ul>')
		.find('a').each(function(){
			var a = $(this);
			var ul = $('#column .docs');
			var ext = a.text().substr(a.text().indexOf('.')+1);
			var text= a.text().substr(0,a.text().indexOf('.'));
			a.text(text);
			var type = $('<em>&nbsp;('+ext+')</em>').appendTo(a);
			a.wrap('<li class='+ext+'></li>').parent().appendTo(ul);
		}).end()
		.remove();
	
	//Projects
	$('#projects-single').tabs().find('#project-nav').show();
	$('.projects-item:even').addClass('even');
	
	
	//Filters
	$filterLeft = $('#filter #left');
	var $allUl = $filterLeft.find('form > ul > li > ul').hide();
	var $reset = $('#reset').hide();
	var $close = $('#close');
	var $open = $('#open');
	
	$filterLeft.click(function(event){
		$target = $(event.target);
		if ($target.is('.level-1')){
			$ul = $target.next('ul');
			if ($('li', $ul).length > 0) {
				$ul.toggle(200);
				$target.toggleClass('active');
			}
		} else if ($target.is('#open')){
			$ul = $target.next('ul');
			$allUl.show(200);
			$('.level-1').addClass('active');
			$target.hide();
			$close.show();
			$reset.show();
			$.cookie('treeOpen', true); //Setting the cookie
		} else if ($target.is('#close')){         		
			$allUl.hide(200);
			$('.level-1').removeClass('active');
			$target.hide();
			$open.show();
			$reset.show();
			$.cookie('treeOpen', null); //Setting the cookie to false
		};
	});
	
	$('#submitFilters').hide(); //Hide submit button, we have auto submit
	
	//Open checked filters
	var $checkedFilters = $(':checked', $filterLeft);
	$checkedFilters.parents('ul').show().prev('.level-1').addClass('active');
	if ($checkedFilters.length > 0) $reset.show();
	
	//We open filters if all have been opened
	if ($.cookie('treeOpen')) {
		$allUl.show();
		$open.hide();
	}
	
});

function SendFilter(checkId) {
	var paramVal = document.getElementById(checkId).value;
	var currentUrl = document.getElementById('currentUrlId').value;
	document.location.href = currentUrl + '?tx_ttnews[cat]=' + paramVal;
}

