jQuery.noConflict();

function stripIt(x){
return x.replace(/[""]/g,'');
};

/* Forum */
jQuery(function($) { 
	/*$('.docTitleBibliotheek').each(function(){
		var linkTitle = $(this).attr('title');
		$(this).find('a').text(linkTitle);
	});*/
	
	//Upload Files
	var $upload = $('#file-upload > div').not(':first').hide();
	$('#add-new-file').click(function(event){
	
		$upload.filter(':hidden:first').slideDown();
		
		event.stopPropagation();
		return false;
	});
	
	//Categories
	var $categoryTable = $('#category-select'),
		$category = $('.category', $categoryTable),
		$topics = $('.topics', $categoryTable);
		
	$category.click(function(event){		
		var $el = $(event.target).closest('tr'),
			$content = $('.'+$el[0].id);						
			
			$category.not($el).hide();
			$topics.not($content).hide();	
		
	});
	
	//Delete
	$('.delete').click(function(){
		if (!confirm('Item verwijderen?')) {
			return false;
		}
	});
		
	$('#tx_mmforum_pi1-poll').click(function(){
		var $hidden = $('#poll');
		$hidden.toggle();
	});
	
});

/*
 * Bibiliotek Functions
 */
jQuery(function($) { 

	var $li = $('.catExpandable >ul >li span');
	var $ul = $li.parent().parent();
	$li.click(function(){
		//if($(this).parent().is('.active') && ($ul.find('.active').length > 0)){
		if($(this).parent().is('.active')){
			$(this).parent().removeClass('active');
		} else {
			//$ul.find('.active').removeClass('active');
			$(this).parent().addClass('active');
		}
	})
	
	//Filters
	$form = $('.searchFormContainer form');
	$news = $('#news');
	$index = $('#index');
	$filters = $('.catExpandable');
	$searchBox = $('#tx-indexedsearch-searchbox-sword');
	$sword = $('#tx_ttnews-searchbox-swords');
	$cat = $('#tx_ttnews-searchbox-cat');
	$filter = $('.catExpandable input:checkbox');
	$submit = $('#tx-indexedsearch-searchbox-button-submit');
	$newsForm = $('.news-search-form form');
	//Results Show
	$indexResults = $('#nrIndexResults strong').text();
	$newsResults = $('#nrNewsResults').text();
	$resultsWrap = $('#nrSearchResults');		
	$filtersearch = $('.filtersearch input');
	$filtersearch.click(function() {
		$form.submit();
	});
	
	//Store search term in cookie
	$searchBox.bind('click change keyup', function(){
		$.cookie('searchTerm', $searchBox.val(), { path: '/'});
	});
	
	if ($.cookie('searchTerm')) $searchBox.val($.cookie('searchTerm'));
	
	//Load set checkboxes from cookie
	var selVal = $.cookie('selVal') || '';	
	selVal = selVal.split(',');
	$.each(selVal, function(i){
		$('input[value='+selVal[i]+']', $filters).attr('checked', true);
	});
	
	//Keep Filters Visible
	if($news.is(':checked')){
		$('.news-list-container-bibliotheek').show();
		$('.tx-indexedsearch').hide();
		$resultsWrap.find('span').remove();
		$resultsWrap.prepend('<span>'+$newsResults+'</span>');
		if($resultsWrap.find('span:empty').length > 0){
			$resultsWrap.hide();
		} else { $resultsWrap.show(); }
	};
	
	$news.click(function(){
		$filters.removeAttr("checked");
		setValue();
		$searchBox.val('');
		$('#txttnewssword').val('');
		$.cookie('search','news', { path: '/', expire: 365 });
		/*
		$('.news-list-container-bibliotheek').show();
		$('.tx-indexedsearch').hide();
		$resultsWrap.find('span').remove();
		$resultsWrap.prepend('<span>'+$newsResults+'</span>');
		
		if($resultsWrap.find('span:empty').length > 0){
			$resultsWrap.hide();
		} else { $resultsWrap.show(); }
		*/
		$form.submit();
		//$('.tx-indexedsearch-searchbox-button-submit').click();
	});
	
 
	if($index.is(':checked')){
		$('.news-list-date-bibliotheek').hide();
		$filter.removeAttr("checked");
		$('.news-list-container-bibliotheek').hide();
		$('.tx-indexedsearch').show();
		$resultsWrap.find('span').remove();
		$resultsWrap.prepend('<span>'+$indexResults+'</span>');
		if($resultsWrap.find('span:empty').length > 0){
			$resultsWrap.hide();
		} else { $resultsWrap.show(); }		
	};
	
	$index.click(function(){
		$filters.removeAttr("checked");
		setValue();
		$searchBox.val('');
		$('#txttnewssword').val('');
		
		$.cookie('search','index', { path: '/', expire: 365 });
		/*
		//$filters.hide();
		$sword.val('');
		$('.news-list-container-bibliotheek').hide();
		$('.tx-indexedsearch').show();
		$resultsWrap.find('span').remove();
		$resultsWrap.prepend('<span>'+$indexResults+'</span>');
		
		if($resultsWrap.find('span:empty').length > 0){
			$resultsWrap.hide();
		} else { $resultsWrap.show(); }
		*/  
		$form.submit();
	});
	
	var activeSearch = $.cookie('search');
	
	$('#'+activeSearch).attr('checked','checked');
	
	$searchBox.bind('change keyup', function(){
		if ($searchBox.val() == '') $searchBox.val(' ');
		$sword.val($searchBox.val());
	});
	
	$form.bind('submit', function(){
		if ($searchBox.val() == '') $searchBox.val(' ');
		if($news.is(':checked')){			
			$newsForm.find('input:text').val($searchBox.val());
			$newsForm.submit();
			return false;
		}
		
	});
	
	$filter.bind('click', function(){
		$news.attr('checked', true);
		$.cookie('search','news', { path: '/', expire: 365 });
		setValue();
		$searchBox.val('');
		$('#txttnewssword').val('');
		$newsForm.submit();
	});
	
	function setValue(){
		var selVal = '';
		$filters.find(':checked').each(function(i){
			var separator = (i == 0)?'':',';
			selVal += separator + $(this).val(); 
		});		
		$cat.val(selVal);
		$.cookie('selVal',selVal, { path: '/' });
		$.cookie('searchTerm',' ');
	}
	
	if ($.cookie('selVal')) setValue();	

	if($resultsWrap.find('span:empty').length > 0){
		$resultsWrap.hide();
	}

	//Add active class to parent tab
	$filters.find('input:checked').each(function(){
		var $parent = $(this).parent().parent().parent();
		if(!$parent.is('.active'));
		!$parent.addClass('active');
	});

	//Add target blank
	$('.fileLinks a').attr('target','_blank');
	
	$(':radio[name*=searchOption]').bind('click change', function(event){
		$(':hidden[name*=searchOption]').val(event.target.value);
	}).trigger('change');			
			
	//Website Pager Layout Hack
	$('.browsebox').find('a:contains(volgende)').wrap('<span class="next"></span>');
	$('.browsebox').find('a:contains(vorige)').wrap('<span class="prev"></span>');	
	
	
});

