var Across = {

    dmn         : 'hu-sk-cbc',
    tld         : 'eu',
    actualForm  : false,
    actualCont  : false,

    settMenuAnimation : function ()
    {
        if ( !$('header-menu') )
        {
            return false;
        }

        var a = $('header-menu').getElementsByClassName("menu-item");

        for (var i=0;i<a.length;i++)
        {
            if ( $(a[i]).hasClassName('active') )
            {
                continue;
            }

            $(a[i]).onmouseover = function () { 
                this.src = this.src.replace(/-off.gif/, "-hover.gif");
            }
            $(a[i]).onmouseout = function () { 
                this.src = this.src.replace(/-hover.gif/, "-off.gif");
            }
        }
    },

    getMessageForm : function (link, id, to)
    {
        if (Across.actualForm != false)
        {
            $(Across.actualForm).innerHTML = Across.actualCont;
        }

		new Ajax.Request(
			'?', {
				method     : "post",
				parameters : {
					Func : 'show.getMessageForm',
					id   : id
				},
				onComplete : function (request) {

                    Across.actualForm = to;
                    Across.actualCont = $(to).innerHTML;
                    $(to).innerHTML = request.responseText;
				}
			}
		);
    },

    sendM : function (thisFom)
    {
        new Ajax.Request(
            '/', {
                method: "post",
                parameters: 'Func=show.sendMessage&'+$(thisFom).serialize(),
                onComplete: function (request){
                    eval("var Result = " + request.responseText);

                    if (Result.error)
                    {
                        Object.keys(Result.items).each(function(s, index) {
                            $(s).value = Result.items[s];
                        });
                    }
                    else
                    {
                        alert(Result.message);
                        $(Across.actualForm).innerHTML = '';
                    }
                }
            }
        ); 
    },
	
	Subscribe : function(thisFom)
	{
		new Ajax.Request(
            '/', {
                method: "post",
                parameters: 'Func=newsletter.Subscribe&'+$(thisFom).serialize(),
                onComplete: function (request){
                    eval("var Result = " + request.responseText);

                    if (Result.error)
                    {
                        var string = '<ul>';
						
						Object.keys(Result.items).each(function(s, index) {
							string += '<li><label for="newsletter_'+s+'">'+Result.items[s]+'</label></li>';
                        });
						string += '</ul>';

						$('subs-errors').innerHTML = string;
                    }
                    else
                    {
						Form.reset('subscribeForm');
                        $('subs-errors').innerHTML = Result.message;
                    }
                }
            }
        );
	},

	clearField : function (item)
	{
		if ($(item).value == $(item).defaultValue)
		{
			$(item).value = '';
		}
	},

    getForumCommentForm : function (to, topic)
    {
        id = arguments[1] ? arguments[1] : false;

		new Ajax.Request(
			'?', {
				method     : "post",
				parameters : {
					Func  : 'forum.getForumCommentForm',
					id    : id,
					topic : topic
				},
				onComplete : function (request) {
                    $(to).innerHTML = request.responseText;
                    Across.actualForm = to;
				}
			}
		);
    },

    sendForumCommentForm : function (thisFom)
    {
        new Ajax.Request(
            '/', {
                method: "post",
                parameters: 'Func=forum.sendMessage&'+$(thisFom).serialize(),
                onComplete: function (request){
                    eval("var Result = " + request.responseText);

                    if (Result.error)
                    {
                        Object.keys(Result.items).each(function(s, index) {

                            if (s == 'captcha')
                            {
                                var d = new Date();
                                $('captchaImage').src = '?getcaptcha&date='+d.getUTCSeconds();
                            }

                            $(s).value = Result.items[s];
                        });
                    }
                    else
                    {
                        alert(Result.message);
                        $(Across.actualForm).innerHTML = '';
                        window.location = window.location;
                    }
                }
            }
        ); 
    },

    toggleVideo : function ()
    {
        if (!$('player_holder'))
        {
            return false;
        }

//        $('player_holder').style.visibility = ($('player_holder').style.visibility == 'hidden') ? 'visible' : 'hidden';
/*
        if ($('player_holder'))
        {
        }
*/
    }
};

Event.observe(window, 'load', function () {
    Across.settMenuAnimation();
});

