_isInit = null;
_rebindonload = false;
var cached_results = null;
var _currentPod = null;
var cached_whatshot = null;
var _isloggedon = null;

<!-- dynamically load RH pod client side -->
function loadPod(pod) {
	if  (pod == 'hot') {
		$("#dynamicsidebar").html(hot_pod);
		_currentPod = 'hot';
	} else if (pod == "more") {
		$("#dynamicsidebar").html(more_pod);
		_currentPod = "more";
	} else if (pod == 'result') {
		$("#dynamicsidebar").html(result_pod);
		_currentPod = 'result';
	} else if (pod == 'bestbuys') {
		$("#dynamicsidebar").html(bestbuys_pod);
		_currentPod = 'bestbuys';
	}
	return;
}

var mcOptions = {
select:resetYears
}

function resetYears() {
	//alert('reset 1');
	$('#yrMin').val("0");
	$('#yrMax').val("0");
	
	//$("#yrMin option[value=0]").attr("selected",true);
	//val($(this).html())
     


	return;
}

<!-- global client side -->
$(document).ready(function() {
   
   $(function() {
	<!-- build result template cache-->
	if (cached_results == null) {
	  $.get("/dev/results.htm", function(data){
	   cached_results = data;
	});
	  
	}
	
	<!-- test for logged on state -->
	if (_isloggedon == null) {	
		var stateurl = 'index.cfm?fuseaction=app.ajaxuserstate&ts=' + new Date().getTime();
		$.get(stateurl, _isloggedon, function(data){
		  _isloggedon = data;
		});
	}

	
	<!-- initialise DD menu -->
	if (_isInit == null) {
	  if( $("#makemodel").length > 0 ) {
		  	$('#yrMin').selectbox();
			$('#yrMax').selectbox();
			$("#makemodel").mcDropdown("#categorymenu", mcOptions);

	   }
	} 
		
	<!-- detect page calls -->
	if (document.location.href.indexOf("browsecars") > 0) {
		$('#carouselbox').hide();
		_isHot = 1;
		_repage = 1;
		loadHomeCarousel();
		loadPod('hot');
		$('#whatshotcontent').show('normal');
		rebindmorelink();
	}	
	
	if (document.location.href.indexOf("bestbuys") > 0) {
		$('#carouselbox').hide();
		_isHot = 1;
		_repage = 1;
		doForwardBodySearch(1);
		loadPod('bestbuys');
		$('#carouselbox').show('normal');
		$('#whatshotcontent').hide();
		//rebindmorelink();
	}	
	  
	if (document.location.href.indexOf("gallerysearch") > 0) {
		_repage = 1;
		_rebindonload = true;
		//$('#whatshotcontent').hide();
		//loadPod('result');
		//$('#resultcontent').show('normal');
		doCachedSearch() ;
		//$('#carouselbox').show('normal');
	}	

	if (document.location.href.indexOf("listsearch") > 0) {
		_isHot = 0;
		_repage = 0;
		$('#whatshotcontent').hide();
		loadHomeCarousel();
		//loadPod(_currentPod);
	}	
	
	<!-- init home page carousel if present -->
	jQuery('#showroom_carousel_container').jcarousel({
		scroll: 1,
		start: 1
	});
	
	
	
	return false;
	});


	// bind to the search form's submit event 
	$('#searchform').submit(function() {
		_isHot = 0;
		_repage = 1;
		jQuery('#whatshotcontent').hide();
		jQuery('#resultcontent').show('normal');
		jQuery('#carouselbox').html(cached_results);
		jQuery('#carouselbox').show('normal');
		doFormSearch(false);
		loadPod('result');
		// always return false to prevent standard browser submit 
		return false;
	});
	
	// bind to the body search pod click events
	$('#quicksearch a').click(function() {
		//alert('Quick 2');
		var thisTarget = getURLVariable($(this).attr('href'), 'bodyID');
		if (thisTarget == false) {
//			var mode = getURLVariable($(this).attr('href'), 'BestBuy');
//			if (mode == 1) {
//				jQuery('#whatshotcontent').hide();
//				jQuery('#carouselbox').show('normal');
//				_isHot = 0;
//			  	_rebindonload = true;
//				doForwardBodySearch(thisTarget);
//				loadPod('result');
//				return false;
//			}
//			jQuery('#carouselbox').html(cached_results);
//			jQuery('#carouselbox').hide();
//			jQuery('#whatshotcontent').show('normal')
//			_isHot = 1;
//		  _rebindonload = true;
//		  loadHomeCarousel();
//		  loadPod('hot');
			// swap to either BB/Hist
		return;
		} else {
			if (document.location.href.indexOf("bestbuys") > 0) {
				$('#carouselbox').hide();
				_isHot = 0;
				_repage = 1;
				doForwardBodySearch(thisTarget);
				loadPod('bestbuys');
				$('#carouselbox').show('normal');
				$('#whatshotcontent').hide();
				//rebindmorelink();
			} else {
				jQuery('#carouselbox').html(cached_results);
				jQuery('#whatshotcontent').hide();
				jQuery('#carouselbox').show('normal');
				_isHot = 0;
				_rebindonload = true;
				doBodySearch(thisTarget);
				loadPod('result');
			}
		}
		return false;
	});
		
	// cached search from Gall/List swap
	function doCachedSearch() {
		$('#currentPage').hide();
		$('#currentPage').text(0);
		
		_repage = 1;
		_rebindonload = true;
		var newURL = 'index.cfm?fuseaction=app.ajaxsearch';
		var bodysearch_options = {
			success: fillpage,
			url: newURL,
			type: 'get',
			dataType: 'json',
			timeout:   10000,
			cache: false,
			link_to: '#&nxp=__id__'
		};
		$(this).ajaxSubmit(bodysearch_options);
		jQuery('#carouselbox').html(cached_results);
		$('#whatshotcontent').hide();
		/*$('#carouselbox').show('normal');*/
	    loadPod(_currentPod);
		return false;
	}
	

	
	// body search
	function doBodySearch(thisTarget) {
		$('#currentPage').hide();
		$('#currentPage').text(0);
		_repage = 1;
		_isHot = 0;
		var newURL = 'index.cfm?fuseaction=app.ajaxsearch&bodyID=' + thisTarget + '&ts=' + new Date().getTime();
		var bodysearch_options = {
			success: fillpage,
			url: newURL,
			type: 'get',
			dataType: 'json',
			timeout:   10000,
			cache: false,
			link_to: '#&nxp=__id__'
		};
		$(this).ajaxSubmit(bodysearch_options);
		return false;
	}
		
	// body search
	function doForwardBodySearch(thisTarget) {
		$('#currentPage').hide();
		$('#currentPage').text(0);
		_repage = 1;
		_isHot = 0;
		var newURL = 'index.cfm?fuseaction=app.ajaxfwdsearch&bodyID=' + thisTarget + '&ts=' + new Date().getTime();
		var bodysearch_options = {
			success: fillfwdpage,
			url: newURL,
			type: 'get',
			dataType: 'json',
			timeout:   10000,
			cache: false,
			link_to: '#&nxp=__id__'
		};
		$(this).ajaxSubmit(bodysearch_options);
		return false;
	}		


	// whats hot search from server cache
	function doWhatsHotSearch() {
		$('#currentPage').hide();
		$('#currentPage').text(0);
		  _isHot = 1;
		  _repage= 1;
		var newURL = 'index.cfm?fuseaction=app.getHotCarousel';
			var hotsearch_options = { 
			   url:       newURL,         
			   type:      'get',     
			   dataType:  'json',    
			   cache: false,
			   timeout:   10000,
			   link_to:	'#&nxp=__id__'
			}; 
		$(this).ajaxSubmit(hotsearch_options);	
		$('#carouselbox').hide(); 
		$('#whatshotcontent').show('normal');
		return false;
	}
	
	// form search 
	function doFormSearch(useURL) {
			var vMake = 0;
			var vModel = 0;
			var yrMin = 0;
			var yrMax = 0;
			if (useURL) {
				var makeModel = getQueryVariable('makemodel');
				var makeModelArray = makeModel.split("|");
				vMake = makeModelArray[0];
				vModel = makeModelArray[1];
				yrMin = getQueryVariable('yrMin');
				yrMax = getQueryVariable('yrMax');
			} else {
				var mc = $("#makemodel").mcDropdown();
				var makeModelArray = mc.getValue();
				var makeModelRaw = makeModelArray[0];
				var makeModel = makeModelRaw.split("|");
				//alert('makeModel ' + makeModel);
				vMake = makeModel[0];
				vModel = makeModel[1];
				yrMin = $("#yrMin").selectedText();
				if (yrMin == 'Any') yrMin = 0;
				yrMax = $("#yrMax").selectedText();
				if (yrMax == 'Any') yrMax = 0;
			}
		  
			$('#currentPage').hide();
			$('#currentPage').text(0);
			_repage = 1;
			_isHot = 0;
			var newURL = 'index.cfm?fuseaction=app.ajaxsearch&vMake=' + vMake + '&vModel=' + vModel + '&yrMin=' + yrMin + '&yrMax=' + yrMax + '&ts=' + new Date().getTime();
			var form_options = {
				success: fillpage,
				url: newURL,
				type: 'get',
				dataType: 'json',
				timeout:   10000,
				cache: false,
				link_to: '#&nxp=__id__'
			};
		 $(this).ajaxSubmit(form_options);
		_rebindonload = true;
		 return false;
	}

}); // END DOCUMENT READY

