﻿/* Author: f0rt1 | Copyright: www.niceweb.in.ua | e-mail: niceweb@i.ua | URL: http://www.niceweb.in.ua */

var NiceWeb = {
	Load: function(sys){
		if(sys == 'yes'){
			$('#loading').remove();
			$('body').append('<div id="loading"><div id="loading_text">Загрузка.Пожалуйста подождите...</div></div>');
			$('#loading').show();
		}
		if(sys == 'no'){
			$('#loading').hide();
		}
	},
	Page: function(page){
		NiceWeb.Load('yes');
		$.get(page, function(data){
			$('#content').html('<div id="pre_load" style="display:none;">'+data+'</div>');
			$('#pre_load').fadeIn();
			NiceWeb.Load('no');
		});
		
	},
	Next: function(a, b){
		var width_one = a;
		var cnt_start = b;
		var count_img = $('#container img').size()*width_one;
		var last_stop = count_img-width_one*cnt_start;
		var div = document.getElementById('container');
		var acb = div.scrollLeft+width_one;

		if(acb == last_stop){
			$('.next').fadeOut();
		}

		if(div.scrollLeft != last_stop){
			$('#container').animate({scrollLeft: "+="+width_one});
		} 
		
		$('.prev').fadeIn();

	},
	Prev: function(a){
		var width_one = a;
		var div = document.getElementById('container');
		var acb = div.scrollLeft-width_one;
		
		$('#container').animate({scrollLeft: "-="+width_one});
		
		$('.next').fadeIn();
		if(acb == 0){
			$('.prev').fadeOut();
		}
	},
	Send: function(){
		var xname = $('#name').val();
		var xemail = $('#email').val();
		var xicq = $('#icq').val();
		var xsubj = $('#subj').val();
		var xtext = $('#text').val();
		NiceWeb.Load('yes');
		$.post('/index.php?act=contacts&p=send', {name: xname, email: xemail, icq: xicq, subj: xsubj, text: xtext}, function(data){
			if(data == 'ok'){
				$('#contacts').html('Ваше сообщение было успешно отправлено. <a href="/" onClick="NiceWeb.Page(\'/index.php?\'); return false;">На главную</a>');
				$('#name, #email, #icq, #subj, #text').val('');
			} else {
				NiceWeb.Alert('Информация', data, 'yes');
			}
			NiceWeb.Load('no');
		});
	},
	Alert: function(title, msg, auto){
		$('#error_box').remove();
		
		if(auto == 'yes'){
			var close_link = '';
		} else {
			var close_link = '<div class="close_box" onClick="NiceWeb.Close(); return false;"><div>Закрыть</div></div>';
		}
		
		$('body').append('<div id="error_box"><div class="error_box">'+close_link+'<div class="pad_m">'+msg+'</div><div class="clr"></div><div class="clr"></div></div></div>');
		$('#error_box').slideToggle();
		
		if(auto == 'yes'){
			setTimeout('NiceWeb.Close()', 3000);
		}
	},
	Close: function(){
		$('#error_box').slideToggle();
	}
};
