mb.snp = new ( function($) {
	
	var me = this;
	var link;
	mb.broadcaster.addListener( mb.events.PAGE_LOADED, function(d) { me.setup(d); } );
	mb.broadcaster.addListener( mb.events.FRAGMENT_LOADED, function(d){me.onFragmentLoaded(d); });

	me.setup = function (d)
	{
		if(d.getProperty("subsection") == 'service_and_repairs') {
			//update css style for service and repairs.
			$("#s_Sma .accordion-content div.text-item").eq(0).find("p").eq(1).css({'font-size' :'8px'})
        }

		//me.openAccordion();
		me.showTeaserVideo();
		
		if(d.getProperty("subsection") == "accessories")
		{
			$(".snp.accessories .accordion-pane").eq(1).find("p:last").addClass("article-disclaimer");
			$('.accessories .row').click(
				
				function()
				{
					$('.row').removeClass('selected');
					$(this).addClass('selected');
				}
			);
			
			$('.table_accessories_video .colright a').click(function(){
				
				$('.row').removeClass('selected');
				$(this).parents('.row').addClass('selected');
				
				var contextPath = $(".page-properties .pp-context-path").text();
				var url = contextPath + "/service_and_parts/accessories/feature";
				var file = escape($(this).attr("href"));
				var data = "mediaUrl="+file;
				
				mb.loadFragment(url,data,function(d) { 
					var node = d.getNode();
					mb.modal.show(node,"type2");
	                console.log("media:"+$(node).find('#sp_accessories_video'));
	                
	                var flashVars = {};
					if ( file.indexOf(".flv") >= 0 ) {
						flashVars.content = file;
						flashVars.autoPlay = true;
						flashVars.contextRoot = contextPath;
						var media_container = contextPath + "/swf/mbusa_actionscript_media_container.swf";
	                    var params = { 
	                            scale: "noScale" 
	                            , bgcolor : "#000"
	                            , wmode : "transparent"
	                            , quality : "high"
	                            , menu : "false"
	                            , salign : "tl"
	                        };
	                    
	                    swfobject.embedSWF(
	                    		media_container
	                            , "sp_accessories_video"
	                            , 720
	                            , 405
	                            , "9.0.45"
	                            , false
	                            , flashVars
	                            , params
	                        );
					}
					
	        	});
				
				return false;
				
			});

			$('.carat.maximized-window').click(mb.global.openMaximizedWindow);
		}
	}
	me.openAccordion = function ()
	{
		var pathname = window.location.toString();
		var anchor = pathname.substring(pathname.indexOf("#"), pathname.length);
				
	}
	
	me.showTeaserVideo = function ()
	{
		
		$("#tout-link-3-1").click(
				function () {
					link = $(this);
					$(".swfwrapper").show();
					$(this).hide().next().hide();
					$(".dimmer").show();
					clearTimeout(carouselAutoPlay);
					link.unbind('mouseleave', mb.carousel.autoPlay);
					return false;
				}
		)
	}
	
	mb.broadcaster.addListener( mb.events.VIDEO_COMPLETE, 
			function() {
				$(".flv-link").show();
				
				setTimeout(
						function (){
							$(".swfwrapper").hide();
							$(link).bind('mouseleave', mb.carousel.autoPlay).show().next().show();
							$(".dimmer").hide();
							$(".flv-link").hide();
							carouselAutoPlay = setTimeout("carouselPlayNext()", 5000);
						}
				, 8000);
			} 
	
	);
	
	me.onFragmentLoaded = function( d ) 
	{
		mb.logger.info("snp.onFragmentLoaded : "+d.getProperty("subsection"));
		
		if (d.getProperty("subsection") == "technical_information" )  
		{
			removeHiglight();
			$("#technical_information").addClass("active");
		}

	};
	
	function removeHiglight()
	{
		$(".subnavigation li a").each(function(){
			$(this).removeClass("active");
		});
	}
	
})(jQuery);
