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) {
					if (encodeURIComponent) {
						searchTerm = encodeURIComponent(searchTerm);
					} else {
						searchTerm = escape(searchTerm);
					}
					location.href = WordPress.baseURL + "search/" + 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"}, {allowScriptAccess: "always"});
	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"}, {allowScriptAccess: "always"});
	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=false&BGColor=0xFFFFFF&allowCopy=false&basePath=images/global/ac/&skinPath=standard&cssPath=western.css&xmlPath=dell_nomad_single.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=false&BGColor=0xFFFFFF&allowCopy=false&basePath=images/global/ac/&skinPath=standard&cssPath=western.css&xmlPath=dell_nomad_multi.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", "520", "9.0.0", null, null, {allowScriptAccess: "always"});
	return {
		toString: function () {
			return "[DigitalNomad.LatitudeTimeline]";
		}
	};
}();
DigitalNomad.LatitudePromo = function () {
	swfobject.embedSWF(WordPress.themeURL + "swf/DigitalNomad_small.swf", "latitudePromo", "319", "135", "9.0.0", null, {clickTag1: "http://www.dell.com/content/topics/topic.aspx/global/products/landing/latitude_map?c=us&l=en&s=gen", clickTag2: WordPress.externalURL + "latitude-timeline"}, {allowScriptAccess: "always"});
	return {
		toString: function () {
			return "[DigitalNomad.LatitudePromo]";
		}
	};
}();
DigitalNomad.Tabs = function () {
	function init() {
		$('.tab').hide();
		/*$('.show a').addClass('selected');*/

		/* forumFeed */
		$('#nomadProfiles').show();
		$('#ideaStormForum2').show();

		/* postFeed */
		/*$('#mostRecent').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);
		// email
		$("input#email").focus(function (e) {
			clearField($(this), LABELS.email);
		});
		$("input#email").blur(function (e) {
			restoreField($(this), LABELS.email);
		});
		restoreField($("input#email"), 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#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 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.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]";
		}
	};
}();