var Home = {
	setMenu : function () 
	{
		var items = $('.topmenu .menuHeader');

		for (var i=0;i < items.length; i++)
		{
			$(items[i]).hover(
				function () 
				{
					$(this).addClass('ShowItems');
				}, 
				function () 
				{
					$(this).removeClass('ShowItems');
				}
			);
		}
	},
	initInfos : function ()
	{
        $('div.info, div.error').hover(
			function () {
				$(this).addClass('show-info');
			}, 
			function () {
				$(this).removeClass('show-info');
			}
		);
	},
	
	newsletterSubscibe: function(thisFom)
    {
        Home.actualForm = thisFom;

        $.post("/", 'Func=newsletter.Subscribe&' + $(thisFom).serialize(), function(data)
        {

            if (data.error)
            {
				jQuery.each(data.items, function(i, val)
				{
					$('#newsletter_' + i).val(val);
				});
            }
            else
            {
                $('#subs-errors').html('');
				$('.bg-newsletter').html(data.message);
            }
        }, "json");
    }


};

$(document).ready(function()
{
	Home.setMenu();
	Home.initInfos();
});


var Contacts = {

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

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

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

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

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

var Home = {
	setMenu : function () 
	{
		var items = $('.topmenu .menuHeader');

		for (var i=0;i < items.length; i++)
		{
			$(items[i]).hover(
				function () 
				{
					$(this).addClass('ShowItems');
				}, 
				function () 
				{
					$(this).removeClass('ShowItems');
				}
			);
		}
	},
	initInfos : function ()
	{
        $('div.info, div.error').hover(
			function () {
				$(this).addClass('show-info');
			}, 
			function () {
				$(this).removeClass('show-info');
			}
		);
	},
	
	newsletterSubscibe: function(thisFom)
    {
        Home.actualForm = thisFom;

        $.post("/", 'Func=newsletter.Subscribe&' + $(thisFom).serialize(), function(data)
        {

            if (data.error)
            {
				jQuery.each(data.items, function(i, val)
				{
					$('#newsletter_' + i).val(val);
				});
            }
            else
            {
                $('#subs-errors').html('');
				$('.bg-newsletter').html(data.message);
            }
        }, "json");
    }


};

$(document).ready(function()
{
	Home.setMenu();
	Home.initInfos();
});


var Products = {
    
    Basket : function(id) {
		
        val = $('#piece_'+id).val();

        
		$.post("/", 
			'Func=products.order.basket&id='+id+'&val='+val, function(data)
			{
	            $('#total_'+id).html(data.subtotal);
                $('.basket-block-bruttototal > span').html(data.total+' HUF');
				$('.basket-block-shipping > span').html(data.shipping+' HUF');
				$('.basket-block-totaltotal > span').html(data.totaltotal+' HUF');
				
        }, "json");
    },
	
    shipping : function(val) {
		
		$.post("/", 
			'Func=products.order.getShippingPrice&shipping_method='+val, function(data)
			{
				$('.basket-block-shipping > span').html(data.shipping+' HUF');
				$('.basket-block-totaltotal > span').html(data.totaltotal+' HUF');
				
        }, "json");
    },
    
    Order : function(id) {
        
		$.post("/", 
			'Func=products.order.order', function(data)
			{
	            location.href = data.url;
				
        }, "json");
    }
};

$(document).ready(function()
{
    var v = $('#basketWrapper').html();
    
    if(v)
    {
        floatingMenu.add('floatdiv',  
        {  
            targetTop: 0,  
            // targetBottom: 0,  
            prohibitXMovement: true,  
            snap: true  
        });
    }
});


var newsletter = {

	subscribeForm : function()
	{
		$.post("/", 
			'Func=newsletter.subscribeForm', 
			function(data) {
				dialogHandler.popup(data);
			},
			"text"
		);
	},
    
	Subscribe : function(frm)
	{
		var formdata = frm;
		
		$.post("/", 
			'Func=newsletter.Subscribe&'+$(formdata).serialize(), function(data)
			{
				if (data.error)
	            {
					jQuery.each(data.items, function(i, val)
					{
						$('#newsletter_' + i).val(val);
					});
	            }
	            else
	            {
					formdata.reset();
	                $('#subs-errors').html(data.message);
					$('.newsletter').css('display', 'none');
	            }
				
        }, "json");
	}
}
