/** 
 *	PKM Context Menus (with livequery events) 
 *	decide witch contextmenu will be shown 	
 *	event handler
 */


// decide, in which div-container the eventhandler "have to look"
var PKMSideWindow = "#PKM-Navigation";

//  livequery event handler for calendars
$jq(PKMSideWindow +" .Calendars span.button")


	// notice, if the mouse is over the span-button and hides all other contextmenus
	.livequery('mouseover', function(event) {
		hideHref($jq(this).parent());
		$jq(".contextmenu-enhanced .contextmenu").remove(); 
	})
	
	// notice, if the user click on the span-button and start the function, which create the contextmenu
	.livequery('click', function(event) { pkmShowContextMenuCalendars(event);} )
	
	// makes sure, that the contextmenu will be shown, even if the mouse goes of the span button
	.livequery('mouseout', function(event) {
		showHref($jq(this).parent());
	});

//  livequery event handler for notes
$jq(PKMSideWindow +" .Notes span.button")

	// notice, if the mouse is over the span-button and hides all other contextmenus
	.livequery('mouseover', function(event) {
		hideHref($jq(this).parent());
		$jq(".contextmenu-enhanced .contextmenu").remove(); 
	})
	
	// notice, if the user click on the span-button and start the function, which create the contextmenu
	.livequery('click', function(event) { pkmShowContextMenuNotes(event);} )
	
	// makes sure, that the contextmenu will be shown, even if the mouse goes of the span button
	.livequery('mouseout', function(event) {
		showHref($jq(this).parent());
	});

//  livequery event handler for bookmarks
$jq(PKMSideWindow +" .Bookmarks span.button")
	
	// notice, if the mouse is over the span-button and hides all other contextmenus
	.livequery('mouseover', function(event) {
		hideHref($jq(this).parent());
		$jq(".contextmenu-enhanced .contextmenu").remove(); 
	})
	
	// notice, if the user click on the span-button and start the function, which create the contextmenu
	.livequery('click', function(event) { pkmShowContextMenuBookmarks(event);} )
	
	// makes sure, that the contextmenu will be shown, even if the mouse goes of the span button
	.livequery('mouseout', function(event) {
		showHref($jq(this).parent());
	});
	
//  livequery event handler for tags
$jq(PKMSideWindow +" .Tags span.button")


	// notice, if the mouse is over the span-button and hides all other contextmenus
	.livequery('mouseover', function(event) {
		hideHref($jq(this).parent());
		$jq(".contextmenu-enhanced .contextmenu").remove(); 
	})
	
	// notice, if the user click on the span-button and start the function, which create the contextmenu
	.livequery('click', function(event) { pkmShowContextMenuTags(event);} )
	
	// makes sure, that the contextmenu will be shown, even if the mouse goes of the span button
	.livequery('mouseout', function(event) {
		showHref($jq(this).parent());
	});

//  livequery event handler for contacts
$jq(PKMSideWindow +" .Contacts span.button")
	
	// notice, if the mouse is over the span-button and hides all other contextmenus
	.livequery('mouseover', function(event) {
		hideHref($jq(this).parent());
		$jq(".contextmenu-enhanced .contextmenu").remove(); 
	})
	
	// notice, if the user click on the span-button and start the function, which create the contextmenu
	.livequery('click', function(event) { pkmShowContextMenuContacts(event);} )
	
	// makes sure, that the contextmenu will be shown, even if the mouse goes of the span button
	.livequery('mouseout', function(event) {
		showHref($jq(this).parent());
	});
	
//  livequery event handler for tasks
$jq(PKMSideWindow +" .Tasks span.button")
	
	// notice, if the mouse is over the span-button and hides all other contextmenus
	.livequery('mouseover', function(event) {
		hideHref($jq(this).parent());
		$jq(".contextmenu-enhanced .contextmenu").remove(); 
	})
	
	// notice, if the user click on the span-button and start the function, which create the contextmenu
	.livequery('click', function(event) { pkmShowContextMenuTasks(event);} )
	
	// makes sure, that the contextmenu will be shown, even if the mouse goes of the span button
	.livequery('mouseout', function(event) {
		showHref($jq(this).parent());
	});

