
oVideoPlayer = {
	oVideoPath:"http://media.nationwide.com/videos/",
	oVideoPathWithoutDomain:"/videos/",
	oMovieTitle:null,
	oProductXML:"nwVideoPlayerNextSteps.dat",
	oVideo:null,

	init:function() {
		$("img.videoImg, a.loadVideo").click(function() {
			oVideoPlayer.oVideo = oVideoPlayer.findVideo(this.className);
			oVideoPlayer.oMovieTitle = oVideoPlayer.findVideoName(this.className);
			oVideoPlayer.oProductXML = oVideoPlayer.findProductXML(this.className);
			oVideoPlayer.launchPlayer();
			$('div.videoContent > div.videoDetails').fadeOut('slow', oVideoPlayer.replaceContent($(this).parents('.video')));
		});
		$("img.videoImg:eq(0)").trigger("click");
	},

	launchPlayer:function() {
		var so = new SWFObject("/flash/nwVideo.swf","nwVideo","320","274","8","#FFFFFF");
        so.addParam('allowScriptAccess', 'sameDomain');
        so.addParam('enableJavascript', 'true');
        so.addParam('wmode','transparent');
        so.addVariable('startPlayingCallback','oVideoPlayer.sendAnalytics');
		so.addVariable("moviePath", oVideoPlayer.oVideoPath + oVideoPlayer.oVideo);
		so.addVariable("movieTitle", oVideoPlayer.oMovieTitle);
		so.addVariable("videoMenu",oVideoPlayer.oVideoPath + oVideoPlayer.oProductXML);
		so.addVariable('nwurl',location.href);
        so.write('videoPlayer');
        $('#nwVideo').css('width', '100%');
	},

	replaceContent:function(videoChunk) {
		var oDetails;
		setTimeout(function(){
			$('div.videoContent > div.videoDetails').remove();
			oDetails = $(videoChunk).children('.videoDetails').clone().prependTo("div.videoContent");
			oDetails.show()}
		,500);
		setTimeout(function(){$('div.videoContent').fadeIn('slow')},500);
	},

	findVideo:function(sCN){ return (/flv([A-Za-z0-9-.]+)/i.test(sCN))?RegExp.$1:0; },
	findVideoName:function(sCN){ return (/name(\w+)/i.test(sCN))?RegExp.$1:0; },
	findProductXML:function(sCN){ return (/menu([A-Z0-9-.]+)/i.test(sCN))?RegExp.$1:'nwVideoPlayerNextSteps.dat'; },

	sendAnalytics:function() {
		if (_tag !== 'undefined') {
			_tag.dcsMultiTrack('DCS.dcsuri',oVideoPlayer.oVideoPathWithoutDomain + oVideoPlayer.oVideo, 'WT.ti',oVideoPlayer.oMovieTitle,'DCSext.NWAdEvent','View Ad Video');
		}
	}

};

$(document).ready(function() {
	oVideoPlayer.init();
});