/*	
//	CarCast.co.uk 2008 (v1) 
//	Vehicle Info JavaScript
*/	
	
jQuery( function() {
    $(".picSwitch").click( function() {
        $(".imgVehicle").attr("src", $(this).attr("src").replace("/picswitch/", "/full/"));
        $(".imgVehicle").show();
        $(".vidVehicle").hide();
        $("#fdbk_tab").show();
        
        return false;
    });
    
    $(".vidSwitch")
    .click( function() {
        $(".vidVehicle").show();
        $(".imgVehicle").hide();
        $("#fdbk_tab").hide();
        
        return false;
    });

    $(".imgVehicle").click(function() {
        if ($(".imgVehicle").attr("src").indexOf(".jpg") > 0) {
            window.open($(".imgVehicle").attr("src").replace("/full/", "/orig/"));
        }
        return false;
    });
    
    //$("a.Next").click( LoadNextPage );
    //$("a.FlickerNext").click( LoadNextPage );
    
    //SetInternalLinks();
});	

function LoadNextPage(event) {
    $("a.Next").unbind().each( function() {
        $(this).attr("class", $(this).attr("class").replace(" Next", ""));
    });
    
    currentLink = $("a.FlickerNext");
    currentLink.focus();
    currentLinkParent = currentLink.parent();
    currentCell = $(".VehicleDetails");
    
    //alert("/Ajax/Search?from=" + currentLink.attr("href").replace("?", "&"));
    $.ajax({
        url: "/Ajax/Search?from=" + currentLink.attr("href").replace("?", "&"),
        type: 'GET',
        dataType: 'html',
        timeout: 10000,
        beforeSend: function(){
            currentLinkParent.empty().append('<img src="/img/s/ajax-loading.gif" width="32" alt="Loading..." align="absbottom" /><span class="LoadingLink">Loading</span>');
        },
        error: function(){
            // Failed! Transfer to the originally linked page
            //alert("failed");
            document.location = currentLink.attr("href");
        },
        success: function(html){
            // Success! show the data
            //alert(html);
            currentLinkParent.empty();
            $("#SearchResultsResults").append(html);
            $("a.FlickerNext").click( LoadNextPage );
            SetInternalLinks()
        }
    });
    
    return false;
}

function SetInternalLinks() {
    $("div.ResultsPage").each( function() {
        var page = $(this).attr("class").split(" ")[1];
        $("a."+page).attr("href", "#ResultsPage"+page);
    });
    
    $("a.Next").click( LoadNextPage );
}