function ajaxSubmit(obj) {
var params = {};
var form = $("#" + $(obj).attr('name'));
var i = 0;
form
.find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea")
.filter(":enabled")
.each(function() {
	params[ this.name || this.id || this.parentNode.name+(i++) || this.parentNode.id+(i++) ] = this.value;
	});
$.ajax({
  	type: "POST",
  	url: "ajax_reg.php?method=" + $(obj).attr('id'),
  	data: params,
  	beforeSend: function(msg){
  		form.fadeOut('slow');
  		},
  	success: function(msg){
  		 
  		form.fadeIn('slow'); 
    	form.html(msg);
  	}
});
}

var allow_opacity = true;

function mk_transparent(e,i) {
  //if (allow_opacity)
  //if (!$(e).closest("div").hasClass("opened")) 
  //  $(e).stop().animate({opacity:i});
}

var current = 0; // otvoreny banner
var toggle = true;      // true = slideshow bezi, false = slideshow stoji
var banners = [];       // idcka bannerov
var slide_delay = 3000; // frekvencia slidovania
var timer = false;

$(document).ready(function(){
  
  if ($("#banner_main_wrapper").hasClass("slideshow")) { 
  
    // zistime idcka vsetkych bannerov
    $(".banner_main_item input.itemid").each(function(i,e){
      banners[i] = e.value;
    });
    
    // spustime casovanie slideshow
    timer = setTimeout(function(){start_slideshow()},slide_delay);
    // nabindujeme eventy pri prechode mysi nad bannermi
    $("#banner_main_wrapper").mouseenter(function(){
      toggle = false; 
      clearTimeout(timer);
    });
    
    $("#banner_main_wrapper").mouseleave(function(){
      toggle = true; 
      timer = setTimeout(function(){start_slideshow()},slide_delay);
    });
  
  }
  
});

function start_slideshow() {
  
  if (toggle==false) return;
  
  if (current==0) current = banners[0];
  
  var next = 0;
  is_current = false;
  for (i in banners) {
    if (is_current) {
      next = banners[i];
      break;
    }
    if (banners[i] == current) is_current = true;
  }
  if (next == 0) next = banners[0];
  
  var link = $("#banner_main"+next+" input.itemlink").val();
  
  toggle_banner(next,link);
  timer = setTimeout(function(){start_slideshow()},slide_delay);
  
}

function toggle_banner(id,link) {
  current = id;
      
  if ($("#banner_main"+id).hasClass("closed")) {
    allow_opacity = false;
    //$(".banner_main_item .banner_main_item_info").fadeOut();
    $(".banner_main_item").animate({
      width: 98
    },{complete: function(){
      $(".banner_main_item").removeClass("opened").addClass("closed");
    }});
    $("#banner_main"+id).animate({
      width: 464
    },{complete: function(){
      //$("#banner_main"+id+" .banner_main_item_info").fadeIn();
      $("#banner_main"+id).removeClass("closed").addClass("opened");
      allow_opacity = true;
    }});
  } else {
    if (link!='') 
      document.location.href=link;
  }

}
