$(document).ready(function() {
    
    /* *** PNG Fix *** */
    $(document).pngFix();
    
    /* *** Enter the Cufon *** */
    Cufon.replace('#breadcrumbs, h1, h1 a, h2, h2 a, #right-sidebar h4 a, .message small, .subscribe h3, .story h2, #more h4, #message-hub small, small#id, #message-list h4, #message-list ul small, .pagination, .right .news h4, .feature #column-left h2');
    $('#breadcrumbs p').css('margin', '-19px 0 0 0');  /* Set negative margin only if JavaScript is disabled to properly align the breadcrumb link without using absolute positioning */
	
    /* *** Logo *** */
    $("h1.logo").hover(function(){
		$(this).stop(true, true);
        $(this).animate( { top: "-146px" }, 200);
    },
    function(){
        $(this).animate( { top: "-149px" }, 200);
    });
    
    /* *** Signup Input *** */
    $("#searchform input#s").val('Search Defence Matters');
    $("#searchform input#s").focus(function(){
        if ( $(this).val() == "Search Defence Matters")
        $(this).val('');
    });
	
    $("#searchform input#s").blur(function(){
        if ( $(this).val() == "")
        $(this).val('Search Defence Matters');
    });

	
	
	/*
		Homepage Question / Answer fader 
		Author:	Ben Lacey
		Date:	29-11-2011
	*/
	$("ul li.box").hover(function(){
		var messageID = $(this).find("div").attr('id');
		$("ul li.box a div#" + messageID).fadeOut(1000, function(){
			$("ul li.box a div#answer-" + messageID).fadeIn(500);                                         
		});
	},
	function(){
		var messageID = $(this).find("div").attr('id');
		$("ul li.box div#answer-" + messageID).fadeOut(800, function(){
			$("ul li.box a div#" + messageID).fadeIn(200);
			$("ul li.box a div#answer-" + messageID).css('display', 'none');
		});
	});
	
	
	
	
    /* *** Subscribe RSS *** */
    $(".subscribe a.news").hover(function(){
        $(this).stop(true, true);
        $(this).animate( { marginLeft: "3px" }, 200);
    },
    function(){
        $(this).animate( { marginLeft: "0px" }, 200);
    });
    
    /* *** Message List Hover *** */
    $("#message-list ul li a").hover(function(){
        $(this).stop(true, true);
        $(this).animate( { left: "7px" }, 150);
    },
    function(){
        $(this).animate( { left: "0px" }, 100);
    });
    
    /* *** Message List Hover *** */
    $("#message-list h4 a").hover(function(){
        $(this).stop(true, true);
        $(this).animate( { right: "20px" }, 150);
    },
    function(){
        $(this).animate( { right: "25px" }, 100);
    });
    
    /* *** Story Title *** */
    $(".story h2 a, #more h4 a").animate( { opacity: 0.8 }, 50 )
    $(".story h2 a, #more h4 a").hover(function(){
        $(this).stop(true, true);
        $(this).animate( { opacity: 1.0 }, 50);
        $(this).parent().css( { 'border-bottom' : '1px solid #bdbdbd' } )
    },
    function(){
        $(this).animate( { opacity: 0.8 }, 50);
        $(this).parent().css( { 'border-bottom' : '1px solid #dfdfdf' } )
    });
    
    /* *** Story Image *** */
    $(".story img, #more img").hover(function(){
        $(this).stop(true, true);
        $(this).animate( { opacity: 0.8 }, 200);
    },
    function(){
        $(this).animate( { opacity: 1.0 }, 200);
    });
    
	
    // YouTube video selection on "Careers" page    
    // Apply hover on tabs
    $("ul.careers li").hover(function() {
        $(this).addClass("hover");
    }, function() {
        $(this).removeClass("hover");
    });
    
    // Apply colour change when tabs are clicked (remove colour from current selection)
    $("ul.careers li a").click(function() {
        $("ul.careers li.selected").removeClass("selected");
        $(this).parents("li").addClass("selected");
        
        // Load correct video - work out last character of video ID
        var linkID = $(this).attr("ID");
        numChars = linkID.length-1;
        linkID = linkID.substr(numChars);
		
        $("div.show_video").removeClass("show_video").addClass("hide_video");
        $("#YouTubeVideo"+linkID).removeClass("hide_video").addClass("show_video");
    });
});
