    $(document).ready(function(){
        $('ul#fade a').find('img:first').each(function(){
                $(this).css('z-index', 1000);
                $(this).hover(function(){$(this).fadeOut('400');});
        });

        $('ul#fade a').find('img:last').each(function(){
                $(this).css('z-index', 1001);
                $(this).mouseover(function(){
                           $(this).animate({'opacity':0}, '400');
                });
                $(this).mouseout(function(){
                           if($(this).parent().attr('class')!='active') 
                            $(this).animate({'opacity':1}, '400');
                });
                $(this).click(function(){changeBackground($(this));});
        });

		$('a[rel*=facebox]').facebox();

    });

    function changeBackground(obj){
        if(obj.parent().attr('class')=='active') return;
        var alt = obj.attr('alt');
        var nume = parseInt(alt.substring(alt.indexOf(' ')+1));
        var tmp = nume+'.jpg';
        var url = HTTP_ADDRESS+template_path+'images/'+tmp;
        var first = $('img.flashImage');
        var second = $('img.flashImage2');
        if(parseFloat(second.css('opacity'))>0){
            first.attr('src', url);
            second.animate({'opacity':0}, 2000);
        }else{
            second.attr('src', url);
            second.animate({'opacity':1}, 2000);
        }
        $('ul#fade li a.active').find('img:last').animate({'opacity':1}, '400');
        $('ul#fade li a').attr('class', '');
        obj.css({'opacity':0});
        obj.parent().attr('class', 'active');
    }

    function submitFormViaAjax(form, url, returnResponse){
        var query = serializeForm(form);
        var response = '';
        $.ajax({
          type: "POST",
          url: url,
          data: query,
          success: function(msg){
            if(returnResponse==true)
                response = msg;
            else
                response = 'true';
          }
        });
        return response;
    }

    function serializeForm(form){
        var q='';
        form.find("*").each(function(){
              if($(this).attr('name')!=null && $(this).attr('name')!='' && $(this).attr('name')!='undefined')
                if(q.length>0) q += "&"+$(this).attr('name')+"="+$(this).val();
                    else q += $(this).attr('name')+"="+$(this).val();
        });
        return q;
    }