var Across = {

    FormType       : 'store',

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

    reload : function ()
    {
        window.location = window.location.href;
    },
	
    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"
            );
    },
    
    sendWebInvitation : function (thisFom)
    {
        Across.actualForm = thisFom;

		$.post("/", 
			'Func=users.invitation.sendWebInvitation&'+$(thisFom).serialize(), 
			function(data) {

				if (data.error)
				{
					jQuery.each(data.items, function(i, val) {
						$('#'+i).val(val);
				    });
				}
				else
				{
					$('#send_report').css('display', 'block');
					$('#send_form').css('display', 'none');
				}
			},
			"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.each(function (i) {
				if ( $(this).attr('rel') == $('div.tabcontent > div.active').attr('id') ) {
					tabs.removeClass('active');
					$(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();
        });
    },

    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);


            },
            "json"
		);
	},
	locationTab : function(tabid)
	{
		
		$('a.element').removeClass('active');
		$('#ctab_'+tabid).addClass('active');
		
		$('.tab').hide();
		$('#'+tabid).show();
		
	},
	changeLocation : function(locid)
	{
	
		$('.location').removeClass('active');
		$('#h_'+locid).addClass('active');
		
		$('.contact-title').hide();
		$('#c_'+locid).show();
		
		$('.location-data-container').hide();
		$('#l_'+locid).show();
		
		$('#contacts_'+locid).show();
		$('a.element').removeClass('active');
		$('#ctab_contacts_'+locid).addClass('active');
	},
	
	getForumMessageForm : function(topic_id,parent_msg_id)
	{
		
		$('.forum-error-title').click(
			function() {
				Across.closeMsgWindow('forum-error');
			}
		);
		
		$('.forum-box-title').click(
			function() {
				Across.closeMsgWindow('forum-box');
			}
		);
		
		$.post("/",'Func=forum.list.getForumMessageForm&topic_id='+topic_id+'&parent_msg_id='+parent_msg_id,
		function(data)
		{
			
			if(data.error)
			{
				
				$('.forum-error').fadeIn();
				$('.forum-error-title').html(data.title);
				$('.forum-error-body').html(data.body);
				
			}
			else
			{
				$('.forum-box').fadeIn();
				$('.forum-box-title').html(data.title);
				$('.forum-box-body').html(data.body);
			}
			
		},
		"json"
		);
		
	},
	
	addForumMessage : function(topic_id,parent_msg_id,thisform)
	{
		
		$.post("/",'Func=forum.list.addForumMessage&topic_id='+topic_id+'&parent_msg_id='+parent_msg_id+'&'+$(thisform).serialize(),
		function(data)
		{
			
			if(data.error)
			{
				
				$('.inner-message').fadeIn();
				$('.inner-message-title').html(data.title);
				
			}
			else
			{
				location.reload();
			}
			
		},
		"json"
		);
		
	},
	
	closeMsgWindow : function(classname)
	{
		$('.'+classname).fadeOut();
	},
	showSubcat : function(pid)
	{
		$('.cat-sub').hide();
		$('.s_'+pid).show();
		$('.s_'+pid).css('display','block');
		
		//main categories
		$('.cat-root').removeClass('active');
		
		
	},
	swapImage : function(imageid,imagefile)
	{
		
		$('#i_'+imageid).attr('src','/uploads/products/mid/'+imagefile);
		
	},
	swapDetailImage : function(imagefile)
	{
		
		$('#i_1').attr('src','/uploads/products/detail/'+imagefile);
		
	},
	
	getNewsletter : function (thisform)
	{
		$.post("/",'Func=contacts.subscribe&'+$(thisform).serialize(),
		function(data)
		{
			if( data.error )
			{
				
				$('#email').val(data.msg);
			}
			else
			{
				$('.newsletterfrm-elements').hide();
				$('.newsletterfrm-info').html(data.msg);
			}
		},
		"json"
		);
	}
};

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

	$('.promobox-container').cycle({
				fx: 'fade' 
	});
	
	$('.marque-container').cycle({
				fx: 'fade' 
	});
	
	var car = $('.jcarousel-skin-tango').size();
	if(car != 0)
	{
		for(i=1;i<=car;i++)
		{
			jQuery('#product-images-container_'+i).jcarousel();
		}
	}
	
	jQuery('#detailimage-controll').jcarousel();


});
