/*	
//	CarCast.co.uk 2008 (v2) 
//	Main JavaScript
*/	

jQuery( function() {
    // Put focus on indicated form elements
    $(".FocusOnLoad").focus();
    
    // Add ellipsis & title to certain size-restricted elements
    $(  "span.MakeModel,            span.Derivative," + 
        "p.VehDescDetails,          p.VehicleDescription,"+
        "p.VehDescVehicleLink,      p.VehSubDescDetails,        p.VehicleDescOptionsDetails,"+
        "p.VehDescVehicleLinkThumb, p.VehSubDescDetailsThumb,   p.VehicleDescOptionsThumb,"+
        "p.VehDescVehicleLinkSmPic, p.VehSubDescDetailsSmPic,   p.VehicleDescOptionsSmPic").
        each( function(i) {
	        if (this.style.textOverflow != undefined) {
		        this.style.textOverflow = "ellipsis";
		        this.title = this.innerText;
		    }
	    });

    // Make the Derivative filter get wider
    $("ul#RFFilter select#Filter-Derivative").css("position", "relative")
    .ready ( function() {
        $("ul#RFFilter select#Filter-Derivative").data("origWidth", $("ul#RFFilter select#Filter-Derivative").width()).data("focused", "n");
    })
    .mouseover( function() {
        $(this).width(400);
    })
    .mouseout( function() {
        if ($(this).data("focused") != "y")
            $(this).width($(this).data("origWidth")+2)
    })
    .focus( function() {
        $(this).data("focused", "y").width(400);
    })
    .blur( function() {
        $(this).data("focused", "n").width($(this).data("origWidth")+2)
    })
    .change( function() {
        $(this).blur();
    });

	// Make rel-bookmarks non-clickable, but click-copy-able. Yeah. Uh-huh.
	$(".Copy input").each(function(i) {
		this.onclick = function() { 
			var iStart = 0;
			var iLength = $(this).val().length;
			if (this.createTextRange) {
				var oRange = this.createTextRange();
				oRange.moveStart("character", iStart);
				oRange.moveEnd("character", iLength);
				oRange.select();
			} 
			else if (this.setSelectionRange) {
				this.setSelectionRange(iStart, iLength);
			}
			return false;
		};
	});

    // Contact Us form handling
    $("#ContactCar, #ContactVendor, #ContactRecentCars").hide();
    
    $("#ContactType .rbCar input").click( function() {
        $("#ContactVendor, #ContactCarCast").hide();
        $("#ContactCar, #ContactRecentCars").show();
    });

    $("#ContactType .rbVendor input").click( function() {
        $("#ContactCar, #ContactCarCast").hide();
        $("#ContactVendor, #ContactRecentCars").show();
    });
    
    $("#ContactType .rbCarCastSite input").click( function() {
        $("#ContactCar, #ContactVendor, #ContactRecentCars").hide();
        $("#ContactCarCast").show();
    });
   
    $("#ContactType .rbCarCastBusiness input").click( function() {
        $("#ContactCar, #ContactVendor, #ContactRecentCars").hide();
        $("#ContactCarCast").show();
    });
   
    $("#ContactType .rbCarCastSite input").click();
    
    if($.browser.msie == false) {
		$("body").addClass("NotIE");
    }
    
});
