﻿$(document).ready(function(){
    $('#TrucksPosted').click(function(){
        $('#PostedTitle').html('<th>ST</th><th>STARTING CITY</th><th>DESIRED DESTINATION(S)</th><th>AVAIL. DATE</th><th>EQUIP.</th><th>SIZE</th><th>Company Name</th><th>Phone #</th>');
        //Set DisplayMode
        $('#DisplayType').val('T');
        $('#isOdd').val('1');
        $('#LoadsPosted').removeClass('SelectedPosted');
        $('#TrucksPosted').addClass('SelectedPosted');
        //Load Contents
        $('#scrollUpPart').load('Handlers/RecentlyPosted.ashx', {Type: 'TA'}); 
        
    });
    
    $('#LoadsPosted').click(function(){
        $('#PostedTitle').html('<th>St</th><th>Origin City</th><th>St</th><th>Destination City</th><th>Pickup</th><th>Equip.</th><th>Size</th><th>Weight</th><th>Company Name</th><th>Phone No.</th><th>Miles</th><th>Credit</th>');
        //Set DisplayMode
        $('#DisplayType').val('L');
        $('#isOdd').val('1');
        $('#LoadsPosted').addClass('SelectedPosted');
        $('#TrucksPosted').removeClass('SelectedPosted');
        //Load Contents
        $('#scrollUpPart').load('Handlers/RecentlyPosted.ashx', {Type: 'LA'}); 
    });
    
    $('#PostedRecently').cycle({
        fx:     'scrollUp',
        before:  onBefore,
        after:   onAfter,
        timeout: 4000,
        delay:2000
     });
});


function onBefore() {
    //$('#scrollUpPart tr:first').fadeOut('slow');
}

function onAfter() {
    //$('#scrollUpPart tr:last').fadeOut('slow');
    $.getJSON(
    "Handlers/RecentlyPosted.ashx?Type=" + $('#DisplayType').val(),
    function(json){
        $.each(json,function(i){
            if ($('#DisplayType').val() == 'T')
            {
                if ($('#isOdd').val() == '1')
                {
                    $('#scrollUpPart').prepend("<tr><td>"+json[i].OrigState+"</td><td>"+json[i].OrigCity+"</td><td>"+json[i].Dest +"</td><td>"+json[i].AvailDate+"</td><td>"+json[i].EquipCode+"</td><td>"+json[i].TruckSize+"</td><td>"+json[i].CompName +"</td><td>" + json[i].PhoneNum+"</td></tr>");
                    $('#isOdd').val('0');
                }
                else
                {
                    $('#scrollUpPart').prepend("<tr><td class='Odd'>"+json[i].OrigState+"</td><td class='Odd'>"+json[i].OrigCity+"</td><td class='Odd'>"+json[i].Dest +"</td><td class='Odd'>"+json[i].AvailDate+"</td><td class='Odd'>"+json[i].EquipCode+"</td><td class='Odd'>"+json[i].TruckSize+"</td><td class='Odd'>"+json[i].CompName +"</td><td class='Odd'>" + json[i].PhoneNum+"</td></tr>");
                    $('#isOdd').val('1');
                }
            }
            else if ($('#DisplayType').val() == 'L')
            {
                if ($('#isOdd').val() == '1')
                {
                    $('#scrollUpPart').prepend("<tr><td>"+json[i].OrigState+"</td><td>"+json[i].OrigCity+"</td><td>"+json[i].DestState+"</td><td>"+json[i].DestCity+"</td><td>"+json[i].PickUpDate+"</td><td>"+json[i].EquipCode+"</td><td>"+json[i].LoadSize+"</td><td>"+json[i].Weight+"</td><td>"+json[i].CompName +"</td><td>" + json[i].PhoneNum+"</td><td>" + json[i].Mileage + "</td><td>" + json[i].CREDIT + "</td></tr>");
                    $('#isOdd').val('0');
                }
                else
                {
                    $('#scrollUpPart').prepend("<tr><td class='Odd'>"+json[i].OrigState+"</td><td class='Odd'>"+json[i].OrigCity+"</td><td class='Odd'>"+json[i].DestState+"</td><td class='Odd'>"+json[i].DestCity+"</td><td class='Odd'>"+json[i].PickUpDate+"</td><td class='Odd'>"+json[i].EquipCode+"</td><td class='Odd'>"+json[i].LoadSize+"</td><td class='Odd'>"+json[i].Weight+"</td><td class='Odd'>"+json[i].CompName +"</td><td class='Odd'>" + json[i].PhoneNum + "</td><td class='Odd'>" + json[i].Mileage + "</td><td class='Odd'>" + json[i].CREDIT + "</td></tr>");
                    $('#isOdd').val('1');
                }
            }
            $('#scrollUpPart tr:last').remove();
            $('#scrollUpPart tr:first').fadeIn();

        })
    });

}

