var TheNational_storypage = function () {
	var $S = CBC.SETTINGS;
	var $U = CBC.UTIL;
	var $D = CBC.DOM;
	var $ = $U.getElementsById;

	var _nationalEmbedClipId;
	var _nationalEmbedimage;
	var _swf_url = "/video/swf/UberPlayer.swf";

	return {

		init: function(o) {
			_nationalEmbedClipId = o.nationalEmbedClipId;
			if (o.image) _nationalEmbedimage = o.image;

			var links = $('storybody').getElementsByTagName("a");
			for (var i=0; i<links.length; i++) {
				if (links[i].href.indexOf("/thenational/indepthanalysis/transcripts/") > -1) YAHOO.util.Event.on(links[i], "click", this.openTranscript, links[i]);
			}
			var bars = $D.getElementsByClassName("fullbar",'div','storybody');
			for (var i=0; i<bars.length; i++) {
				var bar = bars[i].getElementsByTagName("h3")[0];
				YAHOO.util.Event.on(bar, "click", this.swapFullBar, bar);
			}
		},

		handleInDepthAnalysis: function() {
			this.formatStoryLabel();
			var _h3 = $('storyhead').getElementsByTagName("h3")[0];

			if (CBC.APP.ThePlatformPlaylist.isHomePage()) {
				if (_h3) _h3.style.display = "none";
				var clipId = ((document.location.hash.indexOf("ID") > -1)) ? document.location.hash.split("#ID=")[1] : _nationalEmbedClipId;
				this.initPlayer(clipId);
			} else {
				if (_h3) _h3.innerHTML = '<a href="' + CBC.APP.ThePlatformPlaylist.getHomePage() + '">' + _h3.innerHTML + '</a> <em>&raquo;</em>';
				$('natplayerwrap').style.display = "none";
			}
		},

		handleRexMurphy: function() {
			this.formatStoryLabel();
			var clipId = ((document.location.hash.indexOf("ID") > -1)) ? document.location.hash.split("#ID=")[1] : _nationalEmbedClipId;
			this.initPlayer(clipId);
		},

		handleAtIssue: function() {
			this.formatStoryLabel();
			var clipId = ((document.location.hash.indexOf("ID") > -1)) ? document.location.hash.split("#ID=")[1] : _nationalEmbedClipId;
			this.initPlayer(clipId);
		},

		initPlayer: function(clipId) {
			var flashvars = { state:"embed", clipId:clipId, site:"", image:_nationalEmbedimage, RSI:$S.getVal("omniSuiteId") };
			var params = { allowFullScreen:"true", allowScriptAccess:"always", menu:"true", salign:"tl", scale:"noscale", bgcolor:"#000000", wmode:"transparent" };
			var attributes={ id:"natplayer", name:"natplayer" };
			swfobject.embedSWF(_swf_url, "natplayer", "594", "393", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
		},

		formatStoryLabel: function() {
			var _storyhead = $('storyhead');
			_storyhead.innerHTML = _storyhead.innerHTML.replace("<h3 ",'<div class="label"><h3 ').replace('</h1>','</h1><span id="socialhead"></span></div>');
			$D.removeClass(_storyhead,"df");
		},

		swapFullBar: function(e, el) {
			var _bar = el.parentNode;
			if (_bar.className.indexOf("open") == -1) $D.addClass(_bar,"open");
			else $D.removeClass(_bar,"open");
			el.blur();
		},

		swapComments: function(el) {
			if ($('socialcomments').innerHTML.length < 10) {
				CBC.APP.PLUCK.Comments.getData();
				$D.addClass(el,"open");
				$D.addClass('socialcomments',"open");
			} else {
				if ($('socialcomments').className.indexOf("open") == -1) {
					$D.addClass(el,"open");
					$D.addClass('socialcomments',"open");
				} else {
					$D.removeClass(el,"open");
					$D.removeClass('socialcomments',"open");
				}
			}
			el.blur();
		},

		openTranscript: function(e, el) {
			YAHOO.util.Event.preventDefault(e);
			window.open(el.href,'transcript','width=614,height=500,scrollbars=1,resizable=0').focus();
			el.blur();
		}

	}

}