var editor = new tx_mmforum_Editor();

/*
 * Search Pager
 */
jQuery(function($){
	$('.browsebox a').each(function(){
	    var event = ''+$(this).attr('onclick');
	        event = event.split(';');
	    
	    $(this).removeAttr('onclick');
	    this.href = 'javascript:void(0);'
	    
	    $(this).click(function(){

		    var input1name = event[0].split('[')[2].split(']')[0],
		        input1val = stripIt(event[0].split('=')[1]),
		        input2name = event[1].split('[')[2].split(']')[0],
		        input2val = stripIt(event[1].split('=')[1]);		  
		    
		    $('input[name*='+input1name+']').val(input1val);
		    $('input[name*='+input2name+']').val(input2val);		    
	
			
		    $('form[name=tx_indexedsearch]').eq(0).submit();
		
		    return false;
	
	    });
	
	});
});

function submitGeneralSearchForm() {
    jQuery(function($) {
        $.cookie('search','index', { path: '/', expire: 365 });
        $.cookie('searchTerm', $('.generalsearchformword').val(), { path: '/'});
    });
    return true;
}

/*
 * Style File - jQuery plugin for styling file input elements
 *  
 * Copyright (c) 2007-2008 Mika Tuupola
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Based on work by Shaun Inman
 *   http://www.shauninman.com/archive/2007/09/10/styling_file_inputs_with_css_and_the_dom
 *
 * Revision: $Id: jquery.filestyle.js 303 2008-01-30 13:53:24Z tuupola $
 *
 */

(function($) {
    
    $.fn.filestyle = function(options) {
                
        /* TODO: This should not override CSS. */
        var settings = {
            width : 250
        };
                
        if(options) {
            $.extend(settings, options);
        };
                        
        return this.each(function() {
            
            var self = this;
            var wrapper = $("<div>")
                            .css({
                                "width": settings.imagewidth + "px",
                                "height": settings.imageheight + "px",
                                "background": "url(" + settings.image + ") 0 0 no-repeat",
                                "background-position": "right",
                                "display": "inline",
                                "position": "absolute",
                                "overflow": "hidden"
                            });
                            
            var filename = $('<input class="file">')
                             .addClass($(self).attr("class"))
                             .css({
                                 "display": "inline",
                                 "width": settings.width + "px"
                             });

            $(self).before(filename);
            $(self).wrap(wrapper);

            $(self).css({
                        "position": "relative",
                        "height": settings.imageheight + "px",
                        "width": settings.width + "px",
                        "display": "inline",
                        "cursor": "pointer",
                        "opacity": "0.0"
                    });

            if ($.browser.mozilla) {
                if (/Win/.test(navigator.platform)) {
                    $(self).css("margin-left", "-142px");                    
                } else {
                    $(self).css("margin-left", "-168px");                    
                };
            } else {
                $(self).css("margin-left", settings.imagewidth - settings.width + "px");                
            };

            $(self).bind("change", function() {
                filename.val($(self).val());
            });
      
        });
        

    };
    
})(jQuery);

jQuery(function($) {

     $(".tx-srfeuserregister-pi1-uploader").filestyle({ 
     image: "fileadmin/new/images/uploapbtn_01.png",
     imageheight : 20,
     imagewidth : 98,
     width : 176
 });

});




