﻿/*  START jQuery functions*/
function doSecurityJQueryFunctions(){
	if (jQueryUsed){
		(function($){
			if(!document.defaultView || !document.defaultView.getComputedStyle){
				var oldCurCSS = jQuery.curCSS;
				jQuery.curCSS = function(elem, name, force){
					if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
						return oldCurCSS.apply(this, arguments);
					}
					var style = elem.style;
					if ( !force && style && style[ name ] ){return style[ name ];}
					return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
				};
			}
		})(jQuery);
		//Stop IE flicker
		if ($.browser.msie == true) {document.execCommand('BackgroundImageCache', false, true);}
		function HomepageNavigationMouseOver(){
			$("#securityColumnOne a").mouseover(function(){
				var y = ($(this).find("b").css("backgroundPosition").split(" ")[1]);
				$(this).find("b").css("backgroundPosition","-180px " + y);
			}).mouseout(function(){
				var y = ($(this).find("b").css("backgroundPosition").split(" ")[1]);
				$(this).find("b").css("backgroundPosition","0px " + y);
			}).blur(function(){$(this).mouseout();}).focus(function(){$(this).mouseover();
			});
		}
		HomepageNavigationMouseOver();
		var checklist = new Array(5);
		for (var i=0; i < checklist.length; i++){
			checklist[i]= new Array;
		}
		var imageTick = "<img src=\"/security/_images/tick.jpg\" alt=\"tick\" /> ";
		var imageCross = "<img src=\"/security/_images/cross.jpg\" alt=\"cross\" /> ";
		checklist[0][0] = "I have anti-virus software installed and I run a scan at least weekly and regulary update it.";
		checklist[0][1] = "I don't know if an anti-virus is installed or up to date.";
		checklist[0][2] = "Good. It is important to scan files and e-mails for viruses.";
		checklist[0][3] = "It is very important to have up to date anti-virus software installed.";
		checklist[1][0] = "I have a firewall and it's up to date.";
		checklist[1][1] = "I don't know if a firewall is installed or up to date.";
		checklist[1][2] = "Good. This protects you from unsolicited connections to your computer.";
		checklist[1][3] = "You should some sort of firewall installed. At a minimum, have your operating firewall enabled.";
		checklist[2][0] = "My PC or Mac automatically receives operating system and browser updates when they are released.";
		checklist[2][1] = "I don't know if my PC or Mac receives any or all available updates.";
		checklist[2][2] = "Good. An up to date system will help protect you from security vulnerabilities.";
		checklist[2][3] = "You should check to see if there are updates available for your operating system and your browsers.";
		checklist[3][0] = "I scan my PC for spyware or adware on a regular basis.";
		checklist[3][1] = "I don't know if any anti-spyware software is installed.";
		checklist[3][2] = "Good. An regular spyware scan will ensure safe browsing.";
		checklist[3][3] = "It is important to scan for spyware regularly.";
		var marginTopSolutionStarted = "340px";
		function populateCheckList(){
			$("#SecuritySolutionStarted li").each(function(){
				var IndexLi = $("#SecuritySolutionStarted li").index(this);
				// populate the solution with radio buttons
				$(this).contents("p").prepend("<input type=\"radio\" name=\"radioGroup" + IndexLi + "\" id=\"radioGroup" + IndexLi + "b\" /><label for=\"radioGroup" + IndexLi + "b\">" + checklist[IndexLi][1] + "</label><br />");
				$(this).contents("p").prepend("<input type=\"radio\" name=\"radioGroup" + IndexLi + "\" id=\"radioGroup" + IndexLi + "a\" /><label for=\"radioGroup" + IndexLi + "a\">" + checklist[IndexLi][0] + "</label><br />");
			});
			// run this on the first click
			$("#SecuritySolutionStarted a:last").one('click',function(){
				// work through the radios to check advice to be given
				$("#SecuritySolutionStarted li p").each(function(){
					var IndexLi = $("#SecuritySolutionStarted li p").index(this);
					if($(this).find("input:first").is(":checked")){
						$(this).prepend(imageTick + checklist[IndexLi][2]);
					}
					else{
						$(this).prepend(imageCross + checklist[IndexLi][3]);
					}
				});
				// remove the radio buttons and labels
				$("#SecuritySolutionStarted p :not(a,img)").remove();
				// hide the first link
				$("#SecuritySolutionStarted li a:even").hide();
				// wrap a span inside
				$("#SecuritySolutionStarted li a:odd").wrap("<span>");
				// show the second link
				$("#SecuritySolutionStarted li a:odd").show();
				// set the text on the link
				$(this).html("<strong>Let's see if you need any more help</strong>");
				marginTopSolutionStarted = $("#SecuritySolutionStarted").height() - 105;
				$("#footer").animate({marginTop: marginTopSolutionStarted}, "slow" );
				return false;
			});
		}
		function initiateSecurityCheckList(){
			// hide the answers and hide the second link to the rough guide

			// save the alt text
			var SecurityCheckListStartedAltText = $("#SecurityCheckListStarted a").text()
			var SecurityCheckListWorriedAltText = $("#SecurityCheckListWorried a").text()

			// get rid of the text, it flickers sometimes
			$("#SecurityCheckListStarted a,#SecurityCheckListWorried a").empty();

			//  add images to links
			$("#SecurityCheckListStarted a").append("<img src=\"/security/_images/heading-started.gif\" /><img src=\"/security/_images/heading-started-hover.gif\" /><img src=\"/security/_images/heading-started-click.gif\" />");
			$("#SecurityCheckListWorried a").append("<img src=\"/security/_images/heading-worried.gif\" /><img src=\"/security/_images/heading-worried-hover.gif\" /><img src=\"/security/_images/heading-worried-click.gif\" />");
			
			$("#SecurityCheckListStarted img").attr("alt",SecurityCheckListStartedAltText);
			$("#SecurityCheckListWorried img").attr("alt",SecurityCheckListWorriedAltText);
			
			// hide the mouseover images
			$("#SecuritySolutionStarted,#SecuritySolutionWorried,#SecuritySolutionStarted li a:odd,#SecurityCheckListStarted img:nth-child(3),#SecurityCheckListWorried img:nth-child(3)").hide();

			//hide the second one slowly, to highlight link
			$("#SecurityCheckListStarted img:nth-child(2)").animate({opacity: 1.0}, 3000).fadeOut("slow")
			$("#SecurityCheckListWorried img:nth-child(2)").animate({opacity: 1.0}, 3000).fadeOut("slow")

			var blnStartedHidden = true;
			var blnWorriedHidden = true;
			$("#SecurityCheckListStarted").toggle(function(){			
				$("#SecuritySolutionStarted").slideDown("slow");
				blnStartedHidden = false;
				$("#footer").animate({marginTop: marginTopSolutionStarted}, "slow" );
				//hide the images and the campaigns	
				$("#SecurityCheckListStarted img:nth-child(1),#SecurityCheckListStarted img:nth-child(2),#campaignSlot1,#campaignSlot2").hide();
				$("#SecurityCheckListStarted img:nth-child(3)").show();
				if ($("#SecuritySolutionWorried").is(":visible")) {
					$("#SecurityCheckListWorried").click().trigger('mouseout');
					$("#SecurityCheckListWorried img:nth-child(2)").mouseout();
				}
			},function(){
				$("#SecuritySolutionStarted").slideUp("slow");
				if(blnWorriedHidden){
					$("#footer").animate({marginTop: "0px"}, "slow" );
					$("#campaignSlot1,#campaignSlot2").fadeIn("slow");
				}
				blnStartedHidden = true;
				$("#SecurityCheckListStarted img:nth-child(1),#SecurityCheckListStarted img:nth-child(3)").hide();
				$("#SecurityCheckListStarted img:nth-child(2)").show();
			});
			$("#SecurityCheckListWorried").toggle(function(){
				$("#SecuritySolutionWorried").slideDown("slow");
				blnWorriedHidden = false;
				$("#footer").animate({marginTop: "147px"}, "slow" );
				$("#SecurityCheckListWorried img:nth-child(1),#SecurityCheckListWorried img:nth-child(2)").hide();
				$("#SecurityCheckListWorried img:nth-child(3)").show();
				$("#campaignSlot1,#campaignSlot2").hide();
				if ($("#SecuritySolutionStarted").is(":visible")){
					$("#SecurityCheckListStarted").click();
					$("#SecurityCheckListStarted img:nth-child(2)").mouseout();
				}
			},function(){
				$("#SecuritySolutionWorried").slideUp("slow");
				if(blnStartedHidden){
					$("#footer").animate({marginTop: "0px"}, "slow" );
					$("#campaignSlot1,#campaignSlot2").fadeIn("slow");
				}
				blnWorriedHidden = true;
				$("#SecurityCheckListWorried img:nth-child(1),#SecurityCheckListWorried img:nth-child(3)").hide();
				$("#SecurityCheckListWorried img:nth-child(2)").show();
			});
			$("#SecurityCheckListStarted img:first").mouseover(function(){
				$("#SecurityCheckListStarted img:nth-child(2)").fadeIn(1000);
			});
			$("#SecurityCheckListStarted img:nth-child(2)").mouseout(function(){
				$("#SecurityCheckListStarted img:nth-child(2)").fadeOut(1000);
				$("#SecurityCheckListStarted img:nth-child(1)").show();
			});
			$("#SecurityCheckListStarted img:nth-child(3)").mouseover(function(){
				$("#SecurityCheckListStarted img:nth-child(1),#SecurityCheckListStarted img:nth-child(2)").hide();
			});
			$("#SecurityCheckListStarted a").focus(function(){
				$("#SecurityCheckListStarted img:first").trigger("mouseover");
			});
			$("#SecurityCheckListStarted a").blur(function(){
				$("#SecurityCheckListStarted img:nth-child(2)").trigger("mouseout");
			});
			$("#SecurityCheckListWorried img:first").mouseover(function(){
				$("#SecurityCheckListWorried img:nth-child(2)").fadeIn(1000);
			});
			$("#SecurityCheckListWorried img:nth-child(2)").mouseout(function(){
				$("#SecurityCheckListWorried img:nth-child(2)").fadeOut(1000);
				$("#SecurityCheckListWorried img:nth-child(1)").show();
			});
			$("#SecurityCheckListWorried img:nth-child(3)").mouseover(function(){$("#SecurityCheckListWorried img:nth-child(1),#SecurityCheckListWorried img:nth-child(2)").hide();});
			$("#SecurityCheckListWorried a").focus(function(){$("#SecurityCheckListWorried img:first").trigger("mouseover");});
			$("#SecurityCheckListWorried a").blur(function(){$("#SecurityCheckListWorried img:nth-child(2)").trigger("mouseout");});
			populateCheckList();
		}
		initiateSecurityCheckList();
		function tidyPopupHelp(){
			var filename = window.location.href.split("/");
			var img = filename[filename.length-1].split(".")[0]
			
			$("body:has(div.helpContent) div.helpContent").append("<img src=\"/security/_images/pop-up-help-" + img + ".gif\" />");
			$("body:has(div.helpContent) img:first").attr("alt","")
			$("body:has(div.helpContent) input,body:has(div.helpContent) hr").remove();
			
		}
		if(window.location.href.indexOf("NRMODE") == -1){
			tidyPopupHelp();		
		}
		function addPopups(){
			$("a[rel=Help]").click(function(){
				popUpWin($(this).attr("href"), "standard", "740", "600");
				return false;
			});
		}
		addPopups();		
		function tidyBackgroundImageOnQuickLinks(){
			$("#quickLinksList a:eq(3)").css("backgroundPosition","right -420px")
		}
		tidyBackgroundImageOnQuickLinks();
		function fixMeaninglessMoreInfoLinksSecurity()
		{			
			// For security site
			$("#securityColumnTwo .slot a.buttonExit").each(function(){
				$(this).append(" <span class='srhelp'>(" + $(this).prev().children(1).attr("alt") + ")</span>");
			})			
			$("span.srhelp")
			.css("display","block")
			.css("position","absolute")
			.css("text-indent","-30000px")
			.css("overflow","hidden")
			;
		}
		fixMeaninglessMoreInfoLinksSecurity();		
	}	
}
// Safari 2 hacks for non-jQuery.
function fixSafari(){
	var br = navigator.userAgent.toLowerCase()
	if(br.indexOf("safari") != -1 && br.indexOf("safari/4") != -1 && br.indexOf("mac") != -1){
		var divs = document.getElementsByTagName("div");
		for(var i=0;i<divs.length;i++){
			if(divs[i].className == "slot")
			{
				divs[i].style.top = "860px";
			}
			if(divs[i].id == "securityPagewrapper")
			{
				divs[i].style.height = "975px";
			}
		}
	}
}
window.onload = fixSafari;
addEvent(window, 'load', doSecurityJQueryFunctions, false);