/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright Â© 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright Â© 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */;
/*
 * Accordionza jQuery Plugin
 * Copyright 2010, Geert De Deckere <geert@idoe.be>
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(4($){3 r=\'1.0.2\';$.K.L=4(q){3 o=$.1q(7,{},$.K.L.12,q);6.G(4(){3 c=$(6);3 d=c.1r(\'13\');3 e=d.w(\':M\');3 f=d.w(\':1s\');3 g=d.w(\'.\'+o.t);3 h=c.14();3 j=c.15();3 k=(o.N===9)?d.w(\':1t(.\'+o.t+\'):M\').O(\'.\'+o.16+\':M\').1u():o.N;3 l=h-(d.H-1)*k;3 m;3 n;3 p=9;c.I({\'17\':\'1v\',\'1w\':\'1x\'});d.I({\'17\':\'1y\',\'x\':\'0\',\'14\':l+\'8\',\'15\':j+\'8\'});d.G(4(i){$(6).I(\'P\',i*k+\'8\').A(\'B\',i)});$(\'.\'+o.C,d).I(\'x\',j+\'8\');4 Q(){R();m=1z(4(){5(!p){S().u(\'D\')}},o.18)}4 R(){1A(m)}4 T(a){5(a===U){3 a=o.19}R();5(a===9){s}1B(n);n=1C(4(){Q()},a)}4 V(a){5(a===U){3 a=7}3 b=g.1D();5(b.H){s b}v 5(a){s f}v{s g}}4 S(a){5(a===U){3 a=7}3 b=g.1E();5(b.H){s b}v 5(a){s e}v{s g}}d.1a(o.J,4(){T();$(6).u(\'D\')});d.1a(\'D\',4(){5($(6).1b(o.t)){s}g.1F(o.t);$(6).1c(o.t);d.w(\':1G(\'+$(6).A(\'B\')+\')\').G(4(){$(6).y(7).z({P:l+($(6).A(\'B\')-1)*k+\'8\'},o.W,o.X)}).1H().w(\':1I(\'+($(6).A(\'B\')+1)+\')\').G(4(){$(6).y(7).z({P:$(6).A(\'B\')*k+\'8\'},o.W,o.X)});$(\'.\'+o.C,g).y(7).z({x:j+\'8\'},o.E,o.F);$(\'.\'+o.C,$(6)).y(7).1J(o.1d).z({x:j-o.Y+\'8\'},o.E,o.F);5($.1e(o.Z)){o.Z.1f(g)}5($.1e(o.10)){o.10.1f($(6))}$.1K.u(\'1L\');g=$(6)});d.O(\'.\'+o.1g).1h(4(){T();3 a=$(6).1M(\'13\').O(\'.\'+o.C);5(!g.1b(o.11)){a.y(7).z({x:j-o.1i+\'8\'},o.E,o.F)}v{a.y(7).z({x:j-o.Y+\'8\'},o.E,o.F)}g.1N(o.11)});5(o.1j){$(1O.1P).1Q(4(a){5(a.1k==1R){V().u(o.J)}v 5(a.1k==1S){S().u(o.J)}})}5(g.H){V().u(\'D\')}v{f.1c(o.t);g=f;e.u(\'D\')}5(o.1l){5(o.1m){c.1T(4(){p=7}).1U(4(){p=9})}Q()}});s 6};$.K.L.12={1l:9,19:9,1d:0,F:\'1n\',Y:1V,1i:0,E:1o,t:\'1W\',C:\'1X\',11:\'1Y\',1g:\'1Z\',16:\'20\',1j:9,Z:1p,10:1p,1m:9,18:21,X:\'1n\',W:1o,J:\'1h\',N:9}})(22);',62,127,'|||var|function|if|this|true|px|false|||||||||||||||||||return|classSlideOpened|trigger|else|filter|top|stop|animate|data|order|classCaption|slide|captionSpeed|captionEasing|each|length|css|slideTrigger|fn|accordionza|first|slideWidthClosed|find|left|startAutoPlay|stopAutoPlay|nextSlide|pauseAutoPlay|undefined|prevSlide|slideSpeed|slideEasing|captionHeight|onSlideClose|onSlideOpen|classCaptionCollapsed|defaults|li|width|height|classHandle|position|slideDelay|autoRestartDelay|bind|hasClass|addClass|captionDelay|isFunction|call|classCaptionToggle|click|captionHeightClosed|navKey|which|autoPlay|pauseOnHover|swing|500|null|extend|children|last|not|outerWidth|relative|overflow|hidden|absolute|setInterval|clearInterval|clearTimeout|setTimeout|prev|next|removeClass|gt|end|lt|delay|event|accordionza_slide|closest|toggleClass|document|documentElement|keyup|37|39|mouseenter|mouseleave|50|slide_opened|slide_caption|slide_caption_collapsed|slide_caption_toggle|slide_handle|5000|jQuery'.split('|'),0,{}));
jQuery(document).ready(function() {
    
    /* IE6 Degrade */ 
    if(jQuery.browser.msie && jQuery.browser.version=="6.0") {
        var currentSlide=Math.floor(Math.random()*4)
        
        mySlide = jQuery('#accordion1 li .slide_content')[currentSlide];
        jQuery('#accordion1')[0].innerHTML = mySlide.innerHTML;
        jQuery('#accordion1').css('width','900px');
        jQuery('#accordion1').css('height','400px');
        jQuery('#accordion1').css('overflow','hidden');
        jQuery('.slide_caption').remove('.slide_caption_toggle');
        jQuery('.slide_caption').css('width','720px');
        jQuery('.slide_caption').css('position','relative');
        jQuery('.slide_caption').css('top','-70px');
        jQuery('.slide_caption').css('margin','0 auto');
        jQuery('#accordion1').css('background-color','#202020');
        jQuery('#accordion1 a').css('display','block');
        jQuery('#accordion1 a').css('margin','0 auto');
        jQuery('#accordion1 a').css('width','760px');
        
    }
    else {
        // Accordion Demo #1
        jQuery('#accordion1').accordionza({
            autoPlay: true,
            captionDelay: 1000,
            captionEasing: 'easeOutBounce',
            captionHeight: 50,
            captionHeightClosed: 10,
            navKey: true,
            slideDelay: 10000
        });
        
        //jQuery("#accordion1 li.slide4").click();
    }

});;
(function($){$.fn.jCarouselLite=function(o){o=$.extend({btnPrev:null,btnNext:null,btnGo:null,mouseWheel:false,auto:null,speed:200,easing:null,vertical:false,circular:true,visible:3,start:0,scroll:1,beforeStart:null,afterEnd:null},o||{});return this.each(function(){var b=false,animCss=o.vertical?"top":"left",sizeCss=o.vertical?"height":"width";var c=$(this),ul=$("ul",c),tLi=$("li",ul),tl=tLi.size(),v=o.visible;if(o.circular){ul.prepend(tLi.slice(tl-v-1+1).clone()).append(tLi.slice(0,v).clone());o.start+=v}var f=$("li",ul),itemLength=f.size(),curr=o.start;c.css("visibility","visible");f.css({overflow:"hidden",float:o.vertical?"none":"left"});ul.css({margin:"0",padding:"0",position:"relative","list-style-type":"none","z-index":"1"});c.css({overflow:"hidden",position:"relative","z-index":"2",left:"0px"});var g=o.vertical?height(f):width(f);var h=g*itemLength;var j=g*v;f.css({width:f.width(),height:f.height()});ul.css(sizeCss,h+"px").css(animCss,-(curr*g));c.css(sizeCss,j+"px");if(o.btnPrev)$(o.btnPrev).click(function(){return go(curr-o.scroll)});if(o.btnNext)$(o.btnNext).click(function(){return go(curr+o.scroll)});if(o.btnGo)$.each(o.btnGo,function(i,a){$(a).click(function(){return go(o.circular?o.visible+i:i)})});if(o.mouseWheel&&c.mousewheel)c.mousewheel(function(e,d){return d>0?go(curr-o.scroll):go(curr+o.scroll)});if(o.auto)setInterval(function(){go(curr+o.scroll)},o.auto+o.speed);function vis(){return f.slice(curr).slice(0,v)};function go(a){if(!b){if(o.beforeStart)o.beforeStart.call(this,vis());if(o.circular){if(a<=o.start-v-1){ul.css(animCss,-((itemLength-(v*2))*g)+"px");curr=a==o.start-v-1?itemLength-(v*2)-1:itemLength-(v*2)-o.scroll}else if(a>=itemLength-v+1){ul.css(animCss,-((v)*g)+"px");curr=a==itemLength-v+1?v+1:v+o.scroll}else curr=a}else{if(a<0||a>itemLength-v)return;else curr=a}b=true;ul.animate(animCss=="left"?{left:-(curr*g)}:{top:-(curr*g)},o.speed,o.easing,function(){if(o.afterEnd)o.afterEnd.call(this,vis());b=false});if(!o.circular){$(o.btnPrev+","+o.btnNext).removeClass("disabled");$((curr-o.scroll<0&&o.btnPrev)||(curr+o.scroll>itemLength-v&&o.btnNext)||[]).addClass("disabled")}}return false}})};function css(a,b){return parseInt($.css(a[0],b))||0};function width(a){return a[0].offsetWidth+css(a,'marginLeft')+css(a,'marginRight')};function height(a){return a[0].offsetHeight+css(a,'marginTop')+css(a,'marginBottom')}})(jQuery);;

