var DigitalNomad = function () {
	return {
		toString: function () {
			return "[DigitalNomad]";
		}
	};
}();


DigitalNomad.Search = function () {
	function init() {
		$("#header form").submit(
			function() {
				var searchTerm = $("#s").val();
				if (searchTerm.length > 0) {
					location.href = WordPress.baseURL + "search/" + escape(searchTerm);
				}
				return false;
			}
		);
	}
	$(document).ready(init);
	return {
		toString: function () {
			return "[DigitalNomad.Search]";
		}
	};
}();

DigitalNomad.MastHead = function () {
	swfobject.embedSWF(WordPress.themeURL + "swf/ddn_header.swf", "masthead", "962", "238", "9.0.0", null, {imgFeed: WordPress.externalURL + "/static/rss/header.rss", rssFeed: WordPress.baseURL + "feed"});
	return {
		toString: function () {
			return "[DigitalNomad.MastHead]";
		}
	}
}();

DigitalNomad.Carousel = function () {
	swfobject.embedSWF(WordPress.themeURL + "swf/ddn_gallery.swf", "dnn_gallery", "319", "129", "9.0.0", null, {imgFeed: WordPress.externalURL + "/static/rss/gallery.rss"});
	return {
		toString: function () {
			return "[DigitalNomad.Carousel]";
		}
	}
}();


DigitalNomad.FeaturedVideo = function () {
	swfobject.embedSWF(
		"http://i.dell.com/images/global/ac/shell/ac.swf?appWidth=217&SED=false&SDContent=true&BGColor=0xFFFFFF&allowCopy=false&basePath=images/global/ac/&skinPath=standard&cssPath=western.css&xmlPath=about_dell_hybrid.xml",
		"featuredVideoPlayer", "217", "199", "9.0.0", null, null, {allowScriptAccess: "always", allowFullScreen: true});
	return {
		toString: function () {
			return "[DigitalNomad.FeaturedVideo]";
		}
	}
}();


DigitalNomad.MediaPlayer = function () {
	swfobject.embedSWF(
		"http://i.dell.com/images/global/ac/shell/ac.swf?appWidth=320&SED=false&SDContent=true&BGColor=0xFFFFFF&allowCopy=false&basePath=images/global/ac/&skinPath=standard&cssPath=western.css&xmlPath=about_dell_digital.xml",
		"mediaPlayerBox", "320", "453", "9.0.0", null, null, {allowScriptAccess: "always", allowFullScreen: true});
	return {
		toString: function () {
			return "[DigitalNomad.MediaPlayer]";
		}
	}
}();


DigitalNomad.LatitudeTimeline = function () {
	swfobject.embedSWF(WordPress.themeURL + "swf/DigitalNomad_big.swf", "latitudeTimeline", "624", "470", "9.0.0", null);
	return {
		toString: function () {
			return "[DigitalNomad.LatitudeTimeline]";
		}
	}
}();


DigitalNomad.LatitudePromo = function () {
	swfobject.embedSWF(WordPress.themeURL + "swf/DigitalNomad_small.swf", "latitudePromo", "319", "135", "9.0.0", null);
	return {
		toString: function () {
			return "[DigitalNomad.LatitudePromo]";
		}
	}
}();
DigitalNomad.Tabs = function () {
	function init() {
		$('.tab').hide();
		$('.show a').addClass('selected');

		/* forumFeed */
		$('#ideaStormForum').show();

		/* postFeed */
		$('#mostCommented').show();

		$('.nav ul li a').bind('click', function (e) {
			var box = this.parentNode.parentNode.parentNode.parentNode.parentNode.id;
			var selectedDiv = this.href.split('#')[1];
			$('#' + box + ' .tab').hide();
			$('#' + box + ' #' + selectedDiv).show();
			$('#' + box + ' .tabs .nav ul').removeClass();
			$('#' + box + ' .tabs .nav ul li a').removeClass();
			$('#' + box + ' .tabs .nav ul').addClass(selectedDiv);
			$(this).addClass('selected');
			e.preventDefault();
		});
	}

	$(document).ready(init);
	return {
		toString: function () {
			return "[DigitalNomad.Tabs]";
		}
	};
}();
/*
DigitalNomad.Tabs = function () {
	function init() {
		$('.tab').hide();

		// show the inital tabs
		$('#nomadProfiles').show();
		$('#ideaStormForum2').show();

		var item = document.getElementById("nomadProfiles");

		$('.nav ul li a').bind('click', function (e) {
			var box = this.parentNode.parentNode.parentNode.parentNode.parentNode.id;
			var selectedDiv = this.href.split('#')[1];
			$('#' + box + ' .tab').hide();
			$('#' + box + ' #' + selectedDiv).show();
			$('#' + box + ' .tabs .nav ul').removeClass();
			$('#' + box + ' .tabs .nav ul li a').removeClass();
			$('#' + box + ' .tabs .nav ul').addClass(selectedDiv);
			$(this).addClass('selected');
			e.preventDefault();
		});
	}

	$(document).ready(init);
	return {
		toString: function () {
			return "[DigitalNomad.Tabs]";
		}
	};
}();

*/

