trigger = new Image();
trigger.src = 'img/car-dics-trigger-sel.gif';


function showCars(tbId) {
	carDisc = document.getElementById(tbId);
	
	if (carDisc.style.display == 'block') {
		carDisc.style.display = 'none';
	} else {
			carDisc.style.display = 'block'
		}
}
function newWin(url, winWidth, winHeight) {
		var countWin;
		if(!winWidth) winWidth = 550;
		if(!winHeight) winHeight = 500;
		PopupWin = window.open(url, 'newWin'+countWin, 'width='+winWidth+', height='+winHeight+',menubar=no,status=no,titlebar=no,toolbar=no,location=no,resizable=no,scrollbars=no');
		countWin++;
}

preloadImages = {
	init:		function() {
					var image_root = 'img';
					var imagesArray = new Array(
						'b-hdr-bg.gif',
						'mnu-bg-hv.gif'
					);
					for (var im = 0; im < imagesArray.length; im++) {
						imgpath = image_root + '/' + imagesArray[im];
						preloadImages.preload(imgpath);
					}
				},
	preload:	function(imgsrc) {
					if (document.images) {	
						var image = new Image();
						image.src = imgsrc;
					}
	}
}

photo_color = {
	gallery:	document.getElementById('gallery'),
	
	init:	function() {
//		alert(document.getElementById('gallery').childNodes.length)
		if (document.getElementById('gallery')) {
			for (i = 0; (i < document.getElementById('gallery').childNodes.length); i++) {
				document.getElementById('gallery').childNodes.item(i).onmouseover = function() {
					if (this.className != 'sel') {
						this.className = 'over'
						
					}
				}
				document.getElementById('gallery').childNodes.item(i).onmouseout = function() {
					if (this.className != 'sel') {
						this.className = ''
					} 
				}
			}
		}
	}
}


function changePhoto_color(my_url, my_width, my_height, my_elm) {
		var color_image = new Image();
		color_image.src = my_url;
		color_image.onload = function() {
			document.getElementById('bigPhoto').src = my_url;
			document.getElementById('bigPhoto').width = my_width;
			document.getElementById('bigPhoto').height = my_height;
			for (i = 0; (i < document.getElementById('gallery').childNodes.length); i++) {
				document.getElementById('gallery').childNodes.item(i).className = '';
			} 
			my_elm.className = 'sel';
		}
}

photo = {
	gallery:	document.getElementById('gallery'),
	
	init:	function() {
		if (document.getElementById('gallery')) {
			for (i = 0; (i < document.getElementById('gallery').getElementsByTagName('table').length); i++) {
				document.getElementById('gallery').getElementsByTagName('table').item(i).onmouseover = function() {
					if (this.className != 'sel') {
						this.className = 'over'
					}
				}
				document.getElementById('gallery').getElementsByTagName('table').item(i).onmouseout = function() {
					if (this.className != 'sel') {
						this.className = ''
					} 
				}
			}
		}
	}
}


function changePhoto(my_url_temp, my_width_temp, my_height_temp, my_elm_temp) {
		document.getElementById('loading').style.display = 'block';
		var my_image = new Image();
		my_url = my_url_temp;
		my_width = my_width_temp;
		my_height = my_height_temp;
		my_elm = my_elm_temp;
		document.getElementById('bigPhoto').display = 'none';
		document.getElementById('bigPhoto').src = my_url;
}

var first = true;

function imgLoad() {
	if (first == true) {first = false;}
		else {
			document.getElementById('bigPhoto').width = my_width;
			document.getElementById('bigPhoto').height = my_height;
			document.getElementById('bigPhoto').display = 'inline';	
			document.getElementById('loading').style.display = 'none';
			for (i = 0; (i < document.getElementById('gallery').getElementsByTagName('table').length); i++) {
				document.getElementById('gallery').getElementsByTagName('table').item(i).className = '';
			} 
			my_elm.className = 'sel';
		}
}



gallery = {
	width: 	0,
	init: 	function() {
					if (document.getElementById('photo-parent')) {
						setInterval('gallery.check()', 1);
						td = document.getElementById('photo-parent').getElementsByTagName('td');
						table = document.getElementById('photo-parent').getElementsByTagName('table');
						count = 0;
						row = false;
					}
				},
	check: 	function() {
					if (document.body.clientWidth != gallery.width) {
						gallery.width = document.body.clientWidth;
						gallery.inline();
					}
				},
	inline: 	function() {
					document.getElementById('photo-parent').style.visibility = 'hidden';

					for (var i = 0; (table.item(i)); i++) td.item(i).style.height = 'auto';
					for (var i = 1; (table.item(i)); i++) if ((row == false) && (table.item(i).offsetTop == table.item(i-1).offsetTop)) count++; else row = true;
					count++;

					for (var i = 0; (td.item(i)); i=i+count) {	
						myHeight = 0;	
						for (var o = 0; (td.item(i+o) && o < count); o++) if (td.item(i+o).offsetHeight > myHeight) myHeight = td.item(i+o).offsetHeight;
						for (var o = 0; (td.item(i+o) && o < count); o++) td.item(i+o).style.height = myHeight + 'px';
					}
					document.getElementById('photo-parent').style.visibility = 'visible';
				}
}



function init() {
	photo.init();
	photo_color.init();
}

if (loaded) init();
loaded = true;

