
function changeImage(curId, img_uri, preId) {
	var cId = "#bigImg-" + curId;
	var pId = "#img" + preId + "-" + curId;

	var cLink = jQuery(cId)[0].parentNode;
	var pLink = jQuery(pId)[0].parentNode;

	var cSource = jQuery(cId).attr("src");
	var pSource = jQuery(pId).attr("src");

	var sourceSm = jQuery(cLink).attr("rev");

	jQuery(pId).fadeOut("slow");
	jQuery(cId).fadeOut();

	jQuery(pId).attr("src", sourceSm);
	jQuery(pLink).attr('href', cSource);


	jQuery(cId).attr("src", img_uri);
	jQuery(cLink).attr("rev", pSource);

	jQuery(pId).fadeIn("slow");
	jQuery(cId).fadeIn();

	return false;
}

function changeOneImage(curId, img_uri, preId) {
	var cId = "#bigImg-" + curId;
	var pId = "#img" + preId + "-" + curId;

	var cHref = jQuery(cId)[0].parentNode;
	var pHref = jQuery(pId)[0].parentNode;

	var cSource = jQuery(cId).attr('src');
	var pSource = jQuery(pId).attr('src');
	
	var cLink = jQuery(cHref).attr('href');
	var pLink = jQuery(pHref).attr('href');

	var cSourceSm = jQuery(cHref).attr("rev");
	var pSourceSm = jQuery(pHref).attr("rev");

	jQuery(pId).fadeOut("slow");
	jQuery(cId).fadeOut();

	jQuery(pId).attr('src', cSourceSm);
	jQuery(cId).attr('src', pSourceSm);

	jQuery(pHref).attr("rev", cSource);
	jQuery(cHref).attr("rev", pSource);

	jQuery(pHref).attr('href', cLink);
	jQuery(cHref).attr('href', pLink);

	jQuery(pId).fadeIn("slow");
	jQuery(cId).fadeIn();

	return false;
}


jQuery(document).ready(function() {

	$(".lightbox").lightbox({
		fileBottomNavCloseImage : '/i/lb/close.gif',
		//fileLoadingImage : '/i/lb/loading.gif',
		overlayOpacity : 0.75,
		borderSize : 10,
		navbarOnTop: true,
//show_info: true,
//download_link: true,
//baseurl: true,
//show_linkback: true,

		strings : {
			help: ' \u2190 / P - предыдущее фото\u00a0\u00a0\u00a0\u00a0\u2192 / N - следующее фото\u00a0\u00a0\u00a0\u00a0ESC / X - закрыть галерею',
			prevLinkTitle: 'предыдущее фото',
			nextLinkTitle: 'следующее фото',
			prevLinkText:  '&laquo; Назад',
			nextLinkText:  'Вперёд &raquo;',
			closeTitle: 'закрыть галерею',
			image: 'Фото ',
			of: ' из '
		},
		fitToScreen: false
	});

	var prevPageUrl = jQuery('#navPrevPage').attr('href');
	var nextPageUrl = jQuery('#navNextPage').attr('href');


	/* Forvard func */
	$(document).bind('keydown', 'Ctrl+right', function(){
		//jQuery('#navNextPage').click(function() {
		//	window.location.href = nextPageUrl;
		if (jQuery('#navNextPage').attr("href")!=undefined){
			window.location.href = jQuery('#navNextPage').attr("href");
		}
		//});
		//jQuery('#navNextPage').trigger('click');
	});
	/* end of forvard func */

	/* Back func */
	$(document).bind('keydown', 'Ctrl+left', function(){
		//jQuery('#navPrevPage').click(function() {
		//	window.location.href = prevPageUrl;
		//});
		if (jQuery('#navPrevPage').attr("href")!=undefined){
			window.location.href = jQuery('#navPrevPage').attr("href");
		}
		//jQuery('#navPrevPage').trigger('click');
	});
	/* end of back func */

	var j = false;
	jQuery('#send-msg').click(function() {
		if(!j) {
			jQuery(".modal-wrap").show();
			j = true;
		} else {
			jQuery(".modal-wrap").hide();
			j = false;
		}
		return false;
	});

	jQuery('#close-link').click(function() {
		jQuery(".modal-wrap").hide();
		j = false;
		return false;
	});

	jQuery('body').click(function(event){
		if (jQuery(event.target).parents('.modal-wrap').size() == 0) {
			jQuery(".modal-wrap").hide();
			j = false;
		}
	});

	$(function(){
		$('.fl2 .squ').hover(
			function(){
				var elem = $(this);
				var elem2 = $('.hoverbl .fl2 .squ');

				object = {
					func: function(){

						elem2.each(function(){
							$(this).css({ position: 'static', zIndex: '0' });
						});

						elem.children('img').stop().animate({width:"200px",height:"200px"}, 250);
						elem.css({
							position: 'relative',
							zIndex: '100'
						});
					}
				}

				setTimeout(function() { object.func.call(object) }, 100);

/*
				$(this).children('img').stop().animate({width:"200px",height:"200px"}, 500);
				$(this).css({
					position: 'relative',
					zIndex: '100'
				});
*/
			},function(){
				var elem = $(this);
				/*$(this).children('img').stop().animate({width:"40px",height:"40px"}, 500);
				$(this).css({
					position: 'static',
					zIndex: '0'
				});*/

				object = {
					func: function(){
						elem.css({ position: 'static', zIndex: '0' });
					}
				}

				$(this).children('img').stop().animate({width:"40px",height:"40px"}, 250);
				//$(this).css({ position: 'static', zIndex: '0' });
				//setTimeout("$(this).css({ position: 'static', zIndex: '0' })", 500);
				setTimeout(function() { object.func.call(object) }, 250);
			}
		);
	});

});


function checkOrder(){
	var err = '';
	if (jQuery("#o_fio").val()==""){
		err+= "Не указаны ФИО\n";
	}
	if (jQuery("#o_email").val()==""){
		err+= "Не указан email\n";
	}
	if (jQuery("#o_phone").val()==""){
		err+= "Не указан телефон\n";
	}
	if (err!=''){
		alert(err);
	}else{
		$.ajax({
			type: "POST",
			url: "/ord.php",
			data: "type="+jQuery("#o_type").val()+"&type_val="+jQuery("#o_type_value").val()+"&fio="+jQuery("#o_fio").val()+"&email="+jQuery("#o_email").val()+"&phone="+jQuery("#o_phone").val()+"&org="+jQuery("#o_org").val(),
			success: function(msg){
				jQuery("#regForm").hide();
				jQuery("#o_msg").show(); 
			}
		});
	}
}