var closetimer;

$(document).ready(function () {

	$('.gallery_box a').lightBox();

    // Rounded corners
    //if($.browser.msie && $.browser.version.substr(0,1)<7){
    //} else {
    //alert($.browser.version.substr(0,1));
    if ($.browser.msie && $.browser.version.substr(0, 1) > 6) {
        $('#home_vehicle_search').each(function () {
            var radii = '<span class="tl"></span><span class="tr"></span><span class="bl"></span><span class="br"></span>';
            markup = $(this).html() + radii;
            $(this).html(markup);
        });
        $('.rounded').each(function () {
            var radii = '<span class="tl"></span><span class="tr"></span><span class="bl"></span><span class="br"></span>';
            markup = $(this).html() + radii;
            $(this).html(markup);
        });
        $('.roundedgrey').each(function () {
            var radii = '<span class="tl"></span><span class="tr"></span><span class="bl"></span><span class="br"></span>';
            markup = $(this).html() + radii;
            $(this).html(markup);
        });
    }


    /*Gallery Switch*/
    $(".thumbs_list li a").click(function () {

        var largePath = $(this).attr("href");

        $("#largeImg").attr({ src: largePath }); return false;

    });

    // Add Scroller Object for homepage
    $jScroller.add("#vendor_logo_box", "#vendor_logo_box_slider", "left", 5);
    // Start Autoscroller
    $jScroller.start();

    $('#slideshow').cycle({
        fx: 'fade',
        speed: 1500,
        timeout: 10000,
        pager: '#pager'
    });

    // Set up the auction calendar tooltip
    initcalendartooltip();

	// Do rounded corners on HP newsimage
    var newsImage = $('#home_news_image_wrap img').attr('src');
    $('#home_news_image_wrap').css("background", "url('" + newsImage + "')");
    $('#home_news_image_wrap').html('');
    
    // Tooltip for grading system
	$('a.tooltip-link').hover(function(){
		var grade = $('a.tooltip-link').text();
		var new_html = '';
		if(grade == 'A') {
			new_html = '<h3>Grade A</h3><p>The Vehicle is in excellent condition, with only minor or no defects in panel surfaces, these would not require body or paintwork, although limited quality repairs may have been performed. Vehicles are in a condition which is ready to submit for retail sale, these vehicles will require no remedial work to body panels, paintwork, interior or glass, & without items/parts missing. These vehicles would be suitable for sale to a retail customer.</p>';
		} else if(grade == 'B') {
			new_html = '<h3>Grade B</h3><p>The vehicle is better than average with only minor chips or scratches in panel surfaces which may require minor body and paint work or paint dent repair. Vehicles that if some limited minor body repairs were carried out the cars would then be a grade A, i.e. minor stone chips, scratches to bumpers/mouldings, removal of minor dents.</p>';
		} else if(grade == 'C') {
			new_html = '<h3>Grade C</h3><p>The vehicle has normal wear and tear (for example, parking lot dings, small scratches, chips and/or minor broken parts). It may require minor conventional body and paintwork or replacement of parts. Vehicles that will require up to 3 panels that would require body shop repairs i.e. scratches/scuffs, dents that would not repair and unsatisfactory repairs that would require refinish.</p>';
		} else if(grade == 'D') {
			new_html = '<h3>Grade D</h3><p>The vehicle shows signs of excessive wear and tear. The body may have dents, scratches and body panels that require replacement. Parts may be broken or missing. Vehicles that will require 4 or more panels to have body shop repairs.</p>';
		} else if(grade == 'E') {
			new_html = '<h3>Grade E</h3><p>The vehicle shows signs of severe abuse or may have sustained major damage.</p>';
		} else {
			new_html = '<h3>Grading System</h3>';
		}
		$('.tooltip-box').html(new_html);
		$('.tooltip-box').toggle();
	});    
    

});


function initcalendartooltip(){

    // Set up the auction calendar tooltip
    $('#footer_wrap').after('<div id="tooltipbox" class="tooltip"></div>');
    $('#tooltipbox').css("position", "absolute");
    $('#tooltipbox').css("display", "none");
    $(".home_auction_calendar_table tr td.saleday a").mouseover(function (e) {
        window.clearTimeout(closetimer);
        $('#tooltipbox').html($(this).parent().children('.tooltip').html());
        $('#tooltipbox').css("left", (e.pageX + 10) + 'px');
        $('#tooltipbox').css("top", (e.pageY) + 'px');
        $('#tooltipbox').css("display", "block");
    });

    $(".home_auction_calendar_table tr td.saleday a").mouseout(function () {
        window.clearTimeout(closetimer);
        closetimer = window.setTimeout(calendartooltipclose, 1500);
    });

    $("#tooltipbox").mouseover(function () {
    	//if(isObject(closetimer)){
        window.clearTimeout(closetimer);
        //}
    });

    $("#tooltipbox").mouseout(function () {
        window.clearTimeout(closetimer);
        closetimer = window.setTimeout(calendartooltipclose, 1500);
    });

    $('.home_auction_calendar_table').removeAttr("title");
    $('.saleday').removeAttr("title");

}

function calendartooltipclose(event){
	
	$('#tooltipbox').css("display", "none");

}


function isObject( what )
{
	return (typeof what == 'object');
}