DigitalNomad.Comments = function () {
	var LABELS = {
			comment: "Comment",
			author: "Name",
			email: "Email (will not be published)",
			url: "Website"
		};
	function clearField(obj, defaultValue) {
		var currentValue = jQuery.trim(obj.val());
		if (currentValue.length === 0 || currentValue === defaultValue) {
			obj.val("");
		}
	}
	function restoreField(obj, defaultValue) {
		var currentValue = jQuery.trim(obj.val());
		if (currentValue.length === 0 || currentValue === defaultValue) {
			obj.val(defaultValue);
		}
	}
	function init() {
		
		// comment
		$("textarea#comment").focus(function (e) {
			clearField($(this), LABELS.comment);
		});
		$("textarea#comment").blur(function (e) {
			restoreField($(this), LABELS.comment);
		});
		restoreField($("textarea#comment"), LABELS.comment);
		// author
		$("input#author").focus(function (e) {
			clearField($(this), LABELS.author);
		});
		$("input#author").blur(function (e) {
			restoreField($(this), LABELS.author);
		});
		restoreField($("input#author"), LABELS.author);
		// emailcom
		$("input#emailcom").focus(function (e) {
			clearField($(this), LABELS.email);
		});
		$("input#emailcom").blur(function (e) {
			restoreField($(this), LABELS.email);
		});
		restoreField($("input#emailcom"), LABELS.email);
		// url
		$("input#url").focus(function (e) {
			clearField($(this), LABELS.url);
		});
		$("input#url").blur(function (e) {
			restoreField($(this), LABELS.url);
		});
		restoreField($("input#url"), LABELS.url);


		// form
		$("#commentform").submit(function (e) {
			var errorMsg = [],
				value;
			// comment.
			if ($("textarea#comment").length > 0) {
				value = jQuery.trim($("textarea#comment").val());
				if (value.length === 0 || value === LABELS.comment) {
					errorMsg.push("Please enter your comment.");
				}
			}
			// check name.
			if ($("input#author").length > 0) {
				value = jQuery.trim($("input#author").val());
				if (value.length === 0 || value === LABELS.author) {
					errorMsg.push("Please enter your name.");
				}
			}
			// check email.
			if ($("input#emailcom").length > 0) {
				value = jQuery.trim($("input#emailcom").val());
				if (value.length === 0 || value === LABELS.email) {
					errorMsg.push("Please enter your email.");
				} else if (!$("input#emailcom").val().match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/)) {
					errorMsg.push("Please enter a valid email.");
				}
			}
			// check website.
			if ($("input#url").length > 0) {
				value = jQuery.trim($("input#url").val());
				if (value === LABELS.url) {
					 $("input#url").val("");
				}
			}
			$("form#commentform div.summary").empty();
			if (errorMsg.length !== 0) {
				$("<ul><li>"+errorMsg.join("</li><li>")+"</li></ul>").appendTo("form#commentform div.summary");
				e.preventDefault();
			}
		});


	}

	$(document).ready(init);
	return {
		toString: function () {
			return "[DigitalNomad.Comments]";
		}
	}
}();


