function USRPictures()
{
    this.request = BASE_URL + 'indexajax.php?action=USRPictures';
    this.data = null;
}


USRPictures.prototype.listByUser = function(offset, usrzu_id) 
{	
	this.request = this.request + '&start=listByUser';
	this.data = {'usrzu_id' : usrzu_id, 'offset' : offset}
	
	this.get();
}


USRPictures.prototype.showByUser = function(id, usrzu_id) 
{
	this.request = this.request + '&start=showByUser';
	this.data = {'usrzu_id' : usrzu_id, 'usrp_id' : id}
	
	this.get();
}

USRPictures.prototype.limitedlistByUser = function(usrzu_id) 
{
	this.request = this.request + '&start=limitedlistByUser';
	this.data = {'usrzu_id' : usrzu_id}
	
	var thumbs = false;
	
	$.ajax({
        'type'     : "get",
        'url'      : this.request,
        'data'     : this.data,
        'dataType' : "xml",
        'success'  : function(xml) {
        	
        	$("response > thumbs", xml).each (
                function()
                {
                	$('#gallery-thumbs-shortlist').html($(this).text());
                	thumbs = true;
                }
            );
        },
        
        'complete' : function()
        {
        	if(thumbs == false)
        	{
        		$('#gallery-thumbs-shortlist-more').html(null);
        	}
        }
    });
	
	return false;
}


USRPictures.prototype.newestUniqueList = function(page, onpage, limit, offset, sex, placeholder) 
{
	this.request = this.request + '&start=newestUniqueList';
	
	$.ajax({
        'type'     : "get",
        'url'      : this.request,
        'dataType' : "xml",
        'data'     : {
			'page'    : page,
			'onpage'  : onpage,
			'limit'   : limit,
			'sex'     : sex,
			'offset'  : offset			
        },
        'success'  : function(xml) {
        	$("response > items", xml).each (
                function()
                {
                	$(placeholder).html($(this).text());
                }
            );
        }
    });
	
	return false;
}


USRPictures.prototype.topmostUniqueList = function(page, onpage, limit, offset, sex, placeholder) 
{
	this.request = this.request + '&start=topmostUniqueList';
	
	$.ajax({
        'type'     : "get",
        'url'      : this.request,
        'dataType' : "xml",
        'data'     : {
			'page'    : page,
			'onpage'  : onpage,
			'limit'   : limit,
			'sex'     : sex,
			'offset'  : offset			
        },
        'success'  : function(xml) {
        	$("response > items", xml).each (
                function()
                {
                	$(placeholder).html($(this).text());
                }
            );
        }
    });
	
	return false;
}


USRPictures.prototype.get = function() 
{   
	if($('.msg').length)
	{
		$('.msg').remove();
	}
	
	$.ajax({
        'type'     : "get",
        'url'      : this.request,
        'data'     : this.data,
        'dataType' : "xml",
        'success'  : function(xml) {
        	
        	$("response > pic", xml).each (
                function()
                {
                	$('#full-photo-content').html($(this).text());
                }
            );
        	
        	$("response > fb-like", xml).each (
                function()
                {
                	$('#fb-like-pane').html($(this).text());
                }
            );
        	
        	$("response > thumbs", xml).each (
                function()
                {
                	$('#gallery-thumbs-content').html($(this).text());
                }
            );
        	
        	$("response > rating", xml).each (
                function()
                {
                	$('#pic-rating-box-content').html($(this).text());
                }
            );
        	
        	$("response > title", xml).each (
                function()
                {
                	$('#pic-change-title-pre-data strong').html($(this).text());
                	$('#header-title-edit-input').attr('value', $(this).text());
                }
            );
        	
        	$("response > counter", xml).each (
                    function()
                    {
                    	$('#pic-change-title-pre-data span').html($(this).text());
                    }
                );
        	
        	$("response > id", xml).each (
                function()
                {
                	$('#usrp_id').attr('value' ,($(this).text()));
                	$('#gallery-photo-header-content').show();
                	$('.gallery-main').removeClass('gallery-no-photo');
                	$('#gallery-report-photo-content').show();
                	$.address.value('pic' + ($(this).text()));
                	
                	$('.gallery-report-photo').html('<a class="thickbox" href="' + BASE_URL + 'zglos_naduzycie_galeria?modal=true&width=456&height=300&usrp_id=' + ($(this).text()) +  '">Zgłoś nadużycie</a>');
                }
            );
        	
        	$("response > offset", xml).each ( function() {
				$('#gallery-offset').attr('value', ($(this).text()));
			});
        	
        	$("response > not_found", xml).each ( function() {
        		if(($(this).text()))
        		{
        			POSITION_Y = $('#full-photo-content').offset().top + 165;
        			POSITION_X = $('#full-photo-content').offset().left + 135;

        			msgerror('Nie znaleziono zdjęcia. Zobacz inne zdjęcia klubowicza.');
        		}
			});
        	
        	$("response > empty", xml).each (
                function()
                {
                	if($(this).text() == 1)
                	{
                		$('.gallery-main').addClass('gallery-no-photo');
    					$('#full-photo-content').html('');
    					$('#gallery-thumbs-content').html('');
    					$('#pic-rating-box-content').html('');
    					$('#header-title-edit-input').attr('');
    					$('#pic-change-title-pre-data strong').html('');
    					$('#pic-change-title-pre-data span').html('');
    					$('#usrp_id').attr('value' , 0);
    					$('#gallery-photo-header-content').hide();
    					$('#gallery-report-photo-content').hide();
                	}                    	
                }
            );
        },
        
        'complete' : function()
        {
        	var statFrameGallery = '<iframe width="1" height="1" marginheight="0" marginwidth="0" scrolling="no" noresize="noresize" frameborder="no" id="gallery-stat-frame" src="' + CONTENT_PATH + '/content/stat/gallery.html" ></iframe>';
        	$('#g-stat-footer').html(statFrameGallery);
        }
    });
	
	return false;
}


USRPictures.prototype.newestContestList = function(placeholder) 
{
	this.request = this.request + '&start=newestContestList';
	
	$.ajax({
        'type'     : "get",
        'url'      : this.request,
        'dataType' : "xml",
        'success'  : function(xml) {
        	$("response > html", xml).each (
                function()
                {
                	$(placeholder).html($(this).text());
                }
            );
        }
    });
	
	return false;
}

USRPictures.prototype.topmostContestList = function(placeholder) 
{
	this.request = this.request + '&start=topmostContestList';
	
	$.ajax({
        'type'     : "get",
        'url'      : this.request,
        'dataType' : "xml",
        'success'  : function(xml) {
        	$("response > html", xml).each (
                function()
                {
                	$(placeholder).html($(this).text());
                }
            );
        }
    });
	
	return false;
}