/**
 *	functions that decide, how the contextmenus have to look like and where they have to be
 *
 */

// for Calendars
function pkmShowContextMenuCalendars(event) {

	// generate coordinates for context menu
	// the menu will be shown, where the event takes place -30px in x-direction and -20px in y-direction
	// and set an id with the combination of x and y coordinates
	menuX = event.pageX - 30;
	menuY = event.pageY - 20;
	menuId = "windowmenu-"+menuX+"-"+menuY;

	// create the plain menu with correct style and position
	$jq(".contextmenu-enhanced").append("<div class='contextmenu' id='"+menuId+"'></div>");
	$jq("#"+menuId)
		.attr({ style: "z-index: "+menuZIndex+"; top: "+menuY+"px; left: "+menuX+"px;" })
		.click( function(ev){ ev.stopPropagation(); });

	// create the menu content
	$jq('#'+menuId).append(
		"<ul>"+
		"<li><a href='"+jsBaseUri+"/synpkm/list/?type=Calendar' ><strong>List/Edit/Delete Calendar </strong></a></li>"+
		"<li><a href='"+jsBaseUri+"/synpkm/edit/?type=Calendar&new=true' >Add Calendar</a></li>"+
		"</ul>");

	// fade in the menu and stop the even propagation
	$jq('#'+menuId).show();
	event.stopPropagation();
}

// for Notes
function pkmShowContextMenuNotes(event) {

	// generate coordinates for context menu
	// the menu will be shown, where the event takes place -30px in x-direction and -20px in y-direction
	// and set an id with the combination of x and y coordinates
	menuX = event.pageX - 30;
	menuY = event.pageY - 20;
	menuId = "windowmenu-"+menuX+"-"+menuY;

	// create the plain menu with correct style and position
	$jq(".contextmenu-enhanced").append("<div class='contextmenu' id='"+menuId+"'></div>");
	$jq("#"+menuId)
		.attr({ style: "z-index: "+menuZIndex+"; top: "+menuY+"px; left: "+menuX+"px;" })
		.click( function(ev){ ev.stopPropagation(); });

	// create the menu content
	$jq('#'+menuId).append(
		"<ul>"+
		"<li><a href='"+jsBaseUri+"/synpkm/list/?type=Note' ><strong>List/Edit/Delete Note </strong></a></li>"+
		"<li><a href='"+jsBaseUri+"/synpkm/edit/?type=Note&new=true' >Add Note</a></li>"+
		"</ul>");

	// fade in the menu and stop the even propagation)
	$jq('#'+menuId).show();
	event.stopPropagation();
}

// for Bookmarks
function pkmShowContextMenuBookmarks(event) {

	// generate coordinates for context menu
	// the menu will be shown, where the event takes place -30px in x-direction and -20px in y-direction
	// and set an id with the combination of x and y coordinates
	menuX = event.pageX - 30;
	menuY = event.pageY - 20;
	menuId = "windowmenu-"+menuX+"-"+menuY;

	// create the plain menu with correct style and position
	$jq(".contextmenu-enhanced").append("<div class='contextmenu' id='"+menuId+"'></div>");
	$jq("#"+menuId)
		.attr({ style: "z-index: "+menuZIndex+"; top: "+menuY+"px; left: "+menuX+"px;" })
		.click( function(ev){ ev.stopPropagation(); });

	// create the menu content
	$jq('#'+menuId).append(
		"<ul>"+
		"<li><a href='"+jsBaseUri+"/synpkm/list/?type=Bookmark' ><strong>List/Edit/Delete Bookmark </strong></a></li>"+
		"<li><a href='"+jsBaseUri+"/synpkm/edit/?type=Bookmark&new=true' >Add Bookmark</a></li>"+
		"</ul>");

	// fade in the menu and stop the even propagation)
	$jq('#'+menuId).show();
	event.stopPropagation();
}

