function handleError() {
	return true;
}

window.onerror = handleError;

function setBW() {
	
	changeLayout(false); //use old functions 
	changeVersionText(); //use old functions
	
}
		
jQuery(document).ready(function(){
	
	//content_resize ---------
	init_plugin('.body_tools a.enlarge', 
			 function(el) {
				el.hide_rightcol();
			});	
	
		
	
	
	//small sliding teasers ---------
	init_plugin('ul.small_teasers', 
			 function(el) {
				el.small_teasers();
			});
			
	//teasers with numbered items ---------
	init_plugin('.teaser ul.numbers', 
			 function(el) {
				el.numbered_teasers();
			});		

	//tabs ---------
	init_plugin('.tab_box',
			 function(el) {
				el.my_tabs();
			});				
	
	//toogleboxes ---------
	init_plugin('#toolscol', 
			 function(el) {
				el.toogleboxes();
			});	
	
	//Accordion ---------
	init_plugin('ul.accordion', 
			 function(el) {
				$('ul.accordion').accordion({
					txt_open: accordion_txt_open,
					txt_close: accordion_txt_close
				});
			});

	//Image Lightbox ---------
	init_plugin('a.image', 
			 function(el) {
				el.lightBox({
					txtImage: 'Bild',
					txtOf: 'von'
				});

			});	

	//intro teasers ---------
	init_plugin('.teaser_animation', 
			 function(el) {
				el.intro_teasers();

			});			

			
	if ($('#tool_list').size() > 0) {
		var is_open = false;
		$('#tool_list > li:not(.icon) > a').hover(function(e){
											var a_self = $(this);
											var li_tag = a_self.parent();
											
											li_tag.addClass('hovered');
											li_tag.siblings().removeClass('hovered').find('.hide_bg').hide();
											
											var is_new = false;
											if (a_self.next().next().size() == 0) {
												var is_new = true;
												li_tag.append('<div class="hide_bg"></div>');
												
												
											} 	
											var bg = a_self.next().next();
											var sub = a_self.next();
											
											var w = sub.width() + 20;
											var h = sub.height() + 20;
											
											var cssObj = {
											  'width' : w + 'px',
											  'height' : h + 'px'
											}
											bg.css(cssObj);
											bg.show();
											
											if (is_new) {
												bg.hover(function(e){
															var bg_self = $(this); 
															bg_self.hide();
															bg_self.parent().removeClass('hovered');
															return false;
													}, 
													function(e){ }
												);
											} 	
											
											
											return false;
										}, 
										function(e){
								
										}
		);
		
	}	
	
	
	if ($(".body_tools .details ul.links li a[href^='#']").size() > 0) {
		initAnchorsToAccordion(".body_tools .details ul.links li a[href^='#']");
	}
	
	
	/*
	jQuery("a.theme_light_square[rel^='prettyPhoto']").prettyPhoto({theme:'light_square', allowresize: false, btnText:close_btn});

	jQuery('.gallery a.image').lightBox({
			txtImage: 'Bild',	// (string) Specify text "Image"
			txtOf: 'von'
	});
	*/
});

function init_plugin (element_selector,callback_fn) {
	var plugin_el = $(element_selector);
	if (plugin_el.length > 0) {
		if (typeof(callback_fn) == 'function') {
			callback_fn(plugin_el);
		}
	}
}

jQuery.cookie = function (key, value, options) {
    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            //options.path ? '; path=' + options.path : '',
            '; path=/',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }
    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

function reloadImagesBlackandwhite(modus) {
	$.each($('img.has_blackandwhite'), function(){
		var parts = $(this).attr('src').toString().split('/');
		var len = parts.length;
		var new_path = "";
		for (var i = 0; i < len; i++) {
			if (modus) {
				if (i < (len-1)) {
					if (new_path != "") new_path += "/";
					new_path += parts[i];
				}	
				else new_path += "/blackandwhite/"+parts[i];	
			} else {
				if (parts[i] != "blackandwhite") {
					if (new_path != "") new_path += "/";
					new_path += parts[i];
				}	
			}
		}
		
		$(this).attr('src', new_path);
	});
	
	
}

var AncorRelToAccordion = new Array();

function initAnchorsToAccordion(sel_ancors) {
	var content_el = $('#content .body .text');
	$.each($(sel_ancors), function(){
							var pos = $(this).attr('href');
							pos = pos.substring(1, pos.length);
							var li_el = content_el.find("a[name='"+pos+"']").parent().parent();
							
							if (li_el.hasClass('acc') == true) {
								AncorRelToAccordion[pos] = li_el.children().eq(0);
								
								$(this).click(function(e){
									var pos = $(this).attr('href');
									pos = pos.substring(1, pos.length);
									if (!AncorRelToAccordion[pos].parent().hasClass('active')) AncorRelToAccordion[pos].trigger('click');
								});
								
							} 
	});
	
}