function usedEquipmentCategorySearchLoad() {
    maxPrice = '100000';
    getCategoryDropDown();
    getMakeDropDown();

    jQuery("#ddlModels").attr("disabled", true);
    jQuery('#ddlMakes').change(function() {
        getModelDropDown();
    });

    getYearDropDowns();
    getSlider();

    jQuery('#btnCategorySearch').click(function() {
        doCategorySearch();
    });

}

function getCategoryDropDown() {
    url =  "js/used_equipment/used_equipment_categories";
    getDropDown(jQuery("#ddlCategories"),url,'All Types','name','tid');
}


function getMakeDropDown() {
    url =  "js/used_equipment/used_equipment_makes";
    getDropDown(jQuery("#ddlMakes"), url, 'All Manufacturers','name','tid',null);
}

function getModelDropDown() {
    url =  "js/used_equipment/used_equipment_models/" + jQuery('#ddlMakes').val();
    getDropDown(jQuery("#ddlModels"),url,'All Models','name','tid',function() {
        if(jQuery("#ddlMakes").val() != '0') {
            jQuery("#ddlModels").attr("disabled", false);
        }
        else {
            jQuery("#ddlModels").attr("disabled", true);
        }
    });

}

function getYearDropDowns() {
    url =  "js/used_equipment/used_equipment_years";
    getDropDown(jQuery("#ddlYearFrom"),url,'','field_ue_year_value','field_ue_year_value',function() {
        jQuery("#ddlYearFrom")[0].selectedIndex = jQuery("#ddlYearFrom option").size()-1;
    }
    );
    getDropDown(jQuery("#ddlYearTo"),url,'','field_ue_year_value','field_ue_year_value',function() {
        jQuery("#ddlYearTo")[0].selectedIndex = 0;
    }
    );
}




