$(document).ready(function() {
	$("#login").fancybox({
		'scrolling'		: 'no',
		'padding'		: '10',
		'overlayColor'	: '#000',
		'titleShow'		: false,
		'onClosed'		: function() {location.reload(true);}
	});
	$("#shopcart").fancybox({
		'width'				: '80%',
		'height'			: '80%',
		'autoScale'			: false,
		'overlayColor'		: '#000',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'onClosed'			: function() 
		{
			$.ajax({
				type:'POST',
				url:'/ajax__json/',
				data:{'js':'receipt'},
				dataType:'json',
				success: function(data)
				{
					$.each(data.receipt, function(i,p)
	    	            {
	    	              $('.order-sum').html(p.ammount);
	    	              $('.order-price').html(p.price);
	    	            });
	    	        }
	    	    });
		}
	});
	// *** FOR BLOCK INFO
	/*
	$("a.gas-down").toggle(
			function () {
				$("#gas").removeClass("block-link").addClass("block-link2");
				$("#gas-down").toggle();
			},
			function () {
				$("#gas").removeClass("block-link2").addClass("block-link");
				$("#gas-down").toggle();
			}
	);
	*/
	$("a.exch-down").toggle(
			function () {
				$("#exch").removeClass("block-link").addClass("block-link2");
				$("#exch-down").toggle();
			},
			function () {
				$("#exch").removeClass("block-link2").addClass("block-link");
				$("#exch-down").toggle();
			}
	);
	// *** FOR SIGNUP
	$("#signup").submit(function (e){
		post_transferx("/signup/",2,this,"/");
		e.preventDefault();
	});
	// *** FOR SIGNUP
	$("#signin").submit(function (e){
		post_transferx("/signin/",2,this,"signin/");
		e.preventDefault();
	});
	$("#contacts").submit(function (e){
		post_transferx("/contacts/",2,this,"contacts/");
		e.preventDefault();
	});
	$("#user").submit(function (e){
		post_transferx("/user/",1,this);
		e.preventDefault();
	});
});
// *** FUNCTIONS *** //
function jsmsg(act,msgst,txt,redirect) {
	var stsmsg = "jsmsg";

	if (redirect == null) {
		var redirect = '';
	}
	if (msgst == 1) {
		$('#'+stsmsg).css('background-color','#fff').css('border-bottom','1px solid #0099FF');
		hideshow(stsmsg,act);
		if(txt) $('#'+stsmsg).slideDown('fast').html(txt);
		$('#'+stsmsg).oneTime('1s',function (){$('#'+stsmsg).fadeOut('slow');});
		$('#'+stsmsg).show();
	}
	else if (msgst == 0) {	
		$('#'+stsmsg).css('background-color','#fff').css('border-bottom','1px solid #f2592f');
		hideshow(stsmsg,act);
		if(txt) $('#'+stsmsg).slideDown('fast').html(txt);
		$('#'+stsmsg).oneTime('2s',function (){$('#'+stsmsg).fadeOut('slow');});
		$('#'+stsmsg).show();
	}
	else if (msgst == 2) {
		$('#'+stsmsg).css('background-color','#fff').css('border-bottom','1px solid #0099FF');
		hideshow(stsmsg,act);
		if(txt) $('#'+stsmsg).slideDown('fast').html(txt);
		$('#'+stsmsg).oneTime('1s',function (){$('#'+stsmsg).fadeOut('slow');});
		$('#'+stsmsg).show();
		$('#'+stsmsg).oneTime('1s',function (){window.location="/"+redirect;});
	}
}
function hideshow(el,act) {
	if(act) $('#'+el).css('visibility','visible');
	else $('#'+el).css('visibility','hidden');
}
function post_transferx(path,donestatus,forms,redirect) {
	if (redirect == null) {
		var redirect = '';
	}
		$.ajax({
		type:'POST',
		url:path,
		data:$(forms).serialize(),
		dataType:'json',
		success: function(data) {
			if (parseInt(data.status) == 1) {
				jsmsg(1,donestatus,data.msg,redirect);
			}
			else if (parseInt(data.status) == 0) {
				jsmsg(1,0,data.msg);
			}
		}
		});
}
jQuery.fn.reldata = function (){
	var rel = jQuery(this).attr('rel');
	if (rel !== undefined) {
		try {
			var relData = eval('(' + rel + ')');
			return relData;
		} catch (err) {
		}
	}
	return false;
};