DigitalNomad.PublicPost = function () {
	var LABELS = {
			name: "Name",
			email: "Email (Will Not Be Published)",
			title: "Title of your Post",
			thoughts: "Your Thoughts"
		};
	function clearField(obj, defaultValue) {
		var currentValue = jQuery.trim(obj.val());
		if (currentValue.length === 0 || currentValue === defaultValue) {
			obj.val("");
		}
	}
	function restoreField(obj, defaultValue) {
		var currentValue = jQuery.trim(obj.val());
		if (currentValue.length === 0 || currentValue === defaultValue) {
			obj.val(defaultValue);
		}
	}


	function init() {
		
		// name
		$("input#name").focus(function (e) {
			clearField($(this), LABELS.name);
		});
		$("input#name").blur(function (e) {
			restoreField($(this), LABELS.name);
		});
		restoreField($("input#name"), LABELS.name);
		// email
		$("input#email").focus(function (e) {
			clearField($(this), LABELS.email);
		});
		$("input#email").blur(function (e) {
			restoreField($(this), LABELS.email);
		});
		restoreField($("input#email"), LABELS.email);
		// title
		$("input#title").focus(function (e) {
			clearField($(this), LABELS.title);
		});
		$("input#title").blur(function (e) {
			restoreField($(this), LABELS.title);
		});
		restoreField($("input#title"), LABELS.title);
		// thoughts
		$("textarea#thoughts").focus(function (e) {
			clearField($(this), LABELS.thoughts);
		});
		$("textarea#thoughts").blur(function (e) {
			restoreField($(this), LABELS.thoughts);
		});
		restoreField($("textarea#thoughts"), LABELS.thoughts);


		// form
		$("#BlendPublicPost").submit(function (e) {
			var errorMsg = [],
				value;
			// check name.
			if ($("input#name").length > 0) {
				value = jQuery.trim($("input#name").val());
				if (value.length === 0 || value === LABELS.name) {
					errorMsg.push("Please enter your name.");
				}
			}
			// check email.
			if ($("input#email").length > 0) {
				value = jQuery.trim($("input#email").val());
				if (value.length === 0 || value === LABELS.email) {
					errorMsg.push("Please enter your email.");
				} else if (!$("input#email").val().match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/)) {
					errorMsg.push("Please enter a valid email.");
				}
			}



			// check category.
			if ($("input#cat_3:checked").length == 0 && $("input#cat_4:checked").length == 0) {
					errorMsg.push("Please select a category.");

			}
			
			// title.
			if ($("input#title").length > 0) {
				value = jQuery.trim($("input#title").val());
				if (value.length === 0 || value === LABELS.title) {
					errorMsg.push("Please enter your title.");
				}
			}
			// check thoughts.
			if ($("textarea#thoughts").length > 0) {
				value = jQuery.trim($("textarea#thoughts").val());
				if (value.length === 0 || value === LABELS.thoughts) {
					errorMsg.push("Please enter your thoughts.");
				}
			}

			// check approve.
			if ($("input#approve:checked").length == 0) {
					errorMsg.push("Please verify that you have read and agree with the terms &amp; conditions.");

			}





			$("form#BlendPublicPost div.summary").empty();
			if (errorMsg.length !== 0) {
				$("<ul><li>"+errorMsg.join("</li><li>")+"</li></ul>").appendTo("form#BlendPublicPost div.summary");
				e.preventDefault();
			}
		});


	}

	
	$(document).ready(init);
	return {
		toString: function () {
			return "[DigitalNomad.PublicPost]";
		}
	}
}();
DigitalNomad.ExternalLink = function () {
	function init() {
		var links = document.getElementsByTagName("a"),
			i = links.length,
			link, href;
		while (--i) {
			link = links[i];
			href = link.href;
			if (!(href.indexOf(WordPress.baseURL) === 0 || href.indexOf(WordPress.externalURL) === 0 || href.indexOf(WordPress.domain) !== -1)) {
				link.setAttribute("target", "_blank");
			}
		}

	}
	$(document).ready(init);
	return {
		toString: function () {
			return "[DigitalNomad.ExternalLink]";
		}
	};
}();