function getDropDown(dropDown, url, defaultMessage, nameField, valField, myFunction) {
    jQuery.ajax({
        type: "POST",
        url: baseUrl + url,
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            bindDropDown(dropDown, msg, defaultMessage, nameField, valField);
            if(myFunction != null) {
                myFunction();
            }
        }
    });

}

function bindDropDown(dropDown, vals, defaultMessage, nameField, valField) {

    dropDown.get(0).options.length = 0;
    if(defaultMessage != '') {
        dropDown.get(0).options[0] = new Option(defaultMessage, "0");
    }
    jQuery.each(vals, function(index, item) {
        dropDown.get(0).options[dropDown.get(0).options.length] = new Option(item[nameField] , item[valField]);
    });
}

function getSlider() {
    jQuery.ajax({
        type: "POST",
        url: baseUrl + 'js/used_equipment/used_equipment_max_price',
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            jQuery( "#slider-range" ).slider({
                range: true,
                step: 500,
                min: 0,
                max: msg[0].price,
                values: [ 0, msg[0].price ],
                slide: function( event, ui ) {
                    jQuery( "#amount" ).val( "$" + addCommas(ui.values[ 0 ]) + " - $" + addCommas(ui.values[ 1 ]) );
                }
            });
            jQuery( "#amount" ).val( "$" + addCommas(jQuery( "#slider-range" ).slider( "values", 0 )) + " - $" + addCommas(jQuery( "#slider-range" ).slider( "values", 1 )) );
            jQuery("#amount").removeAttr("style");
        }
    });
}