// url variable detection
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i = 0; i < vars.length; i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
	return false;
}

function getURLVariable(url, variable) {
    var vars = url.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
    return false;
}

//
function pageselectCallback(page_id) {
    $('#currentPage').text(page_id);
    var _pageID = $('#currentPage').html();
    //alert('call back :' + page_id);
    $("#prevform").hide();
    $("#nextform").hide();

	doPagedSearch(_pageID);

    return false;
}

function fwdpageselectCallback(page_id) {
    $('#currentPage').text(page_id);
    var _pageID = $('#currentPage').html();
    //alert('call back :' + page_id);
    $("#prevform").hide();
    $("#nextform").hide();

	doFwdPagedSearch(_pageID);

    return false;
}

// Create pagination element
function doPagination(recordcount,viewmode) {
	//alert('repaging ...');
	if (viewmode =='H') {
		$("#Pagination").pagination(recordcount, {
			num_edge_entries: 2,
			items_per_page: 6,
			//num_display_entries: 5,
			//prev_show_always: true,
			//next_show_always: true,
			link_to: '#&nxp=__id__',
			callback: pageselectCallback
	
		});
	} else {
		$("#Pagination").pagination(recordcount, {
			num_edge_entries: 2,
			items_per_page: 6,
			//num_display_entries: 5,
			//prev_show_always: true,
			//next_show_always: true,
			link_to: '#&nxp=__id__',
			callback: fwdpageselectCallback
	
		});

	}
}

