var $st		= 0;
var $max	= 0;
var $width	= 0;
var $speed	= 1;
var $shift	= 6;
var	$left	= 0;
var $view1	= false;
var $view2	= false;
var $view3	= false;
var $move	= false;
var $time	= false;

function runGrow() {
	if ($move == "grow") {
		$left	= $width + $shift*1.5;
		$width	= $width + $shift*1.5;
		if ($width<($max-$shift)) {
			$view3.style.left	= $left + "px";
			if ($time) { window.clearTimeout($time); }
			$time = window.setTimeout('runGrow()', $speed);
		} else {
			$view3.style.left	= $max +"px";
			// $cl	= $max;
		}
	}
}
function runShrink() {
	if ($move == "shrink") {
		$width	= $width - $shift;
		$left	= $width - $shift;
		if ($width>$shift) {
			$view3.style.left	= $max - ($max - $width)+"px";
			if ($time) { window.clearTimeout($time); }
			$time = window.setTimeout('runShrink()', $speed);
		} else {
			$width				= $max;
			$left				= 0;
			$view1.style.width	= "0px";
			$view3.style.left	= "0px";
		}
	}
}

function doSwitch($id1, $id2, $id3, $dir) {
	$view1	= document.getElementById($id1);
	$view2	= document.getElementById($id2);
	$view3	= document.getElementById($id3);
	$view1.style.width		= $max+"px";
	$view3.style.width		= $max+"px";
	$view3.style.position	= "absolute";
	$max	= $view2.clientWidth;
	if ($dir == 1) {
		// grow
		$width		= $left ? $left : 0;
		$move		= "grow";
		if ($width<$max) {
			$view3.style.left		= $left;
			if ($time) { window.clearTimeout($time); }
			$time = window.setTimeout('runGrow()', $speed);
		}
	} else {
		$move	= "shrink";
		$width	= $left ? $left : $max;
		if ($time) { window.clearTimeout($time); }
		$time = window.setTimeout('runShrink()', 500);
	}
	return false;
}

/** By Mayhem **/

function top_of_content_area(){
	$HTML = '<table cellpadding="0" cellspacing="0" border="0" class="big text">'+
				'<tr>'+
					'<td><img src="images/text_clt.gif" width="10" height="10" alt=""></td>'+
					'<td class="bt"></td>'+
					'<td><img src="images/text_crt.gif" width="10" height="10" alt=""></td>'+
				'</tr>'+
				'<tr valign="top">'+
					'<td class="bl"></td>'+
					'<td class="big">';
	document.write($HTML)
}

function bottom_of_content_area(){
	$HTML = '</td>'+
		'<td class="br"></td>'+
		'</tr>'+
		'<tr>'+
			'<td><img src="images/text_clb.gif" width="10" height="10" alt=""></td>'+
			'<td class="bb"></td>'+
			'<td><img src="images/text_crb.gif" width="10" height="10" alt=""></td>'+
		'</tr>'+
	'</table>';

}



/** Navigation-car scripts **/

function change_car($car, $link){
	if (document.getElementById("startpage_Model")){
		$image = '<a href="'+$link+'"><img src="images/'+$car+'" border="0" style="margin-bottom:10px"/></a>';
		document.getElementById("startpage_Model").innerHTML = $image;
	}
}

$container_width = 0;
$current_object = 0;
$opened_objects = '<?php echo $js_code?>';
$offset = 30;
$interval = 0;
function start_move($id){
	$current_object = document.getElementById("container_"+$id);
	$current_object.style.display="";
	$new_objects = $opened_objects.replace(";"+$id+";","");
	if ($opened_objects == $new_objects){ // Eto otkritije objekta
		$opened_objects += ';'+$id+';';
		$multipler = 1;
		$container_width = document.getElementById("nav_"+$id).clientWidth;
		$offset = $container_width/3;
		$znak = ">=";
		close_all_objects($id);
	} else {  // Eto zakritije objekta
		$multipler = -1;
		$opened_objects = $new_objects
		$znak = "<=";
		$container_width = 0;
		if (!$current_object.style.width){ // Eto sdelano dlja togo chtobi aktivnij element mog svernutsa posle refresha
			$current_object.style.width = document.getElementById("nav_"+$id).clientWidth;
		}

	}
	$interval = window.setInterval("make_resize()", 1);
}
$old_size = 0;
function make_resize(){
	var $ret;
	$currentSize = $current_object.style.width.replace("px",'')*1;
	eval("if ($currentSize "+$znak+" $container_width) {$ret = 1}");
	if ($ret || $currentSize + $offset*$multipler <= 0) {
		clearInterval($interval);
		if ($container_width == 0){
			$current_object.style.width = "1px"
			$current_object.style.display = "none";
		} else {
			$current_object.style.width = $container_width;
		}
		return;
	}
	$current_object.style.width =  $currentSize + $offset*$multipler + "px";
}

function close_all_objects($id){
	var $obj;
	var $objs = $opened_objects.split(";");
	var $counter = $objs.length;
	for (var $x=0; $x < $counter; $x++) {
		if (!$objs[$x]) continue;
		if ($objs[$x] == $id) continue;
		$obj = document.getElementById("container_"+$objs[$x])
		if (!$obj) continue;
		$opened_objects = $opened_objects.replace(";"+$objs[$x]+";","");
		$obj.style.width = "1px"
		$obj.style.display = "none";
	}
}

