/*function setNavBackground(){
	var navbg = document.getElementById("navcontainer");
	navbg.style.backgroundPosition = document.body.clientWidth * .5 + 330 + "px";
}*/

// Display contact badge button labels
function contactText(lineNum){
	$("#contactText").stop();
	$("#contactText").animate({top:(-lineNum * 16) + "px"}, 250);
}
function contactRestore(){
	contactText(0);
}

// Hilite items in the index by type
function indexHilite(type){
	if(getPath().length < 2)
		$(".indexboxcontent span.icon").not(".icon" + type).parent().stop().fadeTo(250, .15);
}
function indexRestore(){
	$(".indexboxcontent span.icon").parent().stop().fadeTo(250, 1.0);
}

// cookies
function setCookie(name, value, days){
	var date = new Date();
	date.setDate(date.getDate() + days);
	var value = escape(value) + ((days == null) ? "" : "; expires=" + date.toUTCString());
	document.cookie = name + "=" + value;
}
function getCookie(name){
	var i, key, val, cookies = document.cookie.split(";");
	for (i = 0; i < cookies.length; i++){
		key = cookies[i].substr(0, cookies[i].indexOf("="));
		val = cookies[i].substr(cookies[i].indexOf("=") + 1);
		key = left.replace(/^\s+|\s+$/g, "");
	}
	if (key == name)
	    return unescape(val);
}
function cookiesObject(){
	obj = {};
	cookies = document.cookie.split(";");
	for(var i = 0; i < cookies.length; i++){
		key = cookies[i].substr(0, cookies[i].indexOf("="));
		val = cookies[i].substr(cookies[i].indexOf("=") + 1);
		key = key.replace(/^\s+|\s+$/g, "");
		obj[key] = unescape(val);
	}
	return obj;
}

$("document").ready(function(){
	
	// Hide windows specific messages
	if (navigator.userAgent.indexOf("Windows NT 6.") == -1)
		$(".windowsalert").hide();
		
	// Hide inapplicable nav items
	var path = getPath();
	if(path.length > 1){
		var type = path.pop();
		if(type.charAt(type.length - 1) == "s")
			type = type.substr(0, type.length - 1);
		$(".indexboxcontent span.icon").not(".icon" + type).parent().parent().remove();
		$(".itembox, .galleryitem").not(".item" + type).remove();
	}
	
	// Scroll to anchor
	if(window.location.hash){
		$('html,body').scrollTop(0);
		$('html,body').animate({scrollTop: $(window.location.hash).offset().top - 25}, null, null, function(){
			$(window.location.hash).stop().animate({opacity:0}).animate({opacity:1});
		});
	}
	
	// Preload images
	var preload = ["/media/img/layout/selection-border.png", "/media/img/layout/selection-border-active.png"];
	for(var i in preload){
		(new Image()).src = preload[i];
	}
});

// Get url file path with trimmed slashes, ex: extensions/commands
function getPath(){
	var path = location.pathname;
	while(path.charAt(path.length - 1) == "/") path = path.substr(0, path.length - 1);
	while(path.charAt(0) == "/") path = path.substr(1);
	path = path.split("/");
	return path;
}