function rebindmorelink() {  
	//alert('rebind');
	 $('.dtl_topbar a').click(function() {
	  // remove all stacked events							   
	  $('.dtl_topbar a').unbind("click");
	  // rebind
	  var thisTarget = getURLVariable($(this).attr('href'), 'auctionid');
	  doLikeSearch(thisTarget);
	  return false;
   });
	 
}

// Paged Search
function doPagedSearch(nextPage) {
    $("#picture_0").ajaxStart(function() {
        $(this).html('<img src="/images/template/ajax-loader.gif" alt="loading" border="0">');
    });
    $("#picture_1").ajaxStart(function() {
        $(this).html('<img src="/images/template/ajax-loader.gif" alt="loading" border="0">');
    });
    $("#picture_2").ajaxStart(function() {
        $(this).html('<img src="/images/template/ajax-loader.gif" alt="loading" border="0">');
    });
    $("#picture_3").ajaxStart(function() {
        $(this).html('<img src="/images/template/ajax-loader.gif" alt="loading" border="0">');
    });
    $("#picture_4").ajaxStart(function() {
        $(this).html('<img src="/images/template/ajax-loader.gif" alt="loading" border="0">');
    });
    $("#picture_5").ajaxStart(function() {
        $(this).html('<img src="/images/template/ajax-loader.gif" alt="loading" border="0">');
    });
    _repage = 0;
    var newURL = 'index.cfm?fuseaction=app.ajaxsearch&nxp=' + nextPage;
    var pagedsearch_options = {
        repage: false,
        success: fillpage,
        url: newURL,
        type: 'get',
        dataType: 'json',
		timeout:   10000,
        cache: false,
        link_to: '#&nxp=__id__'
    };
	 _rebindonload = true;
    $(this).ajaxSubmit(pagedsearch_options);
	
}


