$(function(){
	downloads.start();
});

downloads = {

	start: function(){
		this.tableDom();
	},

	tableDom: function(){
		var _path = location.search ? decodeURI(location.search.replace(/^\?path=/, '')) : '';
		$('<img src="/ajax-loader-big.gif" />').css({
			position: 'absolute',
			top: '100px',
			left: ($('#result').width() - 35) / 2 + 'px'
		}).appendTo('#result');
		downloads.httpAjax({
			post: {
				ajax: 'getDom',
				path: _path
			},
			func: function(res){
				if(res.status == 'ok'){
					$('#result').fadeOut('fast', function(){
						$(this).html(res.dom).fadeIn('fast');
						$('tr:odd', '#downloads').addClass('odd');
					});
				}else{
					alert(res.status);
				}
			}
		});
	},

	httpAjax: function(obj){
		$.ajax({
			url: '/index.html',
			cache: false,
			type: 'POST',
			dataType: 'json',
			data: obj.post,
			error: function(XMLHttpRequest, textStatus, errorThrown){
//				alert("ERROR!\n\nXMLHttpRequest: " + XMLHttpRequest + "\ntextStatus: " + textStatus + "\nerrorThrown: " + errorThrown);
			},
			success: function(res){
				obj.func(res);
			}
		});
	}

}
