var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var deltaBetweenMiddleHeightAndResultHeight;
var deltaBetweenFilterHeightAndFilterContentHeight;
var filterShown = true;

function repairHeights(){
	setHeighs(getNewHeight());
}

function enlargeProjectHeights(incBy){
	var avail = availProjectsHeight();

	if (avail < incBy){
		setHeighs(getNewHeight() + incBy - avail);
	}	
}

function getNewHeight(){
	var filterHeight = $('#filterSectionRealHeight').height() + deltaBetweenFilterHeightAndFilterContentHeight;
	var resultHeight = $('#resultColumnRectangleContentRealHeight').height() + deltaBetweenMiddleHeightAndResultHeight;

	if (filterShown) {
		return Math.max(filterHeight, resultHeight) + 10; // + 10 for extra safe so no scrollbar will appear
	}
	else {
		return resultHeight + 10; // + 10 for extra safe so no scrollbar will appear
	}
}

function setHeighs(height){
	$('.resultColumnRectangleContent').height(height - deltaBetweenMiddleHeightAndResultHeight);
	
	if (filterShown) {
		$('#navColumn').height(height - deltaBetweenFilterHeightAndFilterContentHeight);
	}
	else {
		$('#navColumn').height('auto');
	}
}

function availProjectsHeight(){
	if (filterShown) {
		return $('.resultColumnRectangleContent').height() - $('#resultColumnRectangleContentRealHeight').height() - 10; // -10 just for extra safe
	}
	else {
		return 0;
	}
}

/* about us page script */
$(document).ready(function(){
	initSearchBar();
	
	if(IE6) {
		deltaBetweenMiddleHeightAndResultHeight = 11;
	}else {
		deltaBetweenMiddleHeightAndResultHeight = 2;
	}
	deltaBetweenFilterHeightAndFilterContentHeight = 6 + 6;
	repairHeights();

	$('.questionContainer').find('.question').each(function(index){			
		$(this).toggle(function(){
		$('.questionContainer').find('.answer').eq(index).show();
		$(this).parent().css('background', 'url(images/questionIcon2.gif) no-repeat 0px 7px')
											}, function(){
		$('.questionContainer').find('.answer').eq(index).hide();		
		$(this).parent().css('background', 'url(images/questionIcon.gif) no-repeat 0px 7px')
		})								
		$(this).click(function(){
				repairHeights();
				return false;
		})												
	})

	$('.aboutNav .openNav').each(function(index) {
		$(this).find('.subNav').show();
		$(this).css('background', 'url(images/minus.gif) no-repeat 0px 10px');
	});

	$('.aboutNav .closeNav').each(function(index){
		$(this).find('a').eq(0).click(function(){						   
			 if($(this.parentNode).hasClass('openNav')){
				$('.subNav').eq(index).hide();
				$('.closeNav').eq(index).css('background', 'url(images/plus.gif) no-repeat 0px 8px');	
				
				$(this.parentNode).removeClass('openNav');
				
			}else if($(this.parentNode).hasClass('closeNav')){				
				$('.subNav').hide();
				$('.subNav').eq(index).show();
				$('.closeNav').css('background', 'url(images/plus.gif) no-repeat 0px 8px');
				$('.closeNav').eq(index).css('background', 'url(images/minus.gif) no-repeat 0px 10px');
				$('.closeNav').removeClass('openNav');
				$(this.parentNode).addClass('openNav');
				
			}
			
			repairHeights();
			 	
			return false;
		});		  
	});
	
	$('a.external_link').click( function() { 
		window.open(this.href);  
		return false; 
	});
	
	$('#openBidding').click(function(){
		$('#bidding').parent().find('.answer').show();
		$('#bidding').parent().css('background', 'url(images/questionIcon2.gif) no-repeat 0px 7px');
		repairHeights();	
	});

	$('#openContest').click(function(){
		$('#contest').parent().find('.answer').show();
		$('#contest').parent().css('background', 'url(images/questionIcon2.gif) no-repeat 0px 7px');
		repairHeights();	
	});

	$('#openEmailAlert').click(function(){
		$('#emailalert').parent().find('.answer').show();
		$('#emailalert').parent().css('background', 'url(images/questionIcon2.gif) no-repeat 0px 7px');
		repairHeights();	
	});

	$('#openRSS').click(function(){
		$('#rss').parent().find('.answer').show();
		$('#rss').parent().css('background', 'url(images/questionIcon2.gif) no-repeat 0px 7px');
		repairHeights();	
	});

	$('#openTwitter').click(function(){
		$('#twitter').parent().find('.answer').show();
		$('#twitter').parent().css('background', 'url(images/questionIcon2.gif) no-repeat 0px 7px');
		repairHeights();	
	});
})