function doFwdPagedSearch(nextPage) {
    $("#picture_0").ajaxStart(function() {
        $(this).html('<img src="/images/template/ajax-loader.gif" alt="loading" border="0">');
    });
    $("#picture_1").ajaxStart(function() {
        $(this).html('<img src="/images/template/ajax-loader.gif" alt="loading" border="0">');
    });
    $("#picture_2").ajaxStart(function() {
        $(this).html('<img src="/images/template/ajax-loader.gif" alt="loading" border="0">');
    });
    $("#picture_3").ajaxStart(function() {
        $(this).html('<img src="/images/template/ajax-loader.gif" alt="loading" border="0">');
    });
    $("#picture_4").ajaxStart(function() {
        $(this).html('<img src="/images/template/ajax-loader.gif" alt="loading" border="0">');
    });
    $("#picture_5").ajaxStart(function() {
        $(this).html('<img src="/images/template/ajax-loader.gif" alt="loading" border="0">');
    });
    _repage = 0;
    var newURL = 'index.cfm?fuseaction=app.ajaxfwdsearch&nxp=' + nextPage;
    var fwdpagedsearch_options = {
        repage: false,
        success: fillfwdpage,
        url: newURL,
        type: 'get',
        dataType: 'json',
		timeout:   10000,
        cache: false,
        link_to: '#&nxp=__id__'
    };
	 _rebindonload = false;
    $(this).ajaxSubmit(fwdpagedsearch_options);
	
}



function doLikeSearch(thisTarget) {

   	if (_isloggedon == 1) {
		_repage = 1;
		_isHot = 0;
		var newURL = 'index.cfm?fuseaction=app.ajaxsearch&auctionid=' + thisTarget + '&ts=' + new Date().getTime();
		$('#currentPage').hide();
		$('#currentPage').text(0);
//		$('#currentSearch').text('doLikeSearch');
//		$('#currentID').html(thisTarget);
		var likesearch_options = {
			success: fillpage,
			url: newURL,
			type: 'get',
			dataType: 'json',
			cache: false,
			timeout:   10000,
			link_to: '#&nxp=__id__'
		};
		$(this).ajaxSubmit(likesearch_options);
		$('#whatshotcontent').hide(); 
		$('#carouselbox').show('normal');
		_rebindonload = true;
		loadPod('more');
		return false;
	} else {
		window.location = "index.cfm?fuseaction=app.publicsignin";
		return;
	}
}


function setpodtitle(titleindex) {
	switch (titleindex) {
		case 1:
			$("#podtitle").attr("src", "images/template/table/sedantitle.png");
			break;
		case 2:
			$("#podtitle").attr("src", "images/template/table/wagontitle.png");
			break;
		case 3:
			$("#podtitle").attr("src", "images/template/table/hatchtitle.png");
			break;
		case 4:
			$("#podtitle").attr("src", "images/template/table/mpvtitle.png");
			break;
		case 5:
			$("#podtitle").attr("src", "images/template/table/sportstitle.png");
			break;
		case 7:
			$("#podtitle").attr("src", "images/template/table/vantitle.png");
			break;
		case 8:
			$("#podtitle").attr("src", "images/template/table/suvtitle.png");
			break;
		default:
			$("#podtitle").attr("src", "images/template/table/results.png");
	}

}

