$(document).ready(function(){

//$("a").click(function(){alert("3213123");
var h_td0=$("#td0").height();
var h_td1=$("#td1").height();
var h_td2=$("#td2").height();
var h_td3=$("#td3").height();

//var max_height=Math.max(h_td0>h_td1?h_td0:h_td1,h_td2>h_td3?h_td2:h_td3);
var max_height=Math.max(h_td0,h_td1,h_td2,h_td3);

if(h_td0!=max_height)
{
var space=max_height-h_td0-12;
$("#ad0").css({display:'',height:space});
$.post('includes/space.php',{space: space},function(data){	
	$("#space0").html(data);
	var blank=$("#ad0").height()-$("#space0").height();	
	$("#ad0").css({display:'',height:$("#space0").height()});
	var cc=$(".cc0").length;
	$(".cc0").each(function(i){
		if(i!=cc-1)
		$(this).css({height:blank/(cc-1)});
	});
});
}
if(h_td1!=max_height)
{
var space=max_height-h_td1-12;
$("#ad1").css({display:'',height:space});
$.post('includes/space.php',{space: space},function(data){	
	$("#space1").html(data);
	var blank=$("#ad1").height()-$("#space1").height();	
	$("#ad1").css({display:'',height:$("#space1").height()});
	var cc=$(".cc1").length;
	$(".cc1").each(function(i){
		if(i!=cc-1)
		$(this).css({height:blank/(cc-1)});
	});
	
});
}
if(h_td2!=max_height)
{
var space=max_height-h_td2-12;
$("#ad2").css({display:'',height:space});
$.post('includes/space.php',{space: space},function(data){	
	$("#space2").html(data);
	var blank=$("#ad2").height()-$("#space2").height();	
	$("#ad2").css({display:'',height:$("#space2").height()});
	var cc=$(".cc2").length;
	$(".cc2").each(function(i){
		if(i!=cc-1)
		$(this).css({height:blank/(cc-1)});
	});	
});
}
if(h_td3!=max_height)
{
var space=max_height-h_td3-12;
$("#ad3").css({display:'',height:space});
$.post('includes/space.php',{space: space},function(data){	
	$("#space3").html(data);
	var blank=$("#ad3").height()-$("#space3").height();	
	$("#ad3").css({display:'',height:$("#space3").height()});
	var cc=$(".cc3").length;
	$(".cc3").each(function(i){
		if(i!=cc-1)
		$(this).css({height:blank/(cc-1)});
	});		
});
}

$("#speed_test").click(function(){
	$("#speed_result").text('testing...');	
	var starttime=(new Date()).getTime();
	var size=3865/1024; 
	$.get('media/speed_test.html','',function(){
	var endtime=(new Date()).getTime();		
	var timeslips=(endtime-starttime)/1000;		
	var speed=Math.floor(size/timeslips);
	var bandwith=(speed/1024*8).toFixed(2);	
	var response="Result: <br> "+speed+" kBps download.<br />equals:<br /> "+bandwith+" Mbps bandwith.";
	setTimeout('$("#speed_result").html("'+response+'")',6000);			
	});	
	return false;
	
});
});
