var Across = {

    FormType       : 'update',

	setType : function (to)
	{
		Across.FormType = to;
	},

    back : function ()
    {
        history.go(-1);
    },

    reloadWin : function (to)
    {
        if (to == false)
        {
            window.location = window.location.href;
        }
        else
        {
            window.location = to;
        }
    },

    clearField : function (item)
    {
        $(item).attr('value', '');
    },

    sendM : function (thisFom)
    {
        Across.actualForm = thisFom;

        $.post("/",
            'Func=contacts.sendMessage&'+$(thisFom).serialize(),
            function(data) {

                if (data.error)
                {
                    jQuery.each(data.items, function(i, val) {
                        $('#'+i).val(val);
                    });
                }
                else
                {

                    Across.actualForm.reset();
                    alert(data.message);
                }
            },
            "json"
            );
    },

    registrationType: function()
    {

            if($('#type2').attr('checked') === true)
            {
                $('.user_documents').show();
            }
            else
            {
                $('.user_documents').hide();
            }

    },

    initTab: function ()
    {
        var tabContainers = $('div.tabcontent > div');
        var tabs = $('div.tabs > a');

		if ( $('div.tabcontent > div.active').size() > 0 )
		{
			$('div.tabcontent > div').hide().filter('.active').show();

			tabs.removeClass('active');
			tabs.each(function (i) {
				if ( $(this).attr('rel') == $('div.tabcontent > div.active').attr('id') ) {
					$(this).addClass('active');
				}
			});
		}
		else
		{
	        tabContainers.hide().filter(':first').show();
		}

        $('.tabs a').click( function(){

			tabContainers.hide();
            tabs.removeClass('active');
            $(this).addClass('active');

            $('#' + $(this).attr('rel')).show();
        });
    },

    showImages : function ()
    {
		$('div.tabcontent > div').hide();
		$('#images').show();
		$(document).scrollTo( $('#images'), 800 );

		$('div.tabs > a').each(function (i) {

			if ( $(this).attr('rel') == 'images' ) {
				$('div.tabs > a').removeClass('active');
				$(this).addClass('active');
			}
		});
    },

    initLeftTabs: function ()
    {
        var tabContainers = $('div.left-data > div.boxbody-np');
        var tabs = $('div.left-data > div.tabs-image > a');

		if ( $('div.tabs-image > a').size() > 0 )
		{
			$('div.left-data > div.boxbody-np').hide().filter('.active').show();

			tabs.removeClass('active');

			tabs.each(function (i) {
				if ( $(this).attr('rel') == $('div.left-data > div.boxbody-np').filter('.active').attr('id') ) {
					$(this).addClass('active');
				}
			});
		}
		else
		{
	        tabContainers.hide().filter(':first').show();
		}

        $('div.tabs-image > a').click( function(){
			
			tabContainers.hide();
            tabs.removeClass('active');
            $(this).addClass('active');

			tabContainers.each(function (i, val) {
				if ( $(this).attr('rel') == $(val).attr('id') ) {
					$(this).addClass('active');
				}
			});

            $('#' + $(this).attr('rel')).show();
        });
    },

    copyFields : function (items)
    {
        jQuery.each(items, function(i, val) {
            $('#'+val).val( $('#'+i).val() );
        });
    },

	pushBasket : function (thisFom, id)
    {
        Across.actualForm = thisFom;

        $.post("/",
            'Func=products.basket.pushBasket&id='+id+'&'+$(thisFom).serialize(),
            function(data) {
				$('#right-basket').html(data.data);
				alert('Az Ön kosarának tartalma frissült!');
            },
            "json"
		);
	},

	updateBasket : function (thisFom)
    {
        Across.actualForm = thisFom;

        $.post("/",
            'Func=products.basket.updateBasket&'+$(thisFom).serialize(),
            function(data) {

				if (Across.FormType == 'update')
				{
					Across.reloadWin(false);
				}
				else
				{
					Across.reloadWin(data);
				}
            },
            "text"
		);
	},
	
	toggleBox : function(boxid)
	{
		$('#'+boxid).toggle();
	},
	
	menuHover : function(cn)
	{
		
		$('.'+cn+' img').attr('src','/layout/gfx/'+cn+'-active.png');
		
	},
	
	menuOut : function(cn)
	{
		
		$('.'+cn+' img').attr('src','/layout/gfx/'+cn+'-inactive.png');
		
	}
	
};

$(document).ready(function(){
	Across.initTab();
	Across.initLeftTabs();
	Across.registrationType();
});