function fillfwdpage(response, success) {
    for (var i = 0; i < 6; i++) {

        //var randomtime = new Date().getTime();
		//var isloggedin = response.getResponseHeader('loggedin');


		//dump(response.loggedin);
		
		
        if (response.QUERY.DATA.VEHICLENAME[i] != null) {
			if (i == 0) {
				//$("#tabletitle").html(response.QUERY.DATA.BODYID[i]);
				setpodtitle(response.QUERY.DATA.BODYID[i]);
			}
            /* more */
            //var morehref = "index.cfm?fuseaction=app.ajaxsearch&auctionid=" + response.QUERY.DATA.AUCTIONID[i];
            //$("#morelink_" + i).attr({
            //    href: morehref
            //});
            /* showroom */
			$("#fwd_auction_row_" + i).html("Auction on : " + response.QUERY.DATA.AUCTIONDATE[i]);
            var showroomhref = "index.cfm?fuseaction=app.addtoshowroom&auctionid=" + response.QUERY.DATA.AUCTIONID[i];
           $("#showroom_" + i).attr({
                href: showroomhref
            });
			/* question */
			var questionhref = "index.cfm?fuseaction=app.vehiclequestion&auctionid=" + response.QUERY.DATA.AUCTIONID[i];
            $("#question_" + i).attr({
                href: questionhref
            });
            var imagepath = response.QUERY.DATA.CHASSISID[i] + "/" + response.QUERY.DATA.AUCTIONID[i];
            $("#year_" + i).html(response.QUERY.DATA.YEAR[i]);
            $("#makemodel_" + i).html("<strong>" + response.QUERY.DATA.MAKENAME[i] + "</strong> " + response.QUERY.DATA.VEHICLENAME[i]);
            $("#kms_" + i).html(response.QUERY.DATA.KMS[i] + " kms");

            var picturehref = "/images/chassis/" + imagepath + ".jpg";
            var picturetitle = response.QUERY.DATA.MAKENAME[i] + " " + response.QUERY.DATA.VEHICLENAME[i] + " " + response.QUERY.DATA.YEAR[i];
            var picturerel = "vehicleimagegroup_" + i + response.QUERY.DATA.AUCTIONID[i];
            $("#picture_" + i).attr({
                href: picturehref,
                title: picturetitle,
                rel: picturerel
            });
			
			//$("#sold_" + i).html("<img src='/images/template/sold.gif' width='51' height='51' />");
			
            $("#picture_" + i).html("<img src='/images/chassis/" + imagepath + "_sm.jpg' alt='Front' border='0' />");
			
			// for testing 
			//$("#picture_" + i).html("<img src='/images/nopicture.gif' width='174' height='131' alt='Front' border='0' />");

 			$("#grade_" + i).html(response.QUERY.DATA.CONDITION[i]);
			$("#ccfuel_" + i).html(response.QUERY.DATA.CC[i] + "cc / " + response.QUERY.DATA.FUELTYPE[i]);
           // $("#grade_" + i).html("Grade " + response.QUERY.DATA.CONDITION[i] + "<a href='index.cfm?fuseaction=app.vehiclequestion&auctionid=" + response.QUERY.DATA.AUCTIONID[i] + "'><img src='images/template/question.gif' alt='ask a question about this car' width='16' height='13' border='0' align='absmiddle'/></a>");
            //$("#ccfuel_" + i).html(response.QUERY.DATA.CC[i] + "cc / " + response.QUERY.DATA.FUELTYPE[i]);
           // $("#trans_" + i).html(response.QUERY.DATA.BTC_TRANSMISSION[i]);
            //$("#colour_" + i).html(response.QUERY.DATA.COLOR[i]);
            $("#price_" + i).html("Starting Bid at <strong>NZ " + response.QUERY.DATA.PRICESTART[i] + "</strong>");

            /*tooltip*/
            var equipmentspecs = response.QUERY.DATA.BTC_EQUIPMENT[i];
            $("#specs_" + i).attr({
                name: equipmentspecs
            });

            /* set lightboxes */
            var lightboxhref = "/images/chassis/" + imagepath + "_back.jpg";
            var lightboxtitle = response.QUERY.DATA.MAKENAME[i] + " " + response.QUERY.DATA.VEHICLENAME[i] + " " + response.QUERY.DATA.YEAR[i];
            var lightboxrel = "vehicleimagegroup_" + i + response.QUERY.DATA.AUCTIONID[i];
            $("#lightbox_" + i).attr({
                href: lightboxhref,
                title: lightboxtitle,
                rel: lightboxrel
            });
            $("#lightbox_" + i).html("<img src='/images/chassis/" + imagepath + "_sm.jpg' alt='Back' border='0' />");
            /* </a> */

            $("#picture_" + i).show();
            $("#vehicledetail_" + i).show();
			$("#fwd_auction_row_" + i).show();
			$("#showroom_" + i).show();
			//$("#sold_" + i).show();
        } else {
            $("#vehicledetail_" + i).hide();
            $("#picture_" + i).hide();
			$("#fwd_auction_row_" + i).hide();
			$("#showroom_" + i).hide();
			//$("#sold_" + i).hide();
        }

    } // end of loop

    var currentpageselected = $('#currentPage').html();
    
    if (_repage == 1) {
	  
	  $("#prevform").unbind();
	  $("#nextform").unbind();
	    
        doPagination(response.TOTALROWCOUNT,'F');
        // bind to the form's submit event 
        $('#nextform').submit(function(event) {
            $.pagination.setCurrent($('#nextformpage').val(), event);
            return false;
        });

        // bind to the form's submit event 
        $('#prevform').submit(function(event) {
            $.pagination.setCurrent($('#prevformpage').val(), event);
            return false;
        });

//        $("a.jTip").hover(function() {
//            JT_show(this.name, this.id, this.title)
//        },
//        function() {
//            $('#JT').remove()
//        }).click(function() {
//            return false
//        });

	   if (_rebindonload) {  
	   	rebindmorelink();
		_rebindonload = false;
	   }
	   
        /*	$('.thickbox').click(function() { 
        return false; 
    }); */
		
    } else {
		 //  tb_remove();
		 //  tb_init('a.thickbox');

	}


    var nextpage = parseInt(currentpageselected) + 1;

    var previouspage = parseInt(currentpageselected) - 1;
    if (nextpage > 4) {
        nextpage = 4;
    }
    if (previouspage < 0) {
        previouspage = 0;
    }

    $(document).ready(function() {
		
        $("#nextformpage").val(nextpage);
        $("#prevformpage").val(previouspage);

        if ((currentpageselected < 4) && (response.TOTALROWCOUNT > 6)) {
            /* right (next) hand arrow on */
            $("#nextform").show();
        } else {
            $("#nextform").hide();
        }

        if (currentpageselected > 0) {
            /* left (back) hand arrow on */
            $("#prevform").show();
        } else {
            $("#prevform").hide();
        }
		
		tb_init('a.thickbox, area.thickbox, input.thickbox');
	  
    });

    return false;
}

