var overlayURL = '';
var featureInterval = 0;

$(function() {
	
	$("form#cse-search-box :input[type='text']").focus();
	
	// channel navigation hard links...
	$("#nav div.navTab").click(function() {
		var url = $(this).children("a").attr("href");
		//alert(url);
		// this needs to be changed here
		// this will allow us to redirect accordingly...
		if(url) {
			window.location = url;
		}
	});
	
	// check for classified create page...
	if(channel == 'classifieds' && channelAction == 'create') {
		// here, we want to do the same thing that happens when a user clicks the 
		//alert('works fine');
		$.ajax({
			url: "/dpComponent/classifiedsManager/tools",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&sec=classifieds&tool=create&typeId=&cat=&scat=",
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$("#tools").html(html).show("blind", {direction: "vertical"}, 500);
				$("#content").hide("blind", {direction: "vertical"}, 300);
				$("#ftr_sponsors").hide();
				$("#spnsr div.base").addClass("tools");
				
				toolsClassifiedsCreate("https");
			}
		});
	}
	
	// sortable columns...
	$(".usrColumn").sortable({
		connectWith: '.usrColumn',
		cursor: 'move',
		handle: 'div.mdlBar',
		placeholder: 'mdlPlaceHolder',
		forcePlaceholderSize: true,
		update: function(event,ui) {
			var columnID = $(this).attr('id');
			if(ui.sender && ui.sender.attr('id') == "componentPreview") {
				var addToQuery = "cid=" + channel + "&scid=" + subchannel;
				var sortableOrder = $("#"+columnID).sortable("toArray");	
				var divToHide = ui.sender.children().first().attr('id');
				$("#"+divToHide).remove();
				for(var k in sortableOrder) {
					addToQuery += "&" + columnID + "[]=" + sortableOrder[k];
				}
				$.ajax({
					url: "/dpComponent/user/saveComponentStatus",
					type: "post",
					data: addToQuery.replace(/ /g,""),
					success: function(html) {
						$("#ldr_customize").effect("bounce",{distance:10},200);
					}
				});	
			} else {
				usrColumn[""+columnID+""] = true;
			}
		},
		stop: function() {
			//alert('stop is working!');
			var orderQuery = "cid=" + channel + "&scid=" + subchannel;
			var componentColumns = new Array();
			for (var i in usrColumn) {
				if($("#"+i).sortable("toArray").length >= 1) {
					componentColumns[i] = $("#"+i).sortable("toArray");
				} else {
					componentColumns[i] = " ";
				}
				for(var j in componentColumns[i]) {
					orderQuery += "&" + i + "[]=" + componentColumns[i][j];
				}
			}
			$.ajax({
				url: "/dpComponent/user/saveComponentStatus",
				type: "post",
				data: orderQuery.replace(/ /g,""),
				success: function(html) {
					$("#ldr_customize").effect("bounce",{distance:10},200);
				}
			});
			usrColumn = [];
		}
	});
	$(".usrColumn").disableSelection();
	
	// remove modules...
	$(".remove").live("click", function() {
		var componentID = $(this).parent().parent().attr('id').replace("mdl_","");
		var sectionID = $(this).parent().parent().parent().attr('id').replace("sortableWrap_","");
		var remainingComponents = $(this).parent().parent().parent().sortable("serialize");
		$.ajax({
			url: "/dpComponent/user/removeComponent",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&component=" + componentID + "&section=" + sectionID + "&" + remainingComponents,
			success: function(html) {
				$("#mdl_" + componentID).fadeOut(500, function() { $("#mdl_" + componentID).remove(); });
			}
		});
	});
	
	$("#tools").delegate("#event_solo","click",function() {
	//$("#event_solo").click(function() {
		var postId = $("#postId").val();
		var eventStart = $("#eventStart").val();
		var eventEnd = $("#eventLast").val();
		if(!eventEnd) {
			eventEnd = eventStart;
		}
		var postType = $("#postType").val();
		var featured = "";
		if($("#eventFeature").attr("checked")==true) {
			featured = "1";
		}
		$.ajax({
			url: "/dpComponent/events/addPostToCalendar",
			type: "post",
			data: "id=" + postId + "&type=" + postType + "&start=" + eventStart + "&end=" + eventEnd + "&featured=" + featured,
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$("#calendarStatus").html(html);
				$("#addCalendarForm").html("").hide();
				$("#addCalendarNote").html("This post has been successfully added to the calendar").show();
			}
		});
	});
	
	// horizontal photo scroller...
	$("#photoScrollH").scrollable({
		circular: true,
		easing: "swing",
		items: ".photos",
		next: ".photoNext",
		prev: ".photoPrev",
		speed: 1500
	}).navigator().autoscroll({interval: 10000});
	
	// reuters link from small component...
	$("div.headline.reuters a").live("click", function() {
		var storyID = $(this).parent().attr('id');
		var storyPath = $(this).attr('href');
		window.location = storyPath;
		return false;
	});
	
	// video overlay.  THIS NEEDS TO BE REDONE!
	$("#betaPromo").click(function() {
		overlayURL = "/dpComponent/channel/feedback";
		var overlayAPI = $("#mediaOverlay").data("overlay");
		overlayAPI.onClose(function() {
			$("#mediaOverlay .overlayWrap").html("");
		});
		overlayAPI.load();
		return false;
	});
	
//	if($("#wmLogin").length) {
		$("#corporateContent").delegate("#wmLogin","submit",function() {
		
			var user = $("input#username").val();
			var pass = $("input#password").val();
			var pswd = $.encoding.digests.hexSha1Str(pass).toLowerCase();
			
			// now, we need to open a new window with the url of the page...
			// or, do we just do this one?
			window.open('http://login.neonova.net/login.php?userid='+user+'&passwd='+pswd+'&domain=netsync.net&app=gapps&js=1');
			
			//alert('user: ' + user + ' || pass: ' + pass + ' || encode: ' + pswd);
			return false;
		});
//	}
	
	if($("#spnsrBox").length) {
		// here, we need to add the code to make the sponsor box work...
		//alert('javascript function called successfully');
		
		$("div.spnsrHome div.spnsrOverBut").click(function() {
			var butId = $(this).attr("id").replace("spnsr_","");
			if(!$(this).hasClass("link")) {
				
				// page handled internally...
				$("#spnsrBox div.spnsrOverBut").removeClass("on");
				$(this).addClass("on");
				if($("#corporateWrap").is(":hidden")) {
					$("#featureWrap").hide("blind", {direction: "vertical"}, 300);
					$("#corporateWrap").show("blind", {direction: "vertical"}, 300);
				}
				// load the requested sponsor page...
				$.ajax({
					url: "/dpComponent/ads/sponsorPromo",
					type: "post",
					data: "id="+butId,
					beforeSend: function() {
						// do any before stuff here...
					},
					success: function(html) {
						$("#corporateContent").html(html);
					}
				});
			}
		}).mouseenter(function() {
			$(this).addClass("over");
		}).mouseleave(function() {
			$(this).removeClass("over");
		});
	}
	
	if($("#siteQ").length) {
		$("#siteQ").focus(function() {
			this.value = "";
		});
	}
	
	if($("#tagType").length) {
		$("#tagType").change(function() {
			var tagType = $(this).val();
			//alert('works'+tagType);
			$.ajax({
				url: "/dpComponent/channel/updateTagCloud",
				type: "post",
				data: "tagType=" + tagType,
				success: function(html) {
					$("#headlineSearch").html(html);
				}
			});
		});
	}
	
	if($("#tagSearch").length) {
		$("#tagSearch").focus( function(){
			this.value = "";
		});
		$("#tagSearch").autocomplete({
			source: "/dpComponent/channel/tagsJSON",
			minLength: 2,
			select: function(event, ui) {
				if(ui.item.id) {
					//alert('works: '+ui.item.id);
					window.location = '/viewby/tag/'+ui.item.id;
				}
			}
		}).blur(function() {
			if($(this).val() == "  ") {
				$(this).val('');
			}
		});
	}
	
	$("#pageWrap").delegate("div.videOver a","click",function() {
	//$("div.videOver a").click(function() {
		var videoID = $(this).parent().parent().attr('id');
		overlayURL = "/dpComponent/video/overlayVideo?id="+videoID;
		var overlayAPI = $("#mediaOverlay").data("overlay");
		overlayAPI.onClose(function() {
			$("#mediaOverlay .overlayWrap").html("");
		});
		overlayAPI.load();
		return false;
	});
	
	$("#pageWrap").delegate("div.photOver a","click",function() {
		var id = $(this).attr('href').replace("/photos/index/story/","");
		var next = "";
		var prev = "";
		if($(this).parent().next().children().attr('href')) {
			next = $(this).parent().next().children().attr('href').replace("/photos/index/story/","");
		}
		if($(this).parent().prev().children().attr('href')) {
			prev = $(this).parent().prev().children().attr('href').replace("/photos/index/story/","");
		}
		//alert('id: ' + id + ' || next: ' + next + ' || prev: ' + prev);
		overlayURL = "/dpComponent/photos/overlayImage?id="+id+"&next="+next;
		var overlayAPI = $("#mediaOverlay").data("overlay");
		overlayAPI.onClose(function() {
			$("#mediaOverlay .overlayWrap").html("");
		});
		overlayAPI.load();
		return false;
	});
	
	// content Accordian
	if($("#contentAccordian").length) {
		$("#contentAccordian").tabs("#contentAccordian div.contentTier", {tabs: 'h2', effect: 'slide', initialIndex: null});
	}
	
	// poll voting...
	$("div.pollComponent div.vote").click(function() 
	{
		var id = $(this).attr('id');
		var answer = $("#dpPoll input:radio:checked").val(); // step one, let's ge tthe value of the checked item...
		if(answer) {
			$.ajax({
				url: "/dpComponent/pollManager/castVote",
				type: "post",
				data: "pid=" + id + "&aid=" + answer,
				success: function(html) {
					$("#pollWindow").html(html);
				}
			});
		}
	}).mouseenter(function()
	{
		$(this).addClass("on");
	}).mouseleave(function()
	{
		$(this).removeClass("on");
	});
	
	// NOT SURE WHAT THIS NEEDS TO DO... SHOULD JUST LINK TO CALENDAR PAGE...
	$("div.day.event").click(function() 
	{
		
		if($("div#calendarScroll").length) {
			// set the date...
			// let's grab the date directly from the id...
			var date = $(this).attr('id').replace("grid_","");
			var scrollPos = $("#calendarScroll").offset();
			var eventScroll = $("#day_"+date).offset();
			var eventScrollPos = $("#calendarScroll").scrollTop();
			var scrollToPos = eventScroll.top - scrollPos.top - 12;
			var finalScroll = eventScrollPos + scrollToPos;
			$("div#calendarScroll").animate({scrollTop:finalScroll},300);
			$("#day_"+date).effect("highlight",{ },5000);
		}
		
		//alert('works' + scrollPos.top + " || eventScroll: " + eventScroll.top + " || Event Scroll Pos: " + eventScrollPos + " || to move: " + scrollToPos + " || lenght: " + eventLength + " || date: " + year + "-" + month + "-" + day);
	}).mouseenter(function() 
	{
		$(this).addClass("over");
	}).mouseleave(function() 
	{
		$(this).removeClass("over");
	});
	
	// customize tabs...
	/*
	$("#customize").delegate("#feedAddTab", "click", function(event) 
	{
		if(!$(this).hasClass('on')) {
			$(this).addClass('on');
			$("#feedSuggestTab").removeClass("on");
			$("#feedSuggest").hide();
			$("#feedAdd").show();
		}
	});
	
	$("#customize").delegate("#feedSuggestTab", "click", function(event) 
	{
		if(!$(this).hasClass('on')) {
			$(this).addClass('on');
			$("#feedAddTab").removeClass("on");
			$("#feedSuggest").show();
			$("#feedAdd").hide();
		}
	});
	*/
	
	// add a feed through the system...
	
	
	// change label in main navigation...
	$("#labelTab div.labelIcon").live("click", function()
	{
		var newLabel = $(this).attr('id').replace("main_","");
		var origLabel = $("#channelWrap").attr('class');
		// change the color of the item...
		$("#channelWrap").removeClass(origLabel).addClass(newLabel);
		$("#labelSave").addClass('on').effect("pulsate", { times:2 }, 150);
	});
	
	// change label on component...
	$("div.componentEdit div.labelIcon").live("click", function()
	{
		var componentID = $(this).parent().parent().attr('id').replace("edit_","");
		var newLabel = $(this).attr('id').replace(componentID + "_","");
		var origLabel = $("#mdl_" + componentID).attr('class').replace("componentWrap ","");
		// change the color of the item...
		$("#mdl_" + componentID).removeClass(origLabel).addClass(newLabel);
		// turn on the save button...
		$("#" + componentID + "_labelSave").addClass('on').effect("pulsate",{ times:2 }, 150);
	});
	
	// click add a component to your page...
	$("div.clickAdd a").live("click", function()
	{
		// grab the id# of the added component...
		var componentID = $(this).parent().next().attr('id');
		var columnID = $(this).attr('id').replace("add_s_","");
		// remove the click links...
		$("#clickAdd_" + componentID).remove();
		// fade the component out...
		$("#" + componentID).fadeTo(500, 0.1, function() {
			// load component id# (necessary because it's a different function)
			var component = $(this).attr('id').replace("mdl_","");
			// remove the component from the DOM
			var componentData = $(this).detach();
			// disable component link in item window...
			$("#item_" + component).removeClass('available');
			// prepend the component to the requested section...
			$("#sortableWrap_" + columnID).prepend(componentData);
			// fade the moved component back in...
			$("#mdl_" + component).fadeTo(250, 1).effect("pulsate", { times: 2 }, 500);
			// submit to database...
			var queryData = "cid=" + channel + "&scid=" + subchannel;
			var newSortOrder = $("#sortableWrap_"+columnID).sortable("toArray");
			for(var k in newSortOrder) {
				queryData += "&sortableWrap_" + columnID + "[]=" + newSortOrder[k];
			}
			$.ajax({
				url: "/dpComponent/user/saveComponentStatus",
				type: "post",
				data: queryData.replace(/ /g,""),
				success: function(html) {
					$("#ldr_customize").effect("bounce",{distance:10},200);
				}
			});
		}).live("mouseenter", function() {
			$(this).addClass("on");
		});
		return false;
	});
	
	// update module panels... loads via ajax.
	$(".mdlNavTab a").live("click", function()
	{
		var panelID = $(this).parent().attr('id');
		var componentID = $(this).parent().parent().parent().parent().attr('id').replace("mdl_","");
		var sectionID = $(this).parent().parent().parent().parent().parent().attr('id').replace("sortableWrap_","");
		$.ajax({
			url: "/dpComponent/renderComponent/getComponentPrefs",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&section=" + sectionID + "&component=" + componentID + "&panel=" + panelID,
			success: function(html) {
				//$("#mdl_" + componentID).fadeOut(500, function() { $("#mdl_" + componentID).remove(); });
				$("#mdl_" + componentID).html(html);
				
			}
		});
		return false;
	});
	
	// displays the component edit screen...
	$(".componentIcon.edit").live("click", function()
	{
		// determine component...
		var componentID = $(this).attr('id').replace("mdl_edit_","");
		// show edit, hide body...
		$("#edit_"+componentID).show("blind", { direction: "vertical" }, 300);
		$("#bdy_"+componentID).hide("blind", { direction: "vertical" }, 300);
		// change class of button...
		$(this).removeClass('edit').addClass('cancel');
	});

	// hides the component edit screen...
	$(".componentIcon.cancel").live("click", function()
	{
		// determine component...
		var componentID = $(this).attr('id').replace("mdl_edit_","");
		// hide edit, show body...
		$("#edit_"+componentID).hide("blind", { direction: "vertical" }, 300);
		$("#bdy_"+componentID).show("blind", { direction: "vertical" }, 300);
		// change class of button...
		$("#mdl_edit_"+componentID).removeClass('cancel').addClass('edit');
	});
	
	// edit in place for component title...
	$("div.componentTitle").live("click", function()
	{
		// get the component ID we are working on...
		var componentID = $(this).parent().parent().attr("id").replace("mdl_","");
		// create the code for the text box...
		var revert = $(this).html();
		var formHTML = '<input type=text id="' + componentID + '_edit_title" value="' + revert + '" class="componentTitle edit">';
		$(this).after(formHTML).remove();
		$("#" + componentID + "_edit_title").focus();
		$("#" + componentID + "_edit_title").blur(function() {
			var newTitle = $(this).val();
			var newTextTitle = '<div class="componentTitle edit">' + newTitle + '</div>';
			var originalTextTitle = '<div class="componentTitle edit">' + revert + '</div>';
			if(newTitle == revert) {
				// revert to orignal text...
				$(this).after(originalTextTitle).remove();
			} else {
				$.ajax({
					url: "/dpComponent/user/editComponentTitle",
					type: "post",
					data: "cid=" + channel + "&scid=" + subchannel + "&component=" + componentID + "&title=" + newTitle,
					success: function(html) {
						$("#" + componentID + "_edit_title").after(newTextTitle).remove();
					},
					error: function() {
						$("#" + componentID + "_edit_title").after(originalTextTitle).remove();
					}
				});
			}
		});
		
		
		// we need to unbind the click...
		
		
		// now, we need to turn on the text box, with the appropriate data in it...
		//alert("Component: " + componentID + " | " + $(this).html() );
		
	});
	
	// component preview click...
	$("#componentList div.item.available").live("click", function()
	{
		var componentID = $(this).attr('id').replace("item_","");
		// here, we need to empty the existing previewComponent
		$("#componentPreview").fadeOut(100, function(){}).empty;
		$.ajax({
			url: "/dpComponent/renderComponent/getComponentPrefs",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&component=" + componentID + "&preview=1",
			success: function(html) {
				$("#componentPreview").html(html).fadeIn(500, function() {
					$("#componentPreview").bind("sortupdate", function(e, ui) {
						$("#item_"+componentID).removeClass('available');
					});
				});
			}
		});	
	});
	
	// save label change primary component...
	$("#labelSave.on").live("click", function()
	{
		var newLabel = $("#channelWrap").attr('className').replace("label","");
		$.ajax({
			url: "/dpComponent/user/changePrimaryLabel",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&label=" + newLabel,
			success: function(html) {
				$("#labelSave").removeClass("on").effect("bounce",{distance:10},200);
			}
		});
	});
	
	// save label for component...
	$(".componentLabelSave.on").live("click", function()
	{
		var componentID = $(this).attr('id').replace("_labelSave","");
		var newLabel = $(this).parent().parent().attr('className').replace("componentWrap label","");
		$.ajax({
			url: "/dpComponent/user/changeComponentLabel",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&component=" + componentID + "&label=" + newLabel,
			success: function(html) {
				$("#" + componentID + "_labelSave").removeClass("on").effect("bounce",{distance:10},200);
			}
		});
	});



	// leaderboard...
	$("#ldrBrd").delegate("#ldr_customize.cancel", "click", function(event)
	{
		$("#ldr_customize").removeClass("cancel").addClass("edit").html("Customize Page");
		$("#ldr_logout").removeClass("disabled");
		$("#ftr_sponsors").show();
		$("#ldr_profile").removeClass("disabled").addClass("edit");
		$("#customize").hide("blind", {direction: "vertical"}, 300);
		$("#content").show("blind", {direction: "vertical"}, 500);
		return false;
	});
	
	$("#ldrBrd").delegate("#ldr_customize.edit", "click", function(event)
	{
		var pane = $("#customize");
		if(pane.is(":empty")) {
			$.ajax({
				url: "/dpComponent/user/customize",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel,
				beforeSend: function() {
					$("#ldr_profile").removeClass("edit").addClass("disabled");
					$("#ldr_logout").addClass("disabled");
					$("#ftr_sponsors").hide();
					$("#spnsr div.base").addClass("tools");
					
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					$("#customize").html(html).show("blind", {direction: "vertical"}, 500); // show tools
					$("#content").hide("blind", {direction: "vertical"}, 300); // hide content...
					$("#ldr_customize").removeClass("edit").addClass("cancel").html("I'm Finished");
					// make the suggested feeds scrollable...
					
					$("#feedScroll").scrollable({
						vertical: true,
						easing: "swing",
						disabledClass: "disable"
					});
					
					$("#contributorScroll").scrollable({
						vertical: true,
						easing: "swing",
						disabledClass: "disable"
					});
					
					// let's make the feedNav buttons clickable...
					$(".feedNav .view").click(function() {
						var navId = $(this).attr("id");
						
						if(navId == "toolView") {
						
							// OPEN AN OVERLAY...
							overlayURL = "/dpComponent/rss/manageFeeds?dst=picks";
							var overlayAPI = $("#toolsOverlay").data("overlay");
							
							$("#toolsOverlay").bind("onLoad", function() {
								
								// configure navigation button clicks...
								$("#overlayTopNav .toolsButton").click(function() {
									var toolId = $(this).attr("id");
									displayFeeds(toolId,"");
								});
								
								// unbind, so that it doesn't bunch up...
								$(this).unbind("onLoad");
							});
							overlayAPI.load();
							return false;
		
		
						} else {
							
							// here, we want to switch the buttons, and
							// show the different content, depending on which nav was clicked...
							
							// step one, turn the buttons off...
							$(".feedNav div.view").removeClass("on");
							$(this).addClass("on");
							$("#componentList div.pane").addClass("hide");
							$("#componentPreview").html("");
							// now, we need to determine which view to show...
							switch(navId) {
								case "suggestView":
									$("#feedSuggest").removeClass("hide");
									break;
								
								case "contributorView":
									$("#feedContributor").removeClass("hide");
									break;
									
								case "searchView":
									$("#feedSearch").removeClass("hide");
									break;
									
								case "addView":
									$("#feedAdd").removeClass("hide");
									break;
							}
							//alert("nav: "+navId);
						}
					});
					
					$("#checkFeed").click(function() 
					{
						var feedUrl = $("#furl_add").val();
						if(feedUrl) {
							$.ajax({
								url: "/dpComponent/rss/addRSS",
								type: "post",
								data: "cid=" + channel + "&scid=" + subchannel + "&furl=" + feedUrl + "&preview=1",
								success: function(html) {
									//alert('data sent to server!');
									$("#componentPreview").html(html);
									$("#feedAddWindow").addClass("hide");
									
									// this is a successful return... 
									// we will need to test this a little better...
									
									$("#feedAddedWindow").removeClass("hide");
									$("span#furl_added").html(feedUrl);
									$("#furl_add").val("");
									// here, we also change the text in the box...
									// that way, we can tell people to preview their feed in the area at left...
									
									// we can also clear the box, so that additional feeds can be added...
									
									
								}
							});
						} else {
							// no feed url entered...
						}
						return false;
					});
	
					
					// make the preview column a sortable...
					$("#componentPreview").sortable({ 
						connectWith: '.usrColumn',
						cursor: 'move',
						handle: 'div.mdlBar',
						placeholder: 'mdlPlaceHolder',
						forcePlaceholderSize: true
					});
					
					
					// initialize autocomplete search...
					$("#furl_query").autocomplete({
						source: "/dpComponent/renderComponent/searchResults?cid=" + channel + "&scid=" + subchannel,
						delay: 500,
						minLength: 2,
						select: function(e, ui) {
							$.ajax({
								url: "/dpComponent/renderComponent/getComponentPrefs",
								type: "post",
								data: "cid=" + channel + "&scid=" + subchannel + "&component=" + ui.item.id + "&preview=1",
								success: function(html) {
									// update the componentPreview section...
									$("#componentPreview").html(html);
								}
							});
						}
					});
					// set default value for auto complete search...
					var default_values = new Array();
					$("input.largeText").focus(function() {
						if(!default_values[this.id]) {
							default_values[this.id] = this.value;
						}
						if(this.value == default_values[this.id]) {
							this.value = '';
							$(this).removeClass("inactive").addClass("active");
						}
						$(this).blur(function() {
							if(this.value == '') {
								$(this).removeClass("active").addClass("inactive");
								this.value = default_values[this.id];
							}
						});
						
					});
				}
			});
		} else {
			$("#customize").show("blind", {direction: "vertical"}, 500);
			$("#content").hide("blind", {direction: "vertical"}, 300);
			$("#ldr_customize").removeClass("edit").addClass("cancel").html("I'm Finished");
			$("#ldr_profile").removeClass("edit").addClass("disabled");
			$("#ldr_logout").addClass("disabled");
			$("#ftr_sponsors").hide();
			$("#spnsr div.base").addClass("tools");
		}
		return false;
	});

	$("#ldrBrd").delegate("#ldr_profile.cancel", "click", function(event)
	{
	//$("#userName.cancel a").live("click", function() {
		$("#ldr_profile").removeClass("cancel").addClass("edit").html("View Profile");
		$("#ldr_customize").removeClass("disabled").addClass("edit");
		$("#ldr_logout").removeClass("disabled");
		$("#tools").hide("blind", {direction: "vertical"}, 300);
		$("#content").show("blind", {direction: "vertical"}, 500);
		// run the function here, to bind the profile info...
		//toolsUpdateProfile();
		return false;
	});
	
	$("#ldrBrd").delegate("#ldr_profile.edit", "click", function(event) {
		$.ajax({
			url: "/dpComponent/user/tools",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&sec=user&tool=profile",
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$("#tools").html(html).show("blind", {direction: "vertical"}, 500);
				$("#content").hide("blind", {direction: "vertical"}, 300);
				$("#ldr_profile").removeClass("edit").addClass("cancel").html("I'm Finished");
				$("#ldr_customize").removeClass("edit").addClass("disabled");
				$("#ldr_logout").addClass("disabled");
				
				$("#toolUser .toolsButton").click(function() {
					var buttonId = $(this).attr('id');
					var method = "/dpComponent/user/toolsDisplay"+buttonId+"Ajax";
					var typeId = $(this).parent().attr("id");
					$.ajax({
						url: method,
						type: "post",
						data: "cid=" + channel + "&scid=" + subchannel + "&typeId=" + typeId,
						beforeSend: function() {
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							var msg = "";
							$("#contentLoading").addClass("hide");
							$(".toolsNav div").removeClass("on");
							$("#"+buttonId).addClass("on");
							$("#toolInterface").html(html);
							switch(buttonId) {
								case "Profile":
									toolsUpdateProfile();
									break;
								case "Password":
									toolsUpdatePassword();
									break;
								case "MyNews":
									// here, we need to do some stuff.
									// this should probably be the same as the other stuff...
									configurePreviewTip("/dpComponent/headlines/renderStoryPreview");
									break;
									
									
								// load the code for the default button...
								// copy from above
								default:
									toolsUpdateProfile();
							}
						}
					});
				});
				
				toolsUpdateProfile();	// bind profile listeners...
			}
		});
		return false;
	});
	
	
	//$("#classifiedsComponent").delegate("#classifiedKeywordSearch div.button", "click", function(event) {
	if($("form#classifiedKeywordSearch").length) {
		$("form#classifiedKeywordSearch").validator().submit(function(e) {
			var form = $(this);
			//alert('yes');
			if (!e.isDefaultPrevented()) {
				formData = form.serialize();
				$.ajax({
					url: "/dpComponent/classifieds/updateListSearch",
					type: "post",
					data: "cid="+ channel +"&scid="+ subchannel +"&" + formData,
					dataType: "json",
					beforeSend: function() {
						$("#contentLoading").removeClass("hide");
					},
					error: function() {
						//alert('error!');
					},
					success: function(json) {
						//alert('works');
						$("#contentLoading").addClass("hide");
						if (json.success)  {
							// search successfully run!
							$("#ajxWndw").html(json.html);
							$("body").scrollTop(0);
						} else {
							// server-side validation failed.
							form.data("validator").invalidate(json);
						}
					}
				});
				// prevent the form from being submitted...
				e.preventDefault();
			}
		});
	}
	
	if($("#classifiedSpotlight").length) {
		$("#classifiedSpotlight").click(function() {
				$.ajax({
					url: "/dpComponent/classifieds/updateListFeature",
					type: "post",
					data: "cid="+ channel +"&scid="+ subchannel,
					beforeSend: function() {
						$("#contentLoading").removeClass("hide");
						$("#classifiedLatest").removeClass("on");
					},
					error: function() {
						//alert('error!');
					},
					success: function(html) {
						//alert('works');
						$("#contentLoading").addClass("hide");
						$("#classifiedSpotlight").addClass("on");
						$("#ajxWndw").html(html);
						$("body").scrollTop(0);
					}
				});
		});
	}
	
	if($("#classifiedLatest").length) {
		$("#classifiedLatest").click(function() {
				$.ajax({
					url: "/dpComponent/classifieds/updateListLatest",
					type: "post",
					data: "cid="+ channel +"&scid="+ subchannel,
					beforeSend: function() {
						$("#contentLoading").removeClass("hide");
						$("#classifiedSpotlight").removeClass("on");
					},
					error: function() {
						//alert('error!');
					},
					success: function(html) {
						//alert('works');
						$("#contentLoading").addClass("hide");
						$("#classifiedLatest").addClass("on");
						$("#ajxWndw").html(html);
						$("body").scrollTop(0);
					}
				});
		});
	}
	

	// button to access tools from front-end...
	// this needs to be one function, to control ALL tool buttons...
	// once this is done, we can split it into 5 separate jQuery functions, for each of the content types...
	$(".toolButton").live("click", function() 
	{
		// scroll to the top of the page...
		// might need to consider having it drop down say 100 pixels...
		window.scrollTo(0,0);
		var toolType = $(this).attr('id').split("_");
		
		
		if($(this).hasClass("gst") || $(this).hasClass("fb"))
		{
			// require users to be registered to post content...
			if($(this).hasClass("gst")) {
				overlayURL = "/dpComponent/user/accessInterface/";
			} else {
				overlayURL = "/dpComponent/user/fbFinishInterface/";
			}
			
			var overlayAPI = $("#userOverlay").overlay();
			overlayAPI.load();
			return false;
		} 
		else if(toolType[0] == "feature") 
		{
			// feature module scroll option...
			clearInterval(featureInterval);
			if(toolType[1] == "prev") {
				fadeTopStories("prev");
			} else if(toolType[1] == "next") {
				fadeTopStories("next");
			} else if(toolType[1] == "play") {
				// set the interval here...
				fadeTopStories("next");
				featureInterval = setInterval('fadeTopStories("next")', 10000);
			}
		} 
		else if(toolType[0] == "closeCorporate") 
		{
			$("#featureWrap").show("blind", {direction: "vertical"}, 300);
			$("#corporateWrap").hide("blind", {direction: "vertical"}, 300);
			$("#spnsrBox div.spnsrOverBut").removeClass("on");
		} 
		else if(toolType[0] == "iads") 
		{
			// we need to get the size of the ads in question...
			$.ajax({
				url: "/dpComponent/ads/tools",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&sec="+toolType[0]+"&tool="+toolType[1]+"&typeId="+toolType[2]+"&adD=",
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					$("#tools").html(html).show("blind", {direction: "vertical"}, 500);
					$("#content").hide("blind", {direction: "vertical"}, 300);
					$("#ftr_sponsors").hide();
					$("#spnsr div.base").addClass("tools");
					
					// configure the ad tools navigation...
					// ---------------------------------------------------------------------------------
					// drop-down select...
					$("#toolAds").delegate("#toolInterface #toolAdDimensions", "change", function(event) {
					//$("#toolAdDimensions").change(function() {
						var buttonId = $("div.toolsNav div.on").attr("id").split("_");
						var method = "/dpComponent/ads/toolsDisplay"+buttonId[0]+"Ajax";
						var typeId = $(".toolsNav > div.on").parent().attr("id");
						var adDim = $("#toolAdDimensions").val();
						// run the function...
						updateToolsAdNav(buttonId,method,typeId,adDim);
					});
					// button...
					$("#toolAds").delegate(".toolsButton","click",function(event) {
					//$("#toolAds .toolsButton").click(function() {
					
						// we could split it right here, and pass it along..
						var buttonId = $(this).attr('id').split("_");
						var method = "/dpComponent/ads/toolsDisplay"+buttonId[0]+"Ajax";
						var typeId = $(this).parent().attr("id");
						var adDim = $("#toolAdDimensions").val();
						updateToolsAdNav(buttonId,method,typeId,adDim);
					});
					
					// configure actions by tool type...
					// ---------------------------------------------------------------------------------
					switch(toolType[1]) {
						case "upload":
							msg = "Share Code Here - "+toolType[1];
							toolsAdsShare(msg);
							break;
						default:
							// this is the default run...
							msg = "Management Code Here - "+toolType[1];
							toolsAdsManage("");
							break;
					}
				}
			});
		
		
		// MANAGE VIDEOS...
		} 
		else if(toolType[0] == "videos") 
		{
			$.ajax({
				url: "/dpComponent/videoManager/tools",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&sec="+toolType[0]+"&tool="+toolType[1]+"&typeId="+toolType[2],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					// configure & display tools page...
					$("#contentLoading").addClass("hide");
					$("#tools").html(html).show("blind", {direction: "vertical"}, 500);
					$("#content").hide("blind", {direction: "vertical"}, 300);
					$("#ftr_sponsors").hide();
					$("#spnsr div.base").addClass("tools");
					
					// toolsButton Click Configuration...
					$("#toolVideos .toolsButton").click(function() {
						var buttonId = $(this).attr('id');
						var method = "/dpComponent/videoManager/toolsDisplay"+buttonId+"Ajax";
						var typeId = $(this).parent().attr("id");
						$.ajax({
							url: method,
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&typeId=" + typeId,
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								var msg = "";
								$("#contentLoading").addClass("hide");
								$(".toolsNav div").removeClass("on");
								$("#"+buttonId).addClass("on");
								$("#toolInterface").html(html);
								switch(buttonId) {
									case "Share":
										msg = "Share Code Here - "+buttonId;
										toolsVideosShare(msg);
										break;
										
									default:
										msg = "Management Code Here - "+buttonId;
										toolsVideosManage(msg);
										break;
								}
							}
						});
					});
					// default Page Configuration...
					switch(toolType[1]) {
						case "share":
							msg = "Share Code Here - "+toolType[1];
							toolsVideosShare(msg);
							break;
							
						default:
							msg = "Management Code Here - "+toolType[1];
							toolsVideosManage(msg);
							break;
					}
				}
			});
		} 
		else if(toolType[0] == "photos") 
		{
			
			overlayURL = "/dpComponent/channel/mediaLibraryOverlay?src=standalong&dst=images";
			var overlayAPI = $("#toolsOverlay").data("overlay");
			$("#toolsOverlay").bind("onClose", function() {
				$("#toolsOverlay .overlayWrap").html("");
				$(this).unbind("onClose");	// unbind so we don't bubble up...
			});
			$("#toolsOverlay").bind("onLoad", function() {
			
				
				setTimeout(function(){configureImageDialog("",overlayAPI,"",""); overlayAPI=null},500);
				
				//setTimeout('configureImageDialog("",overlayAPI,"","")',1000);
				
				//configureImageDialog("",overlayAPI,"","");
				$(this).unbind("onLoad"); // unbind so we don't bubble up...
			});
			overlayAPI.load();
			return false;
			
		} 
		else if(toolType[0] == "classifieds") 
		{
			var category = $("#searchComponentPane div.on").attr('id');
			var classification = $("#searchComponentPane div.on div.categoryWrap div.on").attr('id');
			$.ajax({
				url: "/dpComponent/classifiedsManager/tools",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&sec="+toolType[0]+"&tool="+toolType[1]+"&typeId="+toolType[2]+"&cat="+category+"&scat="+classification,
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					$("#tools").html(html).show("blind", {direction: "vertical"}, 500);
					$("#content").hide("blind", {direction: "vertical"}, 300);
					$("#ftr_sponsors").hide();
					$("#spnsr div.base").addClass("tools");
					
					// here, we need to configure the search box...
					
					// on click, we need to check the value...
					// FOCUS
					$("input#SearchQ").focus(function() {
						//alert("val: " + $(this).val());
						if($(this).val() == "keyword search") {
							this.value = "";
							$(this).addClass('active');
							$("#Search").removeClass('off');
						}
					}).blur(function() {
						if($(this).val() == "") {
							$(this).val('keyword search');
							$(this).removeClass('active');
							$("#Search").addClass('off');
						}
					});
					
					$("#toolClassifieds .toolsButton").click(function() {
						var buttonId = $(this).attr('id');
						var method = "/dpComponent/classifiedsManager/toolsDisplay"+buttonId+"Ajax";
						var typeId = $(this).parent().attr("id");
						var category = $("#searchComponentPane div.on").attr('id');
						var classification = $("#searchComponentPane div.on div.categoryWrap div.on").attr('id');
						if($(this).hasClass("off")) {
							return false;
						}
						if(buttonId == "Export") {
							window.location.href = method;
						} else if(buttonId == "Create" && $(this).hasClass('pd')) {
						
							// here is where we would need to make the change...
							// we could do it with a certain class on the item...
							
							// if the class exists, we run the https code.
							// if the class doesn't exist, we don't run it...
							// NICE...
							
							var cUrl = window.document.location.href.replace("http:","https:");
							window.location.href = cUrl + "/create";	
						} else {
							var q = "";
							if(buttonId == "Search") {
								q = $("input#SearchQ").val();
							}
							$.ajax({
								url: method,
								type: "post",
								data: "cid=" + channel + "&scid=" + subchannel + "&typeId=" + typeId + "&cat=" + category + "&scat=" + classification + "&q=" + q,
								beforeSend: function() {
									$("#contentLoading").removeClass("hide");
								},
								success: function(html) {
									var msg = "";
									$("#contentLoading").addClass("hide");
									$(".toolsNav div").removeClass("on");
									$("#"+buttonId).addClass("on");
									$("#toolInterface").html(html);
									switch(buttonId) {
										case "Create":
											toolsClassifiedsCreate(msg);
											break;
											
										default:
											toolsClassifiedsManage(msg);
											break;
									}
								}
							});
						}
					});
					// default Page Configuration...
					switch(toolType[1]) {
						case "create":
							msg = "Share Code Here - "+toolType[1];
							toolsClassifiedsCreate(msg);
							break;
						default:
							msg = "Management Code Here - "+toolType[1];
							toolsClassifiedsManage(msg);
							break;
					}
				}
			});
			 
		// MANAGE TAGS...
		} 
		else if(toolType[0] == "tags" || toolType[0] == "geotags") 
		{
			$.ajax({
				url: "/dpComponent/viewby/tools",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&sec="+toolType[0]+"&tool="+toolType[1]+"&typeId="+toolType[2],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					// configure & display tools page...
					$("#contentLoading").addClass("hide");
					$("#tools").html(html).show("blind", {direction: "vertical"}, 500, function() {
						if(toolType[2] && $("#"+toolType[2].length)) {
							var scrollPos = $("#toolScroll .fixed").offset();
							var eventScroll = $("#"+toolType[2]).offset();
							var eventScrollPos = $("#toolScroll .fixed").scrollTop();
							var scrollToPos = eventScroll.top - scrollPos.top - 12;
							var finalScroll = eventScrollPos + scrollToPos;
							$("#toolScroll .fixed").animate({scrollTop:finalScroll},300);
							$("#"+toolType[2]).addClass("on");
							$("#"+toolType[2]).effect("highlight",{ },5000);
							$("#toolScroll div.rowItem.on").click();
						}
					});
					$("#content").hide("blind", {direction: "vertical"}, 300);
					$("#ftr_sponsors").hide();
					$("#spnsr div.base").addClass("tools");
					
					// toolsButton Click Configuration...
					$("#toolTags .toolsButton").click(function() {
						var buttonId = $(this).attr('id');
						var method = "/dpComponent/viewby/toolsDisplay"+buttonId+"TagsAjax";
						var typeId = $(this).parent().attr("id");
						$.ajax({
							url: method,
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&typeId=" + typeId,
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								var msg = "";
								$("#contentLoading").addClass("hide");
								$(".toolsNav div").removeClass("on");
								$("#"+buttonId).addClass("on");
								$("#toolInterface").html(html);
								switch(buttonId) {
									case "Create":
										msg = "Create Code Here - "+buttonId;
										toolsTagsCreate(msg);
										break;
										
									default:
										msg = "Management Code Here - "+buttonId;
										toolsTagsManage(msg);
										break;
								}
							}
						});
					});
					// default Page Configuration...
					switch(toolType[1]) {
						case "share":
							msg = "Create Code Here - "+toolType[1];
							toolsTagsCreate(msg);
							break;
							
						default:
							msg = "Management Code Here - "+toolType[1];
							toolsTagsManage(msg);
							break;
					}
				}
			});

		// MANAGE ALERTS...
		} 
		else if(toolType[0] == "alerts") 
		{
			$.ajax({
				url: "/dpComponent/channel/tools",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&sec="+toolType[0]+"&tool="+toolType[1]+"&typeId="+toolType[2],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					// configure & display tools page...
					$("#contentLoading").addClass("hide");
					$("#tools").html(html).show("blind", {direction: "vertical"}, 500, function() {
						if(toolType[2] && $("#"+toolType[2].length)) {
							var scrollPos = $("#toolScroll .fixed").offset();
							var eventScroll = $("#"+toolType[2]).offset();
							var eventScrollPos = $("#toolScroll .fixed").scrollTop();
							var scrollToPos = eventScroll.top - scrollPos.top - 12;
							var finalScroll = eventScrollPos + scrollToPos;
							$("#toolScroll .fixed").animate({scrollTop:finalScroll},300);
							$("#"+toolType[2]).effect("highlight",{ },5000);
							$("#"+toolType[2]).addClass("on");
							
							//alert('finalScroll: ' + finalScroll);
							// now, we need to simulate a click...
							$("#toolScroll div.rowItem.on").click();
						}
					});
					$("#content").hide("blind", {direction: "vertical"}, 300);
					$("#ftr_sponsors").hide();
					$("#spnsr div.base").addClass("tools");
					
					// toolsButton Click Configuration...
					$("#toolAlerts .toolsButton").click(function() {
						var buttonId = $(this).attr('id');
						var method = "/dpComponent/viewby/toolsDisplay"+buttonId+"AlertsAjax";
						var typeId = $(this).parent().attr("id");
						$.ajax({
							url: method,
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&typeId=" + typeId,
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								var msg = "";
								$("#contentLoading").addClass("hide");
								$(".toolsNav div").removeClass("on");
								$("#"+buttonId).addClass("on");
								$("#toolInterface").html(html);
								switch(buttonId) {
									case "Create":
										msg = "Create Code Here - "+buttonId;
										toolsAlertsCreate(msg);
										break;
										
									default:
										msg = "Management Code Here - "+buttonId;
										toolsAlertsManage(msg);
										break;
								}
							}
						});
					});
					// default Page Configuration...
					switch(toolType[1]) {
						case "share":
							msg = "Create Code Here - "+toolType[1];
							toolsAlertsCreate(msg);
							break;
							
						default:
							msg = "Management Code Here - "+toolType[1];
							toolsAlertsManage(msg);
							break;
					}
				}
			});
			
			
			
		// MANAGE CONTRIBUTORS...
		} 
		else if(toolType[0] == "contributors") 
		{
			$.ajax({
				url: "/dpComponent/viewby/tools",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&sec="+toolType[0]+"&tool="+toolType[1]+"&typeId="+toolType[2],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					// configure & display tools page...
					$("#contentLoading").addClass("hide");
					$("#tools").html(html).show("blind", {direction: "vertical"}, 500, function() {
						if(toolType[2] && $("#"+toolType[2].length)) {
							var scrollPos = $("#toolScroll .fixed").offset();
							var eventScroll = $("#"+toolType[2]).offset();
							var eventScrollPos = $("#toolScroll .fixed").scrollTop();
							var scrollToPos = eventScroll.top - scrollPos.top - 12;
							var finalScroll = eventScrollPos + scrollToPos;
							$("#toolScroll .fixed").animate({scrollTop:finalScroll},300);
							$("#"+toolType[2]).effect("highlight",{ },5000);
							$("#"+toolType[2]).addClass("on");
							
							//alert('finalScroll: ' + finalScroll);
							// now, we need to simulate a click...
							$("#toolScroll div.rowItem.on").click();
						}
					});
					$("#content").hide("blind", {direction: "vertical"}, 300);
					$("#ftr_sponsors").hide();
					$("#spnsr div.base").addClass("tools");
					
					// toolsButton Click Configuration...
					$("#toolContributors .toolsButton").click(function() {
						var buttonId = $(this).attr('id');
						var method = "/dpComponent/viewby/toolsDisplay"+buttonId+"ContributorsAjax";
						var typeId = $(this).parent().attr("id");
						$.ajax({
							url: method,
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&typeId=" + typeId,
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								var msg = "";
								$("#contentLoading").addClass("hide");
								$(".toolsNav div").removeClass("on");
								$("#"+buttonId).addClass("on");
								$("#toolInterface").html(html);
								switch(buttonId) {
									case "Create":
										msg = "Create Code Here - "+buttonId;
										toolsContributorsCreate(msg);
										break;
										
									default:
										msg = "Management Code Here - "+buttonId;
										toolsContributorsManage(msg);
										break;
								}
							}
						});
					});
					// default Page Configuration...
					switch(toolType[1]) {
						case "share":
							msg = "Create Code Here - "+toolType[1];
							toolsContributorsCreate(msg);
							break;
							
						default:
							msg = "Management Code Here - "+toolType[1];
							toolsContributorsManage(msg);
							break;
					}
				}
			});
		
		// MANAGE CHANNEL TOOLS... (Headlines / Events / Polls)
		}
		else if(toolType[0] == "news") {
			$.ajax({
				url: "/dpComponent/headlines/tools",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&sec="+toolType[0]+"&tool="+toolType[1]+"&typeId="+toolType[2],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					// configure & display tools page...
					$("#contentLoading").addClass("hide");
					$("#tools").html(html).show("blind", {direction: "vertical"}, 500);
					$("#content").hide("blind", {direction: "vertical"}, 300);
					$("#ftr_sponsors").hide();
					$("#spnsr div.base").addClass("tools");
					
					// toolsButton Click Configuration...
					$("#toolNews .toolsButton").click(function() {
						var buttonId = $(this).attr('id');
						var method = "/dpComponent/headlines/toolsDisplay"+buttonId+"Ajax";
						var typeId = $(this).parent().attr("id");
						$.ajax({
							url: method,
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&typeId=" + typeId,
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								var msg = "";
								$("#contentLoading").addClass("hide");
								$(".toolsNav div").removeClass("on");
								$("#"+buttonId).addClass("on");
								$("#toolInterface").html(html);
								switch(buttonId) {
									case "Create":
										msg = "News Create Code Here - "+buttonId;
										toolsNewsCreate(msg);
										break;
										
									default:
										msg = "News Management Code Here - "+buttonId;
										toolsNewsManage(msg);
										break;
								}
							}
						});
					});
					// default page...
					switch(toolType[1]) {
						case "create":
							msg = "News Create Code Here - "+toolType[1];
							toolsNewsCreate(msg);
							break;
							
						default:
							msg = "News Management Code Here - "+toolType[1];
							toolsNewsManage(msg);
							break;
					}
				}
			});
		}
		else  if(toolType[0] == "calendar") {
			$.ajax({
				url: "/dpComponent/events/tools",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&sec="+toolType[0]+"&tool="+toolType[1]+"&typeId="+toolType[2],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					// configure & display tools page...
					$("#contentLoading").addClass("hide");
					$("#tools").html(html).show("blind", {direction: "vertical"}, 500);
					$("#content").hide("blind", {direction: "vertical"}, 300);
					$("#ftr_sponsors").hide();
					$("#spnsr div.base").addClass("tools");
					// toolsButton Click Configuration...
					$("#toolCalendar .toolsButton").click(function() {
						if(!$(this).hasClass("on")) {
							var buttonId = $(this).attr('id');
							var method = "/dpComponent/events/toolsDisplay"+buttonId+"Ajax";
							var typeId = $(this).parent().attr("id");
							$.ajax({
								url: method,
								type: "post",
								data: "cid=" + channel + "&scid=" + subchannel + "&typeId=" + typeId,
								beforeSend: function() {
									$("#contentLoading").removeClass("hide");
								},
								success: function(html) {
									var msg = "";
									$("#contentLoading").addClass("hide");
									$(".toolsNav div").removeClass("on");
									$("#"+buttonId).addClass("on");
									$("#toolInterface").html(html);
									switch(buttonId) {
										case "Create":
											msg = "Calendar Create Code Here - "+buttonId;
											toolsCalendarCreate(msg);
											break;
											
										default:
											msg = "Calendar Management Code Here - "+buttonId;
											toolsCalendarManage(msg);
											break;
									}
								}
							});
						} else {
							alert("please scroll down and click the continue button.");
						}
					});
					// default page...
					switch(toolType[1]) {
						case "create":
							msg = "Calendar Create Code Here - "+toolType[1];
							toolsCalendarCreate(msg);
							break;
							
						default:
							msg = "Calendar Management Code Here - "+toolType[1];
							toolsCalendarManage(msg);
							break;
					}
				}
			});
		}
		else 
		{
			$.ajax({
				url: "/dpComponent/user/tools",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&sec=" + toolType[0] + "&tool=" + toolType[1] + "&typeId=" + toolType[2],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					$("#tools").html(html).show("blind", {direction: "vertical"}, 500);
					$("#content").hide("blind", {direction: "vertical"}, 300);
					$("#ftr_sponsors").hide();
					$("#spnsr div.base").addClass("tools");
					if(toolType[0] == "headline") {
						// PRELOAD A SPECIFIC HEADLINE (REQUESTED)...
						$.ajax({
							url: "/dpComponent/headlines/toolsDisplayOverviewAjax",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + toolType[1],
							beforeSend: function() {
								// we need to remove the class from ANY of the rowitem values...
								//$("#toolScroll div.rowItem").removeClass("on");
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								var postId = $("#postId").val();
								$("#contentLoading").addClass("hide");
								outputArticleTool("",html);
							}
						});
					} else if(toolType[0] == "event") {
						// we need to pre-load the requested event...
						// should be able to just copy content from above...
						$.ajax({
							url: "/dpComponent/events/toolsDisplayOverviewAjax",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + toolType[1],
							beforeSend: function() {
								// we need to remove the class from ANY of the rowitem values...
								//$("#toolScroll div.rowItem").removeClass("on");
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								var postId = $("#postId").val();
								$("#contentLoading").addClass("hide");
								outputEventTool("",html);
							}
						});
					}
				}
			});
		}
	});
	
	// this is currently only running for NEWS & EVENTS
	// we need to deprecate this, and move everything into the main
	// toolButton function, with chained items for each piece... AWESOME!
	/*
	$(".toolNav a").live("click", function()
	{
		var method = $(this).attr('href');
		var parent = $(this).parent();
		var typeId = parent.parent().attr("id");
		var e=CKEDITOR.instances['articleText'];
		if(e) {
			e.destroy();
			e=null;
		}
		$.ajax({
			url: method,
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&typeId=" + typeId,
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				// now, we need to remove the ON from the current tabs...
				$(".toolNav div").removeClass("on");
				$(parent).addClass("on");
				$("#contentLoading").addClass("hide");
				$("#toolInterface").html(html);
			}
		});
		return false;
	});
	*/
	// EVENTS
	// --------------------------------------------------------------------------------------------
	// jquery for step one of event creation...
	
	
	// this is ok to have outside, as it applies to ALL versions of the tools...
	// anything else we need to can be put into functions...
	$("#tools").delegate("#toolsCancel, #toolScroll #toolsClose", "click", function(event)
	{
	//$("#toolsCancel").live("click", function() {
		var e=CKEDITOR.instances['articleText'];
		var html = "loading tools...";
		if(e) {
			e.destroy();
			e=null;
		}
		$("#tools").hide("blind", {direction: "vertical"}, 500, function() {
			$("#tools").html(html);
		});
		$("#content").show("blind", {direction: "vertical"}, 500);
		$("#ftr_sponsors").show("blind", {direction: "vertical"}, 100);
		$("#spnsr div.base").removeClass("tools");
	});
	
	// both on the home page...
	// ---------------------------------------
	if ($("#publisherSlider").length) {
	
		// locate slider...
		var publisherConveyor = $(".content-conveyor", $("#sliderPublisherContent")), 
		publisherItem = $(".item", $("#sliderPublisherContent"));
		publisherConveyor.css("width", publisherItem.length * parseInt(publisherItem.css("width")));  
	
		//config  
		var sliderPublisherOpts = {  
			max: (publisherItem.length * parseInt(publisherItem.css("width"))) - parseInt($(".viewer", $("#sliderPublisherContent")).css("width")),
			slide: function(e, ui) {
				$("#sliderPublisherContent .viewer").attr({scrollLeft: ui.value });
			}
		};
		
		//create slider  
		$("#sliderPublisher").slider(sliderPublisherOpts);
	}
	
	if ($("#expertSlider").length) {
	
		// locate slider...
		var publisherConveyor = $(".content-conveyor", $("#sliderExpertContent")), 
		publisherItem = $(".item", $("#sliderExpertContent"));
		publisherConveyor.css("width", publisherItem.length * parseInt(publisherItem.css("width")));  
	
		//config  
		var sliderOpts = {  
			max: (publisherItem.length * parseInt(publisherItem.css("width"))) - parseInt($(".viewer", $("#sliderPublisherContent")).css("width")),
			slide: function(e, ui) {
				$("#sliderExpertContent .viewer").attr({scrollLeft: ui.value });
			}
		};
		
		//create slider  
		$("#sliderExpert").slider(sliderOpts);
	}
	
	if ($("#photoSlider").length) {
	
		// locate slider...
		var photoConveyor = $(".content-conveyor", $("#sliderPhotoContent")), 
		photoItem = $(".item", $("#sliderPhotoContent"));
		photoConveyor.css("width", photoItem.length * parseInt(photoItem.css("width")));  
	
		//config  
		var sliderPhotoOpts = {  
			max: (photoItem.length * parseInt(photoItem.css("width"))) - parseInt($(".viewer", $("#sliderPhotoContent")).css("width")),
			slide: function(e, ui) {
				$("#sliderPhotoContent .viewer").attr({scrollLeft: ui.value });
			}
		};
		
		//create slider  
		$("#sliderPhoto").slider(sliderPhotoOpts);
	}
	
	$(".ftrVideoWrap").scrollable({circular: true,
		easing: "swing",
		next: ".videoNext",
		prev: ".photoPrev",
		speed: 1500
	}).navigator().autoscroll({interval: 10000});

	// configure the default overlay behavior...
	// -------------------------------------------
	$("div.overlay").overlay({
		effect: 'default',
		top: '2%',
		oneInstance: false,
		mask: {
			color: '#000',
			loadSpeed: 200,
			opacity: 0.8
		},
		onBeforeLoad: function() {
			var wrap = this.getOverlay().find(".overlayWrap");
			wrap.load(overlayURL);
		},
		onBeforeClose: function() {
			clearValidators();
		}
	});
	
	
	/* PHOTO CHANNEL COMPONENTS */
	if($("#sortPhotoByTag").length) {
		$("#sortPhotoByTag").change(function() {
			var tag = $(this).val();
			var uri = window.document.location.href.split("?");
			var uriparts = uri[0].split("/");
			window.location = "/photos/index/"+uriparts[5]+"/"+uriparts[6]+"/"+tag;			
		});
	}
	
	if($("#sortPhotoByLocation").length) {
		$("#sortPhotoByLocation").change(function() {
			var tag = $(this).val();
			var uri = window.document.location.href.split("?");
			var uriparts = uri[0].split("/");
			window.location = "/photos/index/"+uriparts[5]+"/"+uriparts[6]+"/"+tag;			
		});
	}
	
	
	/* START --> CLASSIFIEDS */	
	$(".classifiedsComponent").delegate(".photo.doOverlay", "click", function(event)
	{
		var photoId = $(this).attr("id").replace("photo_","");
		overlayURL = "/dpComponent/classifiedsManager/overlayImage/" + photoId;
		var overlayAPI = $("#mediaOverlay").overlay();
		overlayAPI.load();
		return false;
	});
	
	$(".classifiedsComponent").delegate(".navitem.doOverlay", "click", function(event) 
	{
		var navId = $(this).attr("id").replace("nav_","");
		var classId = $(this).parent().parent().attr("id").replace("classified_","");
		overlayURL = "/dpComponent/classifiedsManager/overlayOptions/"+ classId + "/" + navId;
		var overlayAPI = $("#overlay").overlay();
		overlayAPI.load();
		return false;
	});
	/* END --> CLASSIFIEDS */
	
	
	
	/* START --> CLASSIFIEDS NAVIGATION SYSTEM */
	$("div.classifiedsComponent").delegate("#ajxWndw div.pageNav div.nav .button.page", "click", function(event)
	{
		var pageNum = $(this).html() - 1;
		var metaData = $(this).attr('id').split("|");
		var num = "";
		if(pageNum > 0) {
			num = metaData[0]/pageNum;
		} else {
			num = metaData[0];
		}	
		$.ajax({
			url: "/dpComponent/classifieds/updateList",
			type: "post",
			data: "cat=" + metaData[1] + "&scat=" + metaData[2] + "&startPos=" + metaData[0] + "&num=" + num + "&page=" + pageNum + "&q=" + metaData[3],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#ajxWndw").html(html);
				window.scrollTo(0,0);
			}
		});
	});
	
	$("div.classifiedsComponent").delegate("#ajxWndw div.pageNav div.nav .button.step", "click", function(event)
	{
		var metaData = $(this).attr('id').replace("step_","").split("|");
		$.ajax({
			url: "/dpComponent/classifieds/updateList",
			type: "post",
			data: "cat=" + metaData[2] + "&scat=" + metaData[3] + "&startPos=" + metaData[0] + "&num=" + metaData[1] + "&q=" + metaData[4],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#ajxWndw").html(html);
				window.scrollTo(0,0);
			}
		});
	});
	/* END --> CLASSIFIEDS NAVIGATION SYSTEM */
	
	
	
	/* START --> CALENDAR SYSTEM */
	if(!$("#calendarScroll").length) {
		$("div.calendar div.event").tooltip({predelay:850,delay:150,effect:'slide',relative:true,position: 'top left',offset:[12,110]});
	}
	/* END --> CALENDAR SYSTEM */
	
	/* START --> POSTS NAVIGATION SYSTEM */
	// bind nav clicks to the approrpriate handlers...
	$("div.headlineComponent").delegate("#blogView .button.page.active", "click", function(event)
	{
		var metaData = $(this).attr('id').split("|");
		$.ajax({
			url: "/dpComponent/headlines/stepBlogHeadlines",
			type: "post",
			data: "type=" + metaData[0] + "&typeId=" + metaData[1] + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&typeSubId=" + metaData[4],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
			//	if(!metaData[3]) {
			//		$("#ajxWndwTitle").html("Recent Posts");
			//	}
				$("#blogView").html(html);
				window.scrollTo(0,0);
			}
		});
	});
	
	$("div.headlineComponent").delegate("#blogView .button.step.active", "click", function(event)
	{
		var metaData = $(this).attr('id').split("|");
		$.ajax({
			url: "/dpComponent/headlines/stepBlogHeadlines",
			type: "post",
			data: "type=" + metaData[0] + "&typeId=" + metaData[1] + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&typeSubId=" + metaData[4],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#blogView").html(html);
				window.scrollTo(0,0);
			}
		});
	});
	
	/* START --> POSTS NAVIGATION SYSTEM */
	// bind nav clicks to the approrpriate handlers...
	$("div.headlineComponent").delegate("#headlineSearch .button.page.active", "click", function(event)
	{
		var metaData = $(this).attr('id').split("|");
		$.ajax({
			url: "/dpComponent/headlines/stepListHeadlines",
			type: "post",
			data: "type=" + metaData[0] + "&typeId=" + metaData[1] + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&typeSubId=" + metaData[4],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				if(!metaData[3]) {
					$("#ajxWndwTitle").html("Recent Posts");
				}
				$("#ajxWndw").html(html);
			}
		});
	});
	
	$("div.headlineComponent").delegate("#headlineSearch .button.step.active", "click", function(event)
	{
		var metaData = $(this).attr('id').split("|");
		$.ajax({
			url: "/dpComponent/headlines/stepListHeadlines",
			type: "post",
			data: "type=" + metaData[0] + "&typeId=" + metaData[1] + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&typeSubId=" + metaData[4],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#ajxWndw").html(html);
			}
		});
	});
	
	$("#headlineSearchSubmit").click(function() {
	
		// the resulting form, will need to know what type of search we are doing...
		// what channel, publisher or tag...
		var searchType = $("#headlineSearchType").val();
		var searchTypeId = $("#headlineSearchTypeId").val();
		var searchTypeSubId = $("#headlineSearchTypeSubId").val();
		var textfield = $("#headlineSearchQuery").val();
		//alert('type: ' + searchType + ' | type id: ' + searchTypeId + ' | query: ' + textfield);
		
		
		// now, we need to run the ajax query, and output the results to the page...
		$.ajax({
			url: "/dpComponent/headlines/searchHeadlines",
			type: "post",
			data: "type=" + searchType + "&typeId=" + searchTypeId + "&q=" + textfield + "&typeSubId=" + searchTypeSubId,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#ajxWndw").html(html);
				$("#ajxWndwTitle").html("Search Results");
			}
		});
		
		
	});
	/* END --> POSTS NAVIGATION SYSTEM */
	
	
	
	/* START --> VIDEO NAVIGATION SYSTEM */
	// bind nav clicks to the approrpriate handlers...
	$("div.videoComponent").delegate("#videoSearch .button.page.active", "click", function(event)
	{
		var metaData = $(this).attr('id').split("|");
		$.ajax({
			url: "/dpComponent/videoManager/stepListVideos",
			type: "post",
			data: "type=" + metaData[0] + "&typeId=" + metaData[1] + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&typeSubId=" + metaData[4],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				if(!metaData[3]) {
					$("#ajxWndwTitle").html("Recent Posts");
				}
				$("#ajxWndw").html(html);
			}
		});
	});
	
	$("div.videoComponent").delegate("#videoSearch .button.step.active", "click", function(event)
	{
		var metaData = $(this).attr('id').split("|");
		$.ajax({
			url: "/dpComponent/videoManager/stepListVideos",
			type: "post",
			data: "type=" + metaData[0] + "&typeId=" + metaData[1] + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&typeSubId=" + metaData[4],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#ajxWndw").html(html);
			}
		});
	});
	
	$("#videoSearchSubmit").click(function() {
	
		// the resulting form, will need to know what type of search we are doing...
		// what channel, publisher or tag...
		var searchType = $("#videoSearchType").val();
		var searchTypeId = $("#videoSearchTypeId").val();
		var searchTypeSubId = $("#videoSearchTypeSubId").val();
		var textfield = $("#videoSearchQuery").val();
		//alert('type: ' + searchType + ' | type id: ' + searchTypeId + ' | query: ' + textfield);
		
		
		// now, we need to run the ajax query, and output the results to the page...
		$.ajax({
			url: "/dpComponent/videoManager/searchVideos",
			type: "post",
			data: "type=" + searchType + "&typeId=" + searchTypeId + "&q=" + textfield + "&typeSubId=" + searchTypeSubId,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#ajxWndw").html(html);
				$("#ajxWndwTitle").html("Search Results");
			}
		});
		
		
	});
	/* END --> VIDEO NAVIGATION SYSTEM */

	
	
	
	
		
	// NOT SURE ON THIS ONE...
	// this is relevant to the tools only...
	// should be placed in the #toolAccordian loader
	// although it would have to run multiple times... LOOK INTO IT...
	// create new content/geo tag...
	$("#tools").delegate("#toolAccordian .addNewTag", "click", function(event)
	{
		var metaData = $(this).attr('id').split("|");
		var tagToAdd = "";
		if(metaData[1] == "geo") {
			tagToAdd = $("input#geoTagSearch").val();
		} else {
			tagToAdd = $("input#tagSearch").val();
		}
		overlayURL = "/dpComponent/channel/toolsAddNewTag?id=" + metaData[0] + "&type=" + metaData[1] + "&tag=" + encodeURIComponent(tagToAdd) + "&loc=" + metaData[2];
		var overlayAPI = $("#toolsOverlay").data("overlay");
		overlayAPI.load();
		return false;
	});
	
	$(".overlayNav").delegate("#photoAccordian .addNewTag", "click", function(event)
	{
		var metaData = $(this).attr('id').split("|");
		var tagToAdd = "";
		if(metaData[1] == "geo") {
			tagToAdd = $("input#geoTagSearch").val();
		} else {
			tagToAdd = $("input#tagSearch").val();
		}
		overlayURL = "/dpComponent/channel/toolsAddNewTag?id=" + metaData[0] + "&type=" + metaData[1] + "&tag=" + encodeURIComponent(tagToAdd) + "&loc=" + metaData[2];
		var overlayAPI = $("#toolsOverlay").data("overlay");
		overlayAPI.load();
		return false;
	});
	
		// we'll need a second one of these, to do the contributor section...
	$("#searchpanes").scrollable().navigator({
		navi: "#searchtabs",
		navItem: "a",
		activeClass: "current",
		history: false
	});

	// DEFAULT LAYOUT... HEADLINE SCROLL
	// --------------------------------------------------------------
	if($("#headlinesScroll").length) {
		// configure scroll...
		$("#headlinesScroll").scrollable({
			easing: "swing",
			vertical: true,
			mousewheel: false,
			speed: 1500,
			circular: false,
			next: ".headlineNext",
			prev: ".headlinePrev"
		});
		// let's make sure the NEXT button is turned on...
		$("div.headlineNext").removeClass('disabled');
	}

	// ACCESS USER MANAGEMENT TOOLS...
	$("#tools").delegate("#toolsPublisher #currentAuthor", "click", function(event)
	{
		// define the overlay to use...
		overlayURL = "/dpComponent/user/toolsCurrentAuthor";
		var overlayAPI = $("#toolsOverlay").data("overlay");
		var overlayUserScope = "";
		var userId = "";
		
		// determine initial scope...
		if($(this).hasClass("admin")) {
			overlayUserScope = "admin";
			userId = $(this).attr("class").replace("item_detail admin ","");
			
		} else if($(this).hasClass("trusted")) {
			overlayUserScope = "trusted";
			userId = $(this).attr("class").replace("item_detail trusted ","");
			
		} else {
			overlayUserScope = "standard";
			userId = $(this).attr("class").replace("item_detail ","");
		}
		
		$("#toolsOverlay").bind("onLoad", function() {
			// display the user list...
			displayUsers(overlayUserScope,userId);
			
			// configure navigation button clicks...
			$("#overlayTopNav .toolsButton").click(function() {
				var toolId = $(this).attr("id");
				displayUsers(toolId,"");
			});
			
			// unbind, so that it doesn't bunch up...
			$(this).unbind("onLoad");
		});
		overlayAPI.load();
		return false;
	});

	$("#tools").delegate("#changeAuthor","click",function() {
		$("#changeAuthor").addClass("hide");
		$("#changeAuthorForm").removeClass("hide");
	});

	$("#tools").delegate("#submitNewAuthor","click",function() {
		var newAuthor = $("#newAuthorName").val();
		var post = $("#postId").val();
		$.ajax({
			url: "/dpComponent/headlines/changeAuthorName",
			type: "post",
			data: "c=" + channel + "&s=" + subchannel + "&a=" + newAuthor + "&p=" + post,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},	
			success: function(html) {
				$("#changeAuthorForm").addClass("hide");
				$("#newAuthorName").val(html);
				$("#changeAuthor").html(html).removeClass("hide");
			}
		});
	});

	// OVERLAY CODE FOR TOOLS...
	// ----------------------------------------------------
	// SAME WITH THESE... THESE DO NOT NEED TO BE DELEGATED FOR THE ENTIRE SITE
	// ONLY ONCE THE TOOLS ARE ACTUALLY ACCESSED... NEEDS TO BE MOVED SOMEWHERE...
	
	// display manage tags page...
	// this stuff only needs to be run, when the overlay is loaded...
	// there might be a way to put all of this into an onLoad function
	// for the overlay...
	// that would make it much easier...
	$("#toolsOverlay").delegate(".overlayWrap #overlayManageTags", "click", function(event)
	{
		var type = $("#tagType").val();
		var post = $("#tagPost").val();
		$("#overlayTopNav div").removeClass("current");
		$("#overlayManageTags").addClass("current");
		$.ajax({
			url: "/dpComponent/channel/toolsManageTags",
			type: "post",
			data: "c=" + channel + "&s=" + subchannel + "&z=" + type + "&p=" + post,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},	
			success: function(html) {
				$("#overlayWindow").html(html);
			}
		});
	});
	
	$("#toolsOverlay").delegate(".overlayWrap #overlayContributorsCreate", "click", function(event)
	{
		//alert('works');
		var post = $("#postId").val();
		//alert("post: " + post);
		
		$("#overlayTopNav div").removeClass("current");
		$("#overlayContributorsCreate").addClass("current");
		
		$.ajax({
			url: "/dpComponent/channel/createContributorForm",
			type: "post",
			data: "c=" + channel + "&s=" + subchannel + "&p=" + post,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},	
			success: function(html) {
				$("#overlayWindow").html(html);
			}
		});
		
	});
	
	$("#toolsOverlay").delegate(".overlayWrap #overlayContributorsManage", "click", function(event)
	{
		//alert('works');
		var post = $("#postId").val();
		alert("post: " + post);
		
		$("#overlayTopNav div").removeClass("current");
		$("#overlayContributorsManage").addClass("current");
		
		$.ajax({
			url: "/dpComponent/headlines/toolsDisplayCurrentPublishers",
			type: "post",
			data: "c=" + channel + "&s=" + subchannel + "&p=" + post,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},	
			success: function(html) {
				$("#overlayWindow").html(html);
			}
		});
		
	});
	
	$("#toolsOverlay").delegate(".overlayWrap #overlayCreateTags", "click", function(event)
	{
		//alert('works');
		var type = $("#tagType").val();
		var post = $("#tagPost").val();
		$("#overlayTopNav div").removeClass("current");
		$("#overlayCreateTags").addClass("current");
		$.ajax({
			url: "/dpComponent/channel/toolsRealoadNewTagForm",
			type: "post",
			data: "c=" + channel + "&s=" + subchannel + "&z=" + type + "&p=" + post,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},	
			success: function(html) {
				$("#overlayWindow").html(html);
			}
		});
	});
	
	// OVERLAY SCROLL DIV CLICK
	// this function works in the tags & publishers overlays of the tools.
	// when a user clicks on the tag/contributor name, their info is
	// loaded into the window at the top of the overlay...
	// -----------------------------------------------------
	$("#toolsOverlay").delegate(".overlayWrap #overlayScroll div", "click", function(event)
	{
		var tagId = $(this).attr("id");
		var method = "";
		var success = "";
		if($(this).hasClass("publisher")) {
			method = "/dpComponent/channel/toolsReviewContributors";
			success = "contributorEditInPlace";
		} else if($(this).hasClass("tag")) {
			method = "/dpComponent/channel/toolsPreviewTags";
			success = "tagEditInPlace";
		}
		if(method) {
			$("#overlayScroll div").removeClass("on");
			$(this).addClass("on");
			$.ajax({
				url: method,
				type: "post",
				data: "c=" + channel + "&s=" + subchannel + "&id=" + tagId,
		//		beforeSend: function() {
		//			$("#contentLoading").removeClass("hide");
		//		},	
				success: function(html) {
					$("#itemDetail").html(html);
					eval(success + '()');
				}
			});
		}
	});
	
	// tag creation...
	// needs to work for both geo & standard tags...
	$("#toolsOverlay").delegate(".overlayWrap #createTag", "click", function(event)
	{
		var tagName = $("#tagName").val();
		var tagText = $("#tagText").val();
		var tagType = $("#tagType").val();
		var tagLoc = $("#tagLoc").val();
		var tagContent = '';
		
		if(tagName) {
			if($("#tagContent:checked")) {
				tagContent = $("#tagContent:checked").val();
			}
			
			$.ajax({
				url: "/dpComponent/channel/toolsCreateTag",
				type: "post",
				data: "tagName=" + tagName + "&tagText=" + tagText + "&tagType=" + tagType + "&tagContent=" + tagContent + "&tagLoc=" + tagLoc,
		//		beforeSend: function() {
		//			$("#contentLoading").removeClass("hide");
		//		},
				success: function(html) {
					var tagName = $("#tagName").val();
					var tagType = $("#tagType").val();
					if($("#tagContent:checked")) {
						switch(tagType) {
							case "geo":
								$("#geoTagData").html(html);
								$("#geoTagSearch").val('');
								break;
							default:
								$("#storyTagData").html(html);
								$("#tagSearch").val('');		
						}
					}
					var overlayAPI = $("#toolsOverlay").data("overlay");
					if(overlayAPI.isOpened()) {
						overlayAPI.close();
					}
				}
			});
		}
	});
	
	// contributor creation...
	$("#toolsOverlay").delegate(".overlayWrap #createContributor", "click", function(event) 
	{
		//alert('works');
		// step one, get the necessary data...
		// postId, is the only one that matters...
		
		var contributorName = $("#contributorName").val();
		var assignContributor = "";
		
		if(contributorName) {
			if($("#assignContributor:checked")) {
				assignContributor = $("#assignContributor:checked").val();
			}
			
			$.ajax({
				url: "/dpComponent/channel/toolsCreateContributor",
				type: "post",
				data: "name=" + contributorName + "&assignPost=" + assignContributor,
		//		beforeSend: function() {
		//			$("#contentLoading").removeClass("hide");
		//		},
				success: function(html) {
					// we'll have to return the id# in the html...
					$("#overlayTopNav div").removeClass("current");
					$("#overlayContributorsManage").addClass("current");
					$("#overlayWindow").html(html);
					
					var newContributorId = $("#newContributorId").val();
					
					if(newContributorId) {
						$("#"+newContributorId).addClass("on");
						$.ajax({
							url: "/dpComponent/channel/toolsReviewContributors",
							type: "post",
							data: "c=" + channel + "&s=" + subchannel + "&id=" + newContributorId,
					//		beforeSend: function() {
					//			$("#contentLoading").removeClass("hide");
					//		},	
							success: function(html) {
								$("#itemDetail").html(html);
								var scrollPos = $("#"+newContributorId).position();
								//alert("id: " + contributorId + " | pos: " + Math.round(scrollPos.top));
								$("#overlayScroll").scrollTop(Math.round(scrollPos.top));
								// enable the contributor options...
								contributorEditInPlace();
							}
						});
					}
				}
			});
		}
		
	});
	
	// admin HEADLINE SELECT option
	/*
	$("#toolsOverlay").delegate(".overlayWrap .anAdmin", "click", function(event) 
	{
		var adminId = $(this).attr('id').replace("admin_","");
		var postId = $("#postId").val();
		var postType = $("#postType").val();
		$.ajax({
			url: "/dpComponent/" + postType + "/updateAuthor",
			type: "post",
			data: "id=" + postId + "&adm=" + adminId + "&postType=" + postType,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},	
			success: function(html) {
				$("#currentAuthor").html(html);
				var overlayAPI = $("#toolsOverlay").data("overlay");
				if(overlayAPI.isOpened()) {
					overlayAPI.close();
				}
			}
		});
	});
	*/
	
	// admin HEADLINE SELECT option
	$("#toolsOverlay").delegate(".overlayWrap .photoAdmin", "click", function(event)
	{
		var adminId = $(this).attr('id').replace("admin_","");
		var mediaId = $("#thumbId").val();
		
		//alert('works || admin: ' + adminId + ' || photo: ' + mediaId);
		
		$.ajax({
			url: "/dpComponent/images/updateAuthor",
			type: "post",
			data: "id=" + mediaId + "&adm=" + adminId,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},	
			success: function(html) {
				$("#currentAuthor").html(html);
				var overlayAPI = $("#toolsOverlay").data("overlay");
				if(overlayAPI.isOpened()) {
					overlayAPI.close();
				}
			}
		});
		
	});
	
	// SELECT A NEW PUBLISHER (click)
	// this is an overlay tool...
	$("#tools").delegate("#toolsPublisher #currentPublisher", "click", function(event) 
	{
		overlayURL = "/dpComponent/headlines/toolsCurrentPublisher";
		var overlayAPI = $("#toolsOverlay").data("overlay");
		var contributorId = $("#contributorId").val();
		
		// you already figured out how to do it...
		// -----------------------------------------------
		$("#toolsOverlay").bind("onLoad", function() {
			if(contributorId) {
				$("#"+contributorId).addClass("on");
				$.ajax({
					url: "/dpComponent/channel/toolsReviewContributors",
					type: "post",
					data: "c=" + channel + "&s=" + subchannel + "&id=" + contributorId,
			//		beforeSend: function() {
			//			$("#contentLoading").removeClass("hide");
			//		},	
					success: function(html) {
						$("#itemDetail").html(html);
						var scrollPos = $("#"+contributorId).position();
						//alert("id: " + contributorId + " | pos: " + Math.round(scrollPos.top));
						$("#overlayScroll").scrollTop(Math.round(scrollPos.top));
	
						// enable the contributor options...
						contributorEditInPlace();
					}
				});
			}
			
			// unbind, so that it doesn't bunch up...
			$(this).unbind("onLoad");
		});
		overlayAPI.load();
		
		return false;
	});
	
	

	// jQuery for the Comments Section...
	// ---------------------------------------------------------------------------------------------
	// START -->
	$(".comment div.options div.option.loadComments.empty").live("click", function() {
		var commentID = $(this).parent().parent().parent().attr('id').replace("comment_","");
		var storyID = $("div.commentsList").attr('id').replace("comments_","").replace("_more","");
		var numChildren = $(this).attr('id').replace(commentID+"_","");
		
		
		$(this).removeClass("empty").addClass("cache").addClass("on");
		//$("#comment_"+commentID+"_more").show();
		$.ajax({
			url: "/dpComponent/comments/ajaxLoadComments",
			type: "post",
			data: "story=" + storyID + "&parent=" + commentID + "&haskids=" + numChildren,
			success: function(html) {
				$("#comment_"+commentID+"_more").html(html).show("blind", {direction: "vertical"}, 500);
			}
		});
	});	// initial load of replys...
	$(".comment div.options div.option.loadComments.cache.on").live("click", function() {
		var commentID = $(this).parent().parent().parent().attr('id').replace("comment_","");
		$(this).removeClass("on").addClass("off");
		$("#comment_"+commentID+"_more").hide("blind", {direction: "vertical"}, 250);
	}); // click to close replies...
	$(".comment div.options div.option.loadComments.cache.off").live("click", function() {
		var commentID = $(this).parent().parent().parent().attr('id').replace("comment_","");
		$(this).removeClass("off").addClass("on");
		$("#comment_"+commentID+"_more").show("blind", {direction: "vertical"}, 500);
	}); // click to load cached replies...
	$(".comment div.options div.option.replyToComment.off").live("click", function() {
	
		// i need some way to determine if they are a guest or not...
		// i don't really want to do it on every reply link...
		// it would be easiest to put it in comments_list...
		
		
		var commentID = $(this).parent().parent().parent().attr('id').replace("comment_","");
		var storyID = $("div.commentsList").attr('id').replace("comments_","").replace("_more","");
		var numChildren = $(this).attr('id').replace("comment_"+commentID+"_reply_","");
		var commentsLoaded = true;	// set as true by default...
		
		if($("div.commentsList").hasClass("gst")) {
			
			// load login window...
			overlayURL = "/dpComponent/user/accessInterface/";
			var overlayAPI = $("#userOverlay").overlay();
			overlayAPI.load();
			return false;
			
		} else {
		
			// now, we need to determine if this thing is EMPTY or not...
			if($("#comment_" + commentID + "_replies").hasClass("empty")) {
				commentsLoaded = false;
			}
			// turn ALL buttons off...
			$("div.commentsList div.replyToComment.on").removeClass("on").addClass("off");
			// turn THIS button on...
			$(this).removeClass("off").addClass("on");
			
			// hide all visible form areas...
			$("div.commentsList div.replyComments.on").hide("blind", {direction: "vertical"}, 500);
			$("div.commentsList div.replyComments.on").removeClass("on").addClass("off");	// remove ON notifier from existing forms
			$("#comment_"+commentID+"_reply_form").removeClass("off").addClass("on");	// add ON notifier to the requested form
			$("#comment_"+commentID+"_reply_form").show("blind", {direction: "vertical"}, 500); // show the form for the requested comment...
			
			// remove the class from any of the comments...
			$("div.commentsList div.comment.reply").removeClass("reply");
			
			// add the class to the comment wrap...
			$("#comment_"+commentID).addClass("reply");
			
			// hide the primary add form...
			$("div#commentsCollect_").hide();
			
			// show the existing replies...
			// ------------------------------------------------------------------------------------------
			if(!commentsLoaded) {
				$("#comment_" + commentID + "_replies").removeClass("empty").addClass("cache").addClass("on");
				//$("#comment_"+commentID+"_more").show();
				$.ajax({
					url: "/dpComponent/comments/ajaxLoadComments",
					type: "post",
					data: "story=" + storyID + "&parent=" + commentID + "&haskids=" + numChildren,
					success: function(html) {
						$("#comment_"+commentID+"_more").html(html).show("blind", {direction: "vertical"}, 500);
					}
				});
			}
		}
	}); // reply to button...
	$(".comment div.options div.option.replyToComment.on").live("click", function() {
		var commentID = $(this).parent().parent().parent().attr('id').replace("comment_","");
		var storyID = $("div.commentsList").attr('id').replace("comments_","").replace("_more","");
		$(this).removeClass("on").addClass("off");
		$("#comment_"+commentID).removeClass("reply");
		$("#comment_"+commentID+"_reply_form").removeClass("on").addClass("off");
		$("#comment_"+commentID+"_reply_form").hide("blind", {direction: "vertical"}, 300);
		$("div#commentsCollect_").show("blind", {direction: "vertical"}, 300);
	}); // close reply to box...
	$(".comment div.options div.option.reportAbuse").live("click", function() {
		var commentId = $(this).parent().parent().parent().attr('id').replace("comment_","");
		//alert("damn abusive! " + commentId);
		if($("div.commentsList").hasClass("gst")) {
			
			// load login window...
			overlayURL = "/dpComponent/user/accessInterface/";
			var overlayAPI = $("#userOverlay").overlay();
			overlayAPI.load();
			return false;
			
		} else {
		
			$.ajax({
				url: "/dpComponent/comments/ajaxReportAbuse",
				type: "post",
				data: "comment=" + commentId,
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					// here, we need to hide the comment from the user...
					//alert("reported as abusive!");
					$("#currentStatus").html(html);
					$("#contentLoading").addClass("hide");
					
					// here, we want to hide the comment, and display the "abusive" link...
					$("#commentDetail_"+commentId).hide();
					$("#abuseNotify_"+commentId).show();
					
					// here, we could change the values of the date fields
					// if necessary...
					// for instance, the publish option always increments the archive date...
				}
			});
		}
	});
	$(".comment div.abuseNotify a").live("click", function() {
		var commentId = $(this).parent().attr('id').replace("abuseNotify_","");
		//alert('this works!' + commentId);
		$("#commentDetail_"+commentId).show();
		$("#abuseNotify_"+commentId).hide();
		return false;	
	});
	$("div.commentsSubmit").live("click", function() {
		// step one, we need to get the storyID, parentID, and the value of the comment...
		var commentID = $(this).attr("id").replace("commentsSubmit_","");
		var storyID = $("form#commentsForm_"+commentID+" input#story").val();
		var parentID = $("form#commentsForm_"+commentID+" input#parent").val();
		var comments = $("form#commentsForm_"+commentID+" textarea#commentsText").val();
		$.ajax({
			url: "/dpComponent/comments/ajaxSaveComments",
			type: "post",
			data: "story="+storyID+"&parent="+parentID+"&comment="+commentID+"&text="+comments,
			success: function(html) {
				if(parentID) {
					
					if($("#comment_"+parentID+"_replies").length) {	// replies already exist.  append this one to them...
						// append content.
						$("#comment_"+parentID+"_more").append(html).effect("highlight",3000);
					} else {
						// replace content.
						$("#comment_"+parentID+"_more").html(html).effect("highlight",3000);
					}
					
					$("#comment_"+commentID+"_reply_form").removeClass("on").addClass("off");
					$("#comment_"+commentID+"_reply_form").hide("blind", {direction: "vertical"}, 300);
					
					// replyToComment.on -- replyToComment.off
					$("div.commentsList div.replyToComment.on").removeClass("on").addClass("off");
					$("div.commentsList div.comment.reply").removeClass("reply");
				} else {
					// works great!
					$("#commentsCollect_").before(html).effect("highlight",3000);
				}
				
				//alert("comment: "+commentID+" | story: "+storyID+" | parent: "+parentID+" | comments: "+comments);
				//$("#commentsCollect_"+commentID).hide("blind", {direction: "vertical"}, 500);
				$("form#commentsForm_"+commentID+" textarea#commentsText").val("");
			}
		});
	}); // submit comments...
	// <-- END
	// ---------------------------------------------------------------------------------------------
	
	
	// we need the ldrBrd event delegation here...
	// each of these is a button, that will do a specific thing...
	$("#ldrBrd").delegate("div.user div.button", "click", function(event)
	{
		
		var action = $(this).attr('id');
		switch(action) {
			case "ldr_login":
				// load login window...
				overlayURL = "/dpComponent/user/loginInterface/";
				var overlayAPI = $("#userOverlay").data("overlay");
				overlayAPI.load();
				return false;
				break;
				
			case "ldr_join":
				// load login window...
				overlayURL = "/dpComponent/user/joinInterface/";
				var overlayAPI = $("#userOverlay").data("overlay");
				overlayAPI.load();
				return false;
				break;
				
			case "ldr_info":
				// load login window...
				overlayURL = "/dpComponent/user/infoInterface/";
				var overlayAPI = $("#userOverlay").data("overlay");
				overlayAPI.load();
				return false;
				break;
				
			case "ldr_logout":
				$.ajax({
					url: "/dpComponent/user/ajaxLogout",
					type: "post",
					success: function(html) {
						window.location.reload();
					}
				});
				return false;
				break;
				
			case "user_customize":
			
				break;
				
			case "user_profile":
				
				break;
		}
	});
	
	$("#guestCommentsBox").live("click", function() {
		overlayURL = "/dpComponent/user/accessInterface/";
		var overlayAPI = $("#userOverlay").overlay();
		overlayAPI.load();
		return false;
	});
	
	// jQuery for the ranking component...
	// ---------------------------------------------------------------------------------------------
	// START -->
	
	// classifieds ON clicks...
	$("#classifiedsComponent").delegate("#ajxWndw .classified .profile .showDetail", "click", function() {
		var classId = $(this).parent().parent().attr("id").replace("classified_","");
		if($(this).hasClass("delete")) {
			// DELETE CLASSIFIED AD...
			var answer = confirm("Are you sure you want to delete tihs classified?  This cannot be undone.");
			if(answer) {
				$.ajax({
					url: "/dpComponent/classifiedsManager/userDeleteAd",
					type: "post",
					data: "id=" + classId,
			//		beforeSend: function() {
			//			$("#contentLoading").removeClass("hide");
			//		},	
					success: function(html) {
						//$("#contentLoading").addClass("hide");
						$("#classified_"+classId).remove();
					}
				});
			}
		} else if($(this).hasClass("edit")) {
			// EDIT CLASSIFIED AD...
			alert('edit this ad...' + classId);
		} else {
			// CLOSE ENHANCED CLASSIFIED AD...
			$("#ajxWndw .classified").removeClass("on");
			// adjust the dom as necessary...
			$(this).parent().parent().children(".detail").hide();
			$("#ajxWndw .classified").children(".profile").children(".showDetail").addClass("hide");
			$("#ajxWndw .classified").children(".profile").children(".textNotice").addClass("hide");
		}
	});
	
	// classifieds OFF clicks...
	$("#classifiedsComponent").delegate("#ajxWndw .classified:not(div.on)","mouseenter", function() {
		$(this).addClass("hilite");
		$(this).children(".profile").children(".textNotice").removeClass("hide");

	}).delegate("#ajxWndw .classified:not(div.on)","mouseleave",function() {
		$(this).removeClass("hilite");
		$(this).children(".profile").children(".textNotice").addClass("hide");
		
	}).delegate("#ajxWndw .classified:not(div.on)","click",function(e) {
	
		var classId = $(this).attr("id").replace("classified_","");
		var theClass = $(this);
			
		// turn off the previous classified...
		$("#ajxWndw .classified").removeClass("on").removeClass("hilite");
			
		// turn on this classified...
		$(this).addClass("on");

		// hide all existing detail screens...
		$("#ajxWndw .classified").children(".detail").hide();
		$("#ajxWndw .classified").children(".profile").children(".showDetail").addClass("hide");
		$("#ajxWndw .classified").children(".profile").children(".textNotice").addClass("hide");
			
		$(this).children(".profile").children(".showDetail").removeClass('hide');

		// show this detail screen...
		$(this).children(".detail").show();
		
		// run ajax (only if empty...)
		if(theClass.children(".detail").is(":empty")) {
			$.ajax({
				url: "/dpComponent/classifiedsManager/displayClassifiedDetailAjax",
				type: "post",
				data: "id=" + classId,
				success: function(html) {
					theClass.children(".detail").html(html);
					if(theClass.children(".detail").children(".map").length) {
						var mapAddress = theClass.children(".detail").children(".map").html();
						theClass.children(".detail").children(".map").googleMap(mapAddress);
					}
				}
			});
		}
	});
	
	$("#contentRankDisplay div.star").click(function() {
		
		var selectedStar = $(this).attr("id").replace("s","");
		var storyID = $(this).parent().parent().parent().attr('id').replace("contentMatrix_","");
		
		if($(this).parent().hasClass("gst")) {
		
			// load login window...
			overlayURL = "/dpComponent/user/accessInterface/";
			var overlayAPI = $("#userOverlay").overlay();
			overlayAPI.load();
			return false;
			
		} else {
			$.ajax({
				url: "/dpComponent/channel/contentRankUpdate",
				type: "post",
				data: "cntid=" + storyID + "&rank=" + selectedStar,
				success: function(html) {
					$("#contentRank").html(html);
				}
			});
		}
	
	}).mouseenter(function(selectedStar) 
	{
		var selectedStar = $(this).attr("id").replace("s",""); // attribute id is sN
		var sText = $(this).html();
		if(sText) {
			$("#contentRankTextCurrent").hide();
			$("#contentRankText").html(sText);
			$("#contentRankText").show();
		}
		$(this).parent().addClass("so"+selectedStar);
		$("#sText").addClass("hover");
	}).mouseleave(function(selectedStar) 
	{
		var selectedStar = $(this).attr("id").replace("s","");
		$(this).parent().removeClass("so"+selectedStar);
		$("#contentRankText").html("").hide();
		$("#contentRankTextCurrent").show();
		$("#sText").removeClass("hover");
	});
	// <-- END
	// ---------------------------------------------------------------------------------------------
	
	
	
	// user overlay
	$("#userOverlay").delegate("div.overlayWrap a.ajx", "click", function(event) 
	{
		// load another page into the overlay...
		$.ajax({
			url: $(this).attr('href'),
			type: "get",
			//data: "email=" + email,
			success: function (html) {
				clearValidators();
				$("div.overlayWrap").html(html);
			}
		});
		return false;
	});
	
	$("#userOverlay").delegate("div.overlayWrap input#newUser","blur",function(event) 
	{
		var user = $(this).val();
		var form = $("form#joinForm");
		if(user) {
			$.ajax({
				url: "/dpComponent/user/checkUserName",
				type: "post",
				data: "newUser=" + user,
				dataType: "json",
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},	
				success: function(json) {
					$("#contentLoading").addClass("hide");
					if (json.success)  {
						// do nothing...
						if(form.data("validator")) {
							form.data("validator").destroy();
						}
					} else {
						if(!form.data("validator")) {
							form.validator();
						}
						form.data("validator").invalidate(json);
					}
				}
			});
		}
	});
	
	$("#userOverlay").delegate("div.overlayWrap input.button", "click", function(event) {
		var action = $(this).attr('id');
		switch(action) {
			case "user_login":
				$("form#loginForm").validator().submit(function(e) {
				
					//alert('working');
					// here, we want to remove any existing error message...
					if($("#login_intro").hasClass("overlayError")) {
						$("#login_intro").removeClass("overlayError").html("");
					}
					
					var form = $(this);
					if (!e.isDefaultPrevented()) {
						// passed client-side validation OK.
						var user = $("input[name=loginUser]", this).val();
						var pswd = $("input[name=loginPswd]", this).val();
						var setc = $("input[name=keepActive]", this).val();
						var encodedPswd = "";
						if(pswd) {
							encodedPswd = $.encoding.digests.hexSha1Str(pswd);
						}
						
						$("input#user_login").attr("disabled", true);
						
						
						
						$.ajax({
							url: "/dpComponent/user/ajaxLogin",
							type: "post",
							data: "loginUser=" + user + "&loginPswd=" + encodedPswd + "&keepActive=" + setc,
							dataType: "json",
							beforeSend: function() {
								//$("#contentLoading").removeClass("hide");
							},
						//	error: function(html) {
								// this is the error function here...
						//		alert(html);
						//	},
							success: function(json) {
								//$("#contentLoading").addClass("hide");
								if (json.success)  {
									$("#login_intro").addClass("overlayMatch").html(json.msg);
									window.location.reload();
								} else {
									// server-side validation failed.
									$("#login_intro").addClass("overlayError").html(json.server);
									$("#user_login").removeAttr("disabled");
									form.data("validator").invalidate(json);
									
								}
							}
						});
						// prevent the form from being submitted...
						e.preventDefault();
					}
				});
				break;
				
			case "user_create_account":
				$("form#joinForm").validator().submit(function(e) {
				
					var form = $(this);
					var pswd = $("input[name=newPswd]",this).val();
					var encodedPswd = "";
					if(pswd) {
						encodedPswd = $.encoding.digests.hexSha1Str(pswd);
					}
					
					if(!e.isDefaultPrevented()) {
						// client side validation passed!
						$("#user_create_account").attr("disabled", true);
						$.ajax({
							url: "/dpComponent/user/addUser",
							type: "post",
							data: "epswd="+encodedPswd+"&"+form.serialize(),
							dataType: "json",
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(json) {
								$("#contentLoading").addClass("hide");
								if (json.success)  {
									
									// server validation passed...
									// output the click wrap agreement...
									// -------------------------------------------------
									$("div.overlayWrap").html(json.html);
									var userID = $("div.overlayWrap div.userProfile").attr('id').replace("user_","");
									
									$("form#termsForm").validator().submit(function(e) {
										var terms = $(this);
										if(!e.isDefaultPrevented()) {
											var hasAccepted = $("input[name=terms_accepted]",this).val();
											$("#user_accept_terms").attr("disabled", true);
											$.ajax({
												url: "/dpComponent/user/acceptedTerms",
												type: "post",
												data: "id="+userID+"&"+terms.serialize(),
												dataType: "json",
												beforeSend: function() {
													$("#contentLoading").removeClass("hide");
												},
												success: function(json) {
													$("#contentLoading").addClass("hide");
													if(json.success) {
														$("div.overlayWrap").html(json.html);
														var userID = $("div.overlayWrap div.userProfile").attr('id').replace("user_","");
														$("#fileInput").uploadify({
															"uploader" : "/images/uploadify.swf",
															"script" : "/dpComponent/user/uploadAvatar",
															"fileExt" : "*.png;*.gif;*.jpg;*.jpeg;",
															"cancelImg" : "/images/cancel.png",
															"scriptData" : {"uid": userID},
															"auto" : true,
															"scriptAccess" : "always",
															"folder" : "/images/avatars",
															"onComplete" : function() {
																$.ajax({
																	url: "/dpComponent/user/displayAvatar",
																	type: "post",
																	data: "uid="+userID,
																	success: function (html) {
																		$("#userAvatar").html(html);
																	}
																});
																$("#avatarSelection").hide();
																$("#avatarSelected").show();
															}
														});
														$("#goWelcome a").click(function() {
															window.location.reload();
															return false;
														});
														$(".avatarWrap img").click(function() {
															var filename = $(this).attr('src').replace("/images/avatars/","");
															$.ajax({
																url: "/dpComponent/user/assignAvatar",
																type: "post",
																data: "uid="+userID+"&fn="+filename,
																success: function (html) {
																	$("#userAvatar").html(html);
																	$("#avatarSelection").hide();
																	$("#avatarSelected").show();
																}
															});
														});
													} else {
														$("#login_message").html(json.server);
														$("#user_accept_terms").removeAttr("disabled");
														terms.data("validator").invalidate(json);
													}
												}
											});
											e.preventDefault();
										}
									});
								} else {
									// server-side validation failed.
									$("#stepIntro").html(json.server);
									$("#user_create_account").removeAttr("disabled");
									form.data("validator").invalidate(json);
								}
							}
						});
						e.preventDefault();
					}
				});
				break;
		}
	});
	
	// Print Button
	// ---------------------------------------------------------------------------------------------
	$("div.printButton").click(function() {
		window.open( $(this).parent().attr('href') );
		return false;
	});
	
	
	// uploads a photo...  NOT NEEDED?
	// --------------------------------------------------------------------------------------------
	$("#uploadPhotoButton").click(function() {
		
		// 1) hide photo upload button...
		$("#libraryOptions").hide();
		$("#libraryBrowse").hide();
		$("#mediaSearch").hide();
		//var ckFuncNum = $("#ckFuncNum").val();
		
		// 2) load & show photo upload system...
		$.ajax({
			url: "/dpComponent/images/displayPhotoUploader",
			type: "post",
			//data: "CKEditorFuncNum="+ckFuncNum,
			success: function (html) {
			
				var ckFuncNum = $("#ckFuncNum").val();
				var contributorId = $("#naPublisher", window.opener.document).val();
				if(!contributorId) {
					contributorId = $("#contributorId").val();
				}
				var postId = $("#postId").val();
				var seskey = document.cookie.split(';');
				var tempkey = "";
				var cookieName = "";
				var seskeyVal = "";
				for(i=0; i< seskey.length; i++) {
					tempKey = seskey[i].split("=");
					cookieName = tempKey[0].replace(/^\s+|\s+$/g, "");
					if(cookieName == "seskey") {
						seskeyVal = unescape(tempKey[1].replace(/^\s+|\s+$/g, ""));
					}
				}
				// hide list of images...
				$("#imageList").hide();
				
				// show upload list...(LEFT SIDE OF OVERLAY)
				$("#imageUploadList").show();
				
				// show photo upload manager...(RIGHT SIDE OF OVERLAY)
				$("#uploadPhotoManager").html(html).show();
				
				// configure the upload button...
				$("#uploadPhotos").uploadify({
					"uploader" : "/images/uploadify.swf",
					"script" : "/dpComponent/images/toolsUploadPhotos",
					"fileExt" : "*.png;*.gif;*.jpg;*.jpeg;",
					"fileDesc" : "put a description here",
					"cancelImg" : "/images/cancel.png",
					"scriptData" : {"channel": channel, "subChannel": subchannel, "CKEditorFuncNum": ckFuncNum, "contributorId": contributorId, "postId": postId, "seskeyVal": seskeyVal},	// use for first auto placement? ...
					"multi" : false,
					"auto" : true,
					"scriptAccess" : "always",
					"folder" : "/media/"+dpclient+"/images",
					"onComplete" : function(event, queueID, fileObj, response, data) {
						
						// show the preview of the image...
						$("#imagePreview").html(response).show();
						$("#imageUploadList").hide();
						
						// hide the photo upload manager...
						$("#uploadPhotoManager").hide();
						
						// get values for uploaded file...
						var width = $("img#cropIt").attr("width");
						var height = $("img#cropIt").attr("height");
						var src = $("img#cropIt").attr("src");
						var ckFuncNum = $("img#cropIt").attr("alt");
						var postId = $("#postId").val();
						
						//alert('Contributor: ' + contributorId + ' || Post: ' + postId + ' || seskey: ' + seskeyVal);
						$("img#cropIt").attr("src",src).load(function() {
							$("#imagePreview").show();
						});
		
						
		
						// load and show photo accordian tools...
						// we need to pass along whether or not this is being run from the editor...
						$.ajax({
							url: "/dpComponent/images/displayPhotoAccordian",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&imgS=" + src + "&imgW=" + width + "&imgH=" + height + "&CKEditorFuncNum=" + ckFuncNum + "&postId=" + postId,
							success: function(html) {
								$("#photoAccordian").html(html).show();
								// attach the accordian functionality...
								$("#photoAccordian").tabs("#photoAccordian div.tier", {tabs: 'h2', effect: 'slide', initialIndex: null});
								
								// these ALL need to be grouped together
								// with the appropriate values passed via function...
								$("#tagSearch").autocomplete({
									source: "/dpComponent/channel/tagsJSON",
									minLength: 2,
									select: function(event, ui) {
										var imgId = $("img#cropIt").attr('src').replace("/media/"+dpclient+"/images/","").split(".");
										if(ui.item.id && imgId) {
											$.ajax({
												url: "/dpComponent/images/toolsAddTag",
												type: "post",
												data: "cid=" + channel + "&scid=" + subchannel + "&id=" + imgId[0] + "&tag=" + ui.item.id + "&type=" + ui.item.geo,
												beforeSend: function() {
													$("#contentLoading").removeClass("hide");
												},
												success: function(html) {
													$("#contentLoading").addClass("hide");
													$("#storyTagData").html(html);
													$("input#tagSearch").val('');
												}
											});
										}
									}
								}).blur(function() {
									if($(this).val() == "  ") {
										$(this).val('');
									}
								});
								
								// content geo-tag search...
								$("#geoTagSearch").autocomplete({
									source: "/dpComponent/channel/geoTagsJSON",
									minLength: 2,
									select: function(event, ui) {
										var imgId = $("img#cropIt").attr('src').replace("/media/"+dpclient+"/images/","").split(".");
										if(ui.item.id && imgId) {
											$.ajax({
												url: "/dpComponent/images/toolsAddTag",
												type: "post",
												data: "cid=" + channel + "&scid=" + subchannel + "&id=" + imgId[0] + "&tag=" + ui.item.id + "&type=" + ui.item.geo,
												beforeSend: function() {
													$("#contentLoading").removeClass("hide");
												},
												success: function(html) {
													$("#contentLoading").addClass("hide");
													$("#geoTagData").html(html);
													$("input#geoTagSearch").val('');
												}
											});
										}
									}
								}).blur(function() {
									if($(this).val() == "  ") {
										$(this).val('');
									}
								});
								
								$("#backToImageList").click(function() {
									$("#photoAccordian").hide().html("");
									$("#imageList").show();
									$("#libraryOptions").show();
									$("#libraryBrowse").show();
									
									$("#mediaSearch").show();
									$("#imagePreview").hide().html("");
								});
				
								$("#newPhotoThumb").click(function() {
									var largeImageSrc = $("#imgSrc").val();
									$("#currentThumbText").hide();
									$("#newThumbText").show();
									$("#thumbPreview").removeAttr("width").removeAttr("height").css({ width: "", height: ""});
									$("#thumbPreview").attr("src",largeImageSrc);
									$("#newPhotoThumb").hide();
									JcropAPI = $.Jcrop('img#cropIt',{ 
										onChange: showThumbPreview,
										onSelect: showThumbPreview,
										aspectRatio: 4/3,
										minSize: [100,75]
									});
									$("#createPhotoThumb").show();
								});
								
								// define functionality for create thumbnail button...
								$("#createPhotoThumb").click(function() {
									var xCoord = $("#thumbX").val();
									var yCoord = $("#thumbY").val();
									var thumbW = $("#thumbW").val();
									var thumbH = $("#thumbH").val();
									var thumbS = $("img#cropIt").attr("src");
													
									// resize the image based on user selectable area...
									$.ajax({
										url: "/dpComponent/images/toolsCreateThumbAjax",
										type: "post",
										data: "thumbX=" + xCoord + "&thumbY=" + yCoord + "&thumbW=" + thumbW + "&thumbH=" + thumbH + "&thumbS=" + thumbS,
										success: function(html) {
											//alert(html);
											JcropAPI.destroy();
											$("#newThumbText").hide();
											$("#createPhotoThumb").hide();
											$("#currentThumbText").show();
											$("#newPhotoThumb").show();
										}
									});
								});
							}
						});		
					}
				});
			}
		});
	});
	
	// set variable for jcrop API...
	var JcropAPI;

	// ALL OF THIS IMAGE LIBRARY STUFF COULD BE STORED IN A SEPARATE jQUERY FILE... YES!
	// photo search...
	$("#searchImageStatus,#searchImageDate,#searchImageTag,#searchImageGeoTag,#searchImagePublisher,#searchImageChannel").change(function() {
		var srchStatus = $("#searchImageStatus option:selected").val();
		var srchTag = $("#searchImageTag option:selected").val();
		var srchGeotag = $("#searchImageGeoTag option:selected").val();
		var srchDate = $("#searchImageDate option:selected").val();
		var srchChannel = $("#searchImageChannel option:selected").val();
		var srchPublisher = $("#searchImagePublisher option:selected").val();
		var ckFuncNum = $("#ckFuncNum").val();
		//alert("status: " + status + " || tag: " + tag + " || geotag: " + Geotag + " || date: " + date + " || place: " + place);
		$.ajax({
			url: "/dpComponent/images/toolsLibraryUpdateImageList",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&Sstatus=" + srchStatus + "&Stag=" + srchTag + "&Sgeotag=" + srchGeotag + "&Sdate=" + srchDate + "&Schannel=" + srchChannel + "&Spublisher=" + srchPublisher + "&CKEditorFuncNum=" + ckFuncNum,
		//	beforeSend: function() {
				
		//	},
			success: function(html) {
				$("#imageRows").html(html);
			}
		});
		
	});
	
	
	$(".overlayNav").delegate("#libraryBrowse #viewPhotoByContributor", "click", function(event) 
	{
		var postId = $("#postId").val();
		var contributor = $("#contributorId").val();
		var ckFuncNum = $("#ckFuncNum").val();
		var self = this;
		$.ajax({
			url: "/dpComponent/images/toolsLibraryUpdateImageList",
			type: "post",
			data: "postId=" + postId + "&contributorId=" + contributor + "&ovr=contributor&CKEditorFuncNum=" + ckFuncNum,
			success: function(html) {
				// we need to update the image list...
				$("#imageRows").html(html);
				$("#libraryBrowse div").removeClass("on");
				$(self).addClass("on");
			}
		});
	});
	
	
	$(".overlayNav").delegate("#libraryBrowse #viewPhotoByPost", "click", function(event) 
	{
		var postId = $("#postId").val();
		var contributor = $("#contributorId").val();
		var ckFuncNum = $("#ckFuncNum").val();
		//var contributor = "ugc";
		var self = this;
		$.ajax({
			url: "/dpComponent/images/toolsLibraryUpdateImageList",
			type: "post",
			data: "postId=" + postId + "&contributorId=" + contributor + "&ovr=post&CKEditorFuncNum=" + ckFuncNum,
			success: function(html) {
				// we need to update the image list...
				$("#imageRows").html(html);
				$("#libraryBrowse div").removeClass("on");
				$(self).addClass("on");
			}
		});
	});
	
	$(".overlayNav").delegate("#libraryBrowse #viewPhotoByUser", "click", function(event) 
	{
		var postId = $("#postId").val();
		var contributor = $("#contributorId").val();
		var ckFuncNum = $("#ckFuncNum").val();
		var self = this;
		$.ajax({
			url: "/dpComponent/images/toolsLibraryUpdateImageList",
			type: "post",
			data: "postId=" + postId + "&contributorId=" + contributor + "&ovr=user&CKEditorFuncNum=" + ckFuncNum,
			success: function(html) {
				// we need to update the image list...
				$("#imageRows").html(html);
				$("#libraryBrowse div").removeClass("on");
				$(self).addClass("on");
			}
		});
	});
	
	
	
	// delete photo...
	
	
	// assign photo thumbnail...
	// --------------------------------------------------------------------------------------------
	
	
	/* START --> PHOTO NAVIGATION SYSTEM */
	$("div#imageList").delegate(".listNav .button.page.active", "click", function(event) 
	{
		var metaData = $(this).attr('id').split("|");
		$.ajax({
			url: "/dpComponent/images/toolsLibraryUpdateImageList",
			type: "post",
			data: "Sstatus=" + metaData[0] + "&Stag=" + metaData[1] + "&Sgeotag=" + metaData[2] + "&Sdate=" + metaData[3] + "&Schannel=" + metaData[4] + "&Spublisher=" + metaData[5] + "&startpos=" + metaData[6] + "&CKEditorFuncNum=" + metaData[8] + "&ovr=" + metaData[9] + "&postId=" + metaData[10],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#imageRows").html(html);
			}
		});
	});
	
	$("div#imageList").delegate(".listNav .button.step.active", "click", function(event) 
	{
		var metaData = $(this).attr('id').split("|");
		$.ajax({
			url: "/dpComponent/images/toolsLibraryUpdateImageList",
			type: "post",
			data: "Sstatus=" + metaData[0] + "&Stag=" + metaData[1] + "&Sgeotag=" + metaData[2] + "&Sdate=" + metaData[3] + "&Schannel=" + metaData[4] + "&Spublisher=" + metaData[5] + "&startpos=" + metaData[6] + "&CKEditorFuncNum=" + metaData[8] + "&ovr=" + metaData[9] + "&postId=" + metaData[10],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#imageRows").html(html);
			}
		});
	});
	
	$("#photoSearchSubmit").click(function() {
	
		// the resulting form, will need to know what type of search we are doing...
		// what channel, publisher or tag...
		var searchType = $("#headlineSearchType").val();
		var searchTypeId = $("#headlineSearchTypeId").val();
		var searchTypeSubId = $("#headlineSearchTypeSubId").val();
		var textfield = $("#headlineSearchQuery").val();
		//alert('type: ' + searchType + ' | type id: ' + searchTypeId + ' | query: ' + textfield);
		
		
		// now, we need to run the ajax query, and output the results to the page...
		$.ajax({
			url: "/dpComponent/headlines/searchHeadlines",
			type: "post",
			data: "type=" + searchType + "&typeId=" + searchTypeId + "&q=" + textfield + "&typeSubId=" + searchTypeSubId,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#ajxWndw").html(html);
				$("#ajxWndwTitle").html("Search Results");
			}
		});
		
		
	});
	/* END --> PHOTO NAVIGATION SYSTEM */
	
	/*
	$(".overlayNav").delegate("#photoAccordian #addNewPlacement", "click", function(event) 
	{
		var placeToAdd = $("select#addPlacement").val();
		if(placeToAdd) {
			var matrixData = placeToAdd.split("|");
			$.ajax({
				url: "/dpComponent/images/toolsPlaceContent",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&imgId=" + matrixData[1] + "&component=" + matrixData[0],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					$("#storyMatrixData").html(html);
				}
			});
		}
	});
	
	$(".overlayNav").delegate("#photoAccordian .matrix_remove", "click", function(event) 
	{
		var placeToRemove = $(this).attr('id').split("_");
		if(placeToRemove) {
			$.ajax({
				url: "/dpComponent/images/deleteImageMatrixLink",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&id=" + placeToRemove[3] + "&channel=" + placeToRemove[1] + "&subChannel=" + placeToRemove[2],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					$("#storyMatrixData").html(html);
				}
			});
		}
	});
	*/
	
	$("#tools").delegate("#toolAccordian .matrix_setPrimary", "click", function(event) 
	{
		var placeToUpdate = $(this).attr('id').split("_");
		if(placeToUpdate) {
			$.ajax({
				url: "/dpComponent/headlines/setStoryMatrixPermaLink",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&id=" + placeToUpdate[3] + "&channel=" + placeToUpdate[1] + "&subChannel=" + placeToUpdate[2],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					$("#storyMatrixData").html(html);
				}
			});
		}
	});
	
	// remove content/geo tag...
	/*
	$(".overlayNav").delegate("#photoAccordian .tag_remove", "click", function(event) {
		var tagData = $(this).attr('id').split("_");
		$.ajax({
			url: "/dpComponent/images/removeTag",
			type: "post",
			data: "tagId=" + tagData[0] + "&postId=" + tagData[1],
//			beforeSend: function() {
//				$("#contentLoading").removeClass("hide");
//			},
			success: function(html) {
//				$("#contentLoading").addClass("hide");
				$("#"+html).parent().empty().remove();
			}
		});
	});
	
	
	$(".overlayNav").delegate("#toolsPublisher #currentAuthor", "click", function(event) {
		overlayURL = "/dpComponent/user/toolsPhotoAuthor";
		var overlayAPI = $("#toolsOverlay").data("overlay");
		overlayAPI.load();
		return false;
	});
	
	$(".overlayNav").delegate("#toolsPublisher #currentPublisher", "click", function(event) {
		overlayURL = "/dpComponent/headlines/toolsCurrentPublisher";
		var overlayAPI = $("#toolsOverlay").data("overlay");
		overlayAPI.load();
		return false;
	});
	*/
	
	
	// review photo (in overlay)
	/*
	$(".overlayWindow").delegate("#imageList img.libraryThumb", "click", function(event) {
		var imageId = $(this).attr("id");
		var src = $(this).attr("src").replace("_icon","");
		var width = $(this).attr("width");
		var height = $(this).attr("height");
		
		if($(this).hasClass("ckRequest")) {
			// we need to get the function number for this...
			// then, we can determine how to SEND this image back to the editor...
			var ckFuncNum = $(this).attr("class").replace("libraryThumb ckRequest ","");
		}
		
		var postId = $("#postId").val();
		
		$("#imageList").hide();
		$("#libraryOptions").hide();
		$("#libraryBrowse").hide();
		$("#mediaSearch").hide();
		
		$("#imagePreview").html("<div class='libraryReturn'><div id='backToImageList'>Back to Image list</div>IMAGE PREVIEW</div><img id='cropIt' src=''>");
		$("img#cropIt").attr("src",src).load(function() {
			$("#imagePreview").show();
		});
		
		$.ajax({
			url: "/dpComponent/images/displayPhotoAccordian",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&imgId=" + imageId + "&imgS=" + src + "&imgW=" + width + "&imgH=" + height + "&CKEditorFuncNum=" + ckFuncNum + "&postId=" + postId,
			success: function(html) {
				$("#photoAccordian").html(html).show();
				// attach the accordian functionality...
				$("#photoAccordian").tabs("#photoAccordian div.tier", {tabs: 'h2', effect: 'slide', initialIndex: null});
				
				$("#tagSearch").autocomplete({
					source: "/dpComponent/channel/tagsJSON",
					minLength: 2,
					select: function(event, ui) {
						var imgId = $("img#cropIt").attr('src').replace("/media/"+dpclient+"/images/","").split(".");
						if(ui.item.id && imgId) {
							$.ajax({
								url: "/dpComponent/images/toolsAddTag",
								type: "post",
								data: "cid=" + channel + "&scid=" + subchannel + "&id=" + imgId[0] + "&tag=" + ui.item.id + "&type=" + ui.item.geo,
								beforeSend: function() {
									$("#contentLoading").removeClass("hide");
								},
								success: function(html) {
									$("#contentLoading").addClass("hide");
									$("#storyTagData").html(html);
									$("input#tagSearch").val('');
								}
							});
						}
					}
				}).blur(function() {
					if($(this).val() == "  ") {
						$(this).val('');
					}
				});
				
				// content geo-tag search...
				$("#geoTagSearch").autocomplete({
					source: "/dpComponent/channel/geoTagsJSON",
					minLength: 2,
					select: function(event, ui) {
						var imgId = $("img#cropIt").attr('src').replace("/media/"+dpclient+"/images/","").split(".");
						if(ui.item.id && imgId) {
							$.ajax({
								url: "/dpComponent/images/toolsAddTag",
								type: "post",
								data: "cid=" + channel + "&scid=" + subchannel + "&id=" + imgId[0] + "&tag=" + ui.item.id + "&type=" + ui.item.geo,
								beforeSend: function() {
									$("#contentLoading").removeClass("hide");
								},
								success: function(html) {
									$("#contentLoading").addClass("hide");
									$("#geoTagData").html(html);
									$("input#geoTagSearch").val('');
								}
							});
						}
					}
				}).blur(function() {
					if($(this).val() == "  ") {
						$(this).val('');
					}
				});
								
								
				$("#backToImageList").click(function() {
					$("#photoAccordian").hide().html("");
					$("#imageList").show();
					$("#libraryOptions").show();
					$("#libraryBrowse").show();
					
					$("#mediaSearch").show();
					$("#imagePreview").hide().html("");
				});
				
				$("#newPhotoThumb").click(function() {
					var largeImageSrc = $("#imgSrc").val();
					$("#currentThumbText").hide();
					$("#newThumbText").show();
					$("#thumbPreview").removeAttr("width").removeAttr("height").css({ width: "", height: ""});
					$("#thumbPreview").attr("src",largeImageSrc);
					$("#newPhotoThumb").hide();
					JcropAPI = $.Jcrop('img#cropIt',{ 
						onChange: showThumbPreview,
						onSelect: showThumbPreview,
						aspectRatio: 4/3,
						minSize: [100,75]
					});
					$("#createPhotoThumb").show();
				});
				
				// define functionality for create thumbnail button...
				$("#createPhotoThumb").click(function() {
					var xCoord = $("#thumbX").val();
					var yCoord = $("#thumbY").val();
					var thumbW = $("#thumbW").val();
					var thumbH = $("#thumbH").val();
					var thumbS = $("img#cropIt").attr("src");
									
					// resize the image based on user selectable area...
					$.ajax({
						url: "/dpComponent/images/toolsCreateThumbAjax",
						type: "post",
						data: "thumbX=" + xCoord + "&thumbY=" + yCoord + "&thumbW=" + thumbW + "&thumbH=" + thumbH + "&thumbS=" + thumbS,
						success: function(html) {
							//alert(html);
							JcropAPI.destroy();
							$("#newThumbText").hide();
							$("#createPhotoThumb").hide();
							$("#currentThumbText").show();
							$("#newPhotoThumb").show();
						}
					});
				});
			}
		});
	});
	*/
	
	// index page top stories...
	if ($("#homeTopStory").length) {
		//alert('we have the ajax fade div available.  start the timer...');
		$("#homeFeatureScroll").scrollable({
			vertical: true,
			easing: "swing",
			speed: 1500,
			circular: true
		});
		featureInterval = setInterval('fadeTopStories("next")', 10000);
	}
	
});

// this scrolls forward...
function fadeTopStories(direction) {
	var homeScroll = $("#homeFeatureScroll").data("scrollable");
	var currentlyOn = $("#homeTopStory > div:visible").attr('id');
	var nextOn = $("#homeTopStory > div:visible").next().attr('id');
	var prevOn = $("#homeTopStory > div:visible").prev().attr('id');
	var firstPanel = $("#homeTopStory > div:first").attr('id');
	var lastPanel = $("#homeTopStory > div:last").attr('id');

	//alert("first: " + firstPanel + "|| last:" + lastPanel + " xx");
	if(currentlyOn == firstPanel) {
		prevOn = lastPanel;
	} else if(currentlyOn == lastPanel) {
		nextOn = firstPanel;
	}
	if(currentlyOn) {
		
		// fade out active story...
		$("#"+currentlyOn).fadeOut(1500,function() { /* optional callback function */ });
		
		if(direction=="prev") {
			homeScroll.next(1500);	/* we are inverting the default scroll direction of jQuery Tools Scrollable */
			$("#"+prevOn).fadeIn(1500,function() { /* optional callback */ });
		} else {
			homeScroll.prev(1500);
			$("#"+nextOn).fadeIn(1500,function() { /* optional callback */ });
		}
		
		// fade in the prev story...
	}
}

function showThumbPreview(coords) {
	var width = $("img#cropIt").attr("width");
	var height = $("img#cropIt").attr("height");
	
	if(parseInt(coords.w) > 0) {
		var rx = 100/coords.w;
		var ry = 75/coords.h;
		$("#thumbPreview").css({
			width: Math.round(rx*width) + 'px',
			height: Math.round(ry*height) + 'px',
			marginLeft: '-' + Math.round(rx * coords.x) + 'px',
			marginTop: '-' + Math.round(ry * coords.y) + 'px'
		});
		
		$('#thumbX').val(coords.x);
		$('#thumbY').val(coords.y);
		$('#thumbW').val(coords.w);
		$('#thumbH').val(coords.h);


	}
}

function contributorEditInPlace() {
	//alert('Contributor: outer function is running');
	
	$("#contributorDesc_text").click(function() {
		$(this).hide();
		$("#contributorDesc_edit").show();
		$("#contributorDesc_edit textarea").focus();
	});
					
	$("#contributorDesc_edit textarea").blur(function() {
		// run the ajax function here...
		// can be an exact copy of the function used to update the lead...
		var id = $(this).attr('id').replace("contributorDesc_","");
		var nd = $(this).val();
		var od = $("#contributorDesc_current").val();
		
		if(nd != od) {
			//alert("ID: " + id + " || VAL: " + nd);
			$.ajax({
				url: "/dpComponent/channel/updateContributorLead",
				type: "post",
				data: "id=" + id + "&nd=" + nd,
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					$("#contributorDesc_edit").hide();
					$("#contributorDesc_edit textarea").val(html);
					$("#contributorDesc_current").val(html);
					$("#contributorDesc_text").html(html).show();
				}
			});
		} else {
			$("#contributorDesc_edit").hide();
			$("#contributorDesc_text").show();
		}
	});
	
	$("#contribTypeText").click(function() {
		// we need to turn this off.
		$(this).addClass('hide');
		$("#contribTypeSelect").removeClass('hide');
	});
	
	$("#contribTypeSelect").change(function() {
		var contributorId = $("#contId").val();
		var newVal = $("#contributorType").val();
		$.ajax({
			url: "/dpComponent/channel/updateContributorType",
			type: "post",
			data: "id=" + contributorId + "&type=" + newVal,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},	
			success: function(html) {
				$("#contribTypeText").html(html).removeClass('hide');
				$("#contribTypeSelect").addClass('hide');
			}
		});
		//alert(newVal);
	});
	
	$("#deleteContributor").click(function() {
		var contributorId = $("#contId").val();
		var answer = confirm("Completely Delete this Contributor?");
					
		if(answer) {
			$.ajax({
				url: "/dpComponent/channel/deleteContributor",
				type: "post",
				data: "id=" + contributorId,
		//		beforeSend: function() {
		//			$("#contentLoading").removeClass("hide");
		//		},	
				success: function(html) {
					$("#tagDetail").html(html);
					$("#"+contributorId).remove();
				}
			});
		}
	});
	
	// ASSIGNS A CONTRIBUTOR TO A POST
	// ---------------------------------------------------------------------------------------------
	$(".aPublisher.aButton").click(function(){
		var pubId = $(this).attr('id').replace("publisher_","");
		var postId = "";
		var postType = "";
		var method = "";
		var parentId = "";
		
		
		if($("#toolScroll").length) {
			postId = $("#postId").val();
			parentId = $("#parentId").val();
			postType = $("#postType").val();
			method = "/dpComponent/" + postType + "/updatePublisher";
		} else if($("img#cropIt").length) {
			var postArray = $("img#cropIt").attr("src").replace("/media/"+dpclient+"/images/","").split(".");
			postId = postArray[0];
			postType = "images";
			method = "/dpComponent/images/updatePublisher";
		}
		
		//alert('works');
		
		$.ajax({
			url: method,
			type: "post",
			data: "id=" + postId + "&pub=" + pubId + "&postType=" + postType + "&parent=" + parentId,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},	
			success: function(html) {
				$("#currentPublisher").html(html);
				var overlayAPI = $("#toolsOverlay").data("overlay");
				if(overlayAPI.isOpened()) {
					overlayAPI.close();
				}
			}
		});
	});
	
	$("#tagDetail .tagValue a").click(function() {
	
		var action = $(this).attr("href").split("_");
		//alert('works' + action[0] + " || " + action[1]);
		
		if(action[0] == "#user") {
			//$("#cntName").hide();
			$.ajax({
				url: "/dpComponent/user/getTrustedUsers",
				type: "post",
				data: "cntId=" + action[1],
				success: function(html) {
					$("#cntDesc").hide();
					$("#cntPubl").hide();
					$("#cntDetail").html(html).show();
					$("#cntUser_view").hide();
					$("#cntUser_close").show();
					
					// get autoselect working...
					$("#addTrustedUser").autocomplete({
						source: "/dpComponent/user/usersJSON",
						minLength: 2,
						select: function(event, ui) {
							if(ui.item.id) {
								$.ajax({
									url: "/dpComponent/user/addTrustedUser",
									type: "post",
									data: "cid=" + channel + "&scid=" + subchannel + "&cntId=" + action[1] + "&uid=" + ui.item.id + "&uscp=" + ui.item.scope,
									beforeSend: function() {
										$("#contentLoading").removeClass("hide");
									},
									success: function(html) {
										$("#contentLoading").addClass("hide");
										$("#trustedUserTable").html(html);
										$("input#addTrustedUser").val('');
										
										// need to add the functionality for a user delete button...
										
										// then, the functionality for creating a publisher
										
										// then, the functionality to upload an icon...
										
										// the, we build the link to the appropriate page for the publisher headlines...
										
										
										// then, we do the tools page in the contributor / tag areas...
										// that is a must... We need the ability to manage content from any direction... SWEET!
										
										
									}
								});
							}
						}
					}).blur(function() {
						if($(this).val() == "  ") {
							$(this).val('');
						}
					});
				
				
				}
			});
			
			// now, we need to run an ajax call, and get the users from the database...
			// cntDetail
			// this will require there to be a window, that content can be loaded into...
			
			// now, we need to load the users from the database for this publisher...
			//$query = "SELECT P.user_id,P.is_default,U.firstName,U.lastName,U.username,U.scope FROM users_publishers as P LEFT JOIN users as U ON P.user_id = U.id WHERE P.publisher_id = '".xxx."'";
		} else if(action[0] == "#publ") {
			//$("#cntName").hide();
			//$("#cntDesc").hide();
			//$("#cntUser").hide();
			//$("#cntPubl_view").hide();
			//$("#cntPubl_close").show();
			
			window.location = "/viewby/publisher/"+action[1];
			
			// we need to run an ajax script?
			// really... can't we just make this a window.location code call, and be done with it...
			
			// viewby/publisher/publisher-id-goes-here
			
		} else if(action[0] == "#close") {
			$("#cntDetail").html("").hide();
			//$("#cntName").show();
			
			
			
			$("#cntDesc").show();
			
			$("#cntUser").show();
			$("#cntUser_view").show();
			$("#cntUser_close").hide();
			
			$("#cntPubl").show();
			$("#cntPubl_view").show();
			$("#cntPubl_close").hide();
		}
		// hide the appropriate images...
		// these only run if the url is "user";
		
		
		return false;
	});
}

function updateToolsAdNav(buttonId,method,typeId,adDim) {

	var dataQuery = "";
	if(buttonId[1]) {
		dataQuery = "cid=" + channel + "&scid=" + subchannel + "&typeId=" + typeId + "&adD=" + adDim + "&id="+buttonId[1];
	} else {
		dataQuery = "cid=" + channel + "&scid=" + subchannel + "&typeId=" + typeId + "&adD=" + adDim;
	}
	
	if(buttonId[0] == "Activate") {
		buttonId[0] = "Current";
	}
	
	// we need to remake the method variable...
	$.ajax({
		url: method,
		type: "post",
		data: dataQuery,
		beforeSend: function() {
			$("#contentLoading").removeClass("hide");
		},
		success: function(html) {
			var msg = "";
			$("#contentLoading").addClass("hide");
			$(".toolsNav div").removeClass("on");
			$("#"+buttonId[0]).addClass("on");
			$("#toolInterface").html(html);
			switch(buttonId[0]) {
				case "Upload":
					//alert('running upload code');
					msg = "Share Code Here - "+buttonId;
					toolsAdsShare(msg);
					break;
				default:
					msg = "Management Code Here - "+buttonId;
					toolsAdsManage(buttonId[1]);
					break;
			}
		}
	});
}

// tag overlay tool manage/create
function tagEditInPlace() {
	//alert('Tag: outer function is running');
	
	$("#tagDetail .button").click(function() {
		var tagId = $(this).attr("id").split("_");
		var tagContent = $("#tagLoc").val();
		var tagPost = $("#tagPost").val();
		
		var method = "";
		var message = "";
		
		switch(tagId[0]) {
			case "delete":
				method = "/dpComponent/channel/toolsDeleteTag";
				message = "Tag Successfully Deleted";
				break;
			case "content":
				method = "/dpComponent/channel/toolsSwitchTag2Content";
				message = "Tag Successfully Converted";
				break;
			case "geo":
				method = "/dpComponent/channel/toolsSwitchTag2Geo";
				message = "Tag Successfully Converted";
				break;
		}
		$.ajax({
			url: method,
			type: "post",
			data: "c=" + channel + "&s=" + subchannel + "&z=" + tagContent + "&tag=" + tagId[1],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},	
			success: function(html) {
				$("#overlayScroll #"+html).remove();
				$("#tagDetail").html("<div class='message'>" + message + "</div>");
				// if the tag exists in the current post, delete it's notifier as well...
				if ($("#" + tagId[1] + "_" + tagPost).length) {
					$("#" + tagId[1] + "_" + tagPost).parent().remove();
				}
			}
		});
		
	});
}

// enable the date input overlays in the status area...
// of the main tools...
function enableStatusDateInputs(type) {
	// content publish date...
	$("#publish_date").dateinput({
		selectors: true,
		change: function() {
			var isoDate = this.getValue('yyyy-mm-dd');
			var postId = $("#postId").val();
			
			if(!$("#archive_date").val()) {
				$("#archive_date:date").data("dateinput").setMin(this.getValue(), true);
			} else {
				$("#archive_date:date").data("dateinput").setMin(this.getValue());
			}
			$.ajax({
				url: "/dpComponent/" + type + "/changeStatusDateOne",
				type: "post",
				data: "id=" + postId + "&date=" + isoDate,
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					if(html) {
						$("#currentStatus").html(html);
					}
					$("#contentLoading").addClass("hide");	
					// here, we could change the values of the date fields
					// if necessary...
					// for instance, the publish option always increments the archive date...
				}
			});
		}
	});
	
	// content archive date...
	$("#archive_date").dateinput({
		selectors: true,
		change: function() {
			var isoDate = this.getValue('yyyy-mm-dd');
			var postId = $("#postId").val();
			
			$("#publish_date:date").data("dateinput").setMax(this.getValue(), true);
			$.ajax({
				url: "/dpComponent/" + type + "/changeStatusDateTwo",
				type: "post",
				data: "id=" + postId + "&date=" + isoDate,
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					if(html) {
						$("#currentStatus").html(html);
					}
					$("#contentLoading").addClass("hide");
				}
			});
		}
	});
}

// enables the date selection tools
// for the event creation system...
// ------------------------------------------------------------------------------------------------
function enableCalendarDateInputs() {
	$("#naStart").dateinput({
		selectors: true,
		change: function() {
			//alert('start date is set');
			var isoDate = this.getValue('yyyy-mm-dd');
			var eventId = $("#postId").val();
			//$("#naStart:date").data("dateinput").setMax(this.getValue(), true);
			$("#eventStart").val(isoDate);
			$("#naEnd:date").data("dateinput").setMin(this.getValue(), false);
			
			$("#eventType").removeClass("hide");
			$("#eventStartDateDesc").addClass("hide");
			
			if(!$("#eventRecurDate").hasClass("hide")) {
				$("#eventRecurDate").addClass("hide");
			}
			$("#eventTypeSingle").click(function() {
				// we need to show the recurring functionality
				// and set the value of the end-date to the value of the start-date...
				$("#eventType").addClass("hide");
				$("#eventRecurWeekly").addClass("hide");
				$("#eventRecurMonthly").addClass("hide");
				
				//$("#naStart:date").data("dateinput").setMax(this.getValue(), false);
				$("#naEnd:date").data("dateinput").setValue($("#naStart:date").data("dateinput").getValue());
				
				//$("#eventEnd").val(isoDate);
				
				
			});
			
			$("#eventTypeMulti").click(function() {
				// we need to show the end-date functionality...
				$("#eventEndDate").removeClass("hide");
				$("#eventType").addClass("hide");
			});
		}
	});
				
	// content publish date...
	$("#naEnd").dateinput({
		selectors: true,
		change: function() {
			//alert('end date is set');
			var isoDate = this.getValue('yyyy-mm-dd');
			var eventId = $("#postId").val();
			$("#eventEnd").val(isoDate);
			//$("#naStart:date").data("dateinput").setMax(this.getValue(), false);
			$("#eventEndDateDesc").addClass("hide");
			
			createRecurDates();
			/*
			$.ajax({
				url: "/dpComponent/headlines/changePublishDate",
				type: "post",
				data: "id=" + storyId + "&date=" + isoDate,
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#currentStatus").html(html);
					$("#contentLoading").addClass("hide");	
					// here, we could change the values of the date fields
					// if necessary...
					// for instance, the publish option always increments the archive date...
				}
			});
			*/
		}
	});
}

function createRecurDates() {
	
	var startDayIso = $("#naStart:date").data("dateinput").getValue("yyyy-mm-dd");
	var endDayIso = $("#naEnd:date").data("dateinput").getValue("yyyy-mm-dd");
	
	var startDay = $("#naStart:date").data("dateinput").getValue("yyyymmdd");
	var endDay = $("#naEnd:date").data("dateinput").getValue("yyyymmdd");

	var daysLong = endDay - startDay + 1;
	
	// somewhere, we'll need to add this back in...
	// if, the dates are changed... we need to check first....
	if(daysLong > 3) {
		$("#eventRecurBasic option[value='weekly']").remove();
	} else {
		//$("#selectBox").append('<option value="option5">option5</option>');
		// $('#yourSelect option[value=yourValue]').length > 0;

		if(!$("#eventRecurBasic option[value='weekly']").length) {
			$("#eventRecurBasic").append('<option value="weekly">Recurs Weekly</option>');
		}
		// if there is not a weekly option, we need to add it...
	}
	
	$("#add_dates").removeClass("hide");
	$("#eventRecurDate").removeClass("hide");
	//alert("this is the recur date functionality start: " + startDay + " || end: " + endDay + " || Length: " + daysLong);
	
	$("#eventRecurBasic").change(function() {
		var recurValue = $(this).val();
		if(recurValue == "weekly") {
			//alert("it's a weekly value.  show the week drop down");
			if(!$("#eventRecurMonthly").hasClass("hide")) {
				$("#eventRecurMonthly").addClass("hide");
			}
			$("#eventRecurWeekly").removeClass("hide");
			
		} else if(recurValue == "monthly") {
			if(!$("#eventRecurWeekly").hasClass("hide")) {
				$("#eventRecurWeekly").addClass("hide");
			}
			$.ajax({
				url: "/dpComponent/events/getRecurringData",
				type: "post",
				data: "start=" + startDayIso + "&end=" + endDayIso,
				dataType: "json",
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(json) {
					$("#contentLoading").addClass("hide");
					$("#recurDateList").html(json.date);
					$("#recurDayList").html(json.day);
					$("#eventRecurMonthly").removeClass("hide");
				}
			});
		}
	});
}

function configureTags(type) {

	// content tag search...
	$("#tagSearch").autocomplete({
		source: "/dpComponent/channel/tagsJSON",
		minLength: 2,
		select: function(event, ui) {
		
			var postId = $("#postId").val();
			
			if(ui.item.id && postId) {
				$.ajax({
					url: "/dpComponent/" + type + "/toolsAddTag",
					type: "post",
					data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&tag=" + ui.item.id + "&type=" + ui.item.geo,
					beforeSend: function() {
						$("#contentLoading").removeClass("hide");
					},
					success: function(html) {
						$("#contentLoading").addClass("hide");
						$("#storyTagData").html(html);
						$("input#tagSearch").val('');
					}
				});
			}
		}
	}).blur(function() {
		if($(this).val() == "  ") {
			$(this).val('');
		}
	});
				
	// content geo-tag search...
	$("#geoTagSearch").autocomplete({
		source: "/dpComponent/channel/geoTagsJSON",
		minLength: 2,
		select: function(event, ui) {
		
			var postId = $("#postId").val();
			
			if(ui.item.id && postId) {
				$.ajax({
					url: "/dpComponent/" + type + "/toolsAddTag",
					type: "post",
					data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&tag=" + ui.item.id + "&type=" + ui.item.geo,
					beforeSend: function() {
						$("#contentLoading").removeClass("hide");
					},
					success: function(html) {
						$("#contentLoading").addClass("hide");
						$("#geoTagData").html(html);
						$("input#geoTagSearch").val('');
					}
				});
			}
		}
	}).blur(function() {
		if($(this).val() == "  ") {
			$(this).val('');
		}
	});
}


// AD UPLOAD FUNCTION
// ------------------------------------------------------------------------------------------------
function toolsAdsShare(msg) {
	//alert(msg);
	var adD = $("#toolAdDimensions").val();
	
	// configure the upload button...
	$("#adFileInput").uploadify({
		"uploader" : "/images/uploadify.swf",
		"script" : "/dpComponent/ads/uploadAdImg",
		"fileExt" : "*.png;*.gif;*.jpg;*.jpeg;",
		"cancelImg" : "/images/cancel.png",
		"scriptData" : {"adD": adD},
		"auto" : true,
		"scriptAccess" : "always",
		"folder" : "/images/sponsors/"+adD,
		"onError" : function(event,queueID,fileObj,errorObj) {
			alert('error' + errorObj.type + errorObj.info);
		},
		"onComplete" : function(event,queue,fileObj,response,data) {
			var responseData = response.split("|");
			if(responseData[0] == 1) {
				//alert('fo.name: ' + fileObj.name);
				var adSrc = "/images/" + responseData[2] + "/sponsors/" + adD + "/" + responseData[1];
				$("#adUploadPreview img").attr("src",adSrc).load();
				$("#naFilename").val(responseData[1]);
				$("#adFileInputWrapper").hide();
				$("#adHelpOne").hide();
				$("#adCreateDetail").show();
				$("#adHelpTwo").show();
			} else {
				alert('Unable to upload image' + responseData[1]);
			}
		}
	});
										
										
	$("form#postForm").validator().submit(function(e) {
		var form = $(this);
		if (!e.isDefaultPrevented()) {
			// passed client-side validation OK.
			// you know, we could put some stuff in here to stop spammers...
			// do a SHA1 of the email+dpCode and check on the other end... SWEET!
			formData = form.serialize();
			$.ajax({
				url: "/dpComponent/ads/createAd",
				type: "post",
				data: "cid="+ channel +"&scid="+ subchannel +"&" + formData,
				dataType: "json",
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
//				error: function(html) {
//					// this is the error function here...
//					alert(html);
//				},
				success: function(json) {
					$("#contentLoading").addClass("hide");
					if (json.success)  {
						// video successfully shared!
						//$("#videoCreate").addClass('hide');
						$("#adCreateDetail").html(json.html);
					} else {
						// server-side validation failed.
						form.data("validator").invalidate(json);
					}
				}
			});
			// prevent the form from being submitted...
			e.preventDefault();
		}
	});
}

// AD MANAGE FUNCTION
// ------------------------------------------------------------------------------------------------
function toolsAdsManage(postId) {
	// we need to put the stuff here, to manage the video...
	//alert("video manage function is running!");
	
	//$("#toolVideos #toolScroll .rowItem").click(function() {
	// ahhh.  this only happens on a .rowItem "click"...
	// how can I bind it directly...
	$("#toolScroll").delegate(".rowItem", "click", function(event) {
		var itemId = $(this).attr('id');
		var item = $(this);
		$.ajax({
			url: "/dpComponent/ads/toolsDisplayOverviewAjax",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + itemId,
			beforeSend: function() {
				// we need to remove the class from ANY of the rowitem values...
				$("#toolScroll div.rowItem").removeClass("on");
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$(item).addClass("on");
				//alert('post: ' + itemId);
				// output video accordian...
				
				$("#toolWindow").html(html);
				$("#toolAccordian").tabs("#toolAccordian div.tier", {tabs: 'h2', effect: 'slide', initialIndex: null});
				
				// configure event buttons...
				$("#ads_publish").click(function() {
					var postId = $("#postId").val();
					var adD = $("#toolAdDimensions").val();
					var metaData = "";
					if ($("#toolScroll div.listNav div.button.page.on").length) {
						metaData = $("#toolScroll div.listNav div.button.page.on").attr("id").split("|");
					} else {
						metaData = array();
					}
					var status = "";
					if($("#Current").hasClass("on")) {
						status = "current";
					} else if($("#Archive").hasClass("on")) {
						status = "archive";
					} else if($("#Pending").hasClass("on")) {
						status = "pending";
					}
				
					$.ajax({
						url: "/dpComponent/ads/toolsPublishAd",
						type: "post",
						data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&startpos=" + metaData[2] + "&status=" + status + "&adD=" + adD,
						beforeSend: function() {	
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							$("#toolWindow").html("");
							$("#toolScroll").html(html);					
						}
					});
					
				});
				
				$("#ads_archive").click(function() {
					var postId = $("#postId").val();
					var adD = $("#toolAdDimensions").val();
					var metaData = "";
					if ($("#toolScroll div.listNav div.button.page.on").length) {
						metaData = $("#toolScroll div.listNav div.button.page.on").attr("id").split("|");
					} else {
						metaData = array();
					}
					var status = "";
					if($("#Current").hasClass("on")) {
						status = "current";
					} else if($("#Archive").hasClass("on")) {
						status = "archive";
					} else if($("#Pending").hasClass("on")) {
						status = "pending";
					}
					
					$.ajax({
						url: "/dpComponent/ads/toolsArchiveAd",
						type: "post",
						data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&startpos=" + metaData[2] + "&status=" + status + "&adD=" + adD,
						beforeSend: function() {	
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							
							$("#toolWindow").html("");
							$("#toolScroll").html(html);
						}
					});
				});
				
				$("#ads_delete").click(function() {
					// we need the following data...
					var postId = $("#postId").val();
					var adD = $("#toolAdDimensions").val();
					var answer = confirm("Remove this Banner Ad from the site?");
					
					if(answer) {
						var metaData = "";
						if ($("#toolScroll div.listNav div.button.page.on").length) {
							metaData = $("#toolScroll div.listNav div.button.page.on").attr("id").split("|");
						} else {
							metaData = array();
						}
						var status = "";
						if($("#Current").hasClass("on")) {
							status = "current";
						} else if($("#Archive").hasClass("on")) {
							status = "archive";
						} else if($("#Pending").hasClass("on")) {
							status = "pending";
						}

						$.ajax({
							url: "/dpComponent/ads/toolsDeleteAd",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&startpos=" + metaData[2] + "&status=" + status + "&adD=" + adD,
							beforeSend: function() {	
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
							
								// this should be the default sidebar...
								$("#toolWindow").html("");
								
								// remove the item from the list...
								$("#toolScroll").html(html);
							}
						});
					}
				});
				
				$("#toolsStatus .title").click(function() {
					var postId = $("#postId").val();
					// update DOM...
					$("#title_"+postId).hide();
					$("#titleEdit_"+postId).show();
					$("#newTitle").focus();
				});
				$("#toolsStatus #newTitle").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origTitle").val();	
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/ads/toolsUpdateTitle",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
				//			beforeSend: function() {
				//				$("#contentLoading").removeClass("hide");
				//			},
							success: function(html) {
								$("#toolsStatus .title").html(html);
								$("#toolScroll .rowItem.on .adTitle").html(html);
								//$(item).children(".articleHeadline").html(html);
								
								$("#toolsStatus #origTitle").val(html);
								$("#toolsStatus #newTitle").val(html);
							}
						});
					}
					$("#title_"+postId).show();
					$("#titleEdit_"+postId).hide();
				});
				
				$("#toolsStatus .alt").click(function() {
					var postId = $("#postId").val();
					// update DOM...
					$("#alt_"+postId).hide();
					$("#altEdit_"+postId).show();
					$("#newAlt").focus();
				});
				$("#toolsStatus #newAlt").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origAlt").val();	
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/ads/toolsUpdateAlt",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
				//			beforeSend: function() {
				//				$("#contentLoading").removeClass("hide");
				//			},
							success: function(html) {
								$("#toolsStatus .alt").html(html);
								$("#toolsStatus #origAlt").val(html);
								$("#toolsStatus #newAlt").val(html);
							}
						});
					}
					$("#alt_"+postId).show();
					$("#altEdit_"+postId).hide();
				});
				
				$("#toolsStatus .url").click(function() {
					var postId = $("#postId").val();
					// update DOM...
					$("#url_"+postId).hide();
					$("#urlEdit_"+postId).show();
					$("#newUrl").focus();
					return false;
				});
				$("#toolsStatus #newUrl").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origUrl").val();	
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/ads/toolsUpdateUrl",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
				//			beforeSend: function() {
				//				$("#contentLoading").removeClass("hide");
				//			},
							success: function(html) {
								$("#toolsStatus .url").html(html);
								$("#toolsStatus #origUrl").val(html);
								$("#toolsStatus #newUrl").val(html);
							}
						});
					}
					$("#url_"+postId).show();
					$("#urlEdit_"+postId).hide();
				});
				
				//enableStatusDateInputs('videoManager');
				
				$("#toolAccordian").delegate("#addNewPlacement", "click", function(event) {
				//$("#addCalendarPlacement").click(function() {
					var placeToAdd = $("select#addPlacement").val();
					var postId = $("#postId").val();
					
					if(placeToAdd && postId) {
						var matrixData = placeToAdd.split("_");
						$.ajax({
							url: "/dpComponent/ads/toolsPlaceContent",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&channel=" + matrixData[0] + "&subChannel=" + matrixData[1] + "&scid=" + matrixData[2],
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#storyMatrixData").html(html);
							}
						});
					}
				});
	
				$("#toolAccordian").delegate("#storyMatrixData .matrix_remove", "click", function(event) {
					var placeToRemove = $(this).attr('id').split("_");
					var postId = $("#postId").val();
					if(placeToRemove) {
						$.ajax({
							url: "/dpComponent/ads/deleteStoryMatrixEntry",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&channel=" + placeToRemove[1] + "&subChannel=" + placeToRemove[2],
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#storyMatrixData").html(html);
							}
						});
					}
				});
			}
		});
	});
	
	if(postId) {
		// simulate a click...
		$("#toolScroll div.rowItem.on").click();
	}
	
	$("div#toolScroll").delegate(".button.page.active", "click", function(event) {
		var adD = $("#toolAdDimensions").val();
		var metaData = $(this).attr('id').split("|");
		var status = "";
		if($("#Current").hasClass("on")) {
			status = "current";
		} else if($("#Archive").hasClass("on")) {
			status = "archives";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		}
		$.ajax({
			url: "/dpComponent/ads/toolsDisplayStep",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + metaData[1] + "&adD=" + adD,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolScroll").html(html);
			}
		});
	});
	
	$("div#toolScroll").delegate(".button.step.active", "click", function(event) {
		var adD = $("#toolAdDimensions").val();
		var metaData = $(this).attr('id').split("|");
		var status = "";
		if($("#Current").hasClass("on")) {
			status = "current";
		} else if($("#Archive").hasClass("on")) {
			status = "archives";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		}
		$.ajax({
			url: "/dpComponent/ads/toolsDisplayStep",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + metaData[1] + "&adD=" + adD,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolScroll").html(html);
			}
		});
	});
	
}

function toolsNewsCreate(msg) {
	//alert('msg:' + msg);
	$("#toolNews").delegate("#createHeadline", "click", function(event)
	{
		var headline = $("#naHeadline").val();
		var contributor = $("#naPublisher").val();
		var author = $("#naAuthor").val();
		if(headline) {
			// create the article placeholder...
			$.ajax({
				url: "/dpComponent/headlines/createArticleHeadline",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&headline=" + headline + "&contributor=" + contributor + "&author=" + author,
				dataType: "json",
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				error: function(html) {
					// this is a server error here!!!
					alert('we experienced an error.  please try again');
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					$("#articleHeadlineCreate").addClass("hide");
					$("#articleIntroText").addClass("hide");
					$("#articleFormDetail").removeClass('hide');
					$("#previewAnArticle").removeClass('hide');
					$("#createAnArticle").removeClass('hide');
					// ok, the headline has been created...
					if ($("#articleText").length) {
						$("#articleText").ckeditor({
							filebrowserImageBrowseUrl: "/dpComponent/images/toolsLibraryBrowse?channel=" + channel + "&subChannel=" + subchannel + "&postId=" + html.id + "&contributorId=" + html.contributor,
							startupFocus: true
						});
						//CKEDITOR.instances['articleText']
					}
					// change the help instructions...
					$("#helpStepOne").addClass('hide');
					$("#helpStepTwo").removeClass('hide');
					// use return json data to populate preview page...
					
					$("#postId").val(html.id);
					$("#articleContributorData").html(html.contributor);
					$("#articleAuthorData").html(html.author);
					$("#articlePublishDate").html(html.postDate);
					$("#articleHeadlineData").html(html.headline);
					
					// enable the buttons...
				}
			});
		}
	});
	
	$("#toolNews").delegate("#createAnArticle", "click", function(event)
	{
		var headline = $("#naHeadline").val();
		var contributor = $("#naPublisher").val();
		var author = $("#naAuthor").val();
		var e=CKEDITOR.instances['articleText'];
		var htmlData = "";
		if(e) {
			htmlData = encodeURIComponent(e.getData());
		} else {
			htmlData = encodeURIComponent($("#previewText").html()).replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0'); // adds slashes...
		}
		$.ajax({
			url: "/dpComponent/headlines/createAnArticle",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&headline=" + headline + "&author=" + author + "&contributor=" + contributor + "&text=" + htmlData,
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				var postId = $("#postId").val();
				var e=CKEDITOR.instances['articleText'];
				if(e) {
					e.destroy();
					e=null;
				}
				$("#helpStepTwo").addClass('hide');
				$("#helpStepThree").removeClass('hide');
				$("#contentLoading").addClass("hide");
				$("#createScreen").html('').hide();
				$("#previewScreen").html('').hide();
				$("#successScreen").html(html).show();
				if(postId) {
					$.ajax({
						url: "/dpComponent/headlines/toolsDisplayOverviewAjax",
						type: "post",
						data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId,
						beforeSend: function() {
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							$("#toolWindow").html(html);
							$("#toolAccordian").tabs("#toolAccordian div.tier", {tabs: 'h2', effect: 'slide', initialIndex: null});
							enableStatusDateInputs('headlines');
							$("#tagSearch").autocomplete({
								source: "/dpComponent/channel/tagsJSON",
								minLength: 2,
								select: function(event, ui) {
									var storyId = $("#postId").val();
									if(ui.item.id && storyId) {
										$.ajax({
											url: "/dpComponent/headlines/toolsAddTag",
											type: "post",
											data: "cid=" + channel + "&scid=" + subchannel + "&id=" + storyId + "&tag=" + ui.item.id + "&type=" + ui.item.geo,
											beforeSend: function() {
												$("#contentLoading").removeClass("hide");
											},
											success: function(html) {
												$("#contentLoading").addClass("hide");
												$("#storyTagData").html(html);
												$("input#tagSearch").val('');
											}
										});
									}
								}
							}).blur(function() {
								if($(this).val() == "  ") {
									$(this).val('');
								}
							});
							// content geo-tag search...
							$("#geoTagSearch").autocomplete({
								source: "/dpComponent/channel/geoTagsJSON",
								minLength: 2,
								select: function(event, ui) {
									var storyId = $("#postId").val();
									if(ui.item.id && storyId) {
										$.ajax({
											url: "/dpComponent/headlines/toolsAddTag",
											type: "post",
											data: "cid=" + channel + "&scid=" + subchannel + "&id=" + storyId + "&tag=" + ui.item.id + "&type=" + ui.item.geo,
											beforeSend: function() {
												$("#contentLoading").removeClass("hide");
											},
											success: function(html) {
												$("#contentLoading").addClass("hide");
												$("#geoTagData").html(html);
												$("input#geoTagSearch").val('');
											}
										});
									}
								}
							}).blur(function() {
								if($(this).val() == "  ") {
									$(this).val('');
								}
							});
						
						}
					});
					
					// we need to add some components here for trusted users...
					// trusted users should be able to determine the start date of their article...
					// ----------------------------------------------------------------------------
					// suggest new placement button...
					$("#userPlacement.zeb #suggestNewPlacement").click(function() {
						var postId = $("#postId").val();
						var placement = $("#suggestPlacement").val().split("_");
						$.ajax({
							url: "/dpComponent/headlines/suggestPlacement",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&p=" + postId + "&c=" + placement[0] + "&s=" + placement[1],
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#sgst_plc").html(html);
								$("#userPlacement").removeClass("zeb");
								$("#userPlacement .editType .descrip").hide();
								
								// user suggested location
								// ----------------------------------------------------------------
								$("#userLocation").addClass("zeb").removeClass('hide');
								$("#userLocation.zeb #suggestNewLocation").click(function() {
									var postId = $("#postId").val();
									var tag = $("#geoTags").val();
									$.ajax({
										url: "/dpComponent/headlines/suggestTag",
										type: "post",
										data: "cid=" + channel + "&scid=" + subchannel + "&p=" + postId + "&t=" + tag + "&g=1",
										beforeSend: function() {
											$("#contentLoading").removeClass("hide");
										},
										success: function(html) {
											$("#contentLoading").addClass("hide");
											$("#sgst_geo").html(html);
											$("#userLocation").removeClass("zeb");
											$("#userLocation .editType .descrip").hide();
											
											
											// here is where we configure the AUTO COMPLETE function
											// for the suggest a tag area...
											// we need some way to count this...
											// the best way, would be to store the item somewhere in the html5 data structure...
											
											$("#tagPhoto").autocomplete({
												source: "/dpComponent/channel/tagsJSON",
												minLength: 2,
												select: function(event, ui) {
													//var imgId = $("img#cropIt").attr('src').replace("/media/"+dpclient+"/images/","").split(".");
													if(ui.item.id && postId) {
														$.ajax({
															url: "/dpComponent/headlines/toolsSuggestTag",
															type: "post",
															data: "tagContent=" + postId + "&tagName=" + ui.item.id + "&type=" + ui.item.geo,
															dataType: "json",
															beforeSend: function() {
																$("#contentLoading").removeClass("hide");
															},
															success: function(json) {
																$("#contentLoading").addClass("hide");
																if(json) {
																	if(json.count) {
																		//alert('have count' + json.count);
																		$("input#tagPhoto").val('');
																		switch(json.count) {
																			case "1":
																				$("#tagOne").html(json.name);
																				break;
																				
																			case "2":
																				$("#tagTwo").html(json.name);
																				break;
																			
																			case "3":
																				$("#tagThree").html(json.name);
																				$("#tagAddForm").remove();
																				break;
																		}
																	}
																}
															}
														});
													}
												}
											}).blur(function() {
												if($(this).val() == "  ") {
													$(this).val('');
												}
											});
											
											// create new content tag...
											$("#tagAddForm .addNewPhotoTag").click(function() {
												var tagVal = $("#tagPhoto").val();
												var tagData = $(this).attr("id").split("|");
												if(tagVal) {
													$.ajax({
														url: "/dpComponent/channel/toolsCreateTag",
														type: "post",
														data: "tagName=" + tagVal + "&tagType=" + tagData[1] + "&tagContent=" + tagData[0] + "&tagLoc=headline_create",
														dataType: "json",
												//		beforeSend: function() {
												//			$("#contentLoading").removeClass("hide");
												//		},
														success: function(json) {
															if(json) {
																if(json.count) {
																	//alert('have count' + json.count);
																	$("input#tagPhoto").val('');
																	switch(json.count) {
																		case "1":
																			$("#tagOne").html(json.name);
																			break;
																			
																		case "2":
																			$("#tagTwo").html(json.name);
																			break;
																		
																		case "3":
																			$("#tagThree").html(json.name);
																			$("#tagAddForm").remove();
																			
																			// this should actually be a call
																			// to a function, that set's up the stuff below...
																			// this code could be organized much better...
																			break;
																	}
																}
															}
														}
													});
												}
											});
											
			
			
			
			
											// the click below can then be re-written to just display the next component, if it's available...
											
											// user suggested tags...
											// ----------------------------------------------------
											$("#userTag").addClass("zeb").removeClass('hide');
											$("#userTag.zeb #suggestNewTag").click(function() {
											
												$("#userTag").removeClass("zeb");
												$("#userTag .editType .descrip").hide();
												$("#userTag #suggestNewTag").hide();
												$("#userTag #tagAddForm").hide();
												
												if ($("#userThumb").length) {
													// ----------------------------
													$("#userThumb").addClass("zeb").removeClass('hide');
													$("#userThumb.zeb img").click(function() {
														var postId = $("#postId").val();
														var thumb = $(this).attr('src').replace("/media/"+dpclient+"/images/","").replace("_icon","").split(".");
														$.ajax({
															url: "/dpComponent/headlines/updatePostThumb",
															type: "post",
															data: "postId=" + postId + "&thumbId=" + thumb[0] + "&thumbExt=" + thumb[1],
															success: function(html) {
																// this all needs to change.  We are already here...
																if ($("#thumbnail_default").length) {
																	$("#thumbnail_default").html(html);
																	$("#thumbnail_default").attr("id","thumbnail_"+thumb[0]);
																}
																$("#postGalleryWrap").hide();
																$("#toolScroll #userThumb").removeClass("zeb");
																$("#userThumb .editType .descrip").hide();
																$("#userThumb .editTypeInput .name").html("Photo Selected");
																				
																$("#toolScroll #userAgain").addClass("zeb").removeClass('hide');
																$("#toolsAgain").click(function() {
																	/*
																	var e=CKEDITOR.instances['articleText'];
																	*/
																	if(e) {
																		e.destroy();
																		e=null;
																	}		
																	$.ajax({
																		url: "/dpComponent/headlines/toolsDisplayCreateAjax",
																		type: "post",
																		data: "cid=" + channel + "&scid=" + subchannel + "&typeId=",
																		beforeSend: function() {
																			$("#contentLoading").removeClass("hide");
																		},
																		success: function(html) {
																			// now, we need to remove the ON from the current tabs...
																			$(".toolNav div").removeClass("on");
																			//$(parent).addClass("on");
																			$("#contentLoading").addClass("hide");
																			$("#toolInterface").html(html);
																		}
																	});
																	return false;
																});
															}
														});
													});
												} else {
																	
													// no photos in article...
													// ----------------------------
													$("#toolScroll #userAgain").addClass("zeb").removeClass('hide');
													$("#toolsAgain").click(function() {
														/*
														var e=CKEDITOR.instances['articleText'];
														*/
														if(e) {
															e.destroy();
															e=null;
														}
																		
														$.ajax({
															url: "/dpComponent/headlines/toolsDisplayCreateAjax",
															type: "post",
															data: "cid=" + channel + "&scid=" + subchannel + "&typeId=",
															beforeSend: function() {
																$("#contentLoading").removeClass("hide");
															},
															success: function(html) {
																// now, we need to remove the ON from the current tabs...
																$(".toolNav div").removeClass("on");
																//$(parent).addClass("on");
																$("#contentLoading").addClass("hide");
																$("#toolInterface").html(html);
															}
														});
														return false;
													});
												}

													
												
											});
										}
									});
								});
							}
						});
					});
				}
				$("#previewAnArticle").addClass('hide');
				$("#createAnArticle").addClass('hide');
				$("#editAnArticle").addClass('hide');
			}
		});
		
	});
	
	$("#toolNews").delegate("#previewAnArticle", "click", function(event)
	{
		var headline = $("#naHeadline").val();
		var e=CKEDITOR.instances['articleText'];
		var htmlData = "";
		if(e) {
			htmlData = e.getData();
			e.destroy();
			e=null;
		}
		$("#previewHeadline").html(headline);
		$("#previewText").html(htmlData);	
		$("#createScreen").hide();
		$("#previewScreen").show();
		$("#previewAnArticle").addClass('hide');
		$("#editAnArticle").removeClass('hide');
	});
	
	$("#toolNews").delegate("#editAnArticle", "click", function(event)
	{
		var htmlData = $("previewText").html();
		var postId = $("#postId").val();
		var contributorId = $("#naPublisher").val();
		$("#previewHeadline").html('');
		$("#previewText").html('');	
		$("#previewScreen").hide();
		$("#editAnArticle").addClass('hide');
		$("#createScreen").show();
		if ($("#articleText").length) {
			$("#articleText").ckeditor({
				filebrowserImageBrowseUrl: "/dpComponent/images/toolsLibraryBrowse?channel=" + channel + "&subChannel=" + subchannel + "&postId=" + postId + "&contributorId=" + contributorId
			}).data(htmlData);
		}
		$("#previewAnArticle").removeClass('hide');
	});
}

function toolsNewsManage(msg) {
	//alert('msg:' + msg);
	
	$("#tools").delegate("#toolNews .rowItem", "click", function(event)
	{
	//$("#toolNews .rowItem").live("click",function() {
		var itemId = $(this).attr('id');
		var item = $(this);
		$.ajax({
			url: "/dpComponent/headlines/toolsDisplayOverviewAjax",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + itemId,
			beforeSend: function() {
				// we need to remove the class from ANY of the rowitem values...
				$("#toolScroll div.rowItem").removeClass("on");
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
			
				$("#contentLoading").addClass("hide");
				$(item).addClass("on");
				var postId = $("#postId").val();
				
				// configure the article accordian...
				outputArticleTool(item,html);
			}
		});
	});
	
	$("#tools").delegate("#toolNews #toolScroll div.statusBox.topStory, #toolNews #toolScroll div.statusBox.feature", "click", function()
	{
		var isOn = false;
		
		// it's not this... it's toolNews .toolNav
		var typeId = $("#toolNews div.toolsNav").attr('id');
		//alert(typeId);
		var headlineId = $(this).parent().parent().attr('id');
		if($(this).hasClass('topStory')) {
			var statusType = "topStory";
		} else {
			var statusType = "feature";
		}
		
		// we need typeId here...
		// this is the contributor/tag/location type...
		
		var status = "";
		var startpos = $(this).parent().attr('class').replace("status sp_","");
		if($("#Current").hasClass("on")) {
			status = "current";
		} else if($("#Archive").hasClass("on")) {
			status = "archives";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		} else if($("#Approve").hasClass("on")) {
			status = "approve";
		}
		if($(this).hasClass('checked')) {
			isOn = true;
		}
		//alert( "type: " + statusType + " | On: " + isOn + " | id: " + headlineId);
		
		$.ajax({
			url: "/dpComponent/headlines/toolsUpdateLayoutStatus",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + headlineId + "&type=" + statusType + "&fstatus=" + isOn + "&startpos=" + startpos + "&status=" + status + "&typeId="+typeId,
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$("#toolScroll").html(html);
			}
		});
	});
	
	/* START --> TOOL POSTS NAVIGATION SYSTEM */
	$("div#tools").delegate("#toolNews #toolScroll .button.page.active", "click", function(event)
	{
		var metaData = $(this).attr('id').split("|");
		var status = "";
		if($("#Current").hasClass("on")) {
			status = "current";
		} else if($("#Archive").hasClass("on")) {
			status = "archives";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		} else if($("#Approve").hasClass("on")) {
			status = "approve";
		}
		$.ajax({
			url: "/dpComponent/headlines/toolsDisplayStep",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + metaData[1],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolScroll").html(html);
			}
		});
	});
	
	$("div#tools").delegate("#toolNews #toolScroll .button.step.active", "click", function(event)
	{
		var metaData = $(this).attr('id').split("|");
		var status = "";
		if($("#Current").hasClass("on")) {
			status = "current";
		} else if($("#Archive").hasClass("on")) {
			status = "archives";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		} else if($("#Approve").hasClass("on")) {
			status = "approve";
		}
		$.ajax({
			url: "/dpComponent/headlines/toolsDisplayStep",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + metaData[1],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolScroll").html(html);
			}
		});
	});
	/* END --> POSTS NAVIGATION SYSTEM */
	
}

function outputArticleTool(item,html) {
	$("#toolWindow").html(html);
	$("#toolAccordian").tabs("#toolAccordian div.tier", {tabs: 'h2', effect: 'slide', initialIndex: null});

	$("#toolAccordian").delegate(".setThumbnail", "click", function(event) {
		var clickedImg = $(this).attr("id").replace("thumbnail_","").replace("default","");
		overlayURL = "/dpComponent/channel/mediaLibraryOverlay?src=tool&dst=images";
		var overlayAPI = $("#toolsOverlay").data("overlay");
		$("#toolsOverlay").bind("onClose", function() {
			$("#toolsOverlay .overlayWrap").html("");
			$(this).unbind("onClose");	// unbind so we don't bubble up...
		});
		$("#toolsOverlay").bind("onLoad", function() {
			setTimeout(function(){configureImageDialog("",overlayAPI,clickedImg,""); overlayAPI=null; clickedImg=null},500);
			//setTimeout('configureImageDialog("",overlayAPI,clickedImg,"")',1000);
			//configureImageDialog("",overlayAPI,clickedImg,"");
			$(this).unbind("onLoad"); // unbind so we don't bubble up...
		});
		overlayAPI.load();
		return false;
	});
	
	$("#add2Calendar").click(function() {
		$("#addCalendarForm").show("blind", {direction: "vertical"}, 500);
		$("#addCalendarNote").hide("blind", {direction: "vertical"}, 300);
		$("#event_date_last").dateinput({
			selectors: true,
			change: function() {
				var isoEnd = this.getValue('yyyy-mm-dd');
				$("#eventLast").val(isoEnd);
			//	if(!$("#eventRecur:visible")) {
					$("#eventRecur").show("blind", {direction: "vertical"}, 500);
			//	}
				// this is the problem here...
				// this needs to be called once, not every time a change is made...
				// FUCK!
				//toolsCalendarRecur();
			}
		});
		$("#event_date").dateinput({
			selectors: true,
			change: function() {
				var isoDate = this.getValue('yyyy-mm-dd');
				var eventId = $("#postId").val();
							
				// set the hidden field in the dom...
				$("#eventStart").val(isoDate);
							
				// set the minimum allowed value of the event end date field...
				$("#event_date_last:date").data("dateinput").setMin(this.getValue(), false);
							
				// show the buttons...
			//	if(!$("#event_type_select:visible")) {
					$("#event_type_select").show("blind", {direction: "vertical"}, 500);
			//	}
				$("#single_day").click(function() {
					// show the recurring stuff...
					$("#event_type_select").hide("blind", {direction: "vertical"}, 300);
					$("#eventRecur").show("blind", {direction: "vertical"}, 500);
					// this is where the recurring calendar functions need to go...
					//toolsCalendarRecur();
				});
				$("#multi_day").click(function() {
					// show the archive date...
					$("#event_type_select").hide("blind", {direction: "vertical"}, 300);
					$("#eventDateLastWrap").show("blind", {direction: "vertical"}, 500);
					// configure the archive date via jquery...
				});
			}
		});
	});
				
	// configure... edit-in-place headline...
	// ------------------------------------------------------------------------------------
	$("#previewWindow .headline").click(function() {
		var postId = $("#postId").val();
		// update DOM...
		$("#headline_"+postId).hide();
		$("#headlineEdit_"+postId).show();
		$("#newHeadline").focus();
	});
	$("#previewWindow #newHeadline").blur(function() {
		var postId = $("#postId").val();
		var nData = $(this).val();
		var oData = $("#origHeadline").val();	
		if(nData != oData) {
			$.ajax({
				url: "/dpComponent/headlines/updateHeadline",
				type: "post",
				data: "id=" + postId + "&nd=" + nData,
	//			beforeSend: function() {
	//				$("#contentLoading").removeClass("hide");
	//			},
				success: function(html) {
					$("#previewWindow .headline").html(html);
					//$("#toolScroll .rowItem.on .articleHeadline").html(html);
					$(item).children(".articleHeadline").html(html);
								
					$("#previewWindow #origHeadline").val(html);
					$("#previewWindow #newHeadline").val(html);
				}
			});
		}
		$("#headline_"+postId).show();
		$("#headlineEdit_"+postId).hide();
	});
				
	// configure... edit-in-place lead...
	// ------------------------------------------------------------------------------------
	$("#previewWindow .lead").click(function() {
		var postId = $("#postId").val();
		// update DOM...
		$("#lead_"+postId).hide();
		$("#leadEdit_"+postId).show();
		$("#newLead").focus();
	});
	$("#previewWindow #newLead").blur(function() {
		var postId = $("#postId").val();
		var nData = $(this).val();
		var oData = $("#origLead").val();
		if(nData != oData) {
			$.ajax({
				url: "/dpComponent/headlines/updateLead",
				type: "post",
				data: "id=" + postId + "&nd=" + nData,
				// here, we need a rotating image for the overlay...
	//			beforeSend: function() {
	//				$("#contentLoading").removeClass("hide");
	//			},
				success: function(html) {
					$("#previewWindow .lead").html(html);
					$("#previewWindow #origLead").val(html);
					$("#previewWindow #newLead").val(html);
				}
			});
		}
		$("#lead_"+postId).show();
		$("#leadEdit_"+postId).hide();
	});
				
	// we are going to have 4 different options here...
	$("#toolAccordian").delegate("#publishNow", "click", function(e) {

		var postId = $("#postId").val();
		var pubDate = $("#publish_date").val();
		$.ajax({
			url: "/dpComponent/headlines/publishNow",
			type: "post",
			data: "id=" + postId + "&pbl=" + pubDate,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolsStatus").html(html);
				enableStatusDateInputs('headlines');
			}
		});
	});
	
	$("#toolAccordian").delegate("#neverArchive", "click", function(e) {
		var postId = $("#postId").val();
		$.ajax({
			url: "/dpComponent/headlines/archiveNever",
			type: "post",
			data: "id=" + postId,
	//		beforeSend: function() {
		//		$("#contentLoading").removeClass("hide");
		//	},
			success: function(html) {
				$("#toolsStatus").html(html);
				enableStatusDateInputs('headlines');
				// this should actually reload the entire toolWindow, so that 
				// multiple items can be published and the navigation system will continue to function...
			}
		});
	});
				
	$("#toolsAlerts").delegate("#createAlert", "click", function(event) {
	//$("#createAlert").click(function() {
		var postId = $("#postId").val();
		var alertType = $("#alertType").val();
		var alertDuration = $("#alertDuration").val();
		var alertPlace = $("#alertPlacement").val();
		$.ajax({
			url: "/dpComponent/headlines/createAlert",
			type: "post",
			data: "id=" + postId + "&type="+alertType+"&duration="+alertDuration+"&place=" + alertPlace,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolsAlerts").html(html);
				// we either need to deletegate both of these, or do something different with them...
							
			}
		});
	});
				
	$("#toolsAlerts").delegate("div.statusBut.removeAlert", "click", function(event) {
		var alertId = $(this).attr('id').replace("removeAlert_","");
		$.ajax({
			url: "/dpComponent/headlines/removeAlert",
			type: "post",
			data: "id=" + alertId,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolsAlerts").html(html);
			}
		});
	});
				
	$("#toolAccordian").delegate("#archiveNow", "click", function(e) {
		//alert('archiveNow');
		var postId = $("#postId").val();
		$.ajax({
			url: "/dpComponent/headlines/archiveNow",
			type: "post",
			data: "id=" + postId,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolsStatus").html(html);
				enableStatusDateInputs('headlines');
				// this should actually reload the entire toolWindow, so that 
				// multiple items can be published and the navigation system will continue to function...
			}
		});
	});
				
	enableStatusDateInputs('headlines');
				
	// configure... interactivity...
	//commentsStatus
	$("#commentsStatus").click(function() {
		var postId = $("#postId").val();
		var currentVal = $(this).html();
		$.ajax({
			url: "/dpComponent/headlines/toggleComments",
			type: "post",
			data: "id=" + postId + "&cur=" + currentVal,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#commentsStatus").html(html);
			}
		});
	});
				
	$("#rankingStatus").click(function() {
		var postId = $("#postId").val();
		var currentVal = $(this).html();
		$.ajax({
			url: "/dpComponent/headlines/toggleRanking",
			type: "post",
			data: "id=" + postId + "&cur=" + currentVal,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#rankingStatus").html(html);
			}
		});
	});
				
				
	// configure... story matrix...
	// ------------------------------------------------------------------------------------
	$("#toolAccordian").delegate("#addNewPlacement", "click", function(event) {
	//$("#addCalendarPlacement").click(function() {
		var placeToAdd = $("select#addPlacement").val();
		var postId = $("#postId").val();
					
		if(placeToAdd && postId) {
			var matrixData = placeToAdd.split("_");
			$.ajax({
				url: "/dpComponent/headlines/toolsPlaceContent",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&channel=" + matrixData[0] + "&subChannel=" + matrixData[1],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					$("#storyMatrixData").html(html);
				}
			});
		}
	});
	
	$("#toolAccordian").delegate("#storyMatrixData .matrix_remove", "click", function(event) {
		var placeToRemove = $(this).attr('id').split("_");
		var postId = $("#postId").val();
		if(placeToRemove) {
			$.ajax({
				url: "/dpComponent/headlines/deleteStoryMatrixEntry",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&channel=" + placeToRemove[1] + "&subChannel=" + placeToRemove[2],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					$("#storyMatrixData").html(html);
				}
			});
		}
	});
				
	// configure the tags autocomplete!
	// ------------------------------------------------------------------------------------
	configureTags('headlines');
				
	// configure tag remove button...
	$("#toolAccordian").delegate(".tag_remove", "click", function(event) {
		var tagData = $(this).attr('id').split("_");
		$.ajax({
			url: "/dpComponent/headlines/removeTag",
			type: "post",
			data: "tagId=" + tagData[0] + "&postId=" + tagData[1],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
	//			$("#contentLoading").addClass("hide");
				$("#"+html).parent().empty().remove();
			}
		});
	});
				
	// configure event buttons...
	$("#headlines_view").click(function() {
		var postId = $("#postId").val();
		$.ajax({
			url: "/dpComponent/headlines/renderStoryPreview",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId,
			beforeSend: function() {	
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$("#toolPreview").html(html).show("blind", {direction: "vertical"}, 500);
				$("#toolScroll").hide("blind", {direction: "vertical"}, 300);
							
				// turn OFF the view button...
				// turn ON the back button...
				$("#toolWindow .button.view").addClass("hide");
				$("#toolWindow .button.delete").addClass("hide");
				$("#toolWindow .button.back").removeClass("hide");
				$("#toolWindow .button.change").removeClass("hide");
							
			}
		});
	});
				
	$("#headlines_back").click(function() {
		var e=CKEDITOR.instances['articleText'];
		if(e) {
			e.destroy();
			e=null;
		}
		// manipulate tool buttons...
		$("#toolWindow .button.view").removeClass("hide");
		$("#toolWindow .button.delete").removeClass("hide");
		$("#toolWindow .button.back").addClass("hide");
		$("#toolWindow .button.change").addClass("hide");
					
		// show the appropriate content...
		$("#toolPreview").hide("blind", {direction: "vertical"}, 500);
		$("#toolScroll").show("blind", {direction: "vertical"}, 300);
	});
				
	$("#headlines_change").click(function() {
		var postId = $("#postId").val();
		var contributorId = $("#contributorId").val();
					
		//alert('where is this happening' + id[2] + ' || post: ' + xPost + ' || contrib: ' + xContrib);
		// turn the editor on...
		if(!$("div.storyWrap").hasClass('edit')) {
			$("div.storyWrap").addClass('edit');
		}
					
		$("#articleText").ckeditor({
			filebrowserImageBrowseUrl: "/dpComponent/images/toolsLibraryBrowse?channel=" + channel + "&subChannel=" + subchannel + "&postId=" + postId + "&contributorId=" + contributorId
		});
					
		// manipulate the buttons...
		if(!$("#toolWindow .button.back").hasClass("hide")) {
			$("#toolWindow .button.back").addClass("hide");
		}
		if(!$("#toolWindow .button.change").hasClass("hide")) {
			$("#toolWindow .button.change").addClass("hide");
		}
		if($("#toolWindow .button.preview").hasClass("hide")) {
			$("#toolWindow .button.preview").removeClass("hide");
		}
		if($("#toolWindow .button.save").hasClass("hide")) {
			$("#toolWindow .button.save").removeClass("hide");
		}
		if($("#toolWindow .button.cancel").hasClass("hide")) {
			$("#toolWindow .button.cancel").removeClass("hide");
		}
	});
				
	$("#headlines_cancel").click(function() {
		var e=CKEDITOR.instances['articleText'];
		if(e) {
			var htmlData = e.getData();
			e.destroy();
		}
		//$("articleText").html(htmlData);
		$("#toolPreview").hide("blind", {direction: "vertical"}, 500);
		$("#toolScroll").show("blind", {direction: "vertical"}, 300);
		// now, we need to close this window...
						
		if(!$("#toolWindow .button.preview").hasClass("hide")) {
			$("#toolWindow .button.preview").addClass("hide");
		}
		if(!$("#toolWindow .button.save").hasClass("hide")) {
			$("#toolWindow .button.save").addClass("hide");
		}
		if(!$("#toolWindow .button.cancel").hasClass("hide")) {
			$("#toolWindow .button.cancel").addClass("hide");
		}
		if(!$("#toolWindow .button.change").hasClass("hide")) {
			$("#toolWindow .button.change").addClass("hide");
		}
		if($("#toolWindow .button.view").hasClass("hide")) {
			$("#toolWindow .button.view").removeClass("hide");
		}
		if($("#toolWindow .button.delete").hasClass("hide")) {
			$("#toolWindow .button.delete").removeClass("hide");
		}
		if($("#toolWindow .button.edit").hasClass("hide")) {
			$("#toolWindow .button.edit").removeClass("hide");
		}
	});
				
	$("#headlines_preview").click(function() {
		var e=CKEDITOR.instances['articleText'];
		if(e) {
			// get editor contents...
			var htmlData = e.getData();
						
			// destory editor instance...
			e.destroy();
						
			if($("div.storyWrap").hasClass('edit')) {
				$("div.storyWrap").removeClass('edit');
			}
					
			// load editor contents into page...
			$("articleText").html(htmlData);
	
			// turn change button back on...
			if($("#toolWindow .button.change").hasClass("hide")) {
				$("#toolWindow .button.change").removeClass("hide");
			}
			// turn preview button off...
			if(!$("#toolWindow .button.preview").hasClass("hide")) {
				$("#toolWindow .button.preview").addClass("hide");
			}
		}
	});
				
	$("#headlines_delete").click(function() {
		// we need the following data...
		var postId = $("#postId").val();
		var typeId = $("#toolNews .toolNav").attr('id');
		var answer = confirm("Completely Delete this Article?");
					
		if(answer) {
		// start position of the headline list...
		// the type of headlines we are looking for...
		// 
			var metaData = "";
			if ($("#toolScroll div.listNav div.button.page.on").length) {
				metaData = $("#toolScroll div.listNav div.button.page.on").attr("id").split("|");
			} else {
				metaData = array();
			}
			var status = "";
			if($("#Current").hasClass("on")) {
				status = "current";
			} else if($("#Archive").hasClass("on")) {
				status = "archives";
			} else if($("#Pending").hasClass("on")) {
				status = "pending";
			} else if($("#Approve").hasClass("on")) {
				status = "approve";
			}
						
			//alert('Status: ' + status + ' || sp: ' + metaData[2]);
			// i need itmc...
			$.ajax({
				url: "/dpComponent/headlines/toolsDeleteArticle",
				type: "post",
							
				// we need typeId (id# of the type being sent over...
							
				data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + typeId,
				beforeSend: function() {	
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
							
					// replace the side bar...
					// this should be the default sidebar...
					$("#toolWindow").html("");
								
					// remove the item from the list...
					$("#toolScroll").html(html);

				}
			});
		}
	});
				
	$("#headlines_save").click(function() {
		var postId = $("#postId").val();
		var e=CKEDITOR.instances['articleText'];
		var htmlData = "";
					
		if(e) {
			htmlData = encodeURIComponent(e.getData());
			e.destroy();
			e=null;
		} else {
			// adds slashes...
			htmlData = encodeURIComponent($("#articleText").html()).replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
		}
		$.ajax({
			url: "/dpComponent/headlines/toolsSaveArticleData",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&eData=" + htmlData,
			beforeSend: function() {	
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				if($("div.storyWrap").hasClass('edit')) {
					$("div.storyWrap").removeClass('edit');
				}
						
				$("#eventText").html(html);
				if(!$("#toolWindow .button.preview").hasClass("hide")) {
					$("#toolWindow .button.preview").addClass("hide");
				}
				if(!$("#toolWindow .button.save").hasClass("hide")) {
					$("#toolWindow .button.save").addClass("hide");
				}
				if(!$("#toolWindow .button.cancel").hasClass("hide")) {
					$("#toolWindow .button.cancel").addClass("hide");
				}
					
				// turn on the view button...
				if($("#toolWindow .button.back").hasClass("hide")) {
					$("#toolWindow .button.back").removeClass("hide");
				}
				if($("#toolWindow .button.change").hasClass("hide")) {
					$("#toolWindow .button.change").removeClass("hide");
				}
	
							// just put the editor contents back into the div...
							
			}
		});
	});
}

function toolsCalendarCreate(msg) {
	//alert('msg: ' + msg);
	$("#toolCalendar").delegate("#createHeadline", "click", function(event)
	{
		var title = $("#naTitle").val();
		var contributor = $("#naContributor").val();
		var author = $("#naAuthor").val();
		var e=CKEDITOR.instances['eventText'];
		if(e) {
			e.destroy();
			e=null;
		}
		if(title) {
			// create the article placeholder...
			$.ajax({
				url: "/dpComponent/events/createEventHeadline",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&title=" + title + "&contributor=" + contributor + "&author=" + author,
				dataType: "json",
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				error: function(html) {
					// this is the error function here...
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					
					// hide step one...
					$("#eventCreateOne").addClass("hide");
					$("#eventIntroText").addClass("hide");
					
					// display step two...
					$("#eventCreateTwo").removeClass('hide');
					$("#previewAnEvent").removeClass('hide');
					$("#createAnEvent").removeClass('hide');
					
					// output the editor...
					if ($("#eventText").length) {
						$("#eventText").ckeditor({
							// here is where it needs to change...
							filebrowserImageBrowseUrl: "/dpComponent/images/toolsLibraryBrowse?channel=" + channel + "&subChannel=" + subchannel + "&postId=" + html.id + "&contributorId=" + html.contributor
						});
						//CKEDITOR.instances['articleText']
					}
					
					// change the help instructions...
					$("#helpStepOne").addClass('hide');
					$("#helpStepTwo").removeClass('hide');
					
					// use return json data to populate preview page...
					$("#postId").val(html.id);
					$("#postEmail").val(html.email);
					$("#eventContributorData").html(html.contributor);
					$("#eventAuthorData").html(html.author);
					$("#eventPublishDate").html(html.postDate);
					$("#eventTitleData").html(html.title);
				}
			});
		}
	});
	
	// jquery for step two of event creation...
	$("#tools").delegate("#toolCalendar #createAnEvent", "click", function(event)
	{
		var title = $("#naTitle").val();
		var contributor = $("#naContributor").val();
		var author = $("#naAuthor").val();
		
		var e=CKEDITOR.instances['eventText'];
		var htmlData = "";
		if(e) {
			// get html data from form...
			htmlData = encodeURIComponent(e.getData());
		} else {
			// get html data from preview...
			htmlData = encodeURIComponent($("#previewText").html()).replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0'); // adds slashes...
		}
				
		$.ajax({
			url: "/dpComponent/events/createAnEvent",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&title=" + title + "&author=" + author + "&contributor=" + contributor + "&text=" + htmlData,
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				var postId = $("#postId").val();
				//alert(html);
				/*
				var e=CKEDITOR.instances['eventText'];
				*/
				if(e) {
					e.destroy();
					e=null;
				}
				$("#contentLoading").addClass("hide");
				$("#helpStepTwo").addClass('hide');
				$("#helpStepThree").removeClass('hide');
				
				$("#createScreen").html('').hide();
				$("#previewScreen").html('').hide();
				$("#successScreen").html(html).show();
				
				if(postId) {
					enableCalendarDateInputs();
					
					$("#eventRecurBasic").change(function() {
						var recurType = $(this).val();
						if(recurType=="Custom") {
							$("#eventRecur").show();
						} else {
							$("#eventRecur").hide();
						}
						//alert("recur type: " + recurType);
					});
					
					// type of custom recurring event setter...
					// this can be configured for top dogs only!
					$("#eventRecurType").change(function() {
						var recurType = $(this).val();
						//alert("recur type: " + recurType);
					});
					
					// set event dates...
					// ---------------------------------------------------------------------------------
					$("#eventDates.zeb div.articleButton").click(function() {
					
						
						var startDate = $("#eventStart").val();
						var endDate = $("#eventEnd").val();
						var displayStart = $("#naStart").val();
						var displayEnd = $("#naEnd").val();
						var recurType = $("#eventRecurBasic").val();
						var recurWeeks = $("#eventRecurWeeks").val();
						var recurMonths = $("#eventRecurMonths").val();
						var recurMonthType = $("#eventRecurMonthlyOptions input:radio:checked").val();
						var recurMonthTypeSelect = $("#monthRecurTypeSelect").val();
						
						if(!startDate) {
							alert("Please select a date for your event");
						} else {
							
							$.ajax({
								url: "/dpComponent/events/toolsUpdateEventDates",
								type: "post",
								data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&start=" + startDate + "&end=" + endDate + "&dstart=" + displayStart + "&dend=" + displayEnd + "&recurType=" + recurType + "&recurWeeks=" + recurWeeks + "&recurMonths=" + recurMonths + "&recurMonthType=" + recurMonthType + "&recurMonthTypeSelect=" + recurMonthTypeSelect,
								beforeSend: function() {
									$("#contentLoading").removeClass("hide");
								},
								success: function(html) {
									$("#contentLoading").addClass("hide");
									$("#sgst_dates").html(html);
									$("#eventDates").removeClass("zeb");
									$("#eventDates .editType .descrip").hide();
									
									$("#helpStepThree .enhanceStep").addClass('hide');
									$("#enhanceMap").removeClass("hide");

									// HERE IS WHERE THE ADDITIONS GO...
									
									$("#eventMap").addClass("zeb").removeClass("hide");
									$("#eventMap div.articleButton").click(function() {
									
										var postId = $("#postId").val();
										var address = $("#eventAddress").val();
										
										$.ajax({
											url: "/dpComponent/events/addAddress",
											type: "post",
											data: "cid=" + channel + "&scid=" + subchannel + "&p=" + postId + "&a=" + address,
											beforeSend: function() {
												$("#contentLoading").removeClass("hide");
											},
											success: function(html) {
												$("#contentLoading").addClass("hide");
												$("#event_map").html(html);
												$("#eventMap").removeClass("zeb");
												$("#eventMap .editType .descrip").hide();
												if($("#viewMap").length) {
													var mapAddress = $("#viewMap").html();
													$("#viewMap").googleMap(mapAddress);
												}
												
												$("#helpStepThree .enhanceStep").addClass('hide');
												$("#enhancePlacement").removeClass("hide");
												
												
												
									// event placement
									// ---------------------------------------------------------------------
									$("#eventPlacement").addClass("zeb").removeClass("hide");
									$("#eventPlacement div.articleButton").click(function() {
										
										var postId = $("#postId").val();
										var placement = $("#suggestPlacement").val().split("_");
										$.ajax({
											url: "/dpComponent/events/suggestPlacement",
											type: "post",
											data: "cid=" + channel + "&scid=" + subchannel + "&p=" + postId + "&c=" + placement[0] + "&s=" + placement[1],
											beforeSend: function() {
												$("#contentLoading").removeClass("hide");
											},
											success: function(html) {
												$("#contentLoading").addClass("hide");
												$("#sgst_plc").html(html);
												$("#eventPlacement").removeClass("zeb");
												$("#eventPlacement .editType .descrip").hide();
												
												
												// event location
												// ------------------------------------------------------------
												$("#helpStepThree .enhanceStep").addClass('hide');
												$("#enhanceLocation").removeClass("hide");
												
												$("#eventLocation").addClass("zeb").removeClass("hide");
												$("#eventLocation div.articleButton").click(function() {
													var postId = $("#postId").val();
													var tag = $("#geoTags").val();
													$.ajax({
														url: "/dpComponent/events/suggestTag",
														type: "post",
														data: "cid=" + channel + "&scid=" + subchannel + "&p=" + postId + "&t=" + tag + "&g=1",
														beforeSend: function() {
															$("#contentLoading").removeClass("hide");
														},
														success: function(html) {
															$("#contentLoading").addClass("hide");
															$("#sgst_geo").html(html);
															$("#eventLocation").removeClass("zeb");
															$("#eventLocation .editType .descrip").hide();
															
															// event tags...
															// ---------------------------------------------------
															$("#helpStepThree .enhanceStep").addClass('hide');
															$("#enhanceTags").removeClass("hide");
												
															$("#eventTag").addClass("zeb").removeClass("hide");
															$("#eventTag div.articleButton").click(function() {
																
																var postId = $("#postId").val();
																var tag = $("#contentTags").val();
																//sgst_tg
																$.ajax({
																	url: "/dpComponent/events/suggestTag",
																	type: "post",
																	data: "cid=" + channel + "&scid=" + subchannel + "&p=" + postId + "&t=" + tag,
																	dataType: "json",
																	beforeSend: function() {
																		$("#contentLoading").removeClass("hide");
																	},
																	success: function(data) {
																		$("#contentLoading").addClass("hide");
																		if(data) {
																			if(data[0]) {
																				$("#tagOne").html(data[0]);
																			}
																			if(data[1]) {
																				if(data[1] != "--") {
																					$("#tagTwo").html(data[1]);
																				}
																			}
																			$("#contentTags").val('');
																			
																			if(data[2]) {
																				if(data[2] != "--") {
																					$("#tagThree").html(data[2]);
																				}
																				$("#eventTag").removeClass("zeb");
																				$("#eventTag .editType .descrip").hide();
																				$("#tagAddForm").html("");
																				
																				// event thumbnail...
																				// ------------------------------------
																				if ($("#eventThumb").length) {
																					
																					$("#helpStepThree .enhanceStep").addClass('hide');
																					$("#enhanceThumb").removeClass("hide");
												
												
																					$("#eventThumb").addClass("zeb").removeClass("hide");
																					$("#eventThumb img").click(function() {
																					
																						var postId = $("#postId").val();
																						var thumb = $(this).attr('src').replace("/media/"+dpclient+"/images/","").replace("_icon","").split(".");
																						
																						$.ajax({
																							url: "/dpComponent/events/updatePostThumb",
																							type: "post",
																							data: "postId=" + postId + "&thumbId=" + thumb[0] + "&thumbExt=" + thumb[1],
																							success: function(html) {
																							
																								// this all needs to change.  We are already here...
																						//		$("#thumbnail_default").html(html);
																						//		$("#thumbnail_default").attr("id","thumbnail_"+thumb[0]);
																								$("#toolScroll #eventThumb").removeClass("zeb").hide();
																								$("#userThumb .editType .descrip").hide();
																								
																								$("#toolScroll #eventReview").addClass("zeb").removeClass("hide");
																								$("#toolScroll #eventReviewWindow div.text").html(html);
																								
																								$("#helpStepThree .enhanceStep").addClass('hide');
																								$("#enhanceDone").removeClass("hide");
																					
																								$("#toolsAgain").click(function() {
																									/*
																									var e=CKEDITOR.instances['eventText'];
																									*/
																									if(e) {
																										e.destroy();
																										e=null;
																									}
																									
																									$.ajax({
																										url: "/dpComponent/events/toolsDisplayCreateAjax",
																										type: "post",
																										data: "cid=" + channel + "&scid=" + subchannel + "&typeId=",
																										beforeSend: function() {
																											$("#contentLoading").removeClass("hide");
																										},
																										success: function(html) {
																											// now, we need to remove the ON from the current tabs...
																											$(".toolNav div").removeClass("on");
																											//$(parent).addClass("on");
																											$("#contentLoading").addClass("hide");
																											$("#toolInterface").html(html);
																										}
																									});
																									return false;
									
																									//alert('works');
																								});
																	
																							}
																						});
		
																					});
																				} else {
																				
																					// we need to run some ajax here, that will load the review of the item...
																					var postId = $("#postId").val();
																					$.ajax({
																						url: "/dpComponent/events/outputEventReview",
																						type: "post",
																						data: "postId=" + postId,
																						success: function(html) {
																							
																							// this all needs to change.  We are already here...
																					//		$("#thumbnail_default").html(html);
																					//		$("#thumbnail_default").attr("id","thumbnail_"+thumb[0]);
																							$("#toolScroll #eventThumb").removeClass("zeb").hide();
																							$("#userThumb .editType .descrip").hide();
																								
																							$("#toolScroll #eventReview").addClass("zeb").removeClass("hide");
																							$("#toolScroll #eventReviewWindow div.text").html(html);
																							
																							$("#helpStepThree .enhanceStep").addClass('hide');
																							$("#enhanceDone").removeClass("hide");
																								
																							$("#toolsAgain").click(function() {
																									
																									/*
																									var e=CKEDITOR.instances['eventText'];
																									*/
																									if(e) {
																										e.destroy();
																										e=null;
																									}
																									
																									
																									$.ajax({
																										url: "/dpComponent/events/toolsDisplayCreateAjax",
																										type: "post",
																										data: "cid=" + channel + "&scid=" + subchannel + "&typeId=",
																										beforeSend: function() {
																											$("#contentLoading").removeClass("hide");
																										},
																										success: function(html) {
																											// now, we need to remove the ON from the current tabs...
																											$(".toolNav div").removeClass("on");
																											//$(parent).addClass("on");
																											$("#contentLoading").addClass("hide");
																											$("#toolInterface").html(html);
																										}
																									});
																									return false;
									
																									//alert('works');
																								});
																								
																								
																								
																						}
																					});
																				}
																			}
																		}
																	}
																});
															});
														}
													});
												});
											}
										});
									});
									
									// HERE IS WHERE THE OTHER STUFF GOES...
											}
										});
									});
									
									
								}
							});
						}
					});
					// load the conclusion screen...
					/*
					$.ajax({
						url: "/dpComponent/headlines/toolsDisplayOverviewAjax",
						type: "post",
						data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId,
						beforeSend: function() {
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							//$(item).addClass("on");
							$("#contentLoading").addClass("hide");
							$("#toolWindow").html(html);
							$("#toolAccordian").tabs("#toolAccordian div.tier", {tabs: 'h2', effect: 'slide', initialIndex: null});
									
							// content archive date...
							$("#archive_date").dateinput({
								selectors: true,
								change: function() {
									var isoDate = this.getValue('yyyy-mm-dd');
									var storyId = $("#postId").val();
									$("#publish_date:date").data("dateinput").setMax(this.getValue(), true);
									$.ajax({
										url: "/dpComponent/headlines/changeArchiveDate",
										type: "post",
										data: "id=" + storyId + "&date=" + isoDate,
										beforeSend: function() {
											$("#contentLoading").removeClass("hide");
										},
										success: function(html) {
											$("#currentStatus").html(html);
											$("#contentLoading").addClass("hide");
										}
									});
								}
							});
									
							// content publish date...
							$("#publish_date").dateinput({
								selectors: true,
								change: function() {
									var isoDate = this.getValue('yyyy-mm-dd');
									var storyId = $("#postId").val();
									$("#archive_date:date").data("dateinput").setMin(this.getValue(), true);
									$.ajax({
										url: "/dpComponent/headlines/changePublishDate",
										type: "post",
										data: "id=" + storyId + "&date=" + isoDate,
										beforeSend: function() {
											$("#contentLoading").removeClass("hide");
										},
										success: function(html) {
											$("#currentStatus").html(html);
											$("#contentLoading").addClass("hide");
										}
									});
								}
							});
							
							// content tag search...
							$("#tagSearch").autocomplete({
								source: "/dpComponent/channel/tagsJSON",
								minLength: 2,
								select: function(event, ui) {
									var storyId = $("#postId").val();
									if(ui.item.id && storyId) {
										$.ajax({
											url: "/dpComponent/headlines/toolsAddTag",
											type: "post",
											data: "cid=" + channel + "&scid=" + subchannel + "&id=" + storyId + "&tag=" + ui.item.id + "&type=" + ui.item.geo,
											beforeSend: function() {
												$("#contentLoading").removeClass("hide");
											},
											success: function(html) {
												$("#contentLoading").addClass("hide");
												$("#storyTagData").html(html);
												$("input#tagSearch").val('');
											}
										});
									}
								}
							}).blur(function() {
								if($(this).val() == "  ") {
									$(this).val('');
								}
							});
									
							// content geo-tag search...
							$("#geoTagSearch").autocomplete({
								source: "/dpComponent/channel/geoTagsJSON",
								minLength: 2,
								select: function(event, ui) {
									var storyId = $("#postId").val();
									if(ui.item.id && storyId) {
										$.ajax({
											url: "/dpComponent/headlines/toolsAddTag",
											type: "post",
											data: "cid=" + channel + "&scid=" + subchannel + "&id=" + storyId + "&tag=" + ui.item.id + "&type=" + ui.item.geo,
											beforeSend: function() {
												$("#contentLoading").removeClass("hide");
											},
											success: function(html) {
												$("#contentLoading").addClass("hide");
												$("#geoTagData").html(html);
												$("input#geoTagSearch").val('');
											}
										});
									}
								}
							}).blur(function() {
								if($(this).val() == "  ") {
									$(this).val('');
								}
							});
						
						}
					});
					*/
				}
				// here, we need to do a couple of things...
				$("#previewAnEvent").addClass('hide');
				$("#createAnEvent").addClass('hide');
				$("#editAnEvent").addClass('hide');
			}
		});
		
	});
	
	// event review & edit buttons (CREATION SCRIPT).
	$("#tools").delegate("#toolCalendar #previewAnEvent", "click", function(event)
	{
		var headline = $("#naHeadline").val();
		var e=CKEDITOR.instances['eventText'];
		var htmlData = "";
		if(e) {
			htmlData = e.getData();
			e.destroy();
			e=null;
		}
		$("#previewHeadline").html(headline);
		$("#previewText").html(htmlData);	
		$("#createScreen").hide();
		$("#previewScreen").show();
		$("#previewAnEvent").addClass('hide');
		$("#editAnEvent").removeClass('hide');
	});
	
	$("#tools").delegate("#toolCalendar #editAnEvent", "click", function(event)
	{
		var htmlData = $("previewText").html();
		var postId = $("#postId").val();
		var contributorId = $("#naPublisher").val();
		$("#previewHeadline").html('');
		$("#previewText").html('');	
		$("#previewScreen").hide();
		$("#editAnEvent").addClass('hide');
		$("#createScreen").show();
		if ($("#eventText").length) {
			$("#eventText").ckeditor({
				filebrowserImageBrowseUrl: "/dpComponent/images/toolsLibraryBrowse?channel=" + channel + "&subChannel=" + subchannel + "&postId=" + postId + "&contributorId=" + contributorId
			}).data(htmlData);
		}
		$("#previewAnEvent").removeClass('hide');
	});
}

function toolsCalendarManage(msg) {
	//alert('msg: ' + msg);
	
	$("#toolCalendar").delegate(".rowItem", "click", function(event)
	{
	//$("#toolNews .rowItem").live("click",function() {
		var itemId = $(this).attr('id');
		var item = $(this);
		$.ajax({
			url: "/dpComponent/events/toolsDisplayOverviewAjax",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + itemId,
			beforeSend: function() {
				// we need to remove the class from ANY of the rowitem values...
				$("#toolScroll div.rowItem").removeClass("on");
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				var postId = $("#postId").val();
				$(item).addClass("on");
				$("#contentLoading").addClass("hide");
				
				outputEventTool(item,html);
			}
		});
	});

	$("#tools").delegate("#toolCalendar #toolScroll div.statusBox.topStory, #toolCalendar #toolScroll div.statusBox.feature", "click", function()
	{
		var isOn = false;
		var eventId = $(this).parent().parent().attr('id');
		if($(this).hasClass('topStory')) {
			var statusType = "topStory";
		} else {
			var statusType = "feature";
		}
		var status = "";
		var startpos = $(this).parent().attr('class').replace("status sp_","");
		if($("#Current").hasClass("on")) {
			status = "current";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		}
		if($(this).hasClass('checked')) {
			isOn = true;
		}
		$.ajax({
			url: "/dpComponent/events/toolsUpdateLayoutStatus",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + eventId + "&type=" + statusType + "&fstatus=" + isOn + "&startpos=" + startpos + "&status=" + status,
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$("#toolScroll").html(html);
			}
		});
	});

	$("div#tools #toolCalendar #toolScroll").delegate(".button.page.active", "click", function(event)
	{
		var metaData = $(this).attr('id').split("|");
		var status = "";
		if($("#Current").hasClass("on")) {
			status = "current";
//		} else if($("#archiveCalendar").hasClass("on")) {
//			status = "archives";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		}
		$.ajax({
			url: "/dpComponent/events/toolsDisplayStep",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + metaData[1],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolScroll").html(html);
			}
		});
	});
	
	$("div#tools #toolCalendar #toolScroll").delegate(".button.step.active", "click", function(event)
	{
		var metaData = $(this).attr('id').split("|");
		var status = "";
		if($("#Current").hasClass("on")) {
			status = "current";
//		} else if($("#archiveCalendar").hasClass("on")) {
//			status = "archives";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		}
		$.ajax({
			url: "/dpComponent/events/toolsDisplayStep",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + metaData[1],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolScroll").html(html);
			}
		});
	});
}

function outputEventTool(item,html) {
	$("#toolWindow").html(html);
	$("#toolAccordian").tabs("#toolAccordian div.tier", {tabs: 'h2', effect: 'slide', initialIndex: null});
				
	// configure photo library...
	$("#toolAccordian").delegate(".setThumbnail", "click", function(event) {
	
		var clickedImg = $(this).attr("id").replace("thumbnail_","").replace("default","");
		
		overlayURL = "/dpComponent/channel/mediaLibraryOverlay?src=tool&dst=images";
		var overlayAPI = $("#toolsOverlay").data("overlay");
		$("#toolsOverlay").bind("onClose", function() {
			$("#toolsOverlay .overlayWrap").html("");
			$(this).unbind("onClose");	// unbind so we don't bubble up...
		});
		$("#toolsOverlay").bind("onLoad", function() {
			setTimeout(function(){configureImageDialog("",overlayAPI,clickedImg,""); overlayAPI=null; clickedImg=null},500);
			//setTimeout('configureImageDialog("",overlayAPI,clickedImg,"")',1000);
			//configureImageDialog("",overlayAPI,clickedImg,"");
			$(this).unbind("onLoad"); // unbind so we don't bubble up...
		});
		overlayAPI.load();
		return false;
	});
	
	// configure... edit-in-place headline...
	// ------------------------------------------------------------------------------------
	$("#previewWindow .headline").click(function() {
		var postId = $("#postId").val();
		// update DOM...
		$("#headline_"+postId).hide();
		$("#headlineEdit_"+postId).show();
		$("#newHeadline").focus();
	});
	$("#previewWindow #newHeadline").blur(function() {
		var postId = $("#postId").val();
		var nData = $(this).val();
		var oData = $("#origHeadline").val();	
		if(nData != oData) {
			$.ajax({
				url: "/dpComponent/events/updateHeadline",
				type: "post",
				data: "id=" + postId + "&nd=" + nData,
	//			beforeSend: function() {
	//				$("#contentLoading").removeClass("hide");
	//			},
				success: function(html) {
					$("#previewWindow .headline").html(html);
					$("#toolScroll .rowItem.on .articleHeadline").html(html);
					$("#previewWindow #origHeadline").val(html);
					$("#previewWindow #newHeadline").val(html);
				}
			});
		}
		$("#headline_"+postId).show();
		$("#headlineEdit_"+postId).hide();
	});
	
	// configure... edit-in-place lead...
	// ------------------------------------------------------------------------------------
	$("#previewWindow .lead").click(function() {
		var postId = $("#postId").val();
		// update DOM...
		$("#lead_"+postId).hide();
		$("#leadEdit_"+postId).show();
		$("#newLead").focus();
	});
	$("#previewWindow #newLead").blur(function() {
		var postId = $("#postId").val();
		var nData = $(this).val();
		var oData = $("#origLead").val();
		if(nData != oData) {
			$.ajax({
				url: "/dpComponent/events/updateLead",
				type: "post",
				data: "id=" + postId + "&nd=" + nData,
				// here, we need a rotating image for the overlay...
	//			beforeSend: function() {
	//				$("#contentLoading").removeClass("hide");
	//			},
				success: function(html) {
					$("#previewWindow .lead").html(html);
					$("#previewWindow #origLead").val(html);
					$("#previewWindow #newLead").val(html);
				}
			});
		}
		$("#lead_"+postId).show();
		$("#leadEdit_"+postId).hide();
	});
	
	// publish button
	// ------------------------------------------------------------------------------------
	$("#publishEvent").click(function() {
		var postId = $("#postId").val();
		var parentId = $("#parentId").val();
		$.ajax({
			url: "/dpComponent/events/publishEvent",
			type: "post",
			data: "id=" + postId + "&parent=" + parentId,
	//			beforeSend: function() {
	//				$("#contentLoading").removeClass("hide");
	//			},
			success: function(html) {
				$("#publishEvent").remove();
				$("#currentStatus").html(html);
				// this should actually reload the entire toolWindow, so that 
				// multiple items can be published and the navigation system will continue to function...
			}
		});
	});
	
	enableStatusDateInputs('events');
	
	// configure... interactivity...
	//commentsStatus
	$("#commentsStatus").click(function() {
		var postId = $("#postId").val();
		var currentVal = $(this).html();
		$.ajax({
			url: "/dpComponent/events/toggleComments",
			type: "post",
			data: "id=" + postId + "&cur=" + currentVal,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#commentsStatus").html(html);
			}
		});
	});
	
	$("#rankingStatus").click(function() {
		var postId = $("#postId").val();
		var currentVal = $(this).html();
		$.ajax({
			url: "/dpComponent/events/toggleRanking",
			type: "post",
			data: "id=" + postId + "&cur=" + currentVal,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#rankingStatus").html(html);
			}
		});
	});
	
	$("#toolAccordian").delegate("#addCalendarPlacement", "click", function(event) {
	//$("#addCalendarPlacement").click(function() {
		var placeToAdd = $("select#addPlacement").val();
		var postId = $("#postId").val();
		if(placeToAdd && postId) {
			var matrixData = placeToAdd.split("_");
			$.ajax({
				url: "/dpComponent/events/toolsPlaceContent",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&channel=" + matrixData[0] + "&subChannel=" + matrixData[1],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					$("#eventMatrixData").html(html);
				}
			});
		}
	});
	
	$("#toolAccordian").delegate("#eventMatrixData .matrix_remove", "click", function(event) {
		var placeToRemove = $(this).attr('id').split("_");
		var postId = $("#postId").val();
		
		if(placeToRemove) {
			$.ajax({
				url: "/dpComponent/events/deleteEventMatrixEntry",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&channel=" + placeToRemove[1] + "&subChannel=" + placeToRemove[2],
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
					$("#eventMatrixData").html(html);
				}
			});
		}
	});
	
	// configure the tags autocomplete!
	// ------------------------------------------------------------------------------------
	configureTags('events');

	// configure tag remove button...
	$("#toolAccordian").delegate(".tag_remove", "click", function(event) {
		var tagData = $(this).attr('id').split("_");
		$.ajax({
			url: "/dpComponent/events/removeTag",
			type: "post",
			data: "tagId=" + tagData[0] + "&postId=" + tagData[1],
//			beforeSend: function() {
//				$("#contentLoading").removeClass("hide");
//			},
			success: function(html) {
			//	$("#contentLoading").addClass("hide");
				$("#"+html).parent().empty().remove();
			}
		});
	});
	
	// configure event buttons...
	$("#calendar_view").click(function() {
		var postId = $("#postId").val();
		$.ajax({
			url: "/dpComponent/events/renderEventPreview",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId,
			beforeSend: function() {	
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$("#toolPreview").html(html).show("blind", {direction: "vertical"}, 500);
				$("#toolScroll").hide("blind", {direction: "vertical"}, 300);
				
				// turn OFF the view button...
				// turn ON the back button...
				$("#toolWindow .button.view").addClass("hide");
				$("#toolWindow .button.delete").addClass("hide");
				$("#toolWindow .button.back").removeClass("hide");
				$("#toolWindow .button.change").removeClass("hide");
	
			}
		});		
	});
	
	$("#calendar_back").click(function() {
		var e=CKEDITOR.instances['eventText'];
		if(e) {
			e.destroy();
			e=null;
		}
		// manipulate tool buttons...
		$("#toolWindow .button.view").removeClass("hide");
		$("#toolWindow .button.delete").removeClass("hide");
		$("#toolWindow .button.back").addClass("hide");
		$("#toolWindow .button.change").addClass("hide");
		
		// show the appropriate content...
		$("#toolPreview").hide("blind", {direction: "vertical"}, 500);
		$("#toolScroll").show("blind", {direction: "vertical"}, 300);
	});
	
	$("#calendar_change").click(function() {
	
		var postId = $("#postId").val();
		var contributorId = $("#contributorId").val();
		
		//alert('where is this happening' + id[2] + ' || post: ' + xPost + ' || contrib: ' + xContrib);
		// turn the editor on...
		if(!$("div.storyWrap").hasClass('edit')) {
			$("div.storyWrap").addClass('edit');
		}
		
		$("#eventText").ckeditor({
			filebrowserImageBrowseUrl: "/dpComponent/images/toolsLibraryBrowse?channel=" + channel + "&subChannel=" + subchannel + "&postId=" + postId + "&contributorId=" + contributorId
		});
					
		// manipulate the buttons...
		if(!$("#toolWindow .button.back").hasClass("hide")) {
			$("#toolWindow .button.back").addClass("hide");
		}
		if(!$("#toolWindow .button.change").hasClass("hide")) {
			$("#toolWindow .button.change").addClass("hide");
		}
		if($("#toolWindow .button.preview").hasClass("hide")) {
			$("#toolWindow .button.preview").removeClass("hide");
		}
		if($("#toolWindow .button.save").hasClass("hide")) {
			$("#toolWindow .button.save").removeClass("hide");
		}
		if($("#toolWindow .button.cancel").hasClass("hide")) {
			$("#toolWindow .button.cancel").removeClass("hide");
		}
	});
	
	$("#calendar_cancel").click(function() {
		var e=CKEDITOR.instances['eventText'];
		if(e) {
			var htmlData = e.getData();
			e.destroy();
		}
		//$("articleText").html(htmlData);
		$("#toolPreview").hide("blind", {direction: "vertical"}, 500);
		$("#toolScroll").show("blind", {direction: "vertical"}, 300);
		// now, we need to close this window...

		if(!$("#toolWindow .button.preview").hasClass("hide")) {
			$("#toolWindow .button.preview").addClass("hide");
		}
		if(!$("#toolWindow .button.save").hasClass("hide")) {
			$("#toolWindow .button.save").addClass("hide");
		}
		if(!$("#toolWindow .button.cancel").hasClass("hide")) {
			$("#toolWindow .button.cancel").addClass("hide");
		}
		if(!$("#toolWindow .button.change").hasClass("hide")) {
			$("#toolWindow .button.change").addClass("hide");
		}
		if($("#toolWindow .button.view").hasClass("hide")) {
			$("#toolWindow .button.view").removeClass("hide");
		}
		if($("#toolWindow .button.delete").hasClass("hide")) {
			$("#toolWindow .button.delete").removeClass("hide");
		}
		if($("#toolWindow .button.edit").hasClass("hide")) {
			$("#toolWindow .button.edit").removeClass("hide");
		}
	});
	
	$("#calendar_preview").click(function() {
		var e=CKEDITOR.instances['eventText'];
		if(e) {
			// get editor contents...
			var htmlData = e.getData();

			// destory editor instance...
			e.destroy();

			if($("div.storyWrap").hasClass('edit')) {
				$("div.storyWrap").removeClass('edit');
			}
		
			// load editor contents into page...
			$("eventText").html(htmlData);
	
			// turn change button back on...
			if($("#toolWindow .button.change").hasClass("hide")) {
				$("#toolWindow .button.change").removeClass("hide");
			}
			// turn preview button off...
			if(!$("#toolWindow .button.preview").hasClass("hide")) {
				$("#toolWindow .button.preview").addClass("hide");
			}
		}
	});
	
	$("#calendar_delete").click(function() {
		// we need the following data...
		var postId = $("#postId").val();
		var typeId = $("#toolCalendar .toolNav").attr('id');
		var answer = confirm("Completely Delete this Event?  This will completely remove the event from your online calendar.");
		
		if(answer) {
		// start position of the headline list...
		// the type of headlines we are looking for...
		// 
			var metaData = $("#toolScroll div.listNav div.button.page.on").attr("id").split("|");
			var status = "";
			if($("#Current").hasClass("on")) {
				status = "current";
			} else if($("#Pending").hasClass("on")) {
				status = "pending";
			}

			//alert('Status: ' + status + ' || sp: ' + metaData[2]);
			// i need itmc...
			$.ajax({
				url: "/dpComponent/events/toolsDeleteEvent",
				type: "post",
	
				// we need typeId (id# of the type being sent over...
	
				data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + typeId,
				beforeSend: function() {	
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
	
					// replace the side bar...
					// this should be the default sidebar...
					$("#toolWindow").html("");
		
					// remove the item from the list...
					$("#toolScroll").html(html);

				}
			});
		}
	});
	
	$("#calendar_deleterecur").click(function() {
		// we need the following data...
		var postId = $("#postId").val();
		var parentId = $("#parentId").val();
		var typeId = $("#toolCalendar .toolNav").attr('id');
		var answer = confirm("Completely Delete this Event and all recurring copies?  This will completely remove this event from your online calendar.");
		
		if(answer) {
			var metaData = $("#toolScroll div.listNav div.button.page.on").attr("id").split("|");
			var status = "";
			if($("#Current").hasClass("on")) {
				status = "current";
			} else if($("#Pending").hasClass("on")) {
				status = "pending";
			}
			$.ajax({
				url: "/dpComponent/events/toolsDeleteRecurringEvent",
				type: "post",
				data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&parent=" + parentId + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + typeId,
				beforeSend: function() {	
					$("#contentLoading").removeClass("hide");
				},
				success: function(html) {
					$("#contentLoading").addClass("hide");
	
					// replace the side bar...
					// this should be the default sidebar...
					$("#toolWindow").html("");
		
					// remove the item from the list...
					$("#toolScroll").html(html);

				}
			});
		}
	});
	
	
	
	$("#calendar_save").click(function() {
		var postId = $("#postId").val();
		var e=CKEDITOR.instances['eventText'];
		var htmlData = "";
		
		if(e) {
			htmlData = encodeURIComponent(e.getData());
			e.destroy();
			e=null;
		} else {
			// adds slashes...
			htmlData = encodeURIComponent($("#eventText").html()).replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
		}
		$.ajax({
			url: "/dpComponent/events/toolsSaveEventData",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&eData=" + htmlData,
			beforeSend: function() {	
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				if($("div.storyWrap").hasClass('edit')) {
					$("div.storyWrap").removeClass('edit');
				}

				$("#eventText").html(html);
				// turn off the cancel button...
				// turn off the save button
				// turn off the preview button...
				if(!$("#toolWindow .button.preview").hasClass("hide")) {
					$("#toolWindow .button.preview").addClass("hide");
				}
				if(!$("#toolWindow .button.save").hasClass("hide")) {
					$("#toolWindow .button.save").addClass("hide");
				}
				if(!$("#toolWindow .button.cancel").hasClass("hide")) {
					$("#toolWindow .button.cancel").addClass("hide");
				}
		
				// turn on the view button...
				if($("#toolWindow .button.back").hasClass("hide")) {
					$("#toolWindow .button.back").removeClass("hide");
				}
				if($("#toolWindow .button.change").hasClass("hide")) {
					$("#toolWindow .button.change").removeClass("hide");
				}
	
				// just put the editor contents back into the div...
	
			}
		});
	});
}


// IMAGE OVERLAY CODE...
// ------------------------------------------------------------------------------------------------
function toolsImageUpload(e,api) {
	var src = $("input#src").val();
	var postId = "";
	var contributorId = "";
	if($("#postId").length) {
		postId = $("#postId").val();
	}
	// this needs to be cleaned up through
	// all of the publishers... do it...
	if($("#naPublisher").length) {
		contributorId = $("#naPublisher").val();
	} else if($("#naContributor").length) {
		contributorId = $("#naContributor").val();
	} else if($("#contributorId").length) {
		contributorId = $("#contributorId").val();
	}
	
	
	
	//alert("post: " + postId + " || contributor: "+contributorId);
	var seskey = document.cookie.split(';');
	var tempkey = "";
	var cookieName = "";
	var seskeyVal = "";
	for(i=0; i< seskey.length; i++) {
		tempKey = seskey[i].split("=");
		cookieName = tempKey[0].replace(/^\s+|\s+$/g, "");
		if(cookieName == "seskey") {
			seskeyVal = unescape(tempKey[1].replace(/^\s+|\s+$/g, ""));
		}
	}
	
	
	// if we passed the source to this
	// we could set it up where classified images are automatically private
	// and all other uploaded images are automatically shared.
	
	$("#overlayUpload").uploadify({
		"uploader" : "/images/uploadify.swf",
		"script" : "/dpComponent/images/toolsUploadPhotos",
		"fileExt" : "*.png;*.gif;*.jpg;*.jpeg;",
		"fileDesc" : "put a description here",
		"cancelImg" : "/images/cancel.png",
		"scriptData" : {"channel": channel, "subChannel": subchannel, "contributorId": contributorId, "postId": postId, "seskeyVal": seskeyVal, "src": src},	// use for first auto placement? ...
		"multi" : false,
		"auto" : true,
		"scriptAccess" : "always",
		"folder" : "/media/"+dpclient+"/images",
		"onComplete" : function(event, queueID, fileObj, response, data) {
						
			// show the preview of the image...
			$("#imagePreview").html(response).show();
			
			// get values for uploaded file...
			var width = $("img#cropIt").attr("width");
			var height = $("img#cropIt").attr("height");
			var imageSrc = $("img#cropIt").attr("src");
			var imageId = $("img#cropIt").attr("src").replace("/media/"+dpclient+"/images/","").split(".");
			var src = $("input#src").val();
			var postId = $("#postId").val();
							
			$("img#cropIt").attr("src",imageSrc).load();
			$("#imageSearchBox").hide();
			$("#imageSearchActive").hide();
			$("#imageSearchOff").show();
		
			$("#imagesList").hide();
			//$("#imagePreview").show();
			$("#toolScreen").show();
			$("#imageLegendBox").hide();
				
			configureImageCaption(imageId[0]);
			if(e) {
				if($("#editorScreen").length) {
					$("#editorScreen").show();
				}
			} else if(src=="classified") {
				if($("#editorScreen").length) {
					$("#editorScreen").show();
				}
			}
			configureImageAccordian(e,imageId[0],imageSrc,width,height,src,postId,api);
			
			// add the newly uploaded image to the users display...
			var srt = $("#overlaySubNav div.toolsButton.on").attr("id").split("_");
			var contributor = "";
			if($("#naContributor").length) {
				contributor = $("#naContributor").val();
			} else if($("#naPublisher").length) {
				contributor = $("#naPublisher").val();
			} else if($("#contributorId")) {
				contributor = $("#contributorId").val();	// pull from tool...
			}
			
			$.ajax({
				url: "/dpComponent/images/mediaLibraryOverlayDetailDisplayAjax",
				type: "post",
				data: "src="+src+"&srt="+srt+"&cnt="+contributor+"&upload=1",
				//	beforeSend: function() {
				//		$("#contentLoading").removeClass("hide");
				//	},	
				success: function(html) {
					// update the image list...
					$("#imagesList").html(html);
				}
			});
		}
	});
}



function configureImageDialog(e,api,aImage,dImage) {

	// let's just do a quick pause here, and see if that fixes it.
	// we can always make it more elegant later.
	
	
	var src = $("input#src").val();
	var dst = $("input#dst").val();
	var contributor = "";
	if($("#naContributor").length) {
		contributor = $("#naContributor").val();
	} else if($("#naPublisher").length) {
		contributor = $("#naPublisher").val();
	} else if($("#contributorId")) {
		contributor = $("#contributorId").val();	// pull from tool...
	}
	var postId = $("#postId").val();
	
	if(aImage) {
		// we have an active image...
		var imgSrc = $("#thumbnail_"+aImage+" img").attr("src").replace("_icon","");
		var imgW = $("#thumbnail_"+aImage+" img").attr("width");
		var imgH = $("#thumbnail_"+aImage+" img").attr("height");
		
		// load the image...
		configureImageClick(e,aImage,imgSrc,imgW,imgH,src,postId,api);
	}
	
	// we need to pause for a second...
	
	

	if($("#overlayUpload").length) {
		toolsImageUpload(e,api);
	}
	
	
	// configure the destination (dst) tool buttons...
	$("#overlayTopNav .toolsButton").click(function() {
		var buttonId = $(this).attr("id");
		if(!$(this).hasClass("on")) {
			$("#overlayTopNav div").removeClass("on");
			$(this).addClass("on");
			$.ajax({
				url: "/dpComponent/channel/mediaLibraryOverlaySwitch",
				type: "post",
				data: "dst=" + buttonId + "&src=" + src,
		//		beforeSend: function() {
		//			$("#contentLoading").removeClass("hide");
		//		},	
				success: function(html) {
					$("#overlayWrapper").html(html);
					if($("#overlayUpload").length) {
						// this configures the photo upload tool (if available)
						toolsImageUpload();
					}
				}
			});
		}
	});
		
	// tools button delegation
	$("#overlayWrapper").delegate("div.bar div.toolsButton","click",function() {
		var id = $(this).attr("id").split("_");
		$("div.buttonBar div.toolsButton").removeClass("on");
		$(this).addClass("on");
			
		$.ajax({
			url: "/dpComponent/channel/mediaLibraryOverlaySortSwitch",
			type: "post",
			data: "dst=" + id[0] + "&src=" + src + "&srt=" + id[1] + "&cnt=" + contributor,
		//	beforeSend: function() {
		//		$("#contentLoading").removeClass("hide");
		//	},	
			success: function(html) {
				$("#overlayContentWrap").html(html);
			}
		});			
	});
		
	// image search return...
	$("#overlayWrapper").delegate("#imageSearchReturn","click",function() {
		$("#imageSearchBox").show();
		$("#imageSearchActive").show();
		$("#imageSearchOff").hide();
		$("#editorScreen").hide();
		$("#captionScreen").hide();
		$("#imagesList").show();
		$("#imagePreview").html("").hide();
		$("#imageEditorCaption").attr("disabled","disabled");
		$("#toolScreen").hide();
		$("#photoAccordian").html("").hide();
		$("#imageLegendBox").show();
		$("#imageEditorBox").show();
		$("#imageEditorBoxNav").show();
		if($("#imageEditorBoxMore").length) {
			$("#imageEditorBoxMore").hide();
		}
		if($("#viewTools").length) {
			$("#viewTools").show();
		}
	});
		
	// image classified submit...
	$("#overlayWrapper").delegate("#imageClassified","click",function() {
		var imageSrc = $("#cropIt").attr('src');
		var imageData = imageSrc.replace("/media/"+dpclient+"/images/","").split(".");
		var width = $("img#cropIt").attr("width");
		var postId = $("#postId").val();
		//alert("dst: "+dst+" || srt: "+srt+" || imageSrc: "+imageSrc+" || imageid: "+imageData[0]+" || imageExt: "+imageData[1]+" || width: "+width+" || destination: " + dImage + " || post id: " + postId);
		$.ajax({
			url: "/dpComponent/classifiedsManager/toolsAssignImage",
			type: "post",
			data: "id="+imageData[0]+"&classified="+postId,
			//	beforeSend: function() {
			//		$("#contentLoading").removeClass("hide");
			//	},	
			success: function(html) {
				// here, this needs to change...
				// we are basically going to return the following...
				// 
				$("#postGalleryWrap").append(html);
				if($("#postGalleryWrap > div").size() >= 4) {
					$("#addPhoto").hide();
				}
				api.close();
			}
		});
	});
	
	// image classified submit...
	$("#overlayWrapper").delegate("#imageClassifiedRemove","click",function() {
		var imageSrc = $("#cropIt").attr('src');
		var imageData = imageSrc.replace("/media/"+dpclient+"/images/","").split(".");
		var postId = $("#postId").val();
		$.ajax({
			url: "/dpComponent/classifiedsManager/toolsRemoveImage",
			type: "post",
			data: "id="+imageData[0]+"&classified="+postId,
			//	beforeSend: function() {
			//		$("#contentLoading").removeClass("hide");
			//	},	
			success: function(html) {
				// here, this needs to change...
				// we are basically going to return the following...
				// we are getting a "1" back here...
				// this needs to be configured
				$("#postGalleryWrap #thumbnail_"+imageData[0]).parent().remove();
				
				// turn the button back on if necessary
				if($("#postGalleryWrap > div").size() >= 4) {
					$("#addPhoto").hide();
				} else {
					$("#addPhoto").show();
				}
				//$("#postGalleryWrap").append(html);
		//		if($("#postGalleryWrap > div").size() >= 4) {
		//			$("#addPhoto").hide();
		//		}
				api.close();
			}
		});
	});
	
	// image editor submit...
	$("#overlayWrapper").delegate("#imageEditorSubmit","click",function() {
		//alert('works');
		var form = $("#editorPlacement");
		var formData = form.serialize();
		//var dst = $("#overlayTopNav div.toolsButton.on").attr("id");
		//var srt = $("#overlaySubNav div.toolsButton.on").attr("id").split("_");
		var imageSrc = $("#cropIt").attr('src');
		var imageData = imageSrc.replace("/media/"+dpclient+"/images/","").split(".");
		var width = $("img#cropIt").attr("width");
		var postId = $("#postId").val();
		
		$.ajax({
			url: "/dpComponent/images/getEditorData",
			type: "post",
			data: "id="+imageData[0]+"&postId="+postId+"&"+formData,
			//	beforeSend: function() {
			//		$("#contentLoading").removeClass("hide");
			//	},	
			success: function(html) {
				e.insertHtml(html);
				api.close();
			}
		});
	});
		
	$("#overlayWrapper").delegate("#imageEditorBoxMore a","click",function() {
		$("#imageEditorBox").show();
		$("#imageEditorBoxNav").show();
		$("#imageEditorBoxMore").hide();
		$("#viewTools").show();
		$("#photoAccordian").hide();
		//alert('works');
		return false;
	});
	
	$("#overlayWrapper").delegate("#viewTools a","click",function() {
		// let's get this rolling...
		$("#imageEditorBox").hide();
		$("#imageEditorBoxNav").hide();
		$("#imageEditorBoxMore").show();
		$("#viewTools").hide();
		$("#photoAccordian").show();
		//alert('works');
		return false;
	});
	
	$("#overlayWrapper").delegate("#searchImageGeoTag","change",function() {
		$("#searchImageTag").val("");
	});
	
	$("#overlayWrapper").delegate("#searchImageTag","change",function() {
		$("#searchImageGeoTag").val("");
	});
	
	// image search submit...
	$("#overlayWrapper").delegate("#imageSearchSubmit","click",function() {
		var form = $("#imageSearch");
		var formData = form.serialize();
		var dst = $("#overlayTopNav div.toolsButton.on").attr("id");
		var srt = $("#overlaySubNav div.toolsButton.on").attr("id").split("_");
		$.ajax({
			url: "/dpComponent/channel/mediaLibraryOverlayDetailSwitch",
			type: "post",
			data: "src="+src+"&dst="+dst+"&srt="+ srt[1] +"&cnt=" + contributor + "&"+formData,
			//	beforeSend: function() {
			//		$("#contentLoading").removeClass("hide");
			//	},	
			success: function(html) {
				$("#overlayDetail").html(html);
			}
		});
	});
		
	// image overlay navigation by page...
	$("#overlayWrapper").delegate("#imagesList .listNav .button.page.active", "click", function(event) {
		var metaData = $(this).attr('id').split("|");
		var dst = $("#overlayTopNav div.toolsButton.on").attr("id");
		var srt = $("#overlaySubNav div.toolsButton.on").attr("id").split("_");
		$.ajax({
			url: "/dpComponent/channel/mediaLibraryOverlayDetailSwitch",
			type: "post",
			data: "src="+src+"&dst="+dst+"&srt="+srt[1]+"&cnt="+contributor+"&isSearch=true&searchImageStatus=" + metaData[0] + "&searchImageTag=" + metaData[1] + "&searchImageGeoTag=" + metaData[2] + "&searchImageDate=" + metaData[3] + "&searchImageChannel=" + metaData[4] + "&searchImagePublisher=" + metaData[5] + "&startpos=" + metaData[6] + "&postId=" + metaData[10],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#overlayDetail").html(html);
			}
		});
	});
		
	// image overlay navigation by step...
	$("#overlayWrapper").delegate("#imagesList .listNav .button.step.active", "click", function(event) {
		var metaData = $(this).attr('id').split("|");
		var dst = $("#overlayTopNav div.toolsButton.on").attr("id");
		var srt = $("#overlaySubNav div.toolsButton.on").attr("id").split("_");
		$.ajax({
			url: "/dpComponent/images/mediaLibraryOverlayDetailSwitch",
			type: "post",
			data: "src="+src+"&dst="+dst+"&srt="+srt[1]+"&cnt="+contributor+"&isSearch=true&searchImageStatus=" + metaData[0] + "&searchImageTag=" + metaData[1] + "&searchImageGeoTag=" + metaData[2] + "&searchImageDate=" + metaData[3] + "&searchImageChannel=" + metaData[4] + "&searchImagePublisher=" + metaData[5] + "&startpos=" + metaData[6] + "&postId=" + metaData[10],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#overlayDetail").html(html);
			}
		});
	});
	
	// image list click...
	$("#overlayWrapper").delegate("#imagesList div.image img","mousedown",function(event) {
		var imageId = $(this).attr("id");
		var imageSrc = $(this).attr("src").replace("_icon","");
		var width = $(this).attr("width");
		var height = $(this).attr("height");
		var postId = $("#postId").val();
		
		switch(event.which) {
			case 3:
				// right button click...
				// we could do some cool stuff with this...
				// open up a dialog with some quick options, etc...
				//alert('right button');
				break;
			default:
				configureImageClick(e,imageId,imageSrc,width,height,src,postId,api);
		}
		
	});
}

function configureImageClick(e,imageId,imageSrc,width,height,src,postId,api) {
	// this could be a function
	// that sets the editor click...
	$("#imageSearchBox").hide();
	$("#imageSearchActive").hide();
	$("#imageSearchOff").show();
	$("#imagePreview").html("<img id='cropIt' src=''>");
	$("img#cropIt").attr("src",imageSrc).load();
	$("#imagesList").hide();
	$("#imagePreview").show();
	$("#toolScreen").show();
	$("#imageLegendBox").hide();
		
	// load image caption functionality...
	configureImageCaption(imageId);
	if(e) {
		if($("#editorScreen").length) {
			$("#editorScreen").show();
		}	
	} else if(src=="classified" || src=="classifiedtool") {
		if($("#editorScreen").length) {
			$("#editorScreen").show();
		}	
	}
		
	configureImageAccordian(e,imageId,imageSrc,width,height,src,postId,api);
}

function configureImageCaption(imageId) {
	$.ajax({
		url: "/dpComponent/images/getImageCaption",
		type: "post",
		data: "id="+imageId,
		//		beforeSend: function() {
		//			$("#contentLoading").removeClass("hide");
		//		},	
		success: function(html) {
			$("#captionScreen").html(html).show();
			//$("textarea#nCaptionT").focus();
					
			// we need to determine if there is a caption at this point.
			// if there is one, we turn off the disabled buttons...
			if($("#oCaption").val()) {
				// remove the disabled attributes...
				$("#imageEditorCaption").removeAttr("disabled");
			}
						
			$("#cCaption").click(function() {
				$(this).hide();
				$("#nCaption").show();
				$("textarea#nCaptionT").focus();
			});
						
			$("textarea#nCaptionT").blur(function() {
				var caption = $(this).val();
				var oCaption = $("#oCaption").val();
				if(caption != oCaption) {
					//alert("bluring out of the text area " + imageId + " || " + caption);
					$.ajax({
						url: "/dpComponent/images/updateImageCaption",
						type: "post",
						data: "id="+imageId+"&caption="+caption,
						//		beforeSend: function() {
						//			$("#contentLoading").removeClass("hide");
						//		},	
						success: function(html) {
							$("#cCaption").html(html).show();
							$("#nCaption").hide();
							$("#oCaption").val(html);
							$("#imageEditorCaption").removeAttr("disabled");
						}
					});
							
				} else {
					// just flip the visibility around...
					$("#cCaption").show();
					$("#nCaption").hide();
				}
			});
		}
	});
}

function configureImageAccordian(e,imageId,imageSrc,width,height,src,postId,api) {

	// output and configure the image tools...
	$.ajax({
		url: "/dpComponent/images/mediaLibraryOverlayAccordian",
		type: "post",
		data: "cid=" + channel + "&scid=" + subchannel + "&imgId="+imageId+"&imgS=" + imageSrc + "&imgW=" + width + "&imgH=" + height + "&popSrc=" + src + "&postId=" + postId,
		success: function(html) {
		
			// here is where we are showing the accordian...
			// this whole thing can probably be handled from here...
			
			$("#photoAccordian").html(html);
			if(src != "editor") {
				$("#photoAccordian").show();
			}
			// attach the accordian functionality...
			$("#photoAccordian").tabs("#photoAccordian div.tier", {tabs: 'h2', effect: 'slide', initialIndex: null});
			
			// why are we setting these again... old code that got moved around.
			var imgId = $("#thumbId").val();
			var postId = $("#postId").val();
			var thumb = $("#imgSrc").val().replace("/media/"+dpclient+"/images/","").split(".");
			var postType = $("#postType").val();
			
			// make article thumbnail button...
			$("#photoAccordian #AssignPhotoThumbnail").click(function() {
				$.ajax({
					url: "/dpComponent/" + postType + "/updatePostThumb",
					type: "post",
					data: "postId=" + postId + "&thumbId=" + thumb[0] + "&thumbExt=" + thumb[1],
					success: function(html) {
						$("#previewWindow .imagesmall.setThumbnail").html(html);
						$("#previewWindow .imagesmall.setThumbnail").attr("id","thumbnail_"+thumb[0]);
						api.close();
					}
				});
				return false;
			});
	
			// delete photo...
			$("#DeletePhoto").click(function() {
				var postId = $("#postId").val();
				var thumb = $("#imgSrc").val().replace("/media/"+dpclient+"/images/","").split(".");
				//alert('works: ' + postId + ' || ' + thumb[0]);
				$.ajax({
					url: "/dpComponent/images/deletePhoto",
					type: "post",
					data: "postId=" + postId + "&thumbId=" + thumb[0] + "&thumbExt=" + thumb[1],
					success: function(html) {
					
						// reload the detail window...
						var form = $("#imageSearch");
						var formData = form.serialize();
						var dst = $("#overlayTopNav div.toolsButton.on").attr("id");
						var srt = $("#overlaySubNav div.toolsButton.on").attr("id").split("_");
						var contributor = "";
						if($("#naContributor").length) {
							contributor = $("#naContributor").val();
						} else if($("#naPublisher").length) {
							contributor = $("#naPublisher").val();
						} else if($("#contributorId")) {
							contributor = $("#contributorId").val();	// pull from tool...
						}
						$.ajax({
							url: "/dpComponent/channel/mediaLibraryOverlayDetailSwitch",
							type: "post",
							data: "src="+src+"&dst="+dst+"&srt="+ srt[1] +"&cnt=" + contributor + "&"+formData,
							//	beforeSend: function() {
							//		$("#contentLoading").removeClass("hide");
							//	},	
							success: function(html) {
								// update the image list...
								$("#overlayDetail").html(html);
				
								// configure the overlay window...
								$("#imageSearchBox").show();
								$("#imageSearchActive").show();
								$("#imageLegendBox").show();
								$("#imageSearchOff").hide();
								$("#editorScreen").hide();
								$("#captionScreen").hide();
								$("#imageEditorCaption").attr("disabled","disabled");
								$("#toolScreen").hide();
								$("#photoAccordian").html("");
							}
						});
					}
				});
			});
	
			// assign photo to gallery...
			$("#AssignPhotoToArticle").click(function() {
				var photoId = $("#imgSrc").val().replace("/media/"+dpclient+"/images/","").replace("_sm","").split(".");
				var postId = $("#postId").val();
				var postType = $("#postType").val();
				var self = this;
				$.ajax({
					url: "/dpComponent/images/trackImageUsage",
					type: "post",
					data: "postId=" + postId + "&thumbId=" + photoId[0] + "&thumbExt=" + photoId[1],
					success: function(html) {
						$(self).addClass("hide");
						$("#unAssignPhotoToArticle").removeClass("hide");
						if ($("#MediaAlbumData").length) {
							$.ajax({
								url: "/dpComponent/images/toolsUpdateGalleryDisplay",
								type: "post",
								data: "postId=" + postId + "&thumbId=" + photoId[0] + "&thumbExt=" + photoId[1],
								success: function(html) {
									$("#MediaAlbumData").append(html);
								}
							});
						}
					}
				});
			});
	
			// make images private...
			$("#photoStatus").delegate("#privateMedia","click",function() {
			//$("#privateMedia").click(function() {
				//alert('make private' + imgId);
				$.ajax({
					url: "/dpComponent/images/makePrivate",
					type: "post",
					data: "id=" + imgId,
			//		beforeSend: function() {
			//			$("#contentLoading").removeClass("hide");
			//		},
			//		error: function(request,status,errorThrown) {
			//			alert(errorThrown);
			//		},
					success: function(html) {
					
						//alert('imgId: ' + imgId);
						//alert('success' + html);
						// this only reloads the status portion of the element...
						// we need to turn off a few things...
						if($("#unAssignPhotoToArticle").length) {
							$("#unAssignPhotoToArticle").hide();
							$("#AssignPhotoToArticle").show();
						}
						$("#photoAccordian #photoStatus").html(html);
						// we need to modify the span in the above area...
						$("h2.current span.cstat").html("(PRIVATE)");
						$("#"+imgId).parent().removeClass('isShared');
						
					}
				});
			});
	
			// share images...
			$("#photoStatus").delegate("#shareMedia","click",function() {
			//$("#shareMedia").click(function() {
				//alert('share it' + imgId);
				$.ajax({
					url: "/dpComponent/images/shareMedia",
					type: "post",
					data: "id=" + imgId,
			//		beforeSend: function() {
			//			$("#contentLoading").removeClass("hide");
			//		},
			//		error: function(request,status,errorThrown) {
			//			alert(errorThrown);
			//		},
					success: function(html) {
						$("#photoAccordian #photoStatus").html(html);
						$("h2.current span.cstat").html("(SHARED)");
						$("#"+imgId).parent().addClass('isShared');
					}
				});
			});
	
			// change publisher (could also be used for uploader/user)...
			$("#toolsPublisher #currentPublisher").click(function() {
				var currentPub = $(this).html();
				$(this).hide();
				$("#availablePublishers").show();
				$.ajax({
					url: "/dpComponent/channel/toolsDisplayContributorSelect",
					type: "post",
					data: "opub=" + currentPub,
				//	beforeSend: function() {
				//		$("#contentLoading").removeClass("hide");
				//	},
					success: function(html) {
						$("#availablePublishers").html(html);
						$("#assignNewContributor").change(function() {
							var newPub = $(this).val();
							$.ajax({
								url: "/dpComponent/images/updateImageContributor",
								type: "post",
								data: "id=" + imgId + "&c=" + newPub,
							//	beforeSend: function() {
							//		$("#contentLoading").removeClass("hide");
							//	},
								success: function(html) {
									$("#toolsPublisher #currentPublisher").html(html).show();
									$("#availablePublishers").hide();
								}
							});
						});
					}
				});
			});
			
			// these ALL need to be grouped together
			// with the appropriate values passed via function...
			$("#tagPhoto").autocomplete({
				source: "/dpComponent/channel/tagsJSON",
				minLength: 2,
				select: function(event, ui) {
					//var imgId = $("img#cropIt").attr('src').replace("/media/"+dpclient+"/images/","").split(".");
					if(ui.item.id && imgId) {
						$.ajax({
							url: "/dpComponent/images/toolsAddTag",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + imgId + "&tag=" + ui.item.id + "&type=" + ui.item.geo,
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#photoTagData").html(html);
								$("input#tagPhoto").val('');
							}
						});
					}
				}
			}).blur(function() {
				if($(this).val() == "  ") {
					$(this).val('');
				}
			});
			
			// create new content tag...
			$("#photoAccordian .addNewPhotoTag").click(function() {
				var tagVal = $("#tagPhoto").val();
				var tagData = $(this).attr("id").split("|");
				if(tagVal) {
					//alert('tag value: ' + tagVal);
					$.ajax({
						url: "/dpComponent/channel/toolsCreateTag",
						type: "post",
						data: "tagName=" + tagVal + "&tagType=" + tagData[1] + "&tagContent=" + tagData[0] + "&tagLoc=image",
				//		beforeSend: function() {
				//			$("#contentLoading").removeClass("hide");
				//		},
						success: function(html) {
							$("#photoTagData").html(html);
							$("input#tagPhoto").val('');
						}
					});
				}
			});
			
			// create new geo tag...
			$("#photoAccordian .addNewPhotoGeoTag").click(function() {
				var tagVal = $("#geoTagPhoto").val();
				var tagData = $(this).attr("id").split("|");
				
				if(tagVal) {
					//alert('tag value: ' + tagVal);
					$.ajax({
						url: "/dpComponent/channel/toolsCreateTag",
						type: "post",
						data: "tagName=" + tagVal + "&tagType=" + tagData[1] + "&tagContent=" + tagData[0] + "&tagLoc=image",
				//		beforeSend: function() {
				//			$("#contentLoading").removeClass("hide");
				//		},
						success: function(html) {
							$("#photoGeoData").html(html);
							$("input#geoTagPhoto").val('');
						}
					});
				}
			});
								
			// album geo-tag search...
			$("#geoTagPhoto").autocomplete({
				source: "/dpComponent/channel/geoTagsJSON",
				minLength: 2,
				select: function(event, ui) {
					//var imgId = $("img#cropIt").attr('src').replace("/media/"+dpclient+"/images/","").split(".");
					if(ui.item.id && imgId) {
						$.ajax({
							url: "/dpComponent/images/toolsAddTag",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + imgId + "&tag=" + ui.item.id + "&type=" + ui.item.geo,
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#photoGeoData").html(html);
								$("input#geoTagPhoto").val('');
							}
						});
					}
				}
			}).blur(function() {
				if($(this).val() == "  ") {
					$(this).val('');
				}
			});
			
			// tag delete
			$("#photoGeoData,#photoTagData").delegate(".tag_remove", "click", function(event) {
				var tagData = $(this).attr('id').split("_");
				$.ajax({
					url: "/dpComponent/images/removeTag",
					type: "post",
					data: "tagId=" + tagData[0] + "&postId=" + tagData[1],
		//			beforeSend: function() {
		//				$("#contentLoading").removeClass("hide");
		//			},
					success: function(html) {
		//				$("#contentLoading").addClass("hide");
						$("#"+html).parent().empty().remove();
					}
				});
			});
	
	
			// photo matrix add...
			$("#imageMatrixData").delegate("#addNewImagePlacement", "click", function(event) {
				var placeToAdd = $("select#addImagePlacement").val();
				if(placeToAdd) {
					var matrixData = placeToAdd.split("|");
					$.ajax({
						url: "/dpComponent/images/toolsPlaceContent",
						type: "post",
						data: "cid=" + channel + "&scid=" + subchannel + "&imgId=" + matrixData[1] + "&component=" + matrixData[0],
						beforeSend: function() {
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							$("#imageMatrixData").html(html);
						}
					});
				}
			});
	
			// photo matrix delete
			$("#imageMatrixData").delegate(".matrix_remove", "click", function(event) 
			{
				var placeToRemove = $(this).attr('id').split("_");
				if(placeToRemove) {
					$.ajax({
						url: "/dpComponent/images/deleteImageMatrixLink",
						type: "post",
						data: "cid=" + channel + "&scid=" + subchannel + "&id=" + placeToRemove[3] + "&channel=" + placeToRemove[1] + "&subChannel=" + placeToRemove[2],
						beforeSend: function() {
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							$("#imageMatrixData").html(html);
						}
					});
				}
			});
	
	
			
			// set thumbnail click!
			$("#newPhotoThumb").click(function() {
				var largeImageSrc = $("#imgSrc").val();
				$("#currentThumbText").hide();
				$("#newThumbText").show();
				$("#thumbPreview").removeAttr("width").removeAttr("height").css({ width: "", height: ""});
				$("#thumbPreview").attr("src",largeImageSrc);
				$("#newPhotoThumb").hide();
				JcropAPI = $.Jcrop('img#cropIt',{ 
					onChange: showThumbPreview,
					onSelect: showThumbPreview,
					aspectRatio: 4/3,
					minSize: [100,75]
				});
				$("#createPhotoThumb").show();
			});
								
			// define functionality for create thumbnail button... WORKS...
			$("#createPhotoThumb").click(function() {
				var xCoord = $("#thumbX").val();
				var yCoord = $("#thumbY").val();
				var thumbW = $("#thumbW").val();
				var thumbH = $("#thumbH").val();
				var thumbS = $("img#cropIt").attr("src");
													
				// resize the image based on user selectable area...
				$.ajax({
					url: "/dpComponent/images/toolsCreateThumbAjax",
					type: "post",
					data: "thumbX=" + xCoord + "&thumbY=" + yCoord + "&thumbW=" + thumbW + "&thumbH=" + thumbH + "&thumbS=" + thumbS,
					success: function(html) {
						// remove the cropping API...
						
						
						
						JcropAPI.destroy();
						
						// grab the image source
						var imageSrc = $("#"+html).attr('src');
						
						
						
						// update the grid thumbnail...
						if($("img#"+html).length) {
							d = new Date();
							$("img#"+html).attr("src",imageSrc+"?"+d.getTime()).load(function() {
								$(this).attr("width","90");
								$(this).attr("height","68");
								//alert("image: " + html + " || src: " + imageSrc);
							});
						}
						
						// reconfigure the thumbnail tools.
						$("#newThumbText").hide();
						$("#createPhotoThumb").hide();
						$("#currentThumbText").show();
						$("#newPhotoThumb").show();
					}
				});
			});
		}
	});

}

function showImageDialog(e) {

	overlayURL = "/dpComponent/channel/mediaLibraryOverlay?src=editor&dst=images";
	var overlayAPI = $("#toolsOverlay").data("overlay");

	$("#toolsOverlay").bind("onClose", function() {
		$("#toolsOverlay .overlayWrap").html("");
		$(this).unbind("onClose");	// unbind so we don't bubble up...
	});
		
	$("#toolsOverlay").bind("onLoad", function() {
		setTimeout(function(){configureImageDialog(e,overlayAPI,"",""); overlayAPI=null; e=null},500);
		//setTimeout('configureImageDialog(e,overlayAPI,"","")',1000);
		//configureImageDialog(e,overlayAPI,"","");
		$(this).unbind("onLoad"); // unbind so we don't bubble up...
	});
	overlayAPI.load();
		
	// make it so links don't work if javascript active...
	return false;
}



// VIDEO SHARE FUNCTION
// ------------------------------------------------------------------------------------------------
function toolsVideosShare(msg) {
	//alert("FUNCTION: " + msg);
	$("form#postForm").validator().submit(function(e) {
		var form = $(this);
		if (!e.isDefaultPrevented()) {
			// passed client-side validation OK.
			// you know, we could put some stuff in here to stop spammers...
			// do a SHA1 of the email+dpCode and check on the other end... SWEET!
			formData = form.serialize();
			$.ajax({
				url: "/dpComponent/videoManager/shareYouTubeVideo",
				type: "post",
				data: "cid="+ channel +"&scid="+ subchannel +"&" + formData,
				dataType: "json",
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
//				error: function(html) {
//					// this is the error function here...
//					alert(html);
//				},
				success: function(json) {
					$("#contentLoading").addClass("hide");
					if (json.success)  {
						// video successfully shared!
						$("#videoCreate").addClass('hide');
						$("#videoDetail").html(json.html).removeClass('hide');
					} else {
						// server-side validation failed.
						form.data("validator").invalidate(json);
					}
				}
			});
			// prevent the form from being submitted...
			e.preventDefault();
		}
	});
}

// VIDEO MANAGE FUNCTION
// ------------------------------------------------------------------------------------------------
function toolsVideosManage(msg) {
	// we need to put the stuff here, to manage the video...
	//alert("video manage function is running!");
	
	//$("#toolVideos #toolScroll .rowItem").click(function() {
	$("#toolScroll").delegate(".rowItem", "click", function(event) {
		var itemId = $(this).attr('id');
		var item = $(this);
		$.ajax({
			url: "/dpComponent/videoManager/toolsDisplayOverviewAjax",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + itemId,
			beforeSend: function() {
				// we need to remove the class from ANY of the rowitem values...
				$("#toolScroll div.rowItem").removeClass("on");
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$(item).addClass("on");
				//alert('post: ' + itemId);
				// output video accordian...
				
				$("#toolWindow").html(html);
				$("#toolAccordian").tabs("#toolAccordian div.tier", {tabs: 'h2', effect: 'slide', initialIndex: null});
				
				// configure event buttons...
				$("#videos_view").click(function() {
					var postId = $("#postId").val();
					$.ajax({
						url: "/dpComponent/videoManager/renderVideoPreview",
						type: "post",
						data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId,
						beforeSend: function() {	
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							$("#toolPreview").html(html).show("blind", {direction: "vertical"}, 500);
							$("#toolScroll").hide("blind", {direction: "vertical"}, 300);
							// manage buttons...
							$("#toolWindow .button.view").addClass("hide");
							$("#toolWindow .button.delete").addClass("hide");
							$("#toolWindow .button.back").removeClass("hide");							
						}
					});
				});
				
				$("#videos_back").click(function() {
					// manipulate tool buttons...
					$("#toolWindow .button.view").removeClass("hide");
					$("#toolWindow .button.delete").removeClass("hide");
					$("#toolWindow .button.back").addClass("hide");
					// show the appropriate content...
					$("#toolPreview").hide("blind", {direction: "vertical"}, 500);
					$("#toolScroll").show("blind", {direction: "vertical"}, 300);
				});
				
				$("#videos_delete").click(function() {
					// we need the following data...
					var postId = $("#postId").val();
					var typeId = $("#toolVideos .toolNav").attr('id');
					var answer = confirm("Remove this video from your site?");
					
					if(answer) {
						var metaData = "";
						if ($("#toolScroll div.listNav div.button.page.on").length) {
							metaData = $("#toolScroll div.listNav div.button.page.on").attr("id").split("|");
						} else {
							metaData = array();
						}
						var status = "";
						if($("#Current").hasClass("on")) {
							status = "current";
						} else if($("#Archive").hasClass("on")) {
							status = "archives";
						} else if($("#Pending").hasClass("on")) {
							status = "pending";
						} else if($("#Approve").hasClass("on")) {
							status = "approve";
						}
						
						//alert('Status: ' + status + ' || sp: ' + metaData[2]);
						// i need itmc...
						$.ajax({
							url: "/dpComponent/videoManager/toolsDeleteVideo",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + typeId,
							beforeSend: function() {	
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
							
								// this should be the default sidebar...
								$("#toolWindow").html("");
								
								// remove the item from the list...
								$("#toolScroll").html(html);
							}
						});
					}
				});
				
				$("#previewWindow .headline").click(function() {
					var postId = $("#postId").val();
					// update DOM...
					$("#headline_"+postId).hide();
					$("#headlineEdit_"+postId).show();
					$("#newHeadline").focus();
				});
				$("#previewWindow #newHeadline").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origHeadline").val();	
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/videoManager/updateHeadline",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
				//			beforeSend: function() {
				//				$("#contentLoading").removeClass("hide");
				//			},
							success: function(html) {
								$("#previewWindow .headline").html(html);
								//$("#toolScroll .rowItem.on .articleHeadline").html(html);
								$(item).children(".articleHeadline").html(html);
								
								$("#previewWindow #origHeadline").val(html);
								$("#previewWindow #newHeadline").val(html);
							}
						});
					}
					$("#headline_"+postId).show();
					$("#headlineEdit_"+postId).hide();
				});
				
				$("#previewWindow .lead").click(function() {
					var postId = $("#postId").val();
					// update DOM...
					$("#lead_"+postId).hide();
					$("#leadEdit_"+postId).show();
					$("#newLead").focus();
				});
				$("#previewWindow #newLead").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origLead").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/videoManager/updateLead",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
				//			beforeSend: function() {
				//				$("#contentLoading").removeClass("hide");
				//			},
							success: function(html) {
								$("#previewWindow .lead").html(html);
								$("#previewWindow #origLead").val(html);
								$("#previewWindow #newLead").val(html);
							}
						});
					}
					$("#lead_"+postId).show();
					$("#leadEdit_"+postId).hide();
				});
				
				enableStatusDateInputs('videoManager');
				
				//commentsStatus
				$("#commentsStatus").click(function() {
					var postId = $("#postId").val();
					var currentVal = $(this).html();
					$.ajax({
						url: "/dpComponent/videoManager/toggleComments",
						type: "post",
						data: "id=" + postId + "&cur=" + currentVal,
				//		beforeSend: function() {
				//			$("#contentLoading").removeClass("hide");
				//		},
						success: function(html) {
							$("#commentsStatus").html(html);
						}
					});
				});
				
				$("#rankingStatus").click(function() {
					var postId = $("#postId").val();
					var currentVal = $(this).html();
					$.ajax({
						url: "/dpComponent/videoManager/toggleRanking",
						type: "post",
						data: "id=" + postId + "&cur=" + currentVal,
				//		beforeSend: function() {
				//			$("#contentLoading").removeClass("hide");
				//		},
						success: function(html) {
							$("#rankingStatus").html(html);
						}
					});
				});
				
				$("#toolAccordian").delegate("#addNewPlacement", "click", function(event) {
				//$("#addCalendarPlacement").click(function() {
					var placeToAdd = $("select#addPlacement").val();
					var postId = $("#postId").val();
					
					if(placeToAdd && postId) {
						var matrixData = placeToAdd.split("_");
						$.ajax({
							url: "/dpComponent/videoManager/toolsPlaceContent",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&channel=" + matrixData[0] + "&subChannel=" + matrixData[1],
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#storyMatrixData").html(html);
							}
						});
					}
				});
	
				$("#toolAccordian").delegate("#storyMatrixData .matrix_remove", "click", function(event) {
					var placeToRemove = $(this).attr('id').split("_");
					var postId = $("#postId").val();
					if(placeToRemove) {
						$.ajax({
							url: "/dpComponent/videoManager/deleteStoryMatrixEntry",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&channel=" + placeToRemove[1] + "&subChannel=" + placeToRemove[2],
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#storyMatrixData").html(html);
							}
						});
					}
				});
				
				configureTags('videoManager');
				
				$("#toolAccordian").delegate(".tag_remove", "click", function(event) {
					var tagData = $(this).attr('id').split("_");
					$.ajax({
						url: "/dpComponent/videoManager/removeTag",
						type: "post",
						data: "tagId=" + tagData[0] + "&postId=" + tagData[1],
			//			beforeSend: function() {
			//				$("#contentLoading").removeClass("hide");
			//			},
						success: function(html) {
			//				$("#contentLoading").addClass("hide");
							$("#"+html).parent().empty().remove();
						}
					});
				});
				
				
				// we are going to have 4 different options here...
				$("#toolVideos").delegate("#publishNow", "click", function(e) {
					var postId = $("#postId").val();
					var pubDate = $("#publish_date").val();
					$.ajax({
						url: "/dpComponent/videoManager/publishNow",
						type: "post",
						data: "id=" + postId + "&pbl=" + pubDate,
				//			beforeSend: function() {
				//				$("#contentLoading").removeClass("hide");
				//			},
						success: function(html) {
							$("#toolsStatus").html(html);
							enableStatusDateInputs('videoManager');
							// this should actually reload the entire toolWindow, so that 
							// multiple items can be published and the navigation system will continue to function...
						}
					});
				});
				
				$("#toolVideos").delegate("#archiveNow", "click", function(e) {
					var postId = $("#postId").val();
					$.ajax({
						url: "/dpComponent/videoManager/archiveNow",
						type: "post",
						data: "id=" + postId,
				//			beforeSend: function() {
				//				$("#contentLoading").removeClass("hide");
				//			},
						success: function(html) {
							$("#toolsStatus").html(html);
							enableStatusDateInputs('videoManager');
							$("#"+postId).remove();
							// this should actually reload the entire toolWindow, so that 
							// multiple items can be published and the navigation system will continue to function...
						}
					});
				});
				
				$("#toolVideos").delegate("#neverArchive", "click", function(e) {
					var postId = $("#postId").val();
					$.ajax({
						url: "/dpComponent/videoManager/archiveNever",
						type: "post",
						data: "id=" + postId,
				//			beforeSend: function() {
				//				$("#contentLoading").removeClass("hide");
				//			},
						success: function(html) {
							$("#toolsStatus").html(html);
							enableStatusDateInputs('videoManager');
							// this should actually reload the entire toolWindow, so that 
							// multiple items can be published and the navigation system will continue to function...
						}
					});
				});
			}
		});
	});
	
	
	$("div#toolScroll").delegate(".button.page.active", "click", function(event) {
		var metaData = $(this).attr('id').split("|");
		var status = "";
		if($("#Current").hasClass("on")) {
			status = "current";
		} else if($("#Archive").hasClass("on")) {
			status = "archives";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		} else if($("#Approve").hasClass("on")) {
			status = "approve";
		}
		$.ajax({
			url: "/dpComponent/videoManager/toolsDisplayStep",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + metaData[1],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolScroll").html(html);
			}
		});
	});
	
	$("div#toolScroll").delegate(".button.step.active", "click", function(event) {
		var metaData = $(this).attr('id').split("|");
		var status = "";
		if($("#Current").hasClass("on")) {
			status = "current";
		} else if($("#Archive").hasClass("on")) {
			status = "archives";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		} else if($("#Approve").hasClass("on")) {
			status = "approve";
		}
		$.ajax({
			url: "/dpComponent/videoManager/toolsDisplayStep",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + metaData[1],
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolScroll").html(html);
			}
		});
	});
	
	$("div#toolScroll").delegate("div.statusBox.topStory, div.statusBox.feature", "click", function() {
		var isOn = false;
		var eventId = $(this).parent().parent().attr('id');
		if($(this).hasClass('topStory')) {
			var statusType = "topStory";
		} else {
			var statusType = "feature";
		}
		var status = "";
		var startpos = $(this).parent().attr('class').replace("status sp_","");
		if($("#Current").hasClass("on")) {
			status = "current";
		} else if($("#Archive").hasClass("on")) {
			status = "archives";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		} else if($("#Approved").hasClass("on")) {
			status = "approve";
		}
		if($(this).hasClass('checked')) {
			isOn = true;
		}
		$.ajax({
			url: "/dpComponent/videoManager/toolsUpdateLayoutStatus",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + eventId + "&type=" + statusType + "&fstatus=" + isOn + "&startpos=" + startpos + "&status=" + status,
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$("#toolScroll").html(html);
			}
		});
	});
	
}

// VALIDATOR DESTROY FUNCTION
// ------------------------------------------------------------------------------------------------
function clearValidators() {
	if($("form#loginForm").length && $("form#loginForm").data("validator")) {
		$("form#loginForm").data("validator").destroy();
	}
	if($("form#joinForm").length && $("form#joinForm").data("validator")) {
		$("form#joinForm").data("validator").destroy();
	}
	if($("form#termsForm").length && $("form#termsForm").data("validator")) {
		$("form#termsForm").data("validator").destroy();
	}
	if($("form#profileForm").length && $("form#profileForm").data("validator")) {
		$("form#profileForm").data("validator").destroy();
	}
	if($("form#passwordForm").length && $("form#passwordForm").data("validator")) {
		$("form#passwordForm").data("validator").destroy();
	}
}

// these are the functions for the tools...
function toolsClassifiedsManage(msg) {
	//alert(msg);
	var category = $("#searchComponentPane div.on").attr('id');
	var classification = $("#searchComponentPane div.on div.categoryWrap div.on").attr('id');
	
	//alert("cat: " + category + " || " + classification);
	$("#toolScroll").delegate(".rowItem", "click", function(event) {
		var itemId = $(this).attr('id');
		var item = $(this);
		$.ajax({
			url: "/dpComponent/classifiedsManager/toolsDisplayOverviewAjax",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + itemId + "&cat=" + category + "&scat=" + classification,
			beforeSend: function() {
				// we need to remove the class from ANY of the rowitem values...
				$("#toolScroll div.rowItem").removeClass("on");
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$(item).addClass("on");
				//alert('post: ' + itemId);
				// output video accordian...
				
				$("#toolWindow").html(html);
				$("#toolAccordian").tabs("#toolAccordian div.tier", {tabs: 'h2', effect: 'slide', initialIndex: null});
				
				$("#classifieds_delete").click(function() {
					// we need the following data...
					var postId = $("#postId").val();
					var typeId = $("#toolClassifieds .toolNav").attr('id');
					var answer = confirm("Remove this classified from your site?");
					
					if(answer) {
						var metaData = "";
						if ($("#toolScroll div.listNav div.button.page.on").length) {
							metaData = $("#toolScroll div.listNav div.button.page.on").attr("id").split("|");
						} else {
							metaData = array();
						}
						var status = "";
						if($("#Current").hasClass("on")) {
							status = "published";
						} else if($("#Pending").hasClass("on")) {
							status = "pending";
						} else if($("#Approve").hasClass("on")) {
							status = "submitted";
						}

						$.ajax({
							url: "/dpComponent/classifiedsManager/toolsDeleteClassified",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + typeId + "&cat=" + category + "&scat=" + classification,
							beforeSend: function() {	
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
							
								// this should be the default sidebar...
								$("#toolWindow").html("");
								
								// remove the item from the list...
								$("#toolScroll").html(html);
							}
						});
					}
				});
				
				$("#toolAccordian").delegate(".setThumbnail", "click", function(event) {
					var clickedImg = $(this).attr("id").replace("thumbnail_","").replace("default","");
					overlayURL = "/dpComponent/channel/mediaLibraryOverlay?src=classifiedtool&dst=images";
					var overlayAPI = $("#toolsOverlay").data("overlay");
					$("#toolsOverlay").bind("onClose", function() {
						$("#toolsOverlay .overlayWrap").html("");
						$(this).unbind("onClose");	// unbind so we don't bubble up...
					});
					$("#toolsOverlay").bind("onLoad", function() {
						setTimeout(function(){configureImageDialog("",overlayAPI,clickedImg,""); overlayAPI=null; clickedImg=null},500);
						//setTimeout('configureImageDialog("",overlayAPI,clickedImg,"")',1000);
						//configureImageDialog("",overlayAPI,clickedImg,"");
						$(this).unbind("onLoad"); // unbind so we don't bubble up...
					});
					overlayAPI.load();
					return false;
				});
				
				$("#addPhoto").click(function() {
					overlayURL = "/dpComponent/channel/mediaLibraryOverlay?src=classified&dst=images";
					var overlayAPI = $("#toolsOverlay").data("overlay");
					$("#toolsOverlay").bind("onClose", function() {
						$("#toolsOverlay .overlayWrap").html("");
						$(this).unbind("onClose");	// unbind so we don't bubble up...
					});
					$("#toolsOverlay").bind("onLoad", function() {
						setTimeout(function(){configureImageDialog("",overlayAPI,"",""); overlayAPI=null},500);
						//setTimeout('configureImageDialog("",overlayAPI,"","")',1000);
						//configureImageDialog("",overlayAPI,"","");
						$(this).unbind("onLoad"); // unbind so we don't bubble up...
					});
					overlayAPI.load();
					return false;			
				});
	
				
				$("#previewWindow .headline").click(function() {
					var postId = $("#postId").val();
					// update DOM...
					$("#headline_"+postId).hide();
					$("#headlineEdit_"+postId).show();
					$("#newHeadline").focus();
				});
				$("#previewWindow #newHeadline").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origHeadline").val();	
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/classifiedsManager/updateHeadline",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
				//			beforeSend: function() {
				//				$("#contentLoading").removeClass("hide");
				//			},
							success: function(html) {
								$("#previewWindow .headline").html(html);
								//$("#toolScroll .rowItem.on .articleHeadline").html(html);
								$(item).children(".articleHeadline").html(html);
								
								$("#previewWindow #origHeadline").val(html);
								$("#previewWindow #newHeadline").val(html);
							}
						});
					}
					$("#headline_"+postId).show();
					$("#headlineEdit_"+postId).hide();
				});
				
				$("#previewWindow .lead").click(function() {
					var postId = $("#postId").val();
					// update DOM...
					$("#lead_"+postId).hide();
					$("#leadEdit_"+postId).show();
					$("#newLead").focus();
				});
				$("#previewWindow #newLead").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origLead").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/classifiedsManager/updateLead",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
				//			beforeSend: function() {
				//				$("#contentLoading").removeClass("hide");
				//			},
							success: function(html) {
								$("#previewWindow .lead").html(html);
								$("#previewWindow #origLead").val(html);
								$("#previewWindow #newLead").val(html);
							}
						});
					}
					$("#lead_"+postId).show();
					$("#leadEdit_"+postId).hide();
				});
				
				enableStatusDateInputs('classifiedsManager');
				
				$("#toolAccordian").delegate("#addNewPlacement", "click", function(event) {
					var placeToAdd = $("select#addPlacement").val();
					var postId = $("#postId").val();
					if(placeToAdd && postId) {
						var matrixData = placeToAdd.split("|");
						$.ajax({
							url: "/dpComponent/classifiedsManager/toolsPlaceContent",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&category=" + matrixData[0] + "&subCategory=" + matrixData[1],
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#storyMatrixData").html(html);
							}
						});
					}
				});
				
				$("#toolAccordian").delegate("#storyMatrixData .matrix_remove", "click", function(event) {
					var placeToRemove = $(this).attr('id').split("|");
					var postId = $("#postId").val();
					if(placeToRemove) {
						$.ajax({
							url: "/dpComponent/classifiedsManager/deleteStoryMatrixEntry",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&category=" + placeToRemove[1] + "&subCategory=" + placeToRemove[2],
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#storyMatrixData").html(html);
							}
						});
					}
				});
				
				
				// we are going to have 4 different options here...
				$("#publishNow").click(function() {
					var postId = $("#postId").val();
					var pubDate = $("#publish_date").val();
					$.ajax({
						url: "/dpComponent/classifiedsManager/publishNow",
						type: "post",
						data: "id=" + postId + "&pbl=" + pubDate,
				//			beforeSend: function() {
				//				$("#contentLoading").removeClass("hide");
				//			},
						success: function(html) {
							$("#toolsStatus").html(html);
							enableStatusDateInputs('classifiedsManager');
						}
					});
				});
				$("#archiveNow").click(function() {
					var postId = $("#postId").val();
					$.ajax({
						url: "/dpComponent/classifiedsManager/archiveNow",
						type: "post",
						data: "id=" + postId,
				//			beforeSend: function() {
				//				$("#contentLoading").removeClass("hide");
				//			},
						success: function(html) {
							$("#toolsStatus").html(html);
							enableStatusDateInputs('classifiedsManager');
							// this should actually reload the entire toolWindow, so that 
							// multiple items can be published and the navigation system will continue to function...
						}
					});
				});
				
				$("#add2Calendar").click(function() {
					$("#addCalendarForm").show("blind", {direction: "vertical"}, 500);
					$("#addCalendarNote").hide("blind", {direction: "vertical"}, 300);
					$("#event_date_last").dateinput({
						selectors: true,
						change: function() {
							var isoEnd = this.getValue('yyyy-mm-dd');
							$("#eventLast").val(isoEnd);
							$("#eventRecur").show("blind", {direction: "vertical"}, 500);
							//toolsCalendarRecur();
						}
					});
					$("#event_date").dateinput({
						selectors: true,
						change: function() {
							var isoDate = this.getValue('yyyy-mm-dd');
							var eventId = $("#postId").val();
							
							// set the hidden field in the dom...
							$("#eventStart").val(isoDate);
							
							// set the minimum allowed value of the event end date field...
							$("#event_date_last:date").data("dateinput").setMin(this.getValue(), false);
							
							// show the buttons...
							$("#event_type_select").show("blind", {direction: "vertical"}, 500);
							$("#single_day").click(function() {
								// show the recurring stuff...
								$("#event_type_select").hide("blind", {direction: "vertical"}, 300);
								$("#eventRecur").show("blind", {direction: "vertical"}, 500);
								// this is where the recurring calendar functions need to go...
								//toolsCalendarRecur();
							});
							$("#multi_day").click(function() {
								// show the archive date...
								$("#event_type_select").hide("blind", {direction: "vertical"}, 300);
								$("#eventDateLastWrap").show("blind", {direction: "vertical"}, 500);
								// configure the archive date via jquery...
							});
						}
					});
				});
			}
		});
	});
	
	
	$("div#toolScroll").delegate(".button.page.active", "click", function(event) {
		var metaData = $(this).attr('id').split("|");
		var category = $("#searchComponentPane div.on").attr('id');
		var classification = $("#searchComponentPane div.on div.categoryWrap div.on").attr('id');
		
		var status = "";
		// this is a weak point.
		// this should be automated based on the id# of the element being passed.
		// look into it... one area where we can streamline.
		if($("#Current").hasClass("on")) {
			status = "published";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		} else if($("#Approve").hasClass("on")) {
			status = "submitted";
		} else if($("#Archive").hasClass("on")) {
			status = "archive";
		}
		$.ajax({
			url: "/dpComponent/classifiedsManager/toolsDisplayStep",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + metaData[1] + "&cat=" + category + "&scat=" + classification,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolScroll").html(html);
			}
		});
	});
	
	$("div#toolScroll").delegate(".button.step.active", "click", function(event) {
		var metaData = $(this).attr('id').split("|");
		var category = $("#searchComponentPane div.on").attr('id');
		var classification = $("#searchComponentPane div.on div.categoryWrap div.on").attr('id');
		
		if($("#Current").hasClass("on")) {
			status = "published";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		} else if($("#Approve").hasClass("on")) {
			status = "submitted";
		} else if($("#Archive").hasClass("on")) {
			status = "archive";
		}
		$.ajax({
			url: "/dpComponent/classifiedsManager/toolsDisplayStep",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&startpos=" + metaData[2] + "&q=" + metaData[3] + "&status=" + status + "&typeId=" + metaData[1] + "&cat=" + category + "&scat=" + classification,
	//		beforeSend: function() {
	//			$("#contentLoading").removeClass("hide");
	//		},
			success: function(html) {
				$("#toolScroll").html(html);
			}
		});
	});
	
	$("div#toolScroll").delegate("div.statusBox.feature", "click", function() {
		var isOn = false;
		var eventId = $(this).parent().parent().attr('id');
		var statusType = "feature";
		var status = "";
		var startpos = $(this).parent().attr('class').replace("status sp_","");
		if($("#Current").hasClass("on")) {
			status = "published";
		} else if($("#Pending").hasClass("on")) {
			status = "pending";
		} else if($("#Approved").hasClass("on")) {
			status = "submitted";
		}
		if($(this).hasClass('checked')) {
			isOn = true;
		}
		$.ajax({
			url: "/dpComponent/classifiedsManager/toolsUpdateLayoutStatus",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + eventId + "&type=" + statusType + "&fstatus=" + isOn + "&startpos=" + startpos + "&status=" + status + "&cat=" + category + "&scat=" + classification,
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$("#toolScroll").html(html);
			}
		});
	});
}

function toolsClassifiedsCreate(msg) {
	if($("form#postForm").length) {					
		
		// display title in preview window...
		$("#naTitle").blur(function() {
			$("#previewBox .title").html($(this).val());
		});
				
				
		$("input#skipPay").click(function() {
			// we need to determine if it's on...
			if($(this).is(':checked')) {
				alert('Alert: Payment requirement has been overridden.  This classified ad will be Free.');
				
				// here... they are checking it...
				$("input#naCardNum").removeAttr("required");
				$("select#naCardExpireMonth").removeAttr("required");
				$("select#naCardExpireYear").removeAttr("required");
				$("input#naCardCode").removeAttr("required");
				
				// we should also disable those fields...
				$("input#naCardNum").attr("disabled","disabled");
				$("input#naCardCode").attr("disabled","disabled");
				$("select#naCardExpireMonth").attr("disabled","disabled");
				$("select#naCardExpireYear").attr("disabled","disabled");
				
			} else {
				alert('Alert: Payment is now required for this classified ad.');
				// here, they are turning it back on...
				$("input#naCardNum").attr("required","required");
				$("select#naCardExpireMonth").attr("required","required");
				$("select#naCardExpireYear").attr("required","required");
				$("input#naCardCode").attr("required","required");
				
				$("input#naCardNum").removeAttr("disabled");
				$("input#naCardCode").removeAttr("disabled");
				$("select#naCardExpireMonth").removeAttr("disabled");
				$("select#naCardExpireYear").removeAttr("disabled");
			}
		});
		
		// manage display text... update price, display in window...
		$("#naPostText").keyup(function() {
			var postText = $("#naPostText").val();
			var ptLength = postText.length;					
			$("#previewBox .text").html($(this).val());
			if(ptLength <= 100) {
				// LEVEL ONE -- FREE
				if($("#ccinfo").length) {
					$("#ccinfo").hide();
					$("input#naCardNum").removeAttr("required");
					$("input#naCardExpireMonth").removeAttr("required");
					$("input#naCardExpireYear").removeAttr("required");
					$("input#naCardCode").removeAttr("required");
				}
				
				// we would need to remove the "required" stuff 
				// from each of them...
				
				if($("#priceLevelTwo").hasClass("on")) {
					$("#priceLevelTwo").removeClass("on");
				}
				if($("#priceLevelThree").hasClass("on")) {
					$("#priceLevelThree").removeClass("on");
				}
				if($("#priceLevelFour").hasClass("on")) {
					$("#priceLevelFour").removeClass("on");
				}
				if(!$("#priceLevelOne").hasClass("on")) {
					$("#priceLevelOne").addClass("on");
				}
			} else if(ptLength > 100 && ptLength <= 250) {
				// LEVEL TWO
				if($("#ccinfo").length) {
					$("#ccinfo").show();
					$("input#naCardNum").attr("required","required");
					$("input#naCardExpireMonth").attr("required","required");
					$("input#naCardExpireYear").attr("required","required");
					$("input#naCardCode").attr("required","required");
				}
				
				
				if($("#priceLevelOne").hasClass("on")) {
					$("#priceLevelOne").removeClass("on");
				}
				if($("#priceLevelThree").hasClass("on")) {
					$("#priceLevelThree").removeClass("on");
				}
				if($("#priceLevelFour").hasClass("on")) {
					$("#priceLevelFour").removeClass("on");
				}
				if(!$("#priceLevelTwo").hasClass("on")) {
					$("#priceLevelTwo").addClass("on");
				}
											
			} else if(ptLength > 250 && ptLength <= 500) {
				// LEVEL THREE
				if($("#ccinfo").length) {
					$("#ccinfo").show();
					$("input#naCardNum").attr("required","required");
					$("input#naCardExpireMonth").attr("required","required");
					$("input#naCardExpireYear").attr("required","required");
					$("input#naCardCode").attr("required","required");
				}
				
				if($("#priceLevelOne").hasClass("on")) {
					$("#priceLevelOne").removeClass("on");
				}
				if($("#priceLevelTwo").hasClass("on")) {
					$("#priceLevelTwo").removeClass("on");
				}
				if($("#priceLevelFour").hasClass("on")) {
					$("#priceLevelFour").removeClass("on");
				}
				if(!$("#priceLevelThree").hasClass("on")) {
					$("#priceLevelThree").addClass("on");
				}
			} else if(ptLength > 500) {
				// LEVEL FOUR
				if($("#ccinfo").length) {
					$("#ccinfo").show();
					$("input#naCardNum").attr("required","required");
					$("input#naCardExpireMonth").attr("required","required");
					$("input#naCardExpireYear").attr("required","required");
					$("input#naCardCode").attr("required","required");
				}
				
				if($("#priceLevelOne").hasClass("on")) {
					$("#priceLevelOne").removeClass("on");
				}
				if($("#priceLevelTwo").hasClass("on")) {
					$("#priceLevelTwo").removeClass("on");
				}
				if($("#priceLevelThree").hasClass("on")) {
					$("#priceLevelThree").removeClass("on");
				}
				if(!$("#priceLevelFour").hasClass("on")) {
					$("#priceLevelFour").addClass("on");
				}
				// SET MAXIMUM LENGTH...
				if(ptLength > 750) {
					$("#naPostText").val(postText.substr(0,750));
				}							
			}
		});
		// Display Phone Number in Ad...
		$("#displayPhone").click(function() {
			if($("#displayPhone:checked").val() !== null) {
				$("#previewBox .phone").html( $("#naPhone").val() );
			} else {
				$("#previewBox .phone").html('');
			}
		});
		
		// Change category...
		$("#naCategory").change(function() {
			$.ajax({
				url: "/dpComponent/classifiedsManager/loadClassificationOptions",
				type: "post",
				data: "id="+ $(this).val(),
				dataType: "json",
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
				success: function(json) {
					$("#contentLoading").addClass("hide");
					if(json.length===0) {
						// there is no sub-category/classificiation available...
						$("select#naSubCategory").parent().hide();
					} else {
						var options = '';
						for(var i=0; i<json.length; i++) {
							options += '<option value="' + json[i].optionValue + '">' + json[i].optionDisplay + '</option>';
						}
						$("select#naSubCategory:hidden").parent().show();
						$("select#naSubCategory").html(options);
					}
				}
			})
		});
		
		// form validation
		$("form#postForm").validator().submit(function(e) {
			var form = $(this);
			if (!e.isDefaultPrevented()) {
				formData = form.serialize();
				$.ajax({
					url: "/dpComponent/classifiedsManager/submitClassified",
					type: "post",
					data: "cid="+ channel +"&scid="+ subchannel +"&" + formData,
					dataType: "json",
					beforeSend: function() {
						$("#contentLoading").removeClass("hide");
					},
			//		error: function(request,status,errorThrown) {
			//			alert(errorThrown);
			//		},
					success: function(json) {
						$("#contentLoading").addClass("hide");
						if (json.success)  {
							$("#helpStepOne").hide();
							$("#createScreen").html(json.html);
							$("html").scrollTop(0);
							toolsClassifiedsEnhance();		
						} else {
							form.data("validator").invalidate(json);
						}
					}
				});
				e.preventDefault();
			}
		});
	}
}

function toolsClassifiedsEnhance() {
	
	// this is calling itself.  
	// let's see if that causes any problems...
	// ------------------------------------------------------------------------------------------
	$("form#repostForm").validator().submit(function(e) {
			var form = $(this);
			if (!e.isDefaultPrevented()) {
				formData = form.serialize();
				$.ajax({
					url: "/dpComponent/classifiedsManager/revalidateCC",
					type: "post",
					data: "cid="+ channel +"&scid="+ subchannel +"&" + formData,
					dataType: "json",
					beforeSend: function() {
						$("#contentLoading").removeClass("hide");
					},
			//		error: function(request,status,errorThrown) {
			//			alert(errorThrown);
			//		},
					success: function(json) {
						$("#contentLoading").addClass("hide");
						if (json.success)  {
							$("#helpStepOne").hide();
							$("#createScreen").html(json.html);
							$("html").scrollTop(0);
							toolsClassifiedsEnhance();
						} else {
							form.data("validator").invalidate(json);
						}
					}
				});
				e.preventDefault();
			}
		});
		
		
	// here, is where we configure this...
	$("#photoUploads div.articleButton").click(function() {
		overlayURL = "/dpComponent/channel/mediaLibraryOverlay?src=classified&dst=images";
		var overlayAPI = $("#toolsOverlay").data("overlay");
		$("#toolsOverlay").bind("onClose", function() {
			$("#toolsOverlay .overlayWrap").html("");
			$(this).unbind("onClose");	// unbind so we don't bubble up...
		});
		$("#toolsOverlay").bind("onLoad", function() {
			// we need to pause for a second here...
			// to make sure all of the content is loaded...
			setTimeout(function(){configureImageDialog("",overlayAPI,"",""); overlayAPI=null},500);
			//setTimeout('configureImageDialog("",overlayAPI,"","")',1000);
			//configureImageDialog("",overlayAPI,"","");
			$(this).unbind("onLoad"); // unbind so we don't bubble up...
		});
		overlayAPI.load();
		return false;
	});
	
	$("#postGalleryWrap").delegate("div.classImageRemove","click",function() {
	
		// step one, set variables...
		var postId = $("#postId").val();
		var imgSrc = $(this).prev().attr("src").replace("/media/"+dpclient+"/images/","").replace("_icon","").split(".");
		var imgId = $(this).parent().attr("id").replace("image_","");
		
		var imgWrap = $(this).parent();
		
		// step two, update database and remove photo...
		$.ajax({
			url: "/dpComponent/classifiedsManager/toolsRemoveImage",
			type: "post",
			data: "id="+ imgId +"&classified="+ postId,
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				// if html == 1, it worked... hell if this is running, it worked...
				imgWrap.remove();
				if($("#postGalleryWrap > div").size() < 4) {
					$("#addPhoto").show();
				}
				
			}
		});
		alert("post: " + postId + " || img: " + imgSrc[0] + " || img2: " + imgId);
		
		// step two, it to remove the photo...
		
		// step three, is to ge the count of the div, and re-enable the button if necessary...
		
	});
	
	$("#eventMap div.articleButton").click(function() {
		var postId = $("#postId").val();
		var address = $("#eventAddress").val();
		$.ajax({
			url: "/dpComponent/classifiedsManager/toolsAssignMap",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&p=" + postId + "&a=" + address,
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$("#event_map").html(html);
				//$("#eventMap .editType .descrip").hide();
				if($("#viewMap").length) {
					var mapAddress = $("#viewMap").html();
					$("#viewMap").googleMap(mapAddress);
				}
			}
		});
	});
	
	$("#userLocation div.articleButton").click(function() {
		var postId = $("#postId").val();
		var geotag = $("#geoTags").val();
		
		$.ajax({
			url: "/dpComponent/classifiedsManager/toolsAssignLocation",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&p=" + postId + "&l=" + geotag,
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$("#sgst_geo").html(html);
			}
		});
	});

	$("#toolsClassifiedClose").click(function() {
		// here, we need to do the exact opposite of the other one...
		// grab the url, and replace the https, with http, and send them along...
		
		var cUrl = window.document.location.href.replace("https:","http:").replace("/create","");
		window.location.href = cUrl;	
	
	});
	
	$("#toolsClassifiedAgain").click(function() {
		$.ajax({
			url: "/dpComponent/classifiedsManager/toolsDisplayCreateAjax",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&typeId=",
			beforeSend: function() {
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				// now, we need to remove the ON from the current tabs...
				//$(".toolNav div").removeClass("on");
				//$(parent).addClass("on");
				$("#contentLoading").addClass("hide");
				$("#toolInterface").html(html);
			}
		});
		return false;
	});			
}

function toolsContributorsCreate(msg) {
	$("form#postForm").validator().submit(function(e) {
		var form = $(this);
		if (!e.isDefaultPrevented()) {
			// passed client-side validation OK.
			// you know, we could put some stuff in here to stop spammers...
			// do a SHA1 of the email+dpCode and check on the other end... SWEET!
			formData = form.serialize();
			$.ajax({
				url: "/dpComponent/channel/toolsCreateNewContributor",
				type: "post",
				data: "cid="+ channel +"&scid="+ subchannel +"&" + formData,
				dataType: "json",
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
//				error: function(html) {
//					// this is the error function here...
//					alert(html);
//				},
				success: function(json) {
					$("#contentLoading").addClass("hide");
					if (json.success)  {
						var contributorId = json.id;
						
						// video successfully shared!
						$("#contributorCreate").addClass('hide');
						$("#toolScroll").html(json.html).removeClass('hide');
						$("#toolContributors .toolsNav div#Create").removeClass("on");
						$("#toolContributors .toolsNav div#Current").addClass("on");
						
						
						toolsContributorsManage("internal");

						// this needs to be in a function...
						// we need to work out a system for scrolling
						// directly to where we want...
						if(contributorId && $("#"+contributorId.length)) {
							var scrollPos = $("#toolScroll .fixed").offset();
							var eventScroll = $("#"+contributorId).offset();
							var eventScrollPos = $("#toolScroll .fixed").scrollTop();
							var scrollToPos = eventScroll.top - scrollPos.top - 12;
							var finalScroll = eventScrollPos + scrollToPos;
							$("#toolScroll .fixed").animate({scrollTop:finalScroll},300);
							$("#"+contributorId).addClass("on");
							$("#"+contributorId).effect("highlight",{ },5000);
							
							
							//alert('finalScroll: ' + finalScroll);
							// now, we need to simulate a click...
							$("#toolScroll div.rowItem.on").click();
						}
						
						
					} else {
						// server-side validation failed.
						form.data("validator").invalidate(json);
					}
				}
			});
			// prevent the form from being submitted...
			e.preventDefault();
		}
	});
}

function toolsContributorsManage(msg) {
	//alert(msg);
	$("#toolScroll").delegate(".rowItem", "click", function(event) {
		var itemId = $(this).attr('id');
		var item = $(this);
		$.ajax({
		
			// YOU NEED TO CREATE THIS FILE, USING THE AJAX OVERVIEW CODE...SWEET!
			url: "/dpComponent/channel/toolsDisplayContributorOverview",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + itemId,
			beforeSend: function() {
				// we need to remove the class from ANY of the rowitem values...
				$("#toolScroll div.rowItem").removeClass("on");
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$(item).addClass("on");
				//alert('post: ' + itemId);
				// output video accordian...
				
				$("#toolWindow").html(html);
				$("#toolAccordian").tabs("#toolAccordian div.tier", {tabs: 'h2', effect: 'slide', initialIndex: null});
			
				// configure all of the accordian tools here...
				$("#toolAccordian").delegate(".setThumbnail", "click", function(event) {
				
					var clickedImg = $(this).attr("id").replace("thumbnail_","").replace("default","");
					overlayURL = "/dpComponent/channel/mediaLibraryOverlay?src=tool&dst=images";
					var overlayAPI = $("#toolsOverlay").data("overlay");
					$("#toolsOverlay").bind("onClose", function() {
						$("#toolsOverlay .overlayWrap").html("");
						$(this).unbind("onClose");	// unbind so we don't bubble up...
					});
					$("#toolsOverlay").bind("onLoad", function() {
						setTimeout(function(){configureImageDialog("",overlayAPI,clickedImg,""); overlayAPI=null; clickedImg=null},500);
						//setTimeout('configureImageDialog("",overlayAPI,clickedImg,"")',1000);
						//configureImageDialog("",overlayAPI,clickedImg,"");
						$(this).unbind("onLoad"); // unbind so we don't bubble up...
					});
					overlayAPI.load();
					return false;
					/*
					var existingThumbId = $(this).attr('id').replace("thumbnail_","");
					var postId = $("#postId").val();
					var contributorId = $("#contributorId").val();
					var href = '/dpComponent/images/toolsLibraryBrowse?channel=' + channel + '&subChannel=' + subchannel + '&postId=' + postId + '&thumbId=' + existingThumbId + "&contributorId=" + contributorId;
					window.open(href,'mediaLibrary','width=980,height=600');
					return false;
					*/
				});
				
				// configure... edit-in-place headline...
				// ------------------------------------------------------------------------------------
				$("#previewWindow .name").click(function() {
					var postId = $("#postId").val();
					// update DOM...
					$("#name_"+postId).hide();
					$("#nameEdit_"+postId).show();
					$("#newName").focus();
				});
				// edit-in-place NAME...
				$("#previewWindow #newName").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origName").val();	
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateContributorName",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#previewWindow #name_"+postId).html(html);
								//$("#toolScroll .rowItem.on .articleHeadline").html(html);
								$(item).children(".articleHeadline").html(html);
								$("#previewWindow #origName").val(html);
								$("#previewWindow #newName").val(html);
							}
						});
					}
					$("#name_"+postId).show();
					$("#nameEdit_"+postId).hide();
				});
				// edit-in-place lead...
				$("#previewWindow .lead").click(function() {
					var postId = $("#postId").val();
					$("#lead_"+postId).hide();
					$("#leadEdit_"+postId).show();
					$("#newLead").focus();
				});
				$("#previewWindow #newLead").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origLead").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateContributorLead",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#previewWindow .lead").html(html);
								$("#previewWindow #origLead").val(html);
								$("#previewWindow #newLead").val(html);
							}
						});
					}
					$("#lead_"+postId).show();
					$("#leadEdit_"+postId).hide();
				});
				
				$("#contributors_delete").click(function() {
					var currentContributor = $("#postId").val();
					$.ajax({
						url: "/dpComponent/channel/toolsDeleteContributor",
						type: "post",
						data: "contributor="+currentContributor,
						beforeSend: function() {
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							// once the contributor is deleted, let's remove them from the list...
							$("#"+currentContributor).remove();
						}
					});
					
					alert('delete contributor');
				});
				
				$("#contributors_transfer").click(function() {
					$("#transferList").removeClass('hide');
				});
				
				$("#transferContributorGo").click(function() {
					var currentContributor = $("#postId").val();
					var newContributor = $("#transferContributor").val();
					$.ajax({
						url: "/dpComponent/channel/toolsTransferContributor",
						type: "post",
						data: "cContributor="+currentContributor+"&nContributor="+newContributor,
						beforeSend: function() {
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							$("#contributors_delete").removeClass('hide');
						}
					});
					
					//alert("old: "+currentContributor+" || new: "+newContributor);
				});
				
				// edit-in-place type...
				$("#toolsType .type").click(function() {
					var postId = $("#postId").val();
					$("#type_"+postId).hide();
					$("#typeEdit_"+postId).show();
					$("#newType").focus();
				});
				$("#toolsType #newType").change(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origType").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateContributorType",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#toolsType .type").html(html);
								$("#toolsType #origType").val(html);
								$("#toolsType #newType").val(html);
							}
						});
					}
					$("#type_"+postId).show();
					$("#typeEdit_"+postId).hide();
				});
				
				
				// edit-in-place address...
				$("#toolsLocation .address").click(function() {
					var postId = $("#postId").val();
					$("#address_"+postId).hide();
					$("#addressEdit_"+postId).show();
					$("#newAddress").focus();
				});
				$("#toolsLocation #newAddress").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origAddress").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateContributorAddress",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#toolsLocation .address").html(html);
								$("#toolsLocation #origAddress").val(html);
								$("#toolsLocation #newAddress").val(html);
							}
						});
					}
					$("#address_"+postId).show();
					$("#addressEdit_"+postId).hide();
				});
				
				// edit-in-place city...
				$("#toolsLocation .city").click(function() {
					var postId = $("#postId").val();
					$("#city_"+postId).hide();
					$("#cityEdit_"+postId).show();
					$("#newCity").focus();
				});
				$("#toolsLocation #newCity").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origCity").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateContributorCity",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#toolsLocation .city").html(html);
								$("#toolsLocation #origCity").val(html);
								$("#toolsLocation #newCity").val(html);
							}
						});
					}
					$("#city_"+postId).show();
					$("#cityEdit_"+postId).hide();
				});
				
				// edit-in-place state...
				$("#toolsLocation .state").click(function() {
					var postId = $("#postId").val();
					$("#state_"+postId).hide();
					$("#stateEdit_"+postId).show();
					$("#newState").focus();
				});
				$("#toolsLocation #newState").change(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origState").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateContributorState",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#toolsLocation .state").html(html);
								$("#toolsLocation #origState").val(html);
								$("#toolsLocation #newState").val(html);
							}
						});
					}
					$("#state_"+postId).show();
					$("#stateEdit_"+postId).hide();
				});
				
				// edit-in-place zip...
				$("#toolsLocation .zip").click(function() {
					var postId = $("#postId").val();
					$("#zip_"+postId).hide();
					$("#zipEdit_"+postId).show();
					$("#newZip").focus();
				});
				$("#toolsLocation #newZip").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origZip").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateContributorZip",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#toolsLocation .zip").html(html);
								$("#toolsLocation #origZip").val(html);
								$("#toolsLocation #newZip").val(html);
							}
						});
					}
					$("#zip_"+postId).show();
					$("#zipEdit_"+postId).hide();
				});
				
				$("#toolsLocation #newDisplayLocation").click(function() {
					var postId = $("#postId").val();
					var displayStatus = "";
					if($("#newDisplayLocation").is(':checked')) {
						displayStatus = 1;
					} else {
						displayStatus = 0;
					}
					$.ajax({
						url: "/dpComponent/channel/toolsUpdateContributorLocationDisplay",
						type: "post",
						data: "id=" + postId + "&nd=" + displayStatus,
						// here, we need a rotating image for the overlay...
						beforeSend: function() {
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							$("#publish_location_"+postId).html(html);
						}
					});
				});
				
				// edit-in-place phone...
				$("#toolsContact .phone").click(function() {
					var postId = $("#postId").val();
					$("#phone_"+postId).hide();
					$("#phoneEdit_"+postId).show();
					$("#newPhone").focus();
				});
				$("#toolsContact #newPhone").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origPhone").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateContributorPhone",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#toolsContact .phone").html(html);
								$("#toolsContact #origPhone").val(html);
								$("#toolsContact #newPhone").val(html);
							}
						});
					}
					$("#phone_"+postId).show();
					$("#phoneEdit_"+postId).hide();
				});
				$("#toolsContact #newDisplayPhone").click(function() {
					var postId = $("#postId").val();
					var displayStatus = "";
					if($("#newDisplayPhone").is(':checked')) {
						displayStatus = 1;
					} else {
						displayStatus = 0;
					}
					$.ajax({
						url: "/dpComponent/channel/toolsUpdateContributorPhoneDisplay",
						type: "post",
						data: "id=" + postId + "&nd=" + displayStatus,
						// here, we need a rotating image for the overlay...
						beforeSend: function() {
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							$("#publish_phone_"+postId).html(html);
						}
					});
				});
				
				// edit-in-place email...
				$("#toolsContact .email").click(function() {
					var postId = $("#postId").val();
					$("#email_"+postId).hide();
					$("#emailEdit_"+postId).show();
					$("#newEmail").focus();
				});
				$("#toolsContact #newEmail").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origEmail").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateContributorEmail",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#toolsContact .email").html(html);
								$("#toolsContact #origEmail").val(html);
								$("#toolsContact #newEmail").val(html);
							}
						});
					}
					$("#email_"+postId).show();
					$("#emailEdit_"+postId).hide();
				});
				$("#toolsContact #newAcceptEmail").click(function() {
					var postId = $("#postId").val();
					var displayStatus = "";
					if($("#newAcceptEmail").is(':checked')) {
						displayStatus = 1;
					} else {
						displayStatus = 0;
					}
					$.ajax({
						url: "/dpComponent/channel/toolsUpdateContributorAcceptEmail",
						type: "post",
						data: "id=" + postId + "&nd=" + displayStatus,
						// here, we need a rotating image for the overlay...
						beforeSend: function() {
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							$("#accept_email_"+postId).html(html);
						}
					});
				});
				
				// edit-in-place website...
				$("#toolsSocialMedia .website").click(function() {
					var postId = $("#postId").val();
					$("#website_"+postId).hide();
					$("#websiteEdit_"+postId).show();
					$("#newWebsite").focus();
				});
				$("#toolsSocialMedia #newWebsite").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origWebsite").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateContributorWebsite",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#toolsSocialMedia .website").html(html);
								$("#toolsSocialMedia #origWebsite").val(html);
								$("#toolsSocialMedia #newWebsite").val(html);
							}
						});
					}
					$("#website_"+postId).show();
					$("#websiteEdit_"+postId).hide();
				});
				
				// edit-in-place facebook...
				$("#toolsSocialMedia .facebook").click(function() {
					var postId = $("#postId").val();
					$("#facebook_"+postId).hide();
					$("#facebookEdit_"+postId).show();
					$("#newFacebook").focus();
				});
				$("#toolsSocialMedia #newFacebook").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origFacebook").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateContributorFacebook",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#toolsSocialMedia .facebook").html(html);
								$("#toolsSocialMedia #origFacebook").val(html);
								$("#toolsSocialMedia #newFacebook").val(html);
							}
						});
					}
					$("#facebook_"+postId).show();
					$("#facebookEdit_"+postId).hide();
				});
				
				// edit-in-place twitter...
				$("#toolsSocialMedia .twitter").click(function() {
					var postId = $("#postId").val();
					$("#twitter_"+postId).hide();
					$("#twitterEdit_"+postId).show();
					$("#newTwitter").focus();
				});
				$("#toolsSocialMedia #newTwitter").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origTwitter").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateContributorTwitter",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#toolsSocialMedia .twitter").html(html);
								$("#toolsSocialMedia #origTwitter").val(html);
								$("#toolsSocialMedia #newTwitter").val(html);
							}
						});
					}
					$("#twitter_"+postId).show();
					$("#twitterEdit_"+postId).hide();
				});
				
				// click-in-place xml...
				$("#toolsSyndication .xml").click(function() {
					var postId = $("#postId").val();
					var status = $(this).html();
					$.ajax({
						url: "/dpComponent/channel/toolsUpdateContributorSyndication",
						type: "post",
						data: "id=" + postId + "&st=" + status,
						// here, we need a rotating image for the overlay...
						beforeSend: function() {
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							$("#toolsSyndication .xml").html(html);
							if($("#xml_suggested").length) {
								if(html == "Enabled") {
									$("#toolsSyndication #xml_suggested").show();
								} else {
									$("#toolsSyndication #xml_suggested").hide();
									$("#toolsSyndication .xmlSuggest").html("No");
								}
							}
						}
					});
				});
				
				// click-in-place xml-suggested...
				$("#toolsSyndication .xmlSuggest").click(function() {
					var postId = $("#postId").val();
					var status = $(this).html();
					$.ajax({
						url: "/dpComponent/channel/toolsUpdateContributorSyndicationFeature",
						type: "post",
						data: "id=" + postId + "&st=" + status,
						// here, we need a rotating image for the overlay...
						beforeSend: function() {
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							$("#toolsSyndication .xmlSuggest").html(html);
						}
					});
				});
				
				$("#toolAccordian").delegate("#toolsTrustedUsers .remove", "click", function(event) {
					var userToRemove = $(this).attr('id').replace("x_","");
					var postId = $("#postId").val();
					
					if(userToRemove) {
						$.ajax({
							url: "/dpComponent/channel/removeContributorTrustedUser",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&user=" + userToRemove,
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#toolsTrustedUsers").html(html);
							}
						});
					}
				});
				
				$("#toolAccordian").delegate("#toolsTrustedUsers .isNotDefault", "click", function(event) {
					var userToUpdate = $(this).attr('id').replace("d_","");
					var postId = $("#postId").val();
					
					if(userToUpdate) {
						$.ajax({
							url: "/dpComponent/channel/toolsSetContributorTrustedUserDefault",
							type: "post",
							data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&user=" + userToUpdate,
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#toolsTrustedUsers").html(html);
							}
						});
					}
				});
				
				$("#trustedUserSearch").autocomplete({
					source: "/dpComponent/user/usersJSON",
					minLength: 2,
					select: function(event, ui) {
						var postId = $("#postId").val();
						if(ui.item.id && postId) {
							$.ajax({
								url: "/dpComponent/channel/toolsContributorAddTrustedUser",
								type: "post",
								data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId + "&user=" + ui.item.id,
								beforeSend: function() {
									$("#contentLoading").removeClass("hide");
								},
								success: function(html) {
									$("#contentLoading").addClass("hide");
									$("#toolsTrustedUsers").html(html);
									$("input#trustedUserSearch").val('');
								}
							});
						}
					}
				}).blur(function() {
					if($(this).val() == "  ") {
						$(this).val('');
					}
				});							
			}
		});
	});
	
	$("#toolScroll div.alpha a").click(function() {
		if($("div#toolScroll div.fixed").length) {
			var letter = $(this).html();
			var scrollPos = $("#toolScroll .fixed").offset();
			var eventScroll = $("#alpha_"+letter).offset();
			var eventScrollPos = $("#toolScroll .fixed").scrollTop();
			var scrollToPos = eventScroll.top - scrollPos.top - 12;
			var finalScroll = eventScrollPos + scrollToPos;
			$("#toolScroll .fixed").animate({scrollTop:finalScroll},300);
			$("#alpha_"+letter).effect("highlight",{ },5000);
		}
	});
				
}

function toolsTagsManage(msg) {
	//alert(msg);
	$("#toolScroll").delegate(".rowItem", "click", function(event) {
		var itemId = $(this).attr('id');
		var item = $(this);
		$.ajax({
		
			// YOU NEED TO CREATE THIS FILE, USING THE AJAX OVERVIEW CODE...SWEET!
			url: "/dpComponent/channel/toolsDisplayTagsOverview",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + itemId,
			beforeSend: function() {
				// we need to remove the class from ANY of the rowitem values...
				$("#toolScroll div.rowItem").removeClass("on");
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$(item).addClass("on");
				//alert('post: ' + itemId);
				// output video accordian...
				
				$("#toolWindow").html(html);
				$("#toolAccordian").tabs("#toolAccordian div.tier", {tabs: 'h2', effect: 'slide', initialIndex: null});
			
		
				// configure all of the accordian tools here...
				$("#toolAccordian").delegate(".setThumbnail", "click", function(event) {
					var clickedImg = $(this).attr("id").replace("thumbnail_","").replace("default","");
					overlayURL = "/dpComponent/channel/mediaLibraryOverlay?src=tool&dst=images";
					var overlayAPI = $("#toolsOverlay").data("overlay");
					$("#toolsOverlay").bind("onClose", function() {
						$("#toolsOverlay .overlayWrap").html("");
						$(this).unbind("onClose");	// unbind so we don't bubble up...
					});
					$("#toolsOverlay").bind("onLoad", function() {
						setTimeout(function(){configureImageDialog("",overlayAPI,clickedImg,""); overlayAPI=null; clickedImg=null},500);
						//setTimeout('configureImageDialog("",overlayAPI,clickedImg,"")',1000);
						//configureImageDialog("",overlayAPI,clickedImg,"");
						$(this).unbind("onLoad"); // unbind so we don't bubble up...
					});
					overlayAPI.load();
					return false;
				});
				
				// configure... edit-in-place headline...
				// ------------------------------------------------------------------------------------
				$("#previewWindow .name").click(function() {
					var postId = $("#postId").val();
					// update DOM...
					$("#name_"+postId).hide();
					$("#nameEdit_"+postId).show();
					$("#newName").focus();
				});
				// edit-in-place NAME...
				$("#previewWindow #newName").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origName").val();	
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateTagName",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#previewWindow #name_"+postId).html(html);
								//$("#toolScroll .rowItem.on .articleHeadline").html(html);
								$(item).children(".articleHeadline").html(html);
								$("#previewWindow #origName").val(html);
								$("#previewWindow #newName").val(html);
							}
						});
					}
					$("#name_"+postId).show();
					$("#nameEdit_"+postId).hide();
				});
				// edit-in-place lead...
				$("#previewWindow .lead").click(function() {
					var postId = $("#postId").val();
					$("#lead_"+postId).hide();
					$("#leadEdit_"+postId).show();
					$("#newLead").focus();
				});
				$("#previewWindow #newLead").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origLead").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateTagLead",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#previewWindow .lead").html(html);
								$("#previewWindow #origLead").val(html);
								$("#previewWindow #newLead").val(html);
							}
						});
					}
					$("#lead_"+postId).show();
					$("#leadEdit_"+postId).hide();
				});
			}
		});
	});
	
	$("#toolScroll div.alpha a").click(function() {
		//alert("Letter: "+letter);
		if($("div#toolScroll div.fixed").length) {
			var letter = $(this).html();
			var scrollPos = $("#toolScroll .fixed").offset();
			var eventScroll = $("#alpha_"+letter).offset();
			var eventScrollPos = $("#toolScroll .fixed").scrollTop();
			var scrollToPos = eventScroll.top - scrollPos.top - 12;
			var finalScroll = eventScrollPos + scrollToPos;
			$("#toolScroll .fixed").animate({scrollTop:finalScroll},300);
			$("#alpha_"+letter).effect("highlight",{ },5000);
		}
	});
				
}

function toolsTagsCreate(msg) {
	alert(msg);
}

function toolsAlertsManage(msg) {
	//alert(msg);
	$("#toolScroll").delegate(".rowItem", "click", function(event) {
		var itemId = $(this).attr('id');
		var item = $(this);
		$.ajax({
		
			// YOU NEED TO CREATE THIS FILE, USING THE AJAX OVERVIEW CODE...SWEET!
			url: "/dpComponent/channel/toolsDisplayAlertsOverview",
			type: "post",
			data: "cid=" + channel + "&scid=" + subchannel + "&id=" + itemId,
			beforeSend: function() {
				// we need to remove the class from ANY of the rowitem values...
				$("#toolScroll div.rowItem").removeClass("on");
				$("#contentLoading").removeClass("hide");
			},
			success: function(html) {
				$("#contentLoading").addClass("hide");
				$(item).addClass("on");
				//alert('post: ' + itemId);
				// output video accordian...
				
				$("#toolWindow").html(html);
				$("#toolAccordian").tabs("#toolAccordian div.tier", {tabs: 'h2', effect: 'slide', initialIndex: null});
			
				
				// configure... edit-in-place headline...
				// ------------------------------------------------------------------------------------
				$("#previewWindow .name").click(function() {
					var postId = $("#postId").val();
					// update DOM...
					$("#name_"+postId).hide();
					$("#nameEdit_"+postId).show();
					$("#newName").focus();
				});
				// edit-in-place NAME...
				$("#previewWindow #newName").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origName").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateAlertName",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#previewWindow #name_"+postId).html(html);
								//$("#toolScroll .rowItem.on .articleHeadline").html(html);
								$(item).children(".articleHeadline").html(html);
								$("#previewWindow #origName").val(html);
								$("#previewWindow #newName").val(html);
							}
						});
					}
					$("#name_"+postId).show();
					$("#nameEdit_"+postId).hide();
				});
				
				$("#previewWindow .url").click(function() {
					var postId = $("#postId").val();
					// update DOM...
					$("#url_"+postId).hide();
					$("#urlEdit_"+postId).show();
					$("#newUrl").focus();
				});
				// edit-in-place NAME...
				$("#previewWindow #newUrl").blur(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origUrl").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateAlertUrl",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#previewWindow #url_"+postId).html(html);
								//$("#toolScroll .rowItem.on .articleHeadline").html(html);
								$(item).children(".articleHeadline").html(html);
								$("#previewWindow #origUrl").val(html);
								$("#previewWindow #newUrl").val(html);
							}
						});
					}
					$("#url_"+postId).show();
					$("#urlEdit_"+postId).hide();
				});
			
				// alert type...
				$("#previewWindow .type").click(function() {
					var postId = $("#postId").val();
					$("#type_"+postId).hide();
					$("#typeEdit_"+postId).show();
					$("#newType").focus();
				});
				$("#previewWindow #newType").change(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origType").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateAlertType",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#previewWindow .type").html(html);
								$("#previewWindow #origType").val(html);
								$("#previewWindow #newType").val(html);
							}
						});
					}
					$("#type_"+postId).show();
					$("#typeEdit_"+postId).hide();
				});
				
				// alert place...
				$("#previewWindow .place").click(function() {
					var postId = $("#postId").val();
					$("#place_"+postId).hide();
					$("#placeEdit_"+postId).show();
					$("#newPlace").focus();
				});
				$("#previewWindow #newPlace").change(function() {
					var postId = $("#postId").val();
					var nData = $(this).val();
					var oData = $("#origPlace").val();
					if(nData != oData) {
						$.ajax({
							url: "/dpComponent/channel/toolsUpdateAlertPlacement",
							type: "post",
							data: "id=" + postId + "&nd=" + nData,
							// here, we need a rotating image for the overlay...
							beforeSend: function() {
								$("#contentLoading").removeClass("hide");
							},
							success: function(html) {
								$("#contentLoading").addClass("hide");
								$("#previewWindow .place").html(html);
								$("#previewWindow #origPlace").val(html);
								$("#previewWindow #newPlace").val(html);
							}
						});
					}
					$("#place_"+postId).show();
					$("#placeEdit_"+postId).hide();
				});
				
				// configure event buttons...
				$("#alerts_delete").click(function() {
					var postId = $("#postId").val();
					$.ajax({
						url: "/dpComponent/channel/deleteAlert",
						type: "post",
						data: "cid=" + channel + "&scid=" + subchannel + "&id=" + postId,
						beforeSend: function() {	
							$("#contentLoading").removeClass("hide");
						},
						success: function(html) {
							$("#contentLoading").addClass("hide");
							// clear the window...
							$("#toolWindow").html("");
							// output the alert list...
							$("#"+postId).remove();						
						}
					});
				});
				
			}
		});
	});
	
	$("#toolScroll div.alpha a").click(function() {
		//alert("Letter: "+letter);
		if($("div#toolScroll div.fixed").length) {
			var letter = $(this).html();
			var scrollPos = $("#toolScroll .fixed").offset();
			var eventScroll = $("#alpha_"+letter).offset();
			var eventScrollPos = $("#toolScroll .fixed").scrollTop();
			var scrollToPos = eventScroll.top - scrollPos.top - 12;
			var finalScroll = eventScrollPos + scrollToPos;
			$("#toolScroll .fixed").animate({scrollTop:finalScroll},300);
			$("#alpha_"+letter).effect("highlight",{ },5000);
		}
	});
				
}

function toolsAlertsCreate(msg) {

	$("form#postForm").validator().submit(function(e) {
		var form = $(this);
		if (!e.isDefaultPrevented()) {
			formData = form.serialize();
			$.ajax({
				url: "/dpComponent/channel/toolsCreateNewAlert",
				type: "post",
				data: "cid="+ channel +"&scid="+ subchannel +"&" + formData,
				dataType: "json",
				beforeSend: function() {
					$("#contentLoading").removeClass("hide");
				},
//				error: function(html) {
//					// this is the error function here...
//					alert(html);
//				},
				success: function(json) {
					$("#contentLoading").addClass("hide");
					if (json.success)  {
						var alertId = json.id;
						
						// video successfully shared!
						$("#alertCreate").addClass('hide');
						$("#toolScroll").html(json.html).removeClass('hide');
						$("#toolAlerts .toolsNav div#Create").removeClass("on");
						$("#toolAlerts .toolsNav div#Current").addClass("on");

						toolsAlertsManage("internal");

						// this needs to be in a function...
						// we need to work out a system for scrolling
						// directly to where we want...
						if(alertId && $("#"+alertId.length)) {
							var scrollPos = $("#toolScroll .fixed").offset();
							var eventScroll = $("#"+alertId).offset();
							var eventScrollPos = $("#toolScroll .fixed").scrollTop();
							var scrollToPos = eventScroll.top - scrollPos.top - 12;
							var finalScroll = eventScrollPos + scrollToPos;
							$("#toolScroll .fixed").animate({scrollTop:finalScroll},300);
							$("#"+alertId).addClass("on");
							$("#"+alertId).effect("highlight",{ },5000);
							
							
							//alert('finalScroll: ' + finalScroll);
							// now, we need to simulate a click...
							$("#toolScroll div.rowItem.on").click();
						}
						
						
					} else {
						// server-side validation failed.
						form.data("validator").invalidate(json);
					}
				}
			});
			// prevent the form from being submitted...
			e.preventDefault();
		}
	});
}

function toolsUpdateProfile() {
	$("#editProfile").click(function() {
		$("#profileForm div.dataDisplay").hide();
		$("#profileForm div.dataEdit").show();
		$("#editProfile").hide();
		$("#cancelProfile").show();
		$("#profileSubmit").show();
		
		// set up the validator...
		$("form#profileForm").validator().submit(function(e) {
			var form = $(this);
			if (!e.isDefaultPrevented()) {
				$("#profile_update").attr("disabled", true);
				$.ajax({
					url: "/dpComponent/user/updateProfile",
					type: "post",
					data: form.serialize(),
					dataType: "json",
					beforeSend: function() {
						$("#contentLoading").removeClass("hide");
					},
					success: function(json) {
						$("#contentLoading").addClass("hide");
						if (json.success)  {
							
							// set new values in display...
							$("#displayEmail").html(json.email);
							$("#displayFirstName").html(json.firstName);
							$("#displayLastName").html(json.lastName);
							$("#displayAddress").html(json.address);
							$("#displayCity").html(json.city);
							$("#displayState").html(json.state);
							$("#displayZip").html(json.zip);
							$("#displayPhone").html(json.phone);
							
							// display the form...
							$("#profileForm div.dataDisplay").show();
							$("#profileForm div.dataEdit").hide();
							$("#editProfile").show();
							$("#cancelProfile").hide();
							$("#profileSubmit").hide();

							// destroy the validator...
							clearValidators();
							
							$("#profile_update").removeAttr("disabled");
							
						} else {
							// server-side validation failed.
							$("#profile_update").removeAttr("disabled");
							form.data("validator").invalidate(json);
						}
					}
				});
				e.preventDefault();
			}
		});	
	});
	
	$("#cancelProfile").click(function() {
		$("#profileForm div.dataDisplay").show();
		$("#profileForm div.dataEdit").hide();
		$("#editProfile").show();
		$("#cancelProfile").hide();
		$("#profileSubmit").hide();
		
		// destroy the validator...
		clearValidators();
	});
	
}

function toolsUpdatePassword() {
	$("form#passwordForm").validator().submit(function(e) {
			
			// start here...
			// we need to encrypt the original pass, and the new pass...
			var oPswd = $("input[name=upOpass]",this).val();
			var nPswd = $("input[name=upPass]",this).val();
			//var oPswd = $("input[name=upPass2]",this).val();
			
			if (!e.isDefaultPrevented()) {
				if(oPswd) {
					var encodedOPswd = $.encoding.digests.hexSha1Str(oPswd);
				}
				if(nPswd) {
					var encodedNPswd = $.encoding.digests.hexSha1Str(nPswd);
				}
				$("#password_update").attr("disabled", true);
				$.ajax({
					url: "/dpComponent/user/updateUserPassword",
					type: "post",
					data: "op="+encodedOPswd+"&np="+encodedNPswd,
					dataType: "json",
					beforeSend: function() {
						$("#contentLoading").removeClass("hide");
					},
					success: function(json) {
						$("#contentLoading").addClass("hide");
						if (json.success)  {
							$("#userPasswordWrap").html(json.html);
							// destroy the validator...
							$("#password_update").removeAttr("disabled");
							clearValidators();
						} else {
							// server-side validation failed.
							$("#password_update").removeAttr("disabled");
							form.data("validator").invalidate(json);
						}
					}
				});
				e.preventDefault();
			}
		});	
}

function displayUsers(scope,user) {
	$("#overlayTopNav div.toolsButton").removeClass("on");
	$("#"+scope).addClass("on");
	$.ajax({
		url: "/dpComponent/user/toolsViewMembers",
		type: "post",
		data: "c=" + channel + "&s=" + subchannel + "&type=" + scope,
	//	beforeSend: function() {
	//		$("#contentLoading").removeClass("hide");
	//	},	
		success: function(html) {
			$("#overlayWindow").html(html);
			
			// this is a button click...
			$("div.alpha ").delegate("a","click",function() {
				//alert('works');
				if($("div#overlayWindow div#availableAdmins").length) {
					var letter = $(this).html();
					var scrollPos = $("div#overlayWindow div#availableAdmins").offset();
					var eventScroll = $("#alpha_"+letter).offset();
					var eventScrollPos = $("div#overlayWindow div#availableAdmins").scrollTop();
					var scrollToPos = eventScroll.top - scrollPos.top - 12;
					var finalScroll = eventScrollPos + scrollToPos;
					$("div#overlayWindow div#availableAdmins").animate({scrollTop:finalScroll},300);
					$("#alpha_"+letter).effect("highlight",{ },5000);
				}
			});
			
			if(user) {
				var scrollPos = $("#admin_"+user).position();
				//alert("user: " + user + " || Scroll Pos: " + scrollPos);
				$("#availableAdmins").scrollTop(Math.round(scrollPos.top));
				$("#availableAdmins .anAdmin").removeClass("on");
				$("#availableAdmins #admin_"+user).addClass("on");
				displayUsersManage(user);
			}
			
			// these are button clicks...
			$("#availableAdmins").delegate(".anAdmin","click", function() {
				var selectedUser = $(this).attr("id").replace("admin_","");
				
				$("#availableAdmins .anAdmin").removeClass("on");
				$("#availableAdmins #admin_"+selectedUser).addClass("on");
				
				displayUsersManage(selectedUser);
				
				
			});
		}
	});			
}

function configurePreviewTip(tipMethod) {
	$(".previewTrigger").tooltip({
		position:"center right",
		predelay:300,
		relative:true,
		onBeforeShow: function(event,position) {
			var post = this.getTip().attr("id").replace("tip_","");
			this.getTip().css("top","150px");
			// only load the ajax tip once...
			if(this.getTip().html() == "loading preview...") {
				$.ajax({
					url: tipMethod,
					type: "post",
					data: "id="+post,
					success: function(html) {
						$("#tip_"+post).html(html);
					}
				});
			}
		},
		onShow: function() {
			this.getTip().css("top","150px");
		}
	});
}

function displayUsersManage(user) {
	
	//alert("User: "+user);
	
	// step one... we need to call ajax, and load the userOverview
	$.ajax({
		url: "/dpComponent/user/toolsUserOverview",
		type: "post",
		data: "user="+user,
		//beforeSend: function() {
			//$("#contentLoading").removeClass("hide");
		//},
		success: function(html) {
			//$("#contentLoading").addClass("hide");
			$("#overlayDetail").html(html);
			
			// here is where we make the stuff clickable...
			$("#overlayDetail div.textEdit").click(function() {
				$(this).addClass("hide");
				$(this).next().removeClass("hide");
				var fieldId = $(this).next().attr("id");
				
				$("#"+fieldId+" input:text").focus();
				$("#"+fieldId+" select").focus();
				//alert('works' + fieldId);
			});
			
			// editable inputs... (edit in place)
			$("#overlayDetail input.editable, #overlayDetail select.editable").blur(function() {
				var field = $(this).attr("id").replace("n_","");
				var nFieldVal = $("#n_"+field).val();
				var oFieldVal = $("#o_"+field).val();
				var displayField = $(this).parent().prev();
				var editField = $(this).parent();
				if(nFieldVal != oFieldVal) {
					$.ajax({
						url: "/dpComponent/user/updateProfilePart",
						type: "post",
						data: "u="+user+"&f="+field+"&n="+nFieldVal+"&o="+oFieldVal,
						success: function(html) {
							displayField.html(html).removeClass("hide");
							editField.addClass("hide");
							$("#o_"+field).val(nFieldVal);
						}
					});
				} else {
					$(this).parent().prev().removeClass("hide");
					$(this).parent().addClass("hide");
				}
			});
			
			// editable selects... (edit in place)
			$("#overlayDetail select.editable").change(function() {
				$(this).blur();
			});
			
			// tools buttons...
			$("#overlayDetail div.userPrivileges div.toolsButton").click(function() {
				var contentType = $(this).attr("id");
				var tipMethod = "";
				//var scrollClass = $("#userContentScroll").attr("class");

				// we need to remove the scroll class from UserContentScroll
				//$("#userContentScroll").removeClass(scrollClass);
				
				switch(contentType) {
					case "articles":
						tipMethod = "/dpComponent/headlines/renderStoryPreview";
						//$("#userContentScroll").addClass("articles");
						break;
					case "events":
						tipMethod = "/dpComponent/events/renderEventPreview";
						//$("#userContentScroll").addClass("events");
						break;
					case "classifieds":
						tipMethod = "/dpComponent/classifiedsManager/renderClassifiedPreview";
						//$("#userContentScroll").addClass("classifieds");
						break;
					case "contributors":
						tipMethod = "/dpComponent/user/renderUserPubs";
						//$("#userContentScroll").addClass("contributors");
						break;
				}
				
				$("#overlayDetail div.userPrivileges div.toolsButton").removeClass("on");
				$(this).addClass("on");
				
				$.ajax({
					url: "/dpComponent/user/toolsUserReviewContent",
					type: "post",
					data: "user="+user+"&type="+contentType,
					success: function(html) {
						$("#userContentWrap").html(html);
						
						// THIS IS THE TOOL BUTTON CLICK...
						// WE ARE PUTTING THESE THINGS OUTSIDE OF HERE...
						
						// configure tooltip behavior...
						// this needs to be in a function, so that it can be
						// called from multiple places...
						configurePreviewTip(tipMethod);
						
					}
				});
			});
			
			// display scope select...
			$("#overlayDetail div#scopeDisplay").click(function() {
				$(this).addClass("hide");
				$(this).next().removeClass("hide");
			});
			
			// configure scope select...
			$("#overlayDetail select.scope").change(function() {
				var scope = $(this).val();
				if(scope) {
					//alert('contributors works: '+contributor);
					$.ajax({
						url: "/dpComponent/user/toolsAssignScope",
						type: "post",
						data: "user="+user+"&scope="+scope,
						dataType: "json",
				//		beforeSend: function() {
				//		
				//		},
						success: function(json) {
							// simulate a click...
							//alert('user: '+user);
							displayUsers(json.usertype,user);
							
							// now, we need to switch the fields back...
							//$("#scopeDisplay").html(json.userscope).removeClass("hide");
							//$("#scopeEdit").addClass("hide");
						}
					});
				}		
			});
			
			// row(item) buttons for all types...
			$("#userContentWrap").delegate("div.listing div.rowButton","click",function() {
				var id = $(this).parent().attr("id");
				var action = $(this).html();
				var method = "";
				var dataQuery = "";
				//alert('happening!');
				
				switch(action) {
					case "set as default":
						method = "/dpComponent/user/toolsSetDefaultContributor";
						dataQuery = "user="+user+"&contributor="+id+"&type=contributors";
						//alert('DEFAULT: contributor: '+contributor+' || action: ' + action + ' || user: ' + user);
						break;
					case "remove":
						method = "/dpComponent/user/toolsRemoveContributor";
						dataQuery = "user="+user+"&contributor="+id+"&type=contributors";
						//alert('REMOVE: contributor: '+contributor+' || action: ' + action + ' || user: ' + user);
						break;
					case "delete":
						method = "/dpComponent/classifiedsManager/userDeleteClassified";
						dataQuery = "user="+user+"&classified="+id+"&type=classifieds";
						//alert('REMOVE: contributor: '+contributor+' || action: ' + action + ' || user: ' + user);
						break;
					// no default...
				}
				$.ajax({
					url: method,
					type: "post",
					data: dataQuery,
					//beforeSend: function() {
						//$("#contentLoading").removeClass("hide");
					//},
					success: function(html) {
						$("#userContentWrap").html(html);
					}
				});
			});
			
			// assign contributor select...
			$("#userContentWrap").delegate("select.assign","change",function() {
				var contributor = $(this).val();
				if(contributor) {
					//alert('contributors works: '+contributor);
					$.ajax({
						url: "/dpComponent/user/toolsAssignContributor",
						type: "post",
						data: "user="+user+"&contributor="+contributor+"&type=contributors",
				//		beforeSend: function() {
				//		
				//		},
						success: function(html) {
							$("#userContentWrap").html(html);
							// we need to add the disabled attribute to the added option...
							
						}
					});
				}		
			});
		}
	});
				
}
			
			

function displayFeeds(scope,feed) {
	$("#overlayTopNav div.toolsButton").removeClass("on");
	$("#"+scope).addClass("on");
	$.ajax({
		url: "/dpComponent/rss/toolsViewComponents",
		type: "post",
		data: "c=" + channel + "&s=" + subchannel + "&type=" + scope,
	//	beforeSend: function() {
	//		$("#contentLoading").removeClass("hide");
	//	},	
		success: function(html) {
			$("#overlayWrapper").html(html);
			
			// this is a button click...
			$("div.alpha ").delegate("a","click",function() {
				//alert('works');
				if($("div#overlayDetail div#feedList").length) {
					var letter = $(this).html();
					var scrollPos = $("div#overlayDetail div#feedList").offset();
					var eventScroll = $("#alpha_"+letter).offset();
					var eventScrollPos = $("div#overlayDetail div#feedList").scrollTop();
					var scrollToPos = eventScroll.top - scrollPos.top - 12;
					var finalScroll = eventScrollPos + scrollToPos;
					$("div#overlayWindow div#feedList").animate({scrollTop:finalScroll},300);
					$("#alpha_"+letter).effect("highlight",{ },5000);
				}
			});
			
			if(feed) {
				var scrollPos = $("#component_"+feed).position();
				//alert("user: " + user + " || Scroll Pos: " + scrollPos);
				$("#feedList").scrollTop(Math.round(scrollPos.top));
				$("#feedList .anAdmin").removeClass("on");
				$("#feedList #admin_"+feed).addClass("on");
				//displayUsersManage(user);
			}
			
			$("#overlayWindow").delegate("#shareFeed","click",function() {
				var selectedComponent = $("#overlayWindow .componentWrap").attr("id").replace("mdl_","");
				
				//alert(selectedComponent);
				
				$.ajax({
					url: "/dpComponent/rss/shareFeed",
					type: "post",
					data: "component="+selectedComponent,
					success: function(html) {
						// here, we want to hide these buttons, and display the suggest
						// option...
						// that's the easiest way to do it...
						$("#privateFeed").removeClass("hide");
						$("#shareFeed").addClass("hide");
						$("#shareOptions").removeClass("hide");
						$(".feedSuggestAdd").removeClass("hide");
						$("#component_"+selectedComponent).remove();
					}
				});
			});
			
			$("#overlayWindow").delegate("#suggestFeed","click",function() {
				var selectedComponent = $("#overlayWindow .componentWrap").attr("id").replace("mdl_","");
				var selectedPlace = $("#rss_placement").val();
				$.ajax({
					url: "/dpComponent/rss/suggestFeed",
					type: "post",
					data: "component="+selectedComponent+"&placement="+selectedPlace,
					success: function(html) {
						$("#shareOptions").append(html);
					}
				});
			});
			
			$("#overlayWindow").delegate(".feedSuggestionRemove","click",function() {
				var selectedComponent = $("#overlayWindow .componentWrap").attr("id").replace("mdl_","");
				var selectedPlace = $(this).attr("id");
				$.ajax({
					url: "/dpComponent/rss/deleteSuggestion",
					type: "post",
					data: "component="+selectedComponent+"&placement="+selectedPlace,
					success: function(html) {
						//$("#shareOptions").append(html);
						$("#"+selectedPlace).parent().remove();
					}
				});
				
				//
				alert("comp: " + selectedComponent + " || place: " + selectedPlace);
			});
			
			
			$("#overlayWindow").delegate("#privateFeed","click",function() {
				var selectedComponent = $("#overlayWindow .componentWrap").attr("id").replace("mdl_","");
				$.ajax({
					url: "/dpComponent/rss/privateFeed",
					type: "post",
					data: "component="+selectedComponent,
					success: function(html) {
						// here, we want to hide these buttons, and display the suggest
						// option...
						// that's the easiest way to do it...
						$("#privateFeed").addClass("hide");
						$("#shareFeed").removeClass("hide");
						$("#shareOptions").addClass("hide");
						$(".feedSuggestAdd").addClass("hide");
						$("#component_"+selectedComponent).remove();
					}
				});
			});
			
			$("#overlayWindow").delegate("#deleteFeed","click",function() {
				var selectedComponent = $("#overlayWindow .componentWrap").attr("id").replace("mdl_","");
				//alert(selectedComponent);
				$.ajax({
					url: "/dpComponent/rss/deleteFeed",
					type: "post",
					data: "component="+selectedComponent,
					success: function(html) {
						// here, we want to hide these buttons, and display the suggest
						// option...
						// that's the easiest way to do it...
						$("#overlayWindow").html("feed sucessfully removed");
						$("#component_"+selectedComponent).remove();
					}
				});
			});
			
			
			$("#rss_status").change(function() {
				var status = $(this).val();
				alert("status: "+status);
							
				// here, we need to call a method via ajax,
				// and update the list below...
				// feedList
				$.ajax({
					url: "/dpComponent/rss/changeFeedType",
					type: "post",
					data: "type=rss&status="+status,
					success: function(html) {
						$("#feedList").html(html);
					}
				});				
			});
			
			$("#feedList").delegate(".item","click",function() {
				var selectedComponent = $(this).attr("id").replace("component_","");
				$.ajax({
					url: "/dpComponent/renderComponent/toolsPreviewComponent",
					type: "post",
					data: "cid="+channel+"&scid="+subchannel+"&component="+selectedComponent+"&preview=",
					success: function(html) {
						// output the text for the component preview...
						// output the text for the bottom preview...
						$("#overlayWindow").html(html);
						$(".componentEdit").hide();
					}
				});
				// ok... now, we need to do a few things...
				
				// 1, we need to call ajax, and update 2 locations on the page...
				// that's gonna require the json version, and the return of the proper data...
				
				
				// 
				
				
			});
			
			// these are button clicks...
			/*
			$("#availableAdmins").delegate(".anAdmin","click", function() {
				var selectedUser = $(this).attr("id").replace("admin_","");
				$("#availableAdmins .anAdmin").removeClass("on");
				$("#availableAdmins #admin_"+selectedUser).addClass("on");
				displayUsersManage(selectedUser);
			});
			*/
		}
	});			
}

			
// configure ckEditor instances...
CKEDITOR.on( 'instanceReady', function( ev )
{
	ev.editor.dataProcessor.writer.setRules( 'p',
		{
			indent: false,
			breakBeforeOpen: true,
			breakAfterOpen: false,
			breakBeforeClose: false,
			breakAfterClose: true
		});
});

$.tools.validator.fn("[type=phone]", "Please supply a valid phone number in the following format: xxx-xxx-xxxx", function(input, value) { 
	return /^\d\d\d-\d\d\d-\d\d\d\d$/.test(value);
});

$.tools.validator.fn("[data-equals]", "Value not equal with the $1 field", function(input) {
	var name = input.attr("data-equals"),
		 field = this.getInputs().filter("[name=" + name + "]"); 
	return input.val() == field.val() ? true : [name]; 
});