function doCategorySearch() {
    keyword = 0;
    category = checkEmpty(jQuery('#ddlCategories').val());
    make = checkEmpty(jQuery('#ddlMakes').val());
    model = checkEmpty(jQuery('#ddlModels').val());
    priceFrom = checkEmpty(jQuery("#slider-range").slider("values",0));
    priceTo = checkEmpty(jQuery("#slider-range").slider("values",1));
    yearFrom = checkEmpty(jQuery('#ddlYearFrom').val());
    yearTo = checkEmpty(jQuery('#ddlYearTo').val());
    document.location = baseUrl + 'used-equipment-results/' + keyword + '/' + make + '/' + model + '/' + category + '/' + priceFrom + '/' + priceTo + '/' + yearFrom + '/' + yearTo;
    return false;
}

function checkEmpty(val) {
    if(val == '' || val == null) {
        return '0';
    }
    return val;
}


function usedEquipmentKeywordSearchLoad() {
    jQuery('#btnKeywordSearch').click(function() {
        doKeywordSearch();
    });
}

function doKeywordSearch() {
    keyword = jQuery("#txtKeywords").val();
    category = 0;
    make = 0;
    model = 0;
    priceFrom = 0;
    priceTo = 0;
    yearFrom = 0;
    yearTo = 0;
    document.location = baseUrl + 'used-equipment-results/' + keyword + '/' + make + '/' + model + '/' + category + '/' + priceFrom + '/' + priceTo + '/' + yearFrom + '/' + yearTo;
    return false;
}

/*
 * Loading function for used equipment results page
 */
function usedEquipmentResultsLoad() {
    jQuery(document).ready(function() {
        loadResults();
    });
}


function unitFormat(cellValue, options, rowdata, action)
{
    mylink = "<a href='?q=node/" + rowdata.nid + "'>" + cellValue + "</a>";
    return mylink;
}

