
$(window).resize(function(){
	ieMargins();
	//centerHome();
});

$(document).ready(function(){
	setTimeout('ieMargins();', 1000);
	getURLParam();
	alignBody();
	
/*var projectListHeight = $(".projectList").height();
	$(".projectList li").click(function() {
		$(".projectList li").each(function () {	
			if(this.className == "active") {
				$(this).removeClass("active");
			}
		});
		$(this).addClass("active");
		var liHeight = $(".active ul").height() + 10;
		var liTop = projectListHeight + 10;
		$("ul.projectList ul").css({'top': liTop});
		$("ul.projectList").css({ height: liHeight + projectListHeight });
		jQuery.each(jQuery.browser, function(i, val) {
			if(i=="msie" && jQuery.browser.version=="6.0") {
				ieMargins();
			}
		});
	});*/
	
	$("#search-text").focus(function() {
		if(document.search.searchTxt.value == "Search") {
			document.search.searchTxt.value = "";
		}
	});
	
	$("#search-text").blur(function() {
		if(document.search.searchTxt.value == "") {
			document.search.searchTxt.value = "Search";
		}
	});
	
	if(document.getElementById('homeWrapper') != null) {
		//setTimeout('centerHome();', 1000);
		newsSlider();
	}
	
	/*var surroundingContentHeight = $("#headerWrap").height() + $(".headContent").height() + $("#footerWrap").height();
	var windowHeight = $(window).height();
	var mainContentHeight = $("#mainContainer").height();
	var availableHeight = surroundingContentHeight - windowHeight;
	alert(windowHeight);
	alert("The available height for the list is " + availableHeight + " The actual height is " + mainContentHeight);*/
	
	

});

function centerHome() {
	var homeHeight = $("#homeWrapper").height();
	var windowHeight = $(window).height();
	if(windowHeight > homeHeight) {
		var homeTop = (windowHeight - homeHeight)/3;
		$("#homeWrapper").css({'paddingTop' : homeTop});
	}
	else {
		$("#homeWrapper").css({'paddingTop' : '0px'});
	}
}

var newsCounter = 0;

function newsSlider() {
	newsCounter++;
	var newsObj = document.getElementById('newsSlider');
	newsItems = newsObj.getElementsByTagName('div');
	totalNews = newsItems.length;
	if(newsCounter > totalNews) {
		newsCounter = 1;
	}

	$("#news-" + newsCounter).fadeIn(1500);
	setTimeout('fadeSlide(newsCounter);', 5000);
}

function fadeSlide(newsCounter) {
	$("#news-" + newsCounter).fadeOut(1500, newsSlider);
}

function ieMargins() {
	jQuery.each(jQuery.browser, function(i, val) {
		if(i=="msie" && jQuery.browser.version=="6.0" && document.getElementById('home') == null) {
			var allDivs = document.getElementsByTagName('div');
			var contentHeight = $("#contentContainer").height();
			var headerHeight = $("#headerWrap").height();
			var footerHeight = $("#footerWrap").height();
			var windowHeight = $(window).height();
			var availableHeight = windowHeight - (headerHeight + footerHeight);
			//alert(availableHeight);
			//alert(contentHeight);
			
			if(contentHeight >= availableHeight) {
				$("#header").css({'marginRight' : '17px'});
				$("#footer").css({'marginRight' : '17px'});
				if(document.getElementById('thumbsWrapper') != "null") {
					$("#thumbsWrapper").css({'marginRight' : '17px'});
				}
				for(var i=0; i<allDivs.length; i++) {
					if(allDivs[i].className.indexOf("headerContent") > -1 || allDivs[i].className.indexOf("thumbsContent") > -1 || allDivs[i].className.indexOf("footerContent") > -1) {
						var fixedContent = allDivs[i];
						fixedContent.style.paddingLeft = "17px";
					}
				}
			}
			else {
				$("#header").css({'marginRight' : '0px'});
				$("#footer").css({'marginRight' : '0px'});
				if(document.getElementById('thumbsWrapper') != "null") {
					$("#thumbsWrapper").css({'marginRight' : '0px'});
				}
			}
		}
	});
}


function getURLParam() {
	var href = window.location.href;
  	if (href.indexOf("?") > -1){
		var queryString = href.substr(href.indexOf("?"));
		var params = queryString.split("=");
		$(".projectList li a").each(function () {
			var aName = this.name;
			var parentLI = $(this).parent().get(0);
			for(i=0; i<params.length; i++) {
				if(unescape(params[i]) == aName) {
					$(parentLI).addClass('active');
					firstPHeight = $(".leftContent p:first").height();
					firstH1Height = $(".leftContent h1:first").height();
					ulTop = firstPHeight + firstH1Height + 15;
					ulHeight = ($(".active ul").height() + 15) - ulTop;
					if(ulHeight > $("ul.projectList").height()) {
						$("ul.projectList").css({ height: ulHeight + "px" });
					}
					$(".active ul").prepend("<li class='selectedProjects'><h2>Selected Projects</h2></li>");
					$(".active ul").css({ top: -(ulTop) + "px" });
					jQuery.each(jQuery.browser, function(i, val) {
						if(i=="msie" && jQuery.browser.version=="6.0") {
							ieMargins();
						}
					});
				}
			}
		});
	}
}

function alignBody() {
	if($("#news").length > 0) {
		var leftBodyPos = $("#news .leftContent .body_1").position();
		var leftBodyTop = leftBodyPos.top;
		var rightColh1Height = $("#news .rightContent h1").height();
		var rightBodyTop = leftBodyTop - rightColh1Height;
		
		$("#news .rightContent .body_1").css({'margin-top': rightBodyTop + 'px'});
	}
}
