function bindEvent(el, sType, fn, capture) {
	if(window.attachEvent) {
		el.attachEvent("on" + sType, fn);
	} else if(window.addEventListener) {
		el.addEventListener(sType, fn, (capture));   
	}
}
function $(){
	return document.getElementById(arguments[0]);
}
function setDetailImage(){
	if($('thumbs')){
		var img = $('thumbs').getElementsByTagName('img');
		if(img.length==1){
			$('thumbs').parentNode.parentNode.removeChild($('thumbs').parentNode);
			return;
		}
		for(var i=0;i<img.length;i++){
			img[i].className = 'off';
			img[i].setAttribute("iImage",i);
			img[i].onclick = function(){
				var img = $('thumbs').getElementsByTagName('img');
				for(var k=0;k<img.length;k++){
					img[k].className='off';
				}
				var newimg = new Image();
				var s = newimg.src = 'images/carsdb/'+this.src.substr(this.src.lastIndexOf('/'),this.src.length)+'?t='+Math.random(new Date()); 
				newimg.onload = function(){
					this.className = 'on';
					var p = $('ximage').parentNode;
					p.removeChild($('ximage'));
					var nimg = document.createElement('img');
					nimg.setAttribute("id","ximage");
					nimg.setAttribute("src",s);
					p.appendChild(nimg);
				}
				this.className = 'on';
			}
		}
		img[0].className = 'on';
	}
}
var WindowObjectReference = null; // global variable
var ProductOptionWindow = null;
function enquireWin(){
	if(WindowObjectReference == null || WindowObjectReference.closed){
    	WindowObjectReference = window.open(arguments[0],
           "Enquiry", "width=670,height=430,top=100,left=100,resizable=yes,scrollbars=yes,status=yes");
	} else {
    	WindowObjectReference.focus();
    };
}
function friendWin(){
	if(WindowObjectReference == null || WindowObjectReference.closed){
    	WindowObjectReference = window.open(arguments[0],
           "Emailfriend", "width=630,height=430,top=100,left=100,resizable=yes,scrollbars=yes,status=yes");
	} else {
    	WindowObjectReference.focus();
    };
}
function printcWin(){
	if(WindowObjectReference == null || WindowObjectReference.closed){
    	WindowObjectReference = window.open(arguments[0],
           "Print", "width=650,height=500,top=100,left=100,resizable=yes,scrollbars=yes,status=yes");
	} else {
    	WindowObjectReference.focus();
    };
}
function setEnquireLink(){
	if(!$('enquire')) return;
	$('enquire2').onclick = $('enquire').onclick = function(){
		enquireWin(this.href);
		return false;
	}
	
}
function setPrintLink(){
	if(!$('printc')) return;
	$('printc').onclick = function(){
		printcWin(this.href);
		return false;
	}
	
}
function setFriendLink(){
	if(!$('friend')) return;
	$('friend').onclick = function(){
		friendWin(this.href);
		return false;
	}
	
}
bindEvent(window, "load", setDetailImage, false);
bindEvent(window, "load", setEnquireLink, false);
bindEvent(window, "load", setFriendLink, false);
bindEvent(window, "load", setPrintLink, false);