function fillpage(response, success) {
    for (var i = 0; i < 6; i++) {

        //var randomtime = new Date().getTime();
		//var isloggedin = response.getResponseHeader('loggedin');


		//dump(response.loggedin);
		
		
        if (response.QUERY.DATA.VEHICLENAME[i] != null) {
            /* more */
            var morehref = "index.cfm?fuseaction=app.ajaxsearch&auctionid=" + response.QUERY.DATA.AUCTIONID[i];
            $("#morelink_" + i).attr({
                href: morehref
            });
            /* showroom */
            var showroomhref = "index.cfm?fuseaction=app.addtoshowroom&auctionid=" + response.QUERY.DATA.AUCTIONID[i];
            $("#showroom_" + i).attr({
                href: showroomhref
            });
			/* question */
			var questionhref = "index.cfm?fuseaction=app.vehiclequestion&auctionid=" + response.QUERY.DATA.AUCTIONID[i];
            $("#question_" + i).attr({
                href: questionhref
            });
            var imagepath = response.QUERY.DATA.CHASSISID[i] + "/" + response.QUERY.DATA.AUCTIONID[i];
            $("#year_" + i).html(response.QUERY.DATA.YEAR[i]);
            $("#makemodel_" + i).html("<strong>" + response.QUERY.DATA.MAKENAME[i] + "</strong> " + response.QUERY.DATA.VEHICLENAME[i]);
            $("#kms_" + i).html(response.QUERY.DATA.KMS[i] + " kms");

            var picturehref = "/images/chassis/" + imagepath + ".jpg";
            var picturetitle = response.QUERY.DATA.MAKENAME[i] + " " + response.QUERY.DATA.VEHICLENAME[i] + " " + response.QUERY.DATA.YEAR[i];
            var picturerel = "vehicleimagegroup_" + i + response.QUERY.DATA.AUCTIONID[i];
            $("#picture_" + i).attr({
                href: picturehref,
                title: picturetitle,
                rel: picturerel
            });
			
			$("#sold_" + i).html("<img src='/images/template/sold.gif' width='51' height='51' />");
			
            $("#picture_" + i).html("<img src='/images/chassis/" + imagepath + "_sm.jpg' alt='Front' border='0' />");
			
			// for testing
			//$("#picture_" + i).html("<img src='/images/nopicture.gif' width='174' height='131' alt='Front' border='0' />");

            $("#grade_" + i).html(response.QUERY.DATA.CONDITION[i]);
            $("#ccfuel_" + i).html(response.QUERY.DATA.CC[i] + "cc / " + response.QUERY.DATA.FUELTYPE[i]);
            $("#trans_" + i).html(response.QUERY.DATA.BTC_TRANSMISSION[i]);
            $("#colour_" + i).html(response.QUERY.DATA.COLOR[i]);
            $("#price_" + i).html(response.QUERY.DATA.PRICEEND[i]);

            /*tooltip*/
            var equipmentspecs = response.QUERY.DATA.BTC_EQUIPMENT[i];
            $("#specs_" + i).attr({
                name: equipmentspecs
            });

            /* set lightboxes */
            var lightboxhref = "/images/chassis/" + imagepath + "_back.jpg";
            var lightboxtitle = response.QUERY.DATA.MAKENAME[i] + " " + response.QUERY.DATA.VEHICLENAME[i] + " " + response.QUERY.DATA.YEAR[i];
            var lightboxrel = "vehicleimagegroup_" + i + response.QUERY.DATA.AUCTIONID[i];
            $("#lightbox_" + i).attr({
                href: lightboxhref,
                title: lightboxtitle,
                rel: lightboxrel
            });
            $("#lightbox_" + i).html("<img src='/images/chassis/" + imagepath + "_sm.jpg' alt='Back' border='0' />");
            /* </a> */

            $("#picture_" + i).show();
            $("#vehicledetail_" + i).show();
			$("#sold_" + i).show();
			$("#showroom_" + i).show();
        } else {
            $("#vehicledetail_" + i).hide();
            $("#picture_" + i).hide();
			$("#sold_" + i).hide();
			$("#showroom_" + i).hide();
        }

    } // end of loop

    var currentpageselected = $('#currentPage').html();
    
    if (_repage == 1) {
	  
	  $("#prevform").unbind();
	  $("#nextform").unbind();
	    
        doPagination(response.TOTALROWCOUNT,'H');
        // bind to the form's submit event 
        $('#nextform').submit(function(event) {
            $.pagination.setCurrent($('#nextformpage').val(), event);
            return false;
        });

        // bind to the form's submit event 
        $('#prevform').submit(function(event) {
            $.pagination.setCurrent($('#prevformpage').val(), event);
            return false;
        });

        $("a.jTip").hover(function() {
            JT_show(this.name, this.id, this.title)
        },
        function() {
            $('#JT').remove()
        }).click(function() {
            return false
        });

	   if (_rebindonload) {  
	   	rebindmorelink();
		_rebindonload = false;
	   }
	   
        /*	$('.thickbox').click(function() { 
        return false; 
    }); */
		
    } else {
		 //  tb_remove();
		 //  tb_init('a.thickbox');

	}


    var nextpage = parseInt(currentpageselected) + 1;

    var previouspage = parseInt(currentpageselected) - 1;
    if (nextpage > 4) {
        nextpage = 4;
    }
    if (previouspage < 0) {
        previouspage = 0;
    }

    $(document).ready(function() {
		
        $("#nextformpage").val(nextpage);
        $("#prevformpage").val(previouspage);

        if ((currentpageselected < 4) && (response.TOTALROWCOUNT > 6)) {
            /* right (next) hand arrow on */
            $("#nextform").show();
        } else {
            $("#nextform").hide();
        }

        if (currentpageselected > 0) {
            /* left (back) hand arrow on */
            $("#prevform").show();
        } else {
            $("#prevform").hide();
        }
		
		tb_init('a.thickbox, area.thickbox, input.thickbox');
	  
    });

    return false;
}
