$(document).ready(function() {
   
    $.get('clientes.xml',function(xml){                   

        var text_html = '';
        var text_html2 = '';
        var clientes = new Array();
        var cont = 0;

        $(xml).find("cliente").each(function () {            
            clientes[cont] = $(this).attr('link')+";"+$(this).text();           
            cont++;
        });
       
        for(var x=0; x<clientes.length; x++) {
            vt = clientes[x].split(";");
			
			if($.cookie('from') == 'wm' && vt[0] == 'www.pontofrio.com.br') {
				continue;	
			}
			
			if($.cookie('from') == 'wm' && vt[0] == 'www.extra.com.br') {
				continue;	
			}
			
			text_html2 += '<div class="box-cliente-border"> <div class="box-cliente">';
			text_html2 += "<a href=\"http://"+ vt[0] +"\"><img src=\"/img/clientes/"+ vt[1].replace(/^\s+|\s+$/g,'') +"\" alt=" + vt[2] + " /></a>";
			text_html2 += '</div></div>';
			
        }

        clientes.sort(function() {return 0.5 - Math.random()});

        for(var x=0; x<6; x++) {
            vt = clientes[x].split(";");
			
			//sortear cliente com 10 posicoes a frente
			if($.cookie('from') == 'wm' && vt[0] == 'www.pontofrio.com.br') {
				vt = clientes[x + 10].split(";");
			}
			
			//sortear cliente com 8 posicoes a frente
			if($.cookie('from') == 'wm' && vt[0] == 'www.extra.com.br') {
				vt = clientes[x + 8].split(";");
			}
			
            text_html += '<div class="box-cliente-border"> <div class="box-cliente">';
            text_html += "<a href=\"http://"+ vt[0] +"\"><img src=\"/img/clientes/"+ vt[1].replace(/^\s+|\s+$/g,'') +"\" alt=" + vt[2] + " /></a>";
            text_html += '</div></div>';
        }
        
        $("#random_clientes").html(text_html);
        $("#xml_clientes").html(text_html2);
    });
});





