function set_headline_height(clicked,total)
{
	var isIE = $.browser.msie;
	
	function sortNumber(a,b)
	{
		return b - a;
	}
	
	var arrHeight = [$("#headline_1").outerHeight(true), $("#headline_2").outerHeight(true), $("#headline_3").outerHeight(true), $("#headline_4").outerHeight(true)];
	var arrHighToLow = arrHeight.sort(sortNumber);
	var tallestDiv
	
	if(clicked)
	{
		tallestDiv = arrHighToLow[0];
	} else {
		tallestDiv = arrHighToLow[0] + 20;
	}
	
	for(i=2;i<total;i++)
	{
		if(!isIE)
		{	
			$("#hlink_" + i).css('opacity',0);
		}
	}
	
	rotate(clicked,clicked,tallestDiv,total);
}

function rotate(count,clicked,tallestDiv,total)
{
	var isIE = $.browser.msie;

	countLast = count-1;

	if(count == total)
	{
		count = 1;	
	} else {
		count++;	
	}
	
	if(countLast == total)
	{
		countLast = 1;	
	} else {
		countLast++;	
	}
	
	if(clicked > 0)
	{
		for(i=1;i<=total;i++)
		{
			$("#headline_" + i).css('display','none');
			$("#headline_" + i).children('div').css('display','none');
			$("#hlink_" + i).removeClass('on');
			$("#bg_img").removeClass('home' + i);
		}
		$("#headline_" + clicked).height(tallestDiv);
		$("#headline_" + clicked).css('display','block');
		$("#headline_" + clicked).children('div').css('display','block');
		$("#hlink_" + clicked).addClass('on');
		if(!isIE)
		{
			$("#hlink_" + clicked).css('opacity',1);
		}
		$("#bg_img").addClass('home' + clicked);
		clearTimeout(to);
	} else {
		$("#headline_" + count).height(tallestDiv);
		if(!isIE)
		{
			$("#hlink_" + countLast).animate({
					opacity:0
				},500,function(){
					$("#hlink_" + countLast).removeClass('on');
				});
		} else {
			$("#hlink_" + countLast).removeClass('on');
		}
		$("#headline_" + countLast).children('div').fadeOut(500,
			function(){
				$("#headline_" + countLast).css('display','none');
				$("#headline_" + count).css('display','block');
				$("#hlink_" + count).addClass('on');
				$("#bg_img").removeClass('home' + countLast);
				$("#bg_img").addClass('home' + count);
				if(!isIE)
				{
					$("#hlink_" + count).animate({
						opacity:1
					},500);
				}
				$("#headline_" + count).children('div').fadeIn(500);
		});
		to = setTimeout("rotate(" + count + ",''," + tallestDiv + "," + total + ");", 15000);
	}	
}

function slider(oElement)
{
	var status = $(oElement).html();
	
	if(status == 'Open')
	{
		$(oElement).parent().parent().children('div').slideToggle(100);
		$(oElement).html('Close');
		$(oElement).addClass('on');
		$(oElement).parent().parent().css('background','#d6d7d9');	
	} else {
		$(oElement).parent().parent().children('div').slideToggle(100,function(){
			$(oElement).html('Open');
			$(oElement).removeClass('on');
			$(oElement).parent().parent().css('background','#b4babc');
		});
	}
}

function housePrices(strCSS,oThis)
{
	$("#properties_wrapper ul").children().removeClass("on");
	$(oThis).parent().addClass("on");
	$("#properties_graph").fadeOut(function(){
		$("#properties_graph").css('background','url(/wp-content/images/general/house_' + strCSS + '.gif)');
		$("#properties_graph").fadeIn();
	});
}

//Carousels
function university_initCallback(carousel)
{
	carousel.startAuto(5);
	setTimeout(function() { 
	        carousel.stopAuto(); 
	    }, 16000);
}

$(document).ready(function() {
	
	//university carousel
    if ($("#university_carousel").length != 0) {
    	$("#university_carousel").jcarousel({
    	        visible: 1,
    			auto: 6,
    			scroll: 1,
    			wrap: 'circular',
    			animation: 1000,
    			initCallback: university_initCallback
    	    });
    }
});
