$(document).ready(function() {
	
	// AutoHeight - Sets the element height to the parent height

	$(".AutoHeight").each(function () {
	
		var ah = $(this).parent().attr("class");
		ah = ah.split(" ");
		for ( var i in ah )
		{
    		if ( ah[i].substr(0,2) == "ht" && isInteger(ah[i].substr(2,6)) == true ) {
				$(this).addClass(ah[i]);
			}
		}

	});
	
	$(".colorbox").colorbox();
	
	$("#Albums").click( function() {
		$(".Albums").slideToggle();
	});
	
	$(".ContentBox").each(function () {
	
		var background = $(this).attr("class");
		background = background.split(" ");
		for ( var bgi in background )
		{
			if ( background[bgi].substr(0,2) == "bg" ) {
				$(this).css("background-color", "#" + bg[bgi].substr(2,6) );
			}
		}
		
		var bd = $(this).attr("class");
		bd = bd.split(" ");
		for ( var i in bd )
		{
			if ( bd[i].substr(0,2) == "bd" ) {
				$(this).css("border", "1px solid #" + bd[i].substr(2,6) );
			}
		}

	});
	
	$("#slider-vertical").slider({
			orientation: "vertical",
			range: "min",
			min: 10,
			max: 99,
			value: 99,
			slide: function(event, ui) {
				val = "0." + ui.value;
				$("#amount").val(val);
				if ( val == 0.10 ){ val = 0; }
				eval('$(".LatestNews").animate({opacity: '+val+' }, 0);');
				eval('$(".LatestNews p").animate({opacity: '+val+' }, 0);');
			}
	});
		
	var val = $("#slider-vertical").slider("value");
	if ( val == 10 ) { val = 1; } else { val = "0."+val; }
	$("#amount").val(val);
	eval('$(".LatestNews").animate({opacity: '+val+' }, 0);');
	
	OrinialBorderColor = "";
	$("div.clickable").mouseover( function(){
    	$(this).css("cursor", "hand");
		OrinialBorderColor = $(this).css("border-color");
		$(this).css("border-color", "#5972a3");
	});
	
	$("div.clickable").mouseout( function(){
    	$(this).css("border-color", OrinialBorderColor);
	});
	
	$("div.clickable").click( function(event) {
		window.location = $(this).attr("url");
		event.preventDefault();
	}); 

	$(".tablesorter select").change( function() {
		$(".tablesorterForm").submit();
	});
	
	arr=new Array(0,1,2,3);
	i = -1;
	lastID = 0;
	stayTime = 7;
	showNext();
	function showNext(){
		lastID = arr[i];
		i++;
		if (i >=arr.length ) 
			i=0;
			$('.Slider_' + arr[i]).animate({top:0}, 900, function(){
				setTimeout(showNext,(stayTime*1000));
			});
		
		$('.Slider_' + lastID).animate({top:300},500);
	}

	
	// Accordian
	
	$(".AccordianContent:first").slideDown();
	
	$(".AccordianMenu li a").click(function () {
		$(".AccordianContent").slideUp();
		$("."+this.rel).slideDown();
	});
	
	//$(".SlideOut").click(function () {
	//	$("#" + $(this).parent().attr("id") ).animate({ height: "toggle" }, 500 );
	//});
		
});

function isInteger(s) {
	return (s.toString().search(/^-?[0-9]+$/) == 0);
}