// pereiro.js
// (c) 2010/2011.
// Dick Hoek

// variables.
var id_menuitem_open="";
var id_submenu_open="";
var id_menuitem_highlight="#mhome";
var txt_menuopen="Open submenu";
var txt_menuclose="Sluit submenu";

function initMenu() {
	// Do NOT close this main menu item.
	if (id_menuitem_open.length>0) {
		$(id_menuitem_open).removeAttr("data-state");
		$(id_menuitem_open).attr("title", txt_menuclose);
	}
	// Do NOT hide this submenu.
	if (id_submenu_open.length>0) {
		$(id_submenu_open).removeAttr("data-state");
	}
	// Close all other main menu items (for background image).
	$("#menu > ul.menu > li > a[href='#'][data-state='open']").addClass("closed");
	$("#menu > ul.menu > li > a[href='#'][data-state='open']").attr("title", txt_menuopen);
	//$("#menu > ul.menu > li > a[href='#']").attr("href", "javascript:cancreturn true;");
	// Hide all other submenus.
	$("#menu > ul.menu > li > ul[class='submenu'][data-state='open']").hide();
	// Highlight active (main/sub) menu item.
	$(id_menuitem_highlight).addClass("highlight");
	// Add click events for main menu items to toggle submenu.
	$("#menu > ul.menu > li > a[href='#']").click(function(event) {
		event.preventDefault();
		$("ul", $(this).parent()).animate({height: "toggle"});
		$(this).toggleClass("closed");
		$(this).attr("title", function() {
			return (this.title==txt_menuclose)?txt_menuopen:txt_menuclose;
		});
		$(this).blur();
	});
} // initMenu.

function initExternalLinks() {
	// Add target and title for external links (if empty).
	$("#content p a[href^='http:']").each(function() {
		if ($(this).attr("href").indexOf('www.pereiro.nl')==-1 && $(this).attr("href").indexOf('localhost')==-1) {
			if ($(this).attr("target").length==0) { $(this).attr("target", "_blank"); }
			if ($(this).attr("title").length==0) { $(this).attr("title", "Externe link (nieuw venster)"); }
		}
	}); /* end-each */
}

function initTableRows() {
	// Set different background color for odd table rows.
	$("table#odd-even-1 > tbody > tr:odd").addClass("odd");
	$("table#odd-even-2 > tbody > tr:odd").addClass("odd");
	$("table#odd-even-3 > tbody > tr:odd").addClass("odd");
}

// document ready.
$(document).ready(function() {
	initMenu();
	initExternalLinks();
	initTableRows();
});

// eof

