﻿$(document).ready(function() {
    /* Ticker fucntion start */
    $.fn.ticker = function(s, p) {

        var id = $(this).attr('id'); var first = 0;var speed = s;var pause = p;
        function removeFirst() { first = $('ul#' + id + ' li:first').html(); $('ul#' + id + ' li:first').fadeOut('slow', function() { $(this).remove(); }); addLast(first); }
        function addLast(first) { last = $('<li></li>').html(first).css('display', 'none'); $('ul#' + id).append(last); $('ul#' + id + ' li:last').fadeIn('slow'); }
        setInterval(removeFirst, pause);
    }
    /* Ticker End*/

    /* Fetch clients list. */
    $.ajax({
        type: "GET",
        url: "XML/clients.xml",
        dataType: "xml",
        async: false,
        success: function(xml) {

            var ul = $('<ul id="vticker"></ul>')
            $(xml).find('Client[visible=true]').each(function(i) {

                var name = $(this).children('Name').text();
                var href = $(this).children('Location').text();

                var a = $('<a rel="facebox" href=' + href + '></a>').html(name);
                var li = $('<li></li>').html(a);
                $(ul).append(li);
            });
            $('div#divClients').html(ul);
        }
    });

    //$('#vticker').ticker(500, 2000);

    /* Fetch Alliances */
    //            $.ajax({
    //                type: "GET",
    //                url: "XML/alliances.xml",
    //                dataType: "xml",
    //                async: false,
    //                success: function(xml) {

    //                    $(xml).find('Alliance[visible=true]').each(function(i) {

    //                        var name = $(this).children('Name').text();
    //                        var href = $(this).children('Location').text();
    //                        var img = $(this).children('Image').text();
    //                        var td = '<td><a href=' + href + ' rel="facebox"><img alt="" src="' + img + '" /></a></td>';
    //                        $('table#alliances tr').append(td);
    //                    });

    //                    //var li = $('<li></li>').append('<img alt="" src="Images/alliances_1.jpg" width="180px" height="100px" />');
    //                    //$('ul#alliances').append(li);
    //                }
    //            });

    /* Fetch Testimonials */
    $.ajax({
        type: "GET",
        url: "XML/Testimonials.xml",
        dataType: "xml",
        async: false,
        success: function(xml) {

            var ul = $('<ul id="tTicker"></ul>')
            $(xml).find('Testimonial[visible=true]').each(function(i) {
                var name = $(this).children('Name').text();
                var text = $(this).children('Text').text();
                var detail = $(this).children('Detail').text();
                var dId = $(this).children('Detail').attr('id');

                var li = '<li><p class="justify">' + text + '<b>&mdash; ' + name + '</b><a href="XML/testimonial.htm" rel="facebox">more..</a></p></li>';
                $(ul).append(li);
            });
            $('div#divTestimonial').html(ul);
        }
    });

    $('#tTicker').ticker(300, 8000);

    $('a[rel*=facebox]').facebox();
});
