<?
function repare_ad($ad, $ip=0){
	if(!$ip)
		$ip=ip2long("127.0.0.1");
	$data=$ad['data'][$ip%sizeof($ad['data'])];
	unset($ad['data']);
	$ad['price']=str_replace('$[price]', $data['price'], $ad['price']);
	$ad['ad_id'].="_".$data['l_path'];

	$ad['link'] ="//".$_SERVER['HTTP_HOST'].'/tgo?l='.$ad['link'].$data['l_path'].'&s='.$ad['ad_id'];
	$ad['image']= "//".$_SERVER['HTTP_HOST'].'/timg/'.$ad['image'];
	return $ad;
}