// for Tags
function pkmShowContextMenuTags(event) {

	// generate coordinates for context menu
	// the menu will be shown, where the event takes place -30px in x-direction and -20px in y-direction
	// and set an id with the combination of x and y coordinates
	menuX = event.pageX - 30;
	menuY = event.pageY - 20;
	menuId = "windowmenu-"+menuX+"-"+menuY;

	// create the plain menu with correct style and position
	$jq(".contextmenu-enhanced").append("<div class='contextmenu' id='"+menuId+"'></div>");
	$jq("#"+menuId)
		.attr({ style: "z-index: "+menuZIndex+"; top: "+menuY+"px; left: "+menuX+"px;" })
		.click( function(ev){ ev.stopPropagation(); });

	// create the menu content
	$jq('#'+menuId).append(
		"<ul>"+
		"<li><a href='"+jsBaseUri+"/synpkm/list/?type=Tag' ><strong>List/Edit/Delete Tag </strong></a></li>"+
		"<li><a href='"+jsBaseUri+"/synpkm/edit/?type=Tag&new=true' >Add Tag</a></li>"+
		"</ul>");

	// fade in the menu and stop the even propagation
	$jq('#'+menuId).show();
	event.stopPropagation();
}

// for Contacts
function pkmShowContextMenuContacts(event) {

	// generate coordinates for context menu
	// the menu will be shown, where the event takes place -30px in x-direction and -20px in y-direction
	// and set an id with the combination of x and y coordinates
	menuX = event.pageX - 30;
	menuY = event.pageY - 20;
	menuId = "windowmenu-"+menuX+"-"+menuY;

	// create the plain menu with correct style and position
	$jq(".contextmenu-enhanced").append("<div class='contextmenu' id='"+menuId+"'></div>");
	$jq("#"+menuId)
		.attr({ style: "z-index: "+menuZIndex+"; top: "+menuY+"px; left: "+menuX+"px;" })
		.click( function(ev){ ev.stopPropagation(); });

	// create the menu content
	$jq('#'+menuId).append(
		"<ul>"+
		"<li><a href='"+jsBaseUri+"/synpkm/list/?type=Contact' ><strong>List/Edit/Delete Contact </strong></a></li>"+
		"<li><a href='"+jsBaseUri+"/synpkm/edit/?type=Contact&new=true' >Add Contact</a></li>"+
		"</ul>");

	// fade in the menu and stop the even propagation)
	$jq('#'+menuId).show();
	event.stopPropagation();
}

// for Tasks
function pkmShowContextMenuTasks(event) {

	// generate coordinates for context menu
	// the menu will be shown, where the event takes place -30px in x-direction and -20px in y-direction
	// and set an id with the combination of x and y coordinates
	menuX = event.pageX - 30;
	menuY = event.pageY - 20;
	menuId = "windowmenu-"+menuX+"-"+menuY;

	// create the plain menu with correct style and position
	$jq(".contextmenu-enhanced").append("<div class='contextmenu' id='"+menuId+"'></div>");
	$jq("#"+menuId)
		.attr({ style: "z-index: "+menuZIndex+"; top: "+menuY+"px; left: "+menuX+"px;" })
		.click( function(ev){ ev.stopPropagation(); });

	// create the menu content
	$jq('#'+menuId).append(
		"<ul>"+
		"<li><a href='"+jsBaseUri+"/synpkm/list/?type=Task' ><strong>List/Edit/Delete Task </strong></a></li>"+
		"<li><a href='"+jsBaseUri+"/synpkm/edit/?type=Task&new=true' >Add Task</a></li>"+
		"</ul>");

	// fade in the menu and stop the even propagation)
	$jq('#'+menuId).show();
	event.stopPropagation();
}
