var HCW = {
	Config : {
		sClassIEHover : "ie-hover"
		,sHTMLtag : "can-has-js"
		,sPathImg : "/-/img/"
		,sPathSwf : "/-/swf/"
		,sSelPNG : "img, #mast h1 a, #mast ul.nav, #mast ul.nav li a, #mast div, .main-features li.active a, tm#nav-secondary a:hover, #nav-secondary li.live, #nav-secondary li.live a:hover, #footer .inner, div.col-logo a.seal, div.col-logo a.logotype, div.feature div.details div"
	}

	/*
		STOP EDITING HERE.
	*/
	,init : function() {
		var c = HCW;
		var p = c.Project;

		$(document).ready(function() {
			// List function(s) to fire onload here
			p.tagIt();
			p.slides.init();

			if (typeof DD_belatedPNG != "undefined") {
				DD_belatedPNG.fix(c.Config.sSelPNG);
			}
		});

		p.loadSIFR();
	}

	/*
		CLIENT-SPECIFIC FUNCTIONS
	*/
	,Project : {
		slides : {
			init : function() {
				var c = HCW;
				var p = c.Project;

				// SET PHASERS TO SLIDE-Y
				p.slides.home();
				p.slides.videos();
			}
			,home : function() {
				// Move the lead divs around
				$(".main-stories div.lead").each(function() {
					$(this).appendTo(".main-stories");
				});
				$(".main-stories").attr("class", "main-features");

				// Find the first items (div.lead and ul.nav li:first-child)
				//$(".main-features div.lead:not(:first)").hide();
				//$(".main-features ul.nav li:first").addClass("active");



				var position = Math.ceil(Math.random()*3);

				if (position==1) {
					$("#story-2").hide();
					$("#story-3").hide();
				}
				if (position==2) {
					$("#story-1").hide();
					$("#story-3").hide();
				}
				if (position==3) {
					$("#story-1").hide();
					$("#story-2").hide();
				}

				$(".main-features ul.nav li:nth-child(" + position + ")").addClass("active");










				$(".main-features a").append("<i></i>");
				$(".main-features h1 a").click(function() {
					var sSlug = $(this).attr("href").split("#")[1];

					$(".main-features div.lead:not(#" + sSlug + ")").hide();
					$("#" + sSlug).show();

					$(".main-features li.active").removeClass("active");
					$(this).parents("li").addClass("active");

					return false;
				})
			}
			,videos : function() {
				$(".videos").prepend('<div class="video"></div>');
				$(".videos object").appendTo(".videos .video");
				if (document.all && !window.opera) {
					$(".videos object").each(function() {
						var oMov = $(this);
						var sID = oMov.attr("id");
						var iW = oMov.attr("width");
						var iH = oMov.attr("height");
						var sType = (oMov.attr("type")) ? oMov.attr("type") : "application/x-shockwave-flash";
						var sURL = oMov.attr("data");

						var sHTML = '<embed id="' + sID + '" src="' + sURL + '" type="' + sType + '" width="' + iW + '" height="' + iH + '" allowfullscreen="true" allowscriptaccess="always"></embed>';
						oMov.replaceWith(sHTML);
					});
				}

				var tmp = 0;
				$(".videos ul.vid a").each(function() {
					if (tmp == 0) {
						toggleLink($(this), 1);
					} else {
						toggleLink($(this));
					}
					tmp++;
				});

				$(".videos ul.vid a").click(function() {
					$(".videos ul.vid a").each(function() {
						toggleLink($(this));
					});
					toggleLink($(this), 1);

					return false;
				});

				function toggleLink(oA, sMode) {
					var oLink = $(oA);
					var id = oLink.attr("href").split("#")[1];
					if (oLink.children("i").length == 0) {
						oLink.append("<i></i>");
					}
					if (sMode) {
						$("#" + id).show();
						oLink.children("i").html("Now Playing");
						oLink.parents("li").addClass("active");
					} else {
						$("#" + id).hide();
						oLink.parents("li").removeClass("active");
						oLink.children("i").html("Play Now &raquo;");
					}
				}
			}
		}
		,loadSIFR : function() {
			var c = HCW;

			/*
				Register the fonts
			*/
			var chaparral = {
				src: c.Config.sPathSwf + 'chaparral.swf'
			}
			var whitneySemi = {
				src: c.Config.sPathSwf + 'whitney-semi.swf'
			}

			/*
				Activate the fonts
			*/
			sIFR.activate(chaparral);
			sIFR.activate(whitneySemi);

			/*
				Hi, we're the replacements
			*/
			sIFR.replace(chaparral, {
				selector: 'body.type-landing .feature h1'
				,css: [
					'.sIFR-root { background-color: #ffffff; color: #ffffff; font-size: 28px; }'
				]
				,wmode: 'transparent'
			});
			sIFR.replace(chaparral, {
				selector: 'body.type-article #primary h1'
				,css: [
					'.sIFR-root { background-color: #ffffff; color: #333333; font-size: 28px; }'
				]
				,wmode: 'transparent'
			});
			sIFR.replace(chaparral, {
				selector: '.main-features ul.nav b'
				,css: [
					'.sIFR-root { color: #FFFFFF; font-size: 26px; }'
				]
				,wmode: 'transparent'
			});
			sIFR.replace(whitneySemi, {
				selector: 'body.sect-home h2, body.type-landing #primary h2'
				,css: [
					'.sIFR-root { background-color: #ffffff; color: #333333; font-size: 18px; letter-spacing: 2; text-transform: uppercase; }'
				]
				,wmode: 'transparent'
			});
			sIFR.replace(whitneySemi, {
				selector: 'body.type-landing #additional h2, body.type-landing #additional h3, body.type-article #additional h2, body.type-article #additional h3'
				,css: [
					'.sIFR-root { background-color: #ffffff; color: #333333; font-size: 11px; letter-spacing: 2; text-transform: uppercase; }'
				]
				,wmode: 'transparent'
			});
		}
		,tagIt : function() {
			var c = HCW;
			$("html").addClass(c.Config.sHTMLtag);
		}
	}
};

HCW.init();

