function dollarAnimate(elem)
{
    elem.css({top: 0, opacity: 0}).show().animate({
		opacity: 1, top: -8}, 400, "linear", function() {
			$(this).animate({
				top: -18}, 1000,  "linear", function() {
					$(this).animate({
						top: -30, opacity: 0}, 600,  "linear");    
			});
	});	        				
    
}

function addNew() {
    $('#add_new_item').slideDown();
}
function del_item(id) {
    if (confirm('Biztosan törlöd? A művelet nem vonható vissza!')) {
        document.mod_form.del_item.value=id;
        document.mod_form.submit();
    }
}
function replies(id, level, force) {
    if ($('#replies_'+id)) {
        if ($('#replies_'+id).css('display')=='block' && !force) {
            // becsukni
            $('#replies_'+id).slideUp('fast');
        } else {
            // tartalom lekérdezése, show
            $.get(BASEURL+"sub/hozzaszolas.php?hsz_id="+id+"&level="+level, null, function (html) {
                $('#replies_'+id).html(html);
                $('#replies_'+id).slideDown('fast');
                //w = parseInt($('.replies').css('paddingLeft')) - - parseInt($('.replies').css('border-left-width'));
                w = parseInt($('.replies').css('paddingLeft')) - - parseInt($('.valasz').css('border-left-width')) - - parseInt($('.valasz').css('border-right-width'));
                $('#replies_'+id+' > .valasz > .box').width( parseInt($('.box').width()) - w * level );
            });
        }
    }
}
function search_replies(parent, search) {
    $('#jobb_panel').slideUp('fast');
    $.get(BASEURL+"sub/hozzaszolas.php?main_id="+parent+"&search="+search, null, function (html) {
        $('#jobb_hasab').html(html);
        $('#jobb_panel').slideDown('fast');
    });
}
function del_hsz(id, type, url, item) {
    if (confirm('Biztosan törlöd? A művelet nem vonható vissza!')) {
        $.post(BASEURL+'forum.php?', {'del_item' : 1, 'type': type, 'id': id}, function (ret) {
            alert(ret);
            //$(item).hide();
            if (url) location.href=url;
            else $(item).hide();
        });
    }
}
function del_hsz_attach(id, type, item) {
    if (confirm('Biztosan törlöd? A művelet nem vonható vissza!')) {
        $.post(BASEURL+'forum.php?', {'del_item' : 1, 'type': type, 'id': id}, function (ret) {
            alert(ret);
            $(item).hide();
        });
    }
}

function show_reply_form (id, t, level) {
    //alert(ret['msg']);
    //$.modal(ret['msg'], {'onShow': eval(ret['script'])});
    //$.modal(ret);
    $.post(BASEURL+'forum.php', {'show_form' : 'hsz', 'tema': t, 'id': id, 'level': level}, function (ret) {
        //$.modal(ret['msg'], {'onShow': eval(ret['script'])});
        $.modal(ret['msg']);
        eval(ret['script']);
    });
}
function submit_reply_form(f) {
    $.post(BASEURL+'forum.php', $(f).serializeArray(), function (ret) {
        eval(ret);
    });
}
function del_pic_hash(id, hash, tid) {
    $.ajax({
          url: "hsz_attach.php",
          type: "POST",
          async: false,
          data: {'c': 'delProductImage', "hash": hash,"pic_id": id},
           success: function(data) {
                  $("#termek_kepek_"+tid).empty();
                  for(x in data)
                  {
                      if (data[x].id) $("#termek_kepek_"+tid).append(format_pic(data[x],hash, tid));
                  }
              }
      })                        
    
}
function del_doc_hash(id, hash, tid) {
    $.ajax({
          url: "hsz_attach.php",
          type: "POST",
          async: false,
          data: {'c': 'delProductDoc', "hash": hash,"doc_id": id},
          success: function(data) {
                  $("#termek_docs_"+id).empty();
                  for(x in data)
                  {
                      if (data[x].id) $("#termek_docs_"+tid).append(format_doc(data[x],hash, tid));
                  }
              }
      })                        
    
}
function format_pic(item, hash, tid) {
    return "<li id='"+item.id+"'><img src='/attach/images/"+item.kepnev+"' /><br /><a href='javascript:del_pic_hash("+item.id+", "+hash+", "+tid+")'>X</a></li>";
}
function format_doc(item, hash, tid) {
    return "<li id='"+item.id+"'><a href='/attach/docs/"+item.file+"' target='_blank' >"+item.nev+"</a> <a href='javascript:del_doc_hash("+item.id+", "+hash+", "+tid+")'>X</a></li>";
}

function show_reg_form () {
    $.post(BASEURL+'forum.php', {'show_form' : 'reg'}, function (ret) {
        $.modal(ret['msg']);
        eval(ret['script']);
    });
}
function check_regform(f) {
    if (!f.nickname.value) { alert('Meg kell adni becenevet!'); return false; }
    if (!f.email.value) { alert('Meg kell adni e-mail címet!'); return false; }
    if (!f.pass.value) { alert('Meg kell adni jelszót!'); return false; }
    if (!f.feltetelek.checked) { alert('A felhasználási feltételeket el kell fogadni!'); return false; }
    if (f.pass.value != f.pass2.value) { alert('A két jelszó nem egyezik meg!'); return false; }
    return true;
}
function submit_reg(f) {
    if (check_regform(f)) {
        $.post(BASEURL+'forum.php', $(f).serializeArray(), function (ret) {
            eval(ret);
        });
    }
}
function reactivate(e) {
    $.post(BASEURL+'forum.php', {'submit_form':'reactivate', 'e': e}, function (ret) {
        eval(ret);
    });
}
function forgpass(e) {
    if (e) if (confirm('Biztosan szeretne új jelszót igényelni, a megadott profilhoz?')) {
        $.post(BASEURL+'forum.php', {'submit_form':'forgpass', 'e': e}, function (ret) {
            eval(ret);
        });
    }
}

function clear_form_elements(ele) {
    $(ele).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });
}

$(document).ready(function(){
   $(".banner").each(function() {
       //"Banner-" + $(this).html() + " " + 
       $(this).html($(this).width() + " x " + $(this).height());
   });
   
   var bh = $("#bal_hasab").height()+20;
   if(bh > $("#index-02").height())
   {
       $("#index-02").height(bh);
   }
   
    $("#links").sortable({
          connectWith: "tr",
          handle: ".placeholder"
      });
      
    $("#links li:last").live('focus',function(e) {
         e.preventDefault();
         var ujsor = $("#links li:last").clone().appendTo("#links");
         ujsor.find("input").each(function(i) {
            $(this).removeClass("ui-state-highlight").val("");
         });
     }); 
          
    $("#links .delrow").live("click",function(e) {
     e.preventDefault();
     if($(this).closest("li").parent().children().size() != 1)
     {
     $(this).closest("li").remove();
     }
     
     });          
   
   $("a.reply_link").live("click",function(e) {
       e.preventDefault();
       $("div[rel="+$(this).attr("rel")+"]").slideToggle();
       $(this).parent().find(".reply_link").toggle();
   });
   
   $("a.warning").click(function(e) {
       e.preventDefault();
       $.jGrowl("A hozzászóláshoz kérjük jelentkezzen be.", {theme: 'smoke'});
   });
   
});