function loadResults() {
    /***
     *      title varchar(255),
            description long varchar,
            serialnumber varchar(255),
            hours varchar(255),
            price varchar(255),
            year varchar(255),
            modelid int,
            model varchar(255),
            makeid int,
            make varchar(255),
            categoryid int,
            category varchar(255),
            features long varchar,
            keyword long varchar
     */
    //Defualt pager to page 1, if there is a querystring set the pager to that value
    var $searchPageNum = 1;
    if (getParameterByName('searchPageNum') != null) {
        $searchPageNum = getParameterByName('searchPageNum');
    }
    //Default number of rows to 10, if there is a querystring set the num of rows to that value    
    var $searchRowNum = 10;
    if (getParameterByName('searchRowNum') != null) {
        $searchRowNum = getParameterByName('searchRowNum');
    }
    //Default column sorted to make, if there is a querystring set the sorted columun to that value
    var $searchSortName = 'make';
    if (getParameterByName('searchSortName') != null) {
        $searchSortName = getParameterByName('searchSortName');
    }
    //Default sort direction to acs, if there is a querystring set the sort direction to that value
    var $searchSortDirection = 'asc';
    if (getParameterByName('searchSortDirection') != null) {
        $searchSortDirection = getParameterByName('searchSortDirection');
    }

    jQuery("#results").jqGrid({
        url:  baseUrl + 'js/used_equipment/used_equipment_data' + jsonUrl,
        mytpe: "GET",
        datatype: "json",
        //colNames:['nid', 'unitnumber','title', 'description', 'serialnumber', 'modelid', 'model', 'makeid', 'make', 'categoryid', 'category', 'features','keyword'],
        //SortNames: ['make','category','model','year','price','hours','serialnumber','photo'
        colNames:['Manufacturer','Make','Type','Model','Year','Price','Hours','Serial #','Photo'],
        colModel:[
        {
            name:'detaillink',
            index: 'make'
        },

        {
            name: 'make',
            hidden: true
        },

        {
            name: 'category',
            index: 'category',
            width: 300
        },

        {
            name:'model',
            index: 'model'
        },
        {
            name:'year',
            index: 'year',
            width: 100
        },

        {
            name: 'price',
            formatter:'currency',
            formatoptions:{
                decimalSeparator:".",
                thousandsSeparator: ",",
                decimalPlaces: 2,
                prefix: "$ "
            }
        },

        {
            name: 'hours',
            index: 'hours',
            width: 100
        },
        {
            name: 'serialnumber',
            index: 'serialnumber',
            width: 100
        },
        {
            name: 'photoicon',
            index: 'photo',
            width: 100
        }

        ],
        pager: '#pager',
        page: $searchPageNum,
        rowNum:$searchRowNum,
        rowList:[10,25,50,100],
        pgbuttons: true,
        sortname: $searchSortName,
        sortorder: $searchSortDirection,
        viewrecords: true,
        gridview: true,
        autowidth: true,
        pgbuttons: true,
        height: 'auto',
        caption: 'Used Equipment',
        jsonReader : {
            repeatitems: false,
            id: "nid"
        },
        beforeSelectRow: function(rowid, e) {
            window.location = jQuery("#results #" + rowid + "  a").attr('href');

        }
    });
    jQuery("#results").jqGrid('navGrid','#pager',{
        edit:false,
        add:false,
        del:false
    });

    jQuery(".ui-icon-search").hide();
    jQuery(".ui-icon-refresh").hide();
    jQuery(".ui-jqgrid-titlebar-close").hide();
    jQuery("span.s-ico").show();

}

//Used to get value from querystring parameters
function getParameterByName(name) {
    var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

function usedEquipmentDetailLoad() {

    jQuery("#used-equipment-media-tabs").tabs();


    for(i=0;i< Slides.length;i++) {
        jQuery("#imgSlider ul").append('<li id="imgSlider-' + i + '">' + Slides[i].thumbnail + '</li>');
    }

    jQuery("#imgSlider").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        visible: 4,
        circular: false
    });

    jQuery("#imgSlider ul li").click(function() {
        if(this.id.indexOf('-')>=0 && currentIndex != this.id.substr(this.id.indexOf('-')+1)) {
            if(currentStage == 'a') {
                newStage = 'b';
            }
            else {
                newStage = 'a';
            }


            myIndex = (this.id.substr(this.id.indexOf('-')+1));
            currentIndex = myIndex;
            jQuery('#stage-' + newStage).empty();
            jQuery('#stage-' + newStage).append(Slides[myIndex].content);

            jQuery('#stage-' + currentStage).fadeOut(500);
            jQuery('#stage-' + newStage).fadeIn(500);
            currentStage = newStage;

        }
    });

    jQuery("#imgSlider").width('430');

    jQuery('#stage-' + currentStage).empty();
    jQuery('#stage-' + currentStage).append(Slides[0].content);
    jQuery('#stage-' + currentStage).fadeIn(500);

    if(Slides.length < 2) {
        jQuery(".carousel-wrapper").hide();
        jQuery("#imgSliderWrapper").height(300);
    }
    else {
        jQuery("#used-equipment-media-tabs").height(450);
    }

}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
};

