local top = "spr_s03_0113_top"
local count = 5

function SpriteToTop(sprite) -- todo  sortowanie kawalkow  
    local start = bkg.elements[sprite]:GetRowIndex()
    local stop = bkg.elements[top]:GetRowIndex()
    -- print(start, " ", stop)
    for i = start, (stop - 1) do
        if bkg.elements[i + 1]:GetName()~= top then
            bkg.SwapElements(i, i + 1)
        else
            
        end
 
    end
end



function OnClick()
    local xM, yM = GetMousePos() 
    xM, yM  =  xM / 1280, yM / 720
    local pos = self:GetPosition()
    Cursors:AttachSprite(self:GetName(),Ogre.Vector2(pos.x - xM ,pos.y - yM))
    SpriteToTop(self:GetName())
end

function OnRightClick()
    local newFrame = self:GetCurrentFrame()+1
    if newFrame>3 then
        newFrame = 0
    end
    self:SetCurrentFrame(newFrame)
   PlaySound("snd_s03_0100_rotate_chunk")
end