jQuery(document).ready(function() {	

	startList(); // fixes menu in ie6
	tooltip(); // adds tooltips
	externalLinks(); // adds external links
	dynamicListManagement();
	
});

/* fixes menu in ie6 */
function startList() {
	if (document.all&&document.getElementById) {
		var navRoot = document.getElementById("navigation");
		if(navRoot != null){
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
						this.className+=" over";
					}
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
	}
}

/* adds tooltips */
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".infotip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$(".infotip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

/* adds external links */
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
				anchor.getAttribute("name") == "external")
			anchor.target = "_blank";
	}

}

/* redirect when editing account */
function personaldetailsRedirect() {
	window.setTimeout(function() {
		var url = location.href;
		url = url.split('edit-my-account/personal-details/update.html')[0] + "dashboard.html";
		document.location = url;
	}, 4000);
}

/* redirect for mobile users */
function mobileRedirect() {
	if (screen.width <=350 || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) ) {
		$("input#mobile").attr("value", "true");
	}
	$('.mobile').hide();
}

/* add to liost */
function dynamicListManagement() {
	$('.add').live('click', function() {
		var edititem = $("input#solution").attr("value");
		if (edititem != "") {
			$("ul.dynamicListManagement").append("<li><input type='text' value='" + edititem + "' size='100' /></li>");
			$("input#solution").val("");
			
		}
		return false;
	});
	
}



