<?
$conf[]='.wz_tooltip.js';
define(ONLY_LOCAL, true);

header('Content-type: text/javascript');
//print_r($_SERVER); //debug
if (ONLY_LOCAL && !preg_match(",^http://{$_SERVER['HTTP_HOST']}/,", $_SERVER['HTTP_REFERER'])) {
	print fake_js();
	exit;
}
foreach($conf as $file) {
	print compress_js($file);
}

function compress_js($file) {
	$lines = file($file);
	$comp_js = '';
	if (!is_array($lines)) $lines = array();
	foreach($lines as $line) {
		$comp_js .= rtrim(js_linecompress($line));
	}
	return preg_replace(',/\*.*\*/,', '', &$comp_js);
	//return $comp_js;
}

function js_linecompress($js) {
	$js_len = &strlen($js);
	$comp_js_line = '';
	for($i=0;$i<$js_len;$i++) {
		if ($js[$i] == '/' && $i+1 < $js_len && $js[$i+1] == '/') {
			return one_space(&$comp_js_line);
		} else {
			if ($js[$i] == "\t") {
				$comp_js_line .= ' ';
			} else {
				$comp_js_line .= $js[$i];
			}
		}
	}
 	return one_space(&$comp_js_line);
}

function one_space($buffer) {
	while ((preg_match('/  /',$buffer))) {
			$buffer = &str_replace('  ', ' ', &$buffer);
	}
	return $buffer;
}

function fake_js() {
	echo 'function escape(text) {
		item = parent.event.onmouseover;
		item.background.color = \'#efefff\';
		item.title = text;
	}';
}
?>
