﻿function randomQuote(){
    if($('.quote').html() != null)
    {
        $.ajax({
            cache: false,
            url: "http://www.ocaventures.com/OCARssNews.ashx?contenttype=9",
            success: function(xml){
                var size = $("testimonial", xml).size();
                var random = Math.floor(Math.random()*size);
                var quote = $("testimonial:eq("+random+")", xml).text(); 
                var qu = quote.substring(quote.indexOf('<quote>'), quote.indexOf('</quote>')); 
                var author = $("name:eq("+random+")", xml).text();
                if(qu == ""){       
                    var quote = quote.substring(quote.indexOf('"'), quote.length);
                    var quote = quote.replace(/"/g, '');                                  
                    if(quote.length > 150)
                    {
                        var quote2 = quote.substring(150, quote.length);
                        var pos = quote2.indexOf(" ") + 150;
                        quote = quote.substring(0, pos) + '...';
                    }
                }
                else
                    quote = qu;
                
                var position = $("position:eq("+random+")", xml).text();
                var comp = $("company:eq("+random+")", xml).text();   
                
                author = author + " - " + position + "<br />" + comp;                               
                
                //$('.quote').html(author);
                $('em', '.quote:eq(0)').html(quote);                         
                $('.quote:eq(1)').html(author);
            }
        });
    }
}

$(function(){
    randomQuote();
});
