$(document).ready(function() {
													 
	// прелоад картинок												 
	image1 = new Array ();
	image2 = new Array ();	
	for(i=10; i<=15; i++){
		image1[i]=new Image; 
		image1[i].src="/image/sitem"+i+".png";
		image2[i]=new Image; 
		image1[i].src="/image/item"+i+".png";
	}
	$("li a[href='/zakaz-online']").css("font-size", "12px").css("font-weight", "bold").css("color", "#000");
	$("li.curr").each( function(){
		$(this).parent().parent().find("ul:first").css("display", "block");		
		$(this).parent().parent().parent().parent().find("ul:first").css("display", "block");
		$(this).parent().parent().parent().parent().parent().parent().find("ul:first").css("display", "block");		
	});
	
	$("div.anons_item img").hover(
			function(){
				var name = "/image/item" + $(this).attr("id") + '.png';
				$(this).attr("src", name);
			},
			function(){
				var name = "/image/sitem" + $(this).attr("id") + '.png';
				$(this).attr("src", name);
			}
	);
												 
	$("#full").click( function(){
		$('input[name="fio"]').attr("value", "one1");
		$('input[name="address"]').attr("value", "one3");
		$('input[name="phone"]').attr("value", "one4");
		$('input[name="mobile"]').attr("value", "one5");
		$('input[name="email"]').attr("value", "one6");
		$('textarea[name="notes"]').html("oneoneoneone");		
	});												 
	// зебра в таблицах
	$(".zebra tr.one:even").each( function(){
		$(this).attr("class", "one"); 
	});
	$(".zebra tr.one:odd").each( function(){
		$(this).attr("class", "two"); 
	});
	$("img[align='right']").each(function(i) {
		$(this).css('margin', '10px 0px 0px 10px');
	});
	$("img[align='left']").each(function(i) {
		$(this).css('margin', '10px 10px 0px 0px');
	});
	$("img[align='middle']").each(function(i) {
		$(this).css('margin-top', '10px');
		$(this).css('margin-bottom', '10px');
		$(this).css('margin', '0 auto');
	});
	
/*	$('.info li a').mouseenter( 
		function(){
			$('.info li').attr("class", ""); // тушим подсветку первого пункта меню
			$('div.hide').css("visibility", "hidden");
			var div = $(this).attr('div');
			$('div#'+div).css("visibility", "visible");
			
			$(this).parent().attr("class", "curr");
		}
	);*/

	
	if ($('#message').attr('value') != ''){
		var message;
		message = $('#message').attr('value');
		$.blockUI({ 
			message: message,
			css: { 
				border: 'none', 
				padding: '15px', 
				fontSize: '20pt',
				backgroundColor: '#000', 
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: '.5', 
				color: '#fff' 
			},
			timeout: 3000
		});
	}

	$('#inputButton').DatePicker({
		format:'Y-m-d',
		date: $('#inputDate').val(),
		current: $('#inputDate').val(),
		starts: 1,
		position: 'left',
		onBeforeShow: function(){
			$('#inputDate').DatePickerSetDate($('#inputDate').val(), true);
		},
		onChange: function(formated, dates){
			$('#inputDate').val(formated);
			$('#inputButton').DatePickerHide();
			var header = $('#inputButton').attr('header');
			location.href = '/'+header+'/'+$('#inputDate').attr("value");
		}
	});

	$('#map li a').each(function(){
			var base = $(this).attr("base");
			$(this).css("background-image", "url("+base+")");															 
	});
	
	$('#map li a').hover( 
		function(){
			var hover = $(this).attr("hover");
			$(this).css("background-image", "url("+hover+")");

		}, 
		function(){
			var base = $(this).attr("base");
			$(this).css("background-image", "url("+base+")");
		}
	);

/*	var i = 0;
	var pics;	
	
	if (document.getElementById('roller')) // если найден элемент roller, делаем запрос на получение списка картинок
		$.post('/get_pic.php', {mode:'get_pic'}, onReturnPicList);	

	function onReturnPicList(data){ 
		// получаем список картинок, формируем html, показываем первые три картинки и запускаем процедуру слайдшоу
		array_pic = data.match(/\d+\.jpg/gmi);
		for(j = 0; j<array_pic.length; j++){
			array_pic[j] = '<a href="/gallery"><img src="/uploads/galery_thumb/'+array_pic[j]+'" /></a>';
		}
		if (array_pic.length > 3){
			$('#roller').html(array_pic[0]+array_pic[1]+array_pic[2]);
			i = 2;
			timer = setInterval(SlideShow, 4000);
		}
	}
	function SlideShow(){	
		pics = '';
		for(j=0;j<=2;j++){
			i = i+1;
			if (i == array_pic.length) 
				i = 0;
			pics = pics+array_pic[i];
		}
		
		$('#roller').animate({opacity : 0}, 
			500,
			function(){
				$('#roller').html(pics);	
				$('#roller').animate({opacity : 1},500);
			}
		);
	}	*/
	
// прокрутка роллера вверх	
	$("img.top").click( function(){
		$.post(
			'/module/roller/index.php',	  
			{pos: -1},
			onReturnRoller
		);		
	});

// прокрутка роллера вниз
	$("img.bottom").click( function(){
		$.post(
			'/module/roller/index.php',	
			{pos: 1},
			onReturnRoller
		);
	});
	function onReturnRoller(data){
		var name;
		var i;
		for (i=0;i<4;i++){
			name = data.replace(/(.*)#(.*)#(.*)#(.*)#/gi, "$"+(i+1));
			$('div.roller td#pic'+i).html('<a href="/uploads/pic_good/'+name+'" class="thickbox"><img src="/uploads/pic_good_thumb/'+name+'" width="60" height="60"></a>');
		}
		tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	}
});

function checkForm(obj) {
	var element,pattern;
	for (var i = 0; i < obj.elements.length; i++) { // пробегаемся по всем элементам формы
		element = obj.elements[i];
		// И только если есть чего говорить юзеру в случае ошибки
		if (!element.getAttribute("alt")) continue;
		if (pattern = element.getAttribute("src")) { // если задан регэксп
			pattern = new RegExp(pattern, "g");
			if (!pattern.test(element.value)) {
				alert(element.getAttribute("alt"));
				element.focus();
				return false;
			}
		} 
		else {
				if (element.value == "") { // иначе просто проверка что поле не пустое
				alert(element.getAttribute("alt"));
				element.focus();
				return false;
			}
		} 
	}
	return true;
}
// name - имя cookie
// value - значение cookie
// [expires] - дата окончания действия cookie (по умолчанию - до конца сессии)
// [path] - путь, для которого cookie действительно (по умолчанию - документ, в котором значение было установлено)
// [domain] - домен, для которого cookie действительно (по умолчанию - домен, в котором значение было установлено)
// [secure] - логическое значение, показывающее требуется ли защищенная передача значения cookie
function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}
// name - имя считываемого cookie
function getCookie(name) {
	var prefix = name + "=";
	var cookieStartIndex = document.cookie.indexOf(prefix);
	if (cookieStartIndex == -1)
		return null;
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length;
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}
// name - имя cookie
// [path] - путь, для которого cookie действительно
// [domain] - домен, для которого cookie действительно
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

