var KNAPWERK = KNAPWERK || {
	
	/**
	 * Get the innerHTML of a given DOM elements and puts it in a clean printing template
	 * @param string id: the ID of the DOM element which innerHTML should be printed
	 */
	printPage: function (id) {
		var el = document.getElementById(id);
		if (!el)
			return false;
		
		//disable links to in printversion
		var content = el.innerHTML;
		content = content.replace(/href/gi,"hrefdisabled");
		content = content.replace(/onclick/gi,"onclickdisabled");

		//open popup and call print dialog
		window.print = '<table><tr><td>'+content+'</td></tr></table>';
		var w =  window.open('/print/');
	},
	
	/**
	 * Open the Stuurdoor popup and mail the current URL to a friend
	 * @param string docid: the docID of the page which should be e-mailed.
	 */
	mailArticle: function (docid) {
		if (!docid)
			return false;
		
		popup('/stuurdoor/index.php?id='+docid,'stuurdoor',400,300);
	},
	
	/**
	 * Start the PanelSlider
	 */
	startPanelSlider: function() {
		if (/\/admin\//.test(document.location))
			var cycleSetting = false;
		else
			var cycleSetting = true;
		
		$(".panelslider").hrzAccordion({
			handlePosition		: "right",
			openOnLoad			: 1,
			cycle				: cycleSetting,
			cycleInterval		: 6000,
			closeOpenAnimation	: 1,
			fixedWidth			: "439"
		});
	},
	
	/**
	 * Start the jQuery Lightbox plugin
	 */
	startLightbox: function() {
		$('a.lightbox').lightBox({
			overlayBgColor: '#000',
			overlayOpacity: 0.7,
			imageLoading: '/images/lightbox/loading.gif',
			imageBtnClose: '/images/lightbox/close.gif',
			imageBtnPrev: '/images/lightbox/prev.gif',
			imageBtnNext: '/images/lightbox/next.gif',
			containerResizeSpeed: 350
		});
	},
	
	/**
	 * Center the active submenu directly beneath the belonging menu-item
	 * new site:we dont do this anymore [JV] June 2011
	 */
	centerSubmenu: function() {
		return;
		//get active menu-item position
		$("#nav li").each( function() {
			var classname = $(this).attr('class');
			if (classname.indexOf("active") != -1) {
				var halfWidth = Math.ceil($(this).width() / 2);
				KNAPWERK.centerSubmenu.left = $(this).position().left + halfWidth;
			}
		});
		
		//get active submenu and set the correct left margin
		$(".submenu").each( function() {
			var classname = $(this).attr('class');
			if (classname.indexOf("submenuVisible") != -1) {
				var halfwidth = Math.ceil($(this).width() / 2);
				var marginLeft = KNAPWERK.centerSubmenu.left - halfwidth;
				if (marginLeft > 0)
					$(this).css ('marginLeft',marginLeft + 'px');
			}
		});
	},
	
	/**
	 * Add extra admin-stylesheet when using small browserwindows
	 */
	addAdminStyle: function() {
		if (/\/admin\//.test(document.location)) {
			if (document.body.clientWidth < 900)
				$('head').append('<link rel="stylesheet" href="/css/admin.css" type="text/css">');
		}
	}

};

/**
 * Functions which should be executed after loading the page
 */
 if (typeof $ !='undefined') {
	$(document).ready(function() {	
		KNAPWERK.addAdminStyle();
		KNAPWERK.startPanelSlider();
		KNAPWERK.centerSubmenu();
		KNAPWERK.startLightbox();
	});
}

