$(document).ready(function(){
	$('div.car_types div a').mouseover(function(){
		$('div.car_types div').css('background','none');
		$('div.car_types div.header_type_'+this.id).css('background-color','#108ecb');
	});
	$('div.car_types div').mouseout(function(){
		$('div.car_types div').css('background','none');

	});
	
});
function filter(type,value){
	$('table.catalog tr').hide();
	$('table.catalog td.'+type+' @text["' +value+'"]').parent.show();
}

/* ===================================================================== */
/* Gallery */

function prepareGallery(){
	$('div.gallery td.galleryImage').show();

	$('div.gallery div.img_frame a').click(function(){
		changeImage(this);
		return false;
	});
	$('div.gallery div.img_frame').hover(
		function(){
			$(this).addClass('hover');
		},
		function(){
			$(this).removeClass('hover');
		}
	);
	var first_image = $('div.gallery div.img_frame a:first').get();
	if (first_image) {
		changeImage(first_image);
	}
}

function changeImage(el){
	var img_src = $(el).attr('href');
	if (!img_src){
		return;
	}

	$('#imageContainer').hide();
	$('#imageInfo').hide();
	$('#loading').show();

	$('div.gallery div.img_frame').removeClass('active');
	$(el).parent().addClass('active');
	$('#imageInfo').html($(el).parent().parent().find('.description').html());

	imgPreloader = new Image();
	imgPreloader.onload=function(){
		document.getElementById('galleryImage').src = img_src;
		$('#imageContainer').show('fast');
		$('#imageInfo').show('fast');
		$('#loading').hide();
		imgPreloader.onload=function(){};	//	clear onLoad, IE behaves irratically with animated gifs otherwise 
	}
	imgPreloader.src = img_src;
}


/* Eof Gallery */
/* ===================================================================== */

function setCookie(cookieName,cookieValue,nDays) {

	var today = new Date();
	var expire = new Date();

	if (nDays==null || nDays==0) nDays=1;

	expire.setTime(today.getTime() + 3600000*24*nDays);

	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}



function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);

	if (begin == -1){
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}else{
		begin += 2;
	}

	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}

	return unescape(dc.substring(begin + prefix.length, end));
}
