/*
$(document).ajaxComplete(function(e, x) {
    alert(x.getResponseHeader("Content-Type"));
});
/**/
function GetHeadBanner(url){
	var url2='/p/?url='+escape(url)
	//alert(url2);
	$.ajax({
        type: "GET",
        url: url2,
        dataType: "text/xml",
        success: function (data) {
			var items=GetPLItems(data);
			//console.log(items);
			//alert(items);
			ShowHeadBanner(items,'head_items',5);
		}
    });
};
function ShowHeadBanner(items,id,display_count){
	//alert(data );
	var count = 0,html='',i=0;
	//*
	$('#'+id+' tr').empty();
	for (i in items) {
		if (count>=display_count) break;
		html+='<td class="'+items[i].sex+'" align="center">';
		html+='<a href="'+items[i].link+'" class="photoXML">';
        html+='<img src="'+items[i].foto+'" height="100px" style="border:0;" alt="" />';
        html+='</a><a class="text" href="'+items[i].link+'">'+items[i].name+', '+items[i].age;
        html+='<br />Ищу '+items[i].search+'</a></td>';
		count++;
	}
	$('#'+id+' tr').append(html);
	$('#'+id).show();
};
function GetPLItem(data){
	return {
		link:data.match(/<link>([^<]+)/i).pop(),
		sex:data.match(/<sex>([^<]+)/i).pop()=='Девушка'?'f':'m',
		foto:data.match(/<foto>([^<]+)/i).pop(),
		name:data.match(/<name>([^<]+)/i).pop(),
		age:data.match(/<age>([^<]+)/i).pop(),
		search:data.match(/<search>([^<]+)/i).pop().toLowerCase()
	}
	/*
	return {
		link:data.match(/<link>([^<]+)/i).pop(),
		sex:data.match(/<sex>([^<]+)/i).pop()=='Девушка'?'f':'m',
//		sex:$(data).find('sex').html()=='Девушка'?'f':'m',
		foto:$(data).find('foto').html(),
		name:$(data).find('name').html(),
		age:$(data).find('age').html(),
		search:$(data).find('search').html().toLowerCase()
	}
	/**/
};
function GetPLItems(data) {
	var items = [],po1=0,pos2=0,item='';
	pos1 = data.indexOf('<ITEM>',data);
	while (pos1>=0) {
		pos2 = data.indexOf('</ITEM>',data);
		item=data.substring(pos1,pos2+7);
		data = data.substring(pos2+7);
		pos1 = data.indexOf('<ITEM>',data);
		items.push(GetPLItem(item));
	}
	return items;
};
function GetMBItem(data) {
	var search = data.match(/<search>([^<]+)/i);
	return {
		link:data.match(/<url>([^<]+)/i).pop(),
		sex:data.match(/<gender type="([^"]+)"/i).pop()=='F'?'f':'m',
		foto:data.match(/<src>([^<]+)/i).pop(),
		name:data.match(/<name>([^<]+)/i).pop(),
		age:data.match(/<age>([^<]+)/i).pop(),
		search:search?search.pop().toLowerCase():''
	}
}
function GetMBItems(data) {
	var items = [],po1=0,pos2=0,item='';
	pos1 = data.indexOf('<anketa',data);
	while (pos1>=0) {
		pos2 = data.indexOf('</anketa>',data);
		item=data.substring(pos1,pos2+7);
		data = data.substring(pos2+7);
		items.push(GetMBItem(item));
		pos1 = data.indexOf('<anketa',data);
	}
	return items;
};
function ShowListBanner(items,id,display_count){
	var count = 0,html='',i=0;
	$('#'+id).empty();
	for (i in items) {
		if (count>=display_count) break;
        html+='<li class="'+items[i].sex+'">';
        html+='<a href="'+items[i].link+'" class="photoXML-DOWN"><img src="'+items[i].foto+'" height="100px" style="border:0;" alt="" />';
        html+='</a><a class="text" href="'+items[i].link+'">'+items[i].name+', '+items[i].age;
        if (items[i].search) {
        	html+='<br />Ищу '+items[i].search;
        }
        html+='</a></li>';
		count++;
	}
	$('#'+id).append(html);
	$('#'+id).show();
};
function GetListBanner(url){
	$.ajax({
        type: "GET",
        url: '/p/?url='+escape(url),
        dataType: "text/xml",
        success: function (data) {
			var items=GetPLItems(data);
			//console.log(items);
			ShowListBanner(items,'list_banner',4);
		}
    });
};
