$(document).ready(function(){
	$.each($('.submenu li'), function(){
		$(this).prepend('<div class="hover"></div>');
		$("#" + this.id + " div.hover").css("height",$(this).height());
	});
	
	$('.submenu li').mouseover(
		function() {
			$(this).addClass('hover');	
		}
	);
	
	$('.submenu li').mouseout(
		function() {
			$(this).removeClass('hover');	
		}
	);
	
	//fix for smaller resolution
	if ($("#main").width() < $("#main .content").width()) {
		$("#menu").css("width", $("#main .content").width());
		$("#main").css("width", $("#main .content").width());
		$("#footer").css("width", $("#main .content").width());
	};
	
	if ($("body").hasClass("news")) { addNewsClickEvent() };
});

function highlightMenu(id) {
	$('#' + id).addClass("selected");
	$('#' + id).prev().addClass("prev");
}	

/* PEOPLE */
function showPeoplePreview(id) {
	$("#preview").css("backgroundImage", "url(../_images/people/" + id + "_img.jpg)");
	$("#preview").fadeIn();
	
	$("#preview").click(function () { 
      $("#preview").fadeOut();
    });
}	

function closePreview() {
	$("#preview").fadeOut();	
}

function swicthPeopleContent(trigger, container, newContent) {
	$("#" + trigger.parentNode.parentNode.id + " li.selected").removeClass("selected");
	$("#" + trigger.id).addClass("selected");
	
	if ($("#" + container + " div.parent").is(':visible')) {
		$("#" + container + " div.parent:visible").fadeOut(500, function() {
			$("#" + newContent).css("background", "#FFFFFF");
			$("#" + newContent + " div.line").css("border-top", "1px solid #006689");
			$("#" + newContent).fadeIn(500);
		});	
	}
	else {
		$("#" + newContent).fadeIn(500);
	}
}

function closePeopleContent(listId, container, newContent) {
	$("#" + listId + " li").removeClass("selected");
	
	$("#" + container).fadeOut(500, function() {
		$("#" + container + " div.parent").hide();
		$("#" + container + " div.parent").css("background", "none"); //IE7 Fix
		$("#" + container + " div.parent div.line").css("border-top", "none"); //IE7 fix
		$("#" + newContent).show();
		$("#" + container).fadeIn();
	});
}



/* PROJECTS */
function showProjectPreview(path, id) {
	parentId = path.toLowerCase()
	$("#" + parentId + " div.preview").css("backgroundImage", "url(../_images/projects/" + path + "/" + path + "_" + id + "_img.jpg)");
	$("#" + parentId + " div.preview").fadeIn();
	
	$("#" + parentId + " div.preview").click(function () { 
      $("#" + parentId + " div.preview").fadeOut();
    });

}	

function closeProjectPreview(id) {
	$("#" + id + " div.preview").fadeOut();	
}

function swicthProjectContent(trigger, container, newContent) {
	$("#" + trigger.parentNode.parentNode.parentNode.id + " ul li").removeClass("selected");
	$("#" + trigger.id).addClass("selected");
	
	if ($("#" + container + " div.parent").is(':visible')) {
		$("#" + container + " div.parent:visible").fadeOut(500, function() {
			$("#" + newContent).fadeIn(500);			
		});	
	}
	else {
		$("#" + newContent).fadeIn(500);
	}
}



/* SERVICES */
function swicthServiceContent(trigger, container, newContent) {
	$("#" + trigger.parentNode.id + " li").removeClass("selected");
	$("#" + trigger.id).addClass("selected");
	
	if ($("#" + container + " div.parent").is(':visible')) {
		$("#" + container + " div.parent:visible").fadeOut(500, function() {
			$("#" + newContent).fadeIn(500);
		});	
	}
	else {
		$("#" + newContent).fadeIn(500);
	}
}

function showService(listItemID) {
	if ($("#" + listItemID.id + " div").is(':hidden')) {
		$("#" + listItemID.parentNode.parentNode.id + " li div").slideUp(500);
		
		$("#" + listItemID.parentNode.parentNode.id + " li.selected").removeClass("selected");
		$("#" + listItemID.id).addClass("selected");
		$("#" + listItemID.id + " div").slideDown(500);
	}
	else {
		//alert("in")
		$("#" + listItemID.parentNode.id + " li.selected").removeClass("selected");
		$("#" + listItemID.id + " div").slideUp();
	}	
}
/* NEWS */
function addNewsClickEvent() {
	$.each($('#ul-news li'), function(){
		$(this).click(function () { 
		  var index = $('#ul-news li').index($(this)) + 1;
		  swicthNewsContent(this, "column-right", "news-" + index); 
		});
	});
}	

function swicthNewsContent(trigger, container, newContent) {
	$("#" + trigger.parentNode.id + " li").removeClass("selected");
	$("#" + trigger.id).addClass("selected");
	
	if ($("#" + container + " div.parent").is(':visible')) {
		$("#" + container + " div.parent:visible").fadeOut(500, function() {
			$("#" + newContent).fadeIn(500);
		});	
	}
	else {
		$("#" + newContent).fadeIn(500, function() {});	
	}
}


/* CLIENTS */
function swicthClientContent(trigger, container, newContent) {
	$("#" + trigger.parentNode.id + " li").removeClass("selected");
	$("#" + trigger.id).addClass("selected");
	
	if ($("#" + container + " div.parent").is(':visible')) {
		$("#" + container + " div.parent:visible").fadeOut(500, function() {
			$("#" + newContent).fadeIn(500);
		});	
	}
	else {
		$("#" + newContent).fadeIn(500, function() {
			$("#column-right").css("backgroundImage","none");
			$("#column-right").css("background","#FFFFFF");
		});	
	}
}

