$(function() {
	
	var maxWidth = 592;
	var minWidth = 74;
	var to = "";
	
	$("#carousel .content").css({ display: "none" });
	
	var prevBlock = $("#carousel .who");
		prevBlock.addClass("current");
		prevBlock.css({ width: maxWidth + "px" });
		prevBlock.find(".content").css({ display: "block" });
		prevBlock.find(".nav").css({ display: "none" });
	
	var initialised = false;
		
    $("#carousel > li").click(
		function(){
			
			var thisBlock = $(this);
			
			if (thisBlock[0] != prevBlock[0]) {
			
				$(prevBlock).find(".content").css({ display: "none" });
				$(prevBlock).find(".nav").css({ display: "none" });
				$(thisBlock).find(".nav").css({ display: "none" });

				$(prevBlock).removeClass("current").addClass("transition").animate(
					{ width: minWidth + "px" },
					{
						complete: function() {
							$(this)
								.removeClass("transition")
								.find(".nav")
								.css({ display: "block" });
						},
						duration: 500,
						queue: false
					}
				);

				$(thisBlock).addClass("current").animate(
					{ width: maxWidth + "px" },
					{
						complete: function() {
							var jBlock = $(this);
								jBlock.find(".nav").css({ display: "none" });
								jBlock.find(".content").css({ display: "block" });
								
							northnews.replaceFonts();
							
							$.address.value( jBlock.attr("rel") );
						},
						duration: 500,
						queue: false
					}
				);
				
				prevBlock = thisBlock;
			
			}
			
		}
    );
    
    
    $.address.change(function(event) {
    	
    	var block = (event.pathNames.length) ? event.pathNames[0] : "";
    	
    	try 		{ jwplayer('splashvideo').remove();	}
    	catch (ex) 	{ /* may not be a video */ 			}
    	
    	try 		{ jwplayer('featuredvideo').remove();	}
    	catch (ex) 	{ /* may not be a video */ 				}
		
		northnews.embedVideos();
    	
    	if (initialised == false) {
    		
    		if (block != "")
    			$("#carousel li." + block).trigger('click');
    			
    		initialised = true;
    		
    	}
    	
    });
	
});
