var Framework = new Class({

	basedir: false,
	
	options: { 
		'autostart': true,
		'tooltips': {
			'active': true,  // activate the tooltips
			'type': 'link',  // set type of the tooltips: valid values are 'link' or 'icon'
			'vcard': {
				'active': true,	// activate tooltips for links to the vcard
				'filterRel': 'author',	// string or false, that filters the attribut rel of all links
				'filterUrl': false,	// string or false, that filters the URL of all links
				'filterClass': 'vcard'	// string or false, that filters the class of all links
			},
			'help': true,  // activate tooltips for links to the help-system (rel="help")
			'filterclass': 'ajaxtt',	// filter given elements by this classname 
			'icon': 'templates/layout_pn/img/icons/preview.png',	// use this icon for the tooltips
			'show': {
				'delay': '1000'  // delay value for showing tooltips in ms
			},
			'hide': { 
				'delay': '300',  // delay value for hiding tooltips in ms 
				'auto': true	// let the tooltips hide automatic
			},
			'loading': {
				'title': 'Lade Tooltipp&hellip;',
				'content': 'Tooltipp wird geladen.'
			},
			'error': {
				'title': 'Fehler&hellip;',
				'content': 'Leider konnte der Tooltipp nicht erfolgreich geladen werden.'
			}
						
		},
	
		'predefined': {

			'searchquery': 'Suchbegriffe &hellip;',	// predefined text for the search-field
			'login': 'Loginname &hellip;'	// predefined text for the login-field

		},
		
		'sidebar': { 
			
			'active': true,	// activate sidebar in userprofile
			'defaultStatus': 'max',  // set default status of the sidebar ('close', 'max', false)
			'overlay': {
				'active': true,	 // let the sidebar overlay the content with transparent border
				'active': true,	 // let the sidebar overlay the content with transparent border
				'right': true,  // activate the right border
				'bottom': true,  // activate the bottom border
				'left': true,  // activate the left border
				'top': true,  // activate the top border
				'opacity': '0.9'  // set the opacitiy of the overlay
			},
			'hover': false,  // activate hovering for the sidebar
			'ie6iframe': false  // activate the iframe in IE 6 for fixing an IE 6 specific bug
		
			
		},
		
		'ajaxbox': {
			'active': true,	// activate ajaxboxes
			'autoupdate': {
				'active': false,	// activate the autoupdate-function
				'refreshtime': 300	// refresh time in seconds
			},
			'ajaxbox': 'ajaxbox',	//classname for the ajaxbox-divs
			'ajaxbox-meta': 'ajaxbox-meta',	//classname for the ajaxbox-meta-lists
			'ajaxboxcontent': 'ajaxboxcontent',	//classname for the ajaxboxcontent-divs
			'synconload': true,	// ask for userprofile for ajaxboxes on load
			'onLoadReady': function (boxId) {  // do this after reloading the content of a box via AJAX
				PnetFramework.refreshTooltips('#' + boxId);
			}
		},
		
		'catalognavigation': {
			'active': false,
			'classname': 'editlink',
			'filter': '',
			'image': 'templates/layout_pn/img/application_view_detail.png'
		},
		'filter': {
			'active': false,
			'filterIds': {
				'1': '1', 
				'2': '2'
			},
			'tt': false
		}
	},

	initialize: function(options) {

		this.setOptions(this.options, options);

		if(this.options.autostart) {
			this.start();
		} else {
			window.addEvent('domready', function() {
				this.start();
			}.bind(this));
		}

	},

	start: function() {
			if(this.options.catalognavigation.active == true) this.activateDynamicCatalogNav();
			this.activateUserProfile();
			this.activatePredefinedTexts();
			if(this.options.tooltips.active) this.refreshTooltips('');
	},
	
	refreshTooltips: function(withinElementId) {

		if(this.options.tooltips.active == false) return;
		
		if(withinElementId != '') withinElementId = withinElementId+' ';

 		if(this.options.tooltips.vcard.active == true) {
			$$(withinElementId+'a').each(function (el) {
				// has this link any URL?
				if(el.getProperty('href') == null) {  
					return;
				}

				linkstatus = false;

				// does the link contain the filter-string?
				if(this.options.tooltips.vcard.filterUrl && el.getProperty('href') && el.getProperty('href').contains(this.options.tooltips.vcard.filterUrl) == true) {
					linkstatus = true;
				}
				// does the property rel contain the filter-string?
				if(this.options.tooltips.vcard.filterRel && el.getProperty('rel') && el.getProperty('rel').contains(this.options.tooltips.vcard.filterRel) == true) {
					linkstatus = true;
				}
				// does the linkclasses contain the filter-string?
				if(this.options.tooltips.vcard.filterClass && el.hasClass(this.options.tooltips.vcard.filterClass) == true) {
					linkstatus = true;
				}
				
				if(linkstatus == false) {
					return;
				}
				
				// reformat the link-URL
				if(el.getProperty('href').charAt(0) == '/') {
					el.setProperty('href', window.location.protocol+'//'+window.location.host+el.getProperty('href'));
				}
				// set the title for the AJAX-tooltip
				el.setProperty('title', 'AJAX:'+el.getProperty('href').replace('index.','ajax.')+'&handler=AjaxContentHandler');
				el.addClass(this.options.tooltips.filterclass);
			}.bind(this));
		}
	
		/* add the icon if type == 'icon' */
  		if(this.options.tooltips.type == 'icon') {
			$$(withinElementId+'.' + this.options.tooltips.filterclass).each(function(el) {
				if(el.getElement('img') && el.getElement('img').getProperty('src') == this.options.tooltips.icon) {
					return;
				}
				
				img = new Element('img', {'src': this.options.tooltips.icon}).injectAfter(el);
				img.setProperty('title', el.getProperty('title'));
				img.addClass(this.options.tooltips.filterclass);

				el.removeClass(this.options.tooltips.filterclass);				
			}.bind(this));
		}	
		
		/* remove all the title tags on all elements inside of the elements */
		$$(withinElementId+'.' + this.options.tooltips.filterclass + ' *').each(function(el) {
			el.removeProperty('title');
		}.bind(this));
 
		// start the tooltips-engine
		this.tooltips = new Tooltips ($$(withinElementId+'.' + this.options.tooltips.filterclass), { showDelay: this.options.tooltips.show.delay, hideDelay: this.options.tooltips.hide.delay, maxOpacity: .9, errText: 'ToolTipp-Problem.', fixed: false, closeText: 'Tooltipp schließen' });

		if(this.options.tooltips.help == true) {
			this.tooltips_help = new Tips ($$(withinElementId+'.tips'), { showDelay: 1000, hideDelay: 0, className: 'help', maxOpacity: .9, errText: 'ToolTipp-Problem.', fixed: false});
		}

	},
	
	activateDynamicCatalogNav: function() {
		if(this.options.catalognavigation.active == false) {
			return;
		}
		if($(this.options.catalognavigation.filter)) {
			$(this.options.catalognavigation.filter).getElements('ul.cat-2').each(function(el) {
		        a = el.getParent().getElement('a');
		        link = new Element('a', {'href': a.getProperty('href')}).injectAfter(a);
		        if($(this.options.catalognavigation.filter).hasClass('editor')) {
	                new Element('img', {'src': this.options.catalognavigation.image, 'class': this.options.catalognavigation.classname}).injectInside(link);
		        }
		        a.addEvent('click', function clicker() { el.toggleClass('hidden'); return false;}.bind(el));
		        a.setProperty('href', '#');
		        a.setStyle('cursor', 'pointer');
		
//		        el.addClass('hidden');
			}.bind(this));
		}
	},
	
	activateUserProfile: function() {

 		if(this.options.sidebar.active && $('sysidAPPSidebarright')) { } else { this.options.sidebar.active = false; }

 		/* define three global variables (dont write 'var' before the three lines, this will make these variables local) */
		userProfile = new UserProfile(this.options.sidebar.active);

		if(this.options.ajaxbox.active) {
			this.activateAjaxBoxes(userProfile);
			if(this.options.ajaxbox.synconload) {
				userProfile.syncWithServer();
			}
		}

	},
	
	activateAjaxBoxes: function(objUserProfile) {

		if(this.options.sidebar.active) {
			objUserProfile.addBox(new SidebarBox('sysidAPPSidebarright', this.options.sidebar));
		}

		$$('#col2_content .'+this.options.ajaxbox.ajaxbox).each(function (el) {
			if(el.getProperty('id') != '') {
				objUserProfile.addBox(new AjaxBox(el.getProperty('id'), this.options.ajaxbox));
			}
		}.bind(this));
	
	},
	
	activateSortables: function() {

	},
	
	activateTabs: function() {


	},
	
	activatePredefinedTexts: function() {
	},
	
	activateFilter: function() {
	},

	selectAll: function (el, filterId) {
		if(el.checked == 1) {
			checked = 'checked';
		} else { 
			checked = '';
		}
		$$('.filter_'+filterId).each(function (el) { el.checked = checked; });		
	},

	selectOne: function (el, filterId) {
		$$('.filter_'+filterId).each(function(el) {
			if(el.hasClass(el.id)) {
				el.checked = '';
			}
		})
	}
});
Framework.implement(new Options);

function falser() { return false; }