
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() {

	$(".lgn").fancybox({
		'titlePosition': 'inside',
		'transitionIn': 'none',
		'transitionOut': 'none',
		'padding':0,
		'overlayOpacity'	: 0.7,
		'overlayColor'		: '#fff',
		'showCloseButton': false
	});

	$(".cls").click(function(){
		$.fancybox.close();
		return false;
	});

	$(".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;
		}
	});

	$('.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);
		}
	);

x=getCookie('note');
if(x) {
	x=x.split(",");
	jQuery('#wished').text(x.length);
}

});


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

function checkOrder2(){
	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: "main=1&type="+jQuery("#o_type").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(); 
			}
		});
	}
}

var save_html;
var sended = false;

function rec_check(){
	if (sended==true){
		$("#rec_htm").html(save_html);
	}
}

function send_to_friend(){
	if (jQuery("#f_email").val()==''){
		alert('бШ МЕ СЙЮГЮКХ email');
		return false;
	}
	$.ajax({
			type: "POST",
			url: "/friend.php",
			data: "email="+jQuery("#f_email").val()+"&url="+$("#id_url").val(),
			success: function(msg){
				save_html = $("#rec_htm").html();
				$("#rec_htm").html('<strong>Сообщение отправлено!</strong><br/><br/>');
				sended = true;
			}
		});
}
function add2note(sid,name,img,url){

note=new Array();
noteh=new Array();

post=sid;
x=getCookie('note');
y=getCookie('noteh');

nn='';

for(var i=0;i<name.length;i++)
{
nn=nn+'&'+'#'+name.charCodeAt(i)+';';
}

s='<li><a href='+url+'><img src='+img+'><br/><span>'+nn+'</span></a><br/><a href=javascript:del_from_note('+post+');>&#1091;&#1076;&#1072;&#1083;&#1080;&#1090;&#1100;</a></li>';

added=0;
if(x) {
	x=x.split(",");
	y=y.split(",");

	for (i=0;i<x.length;i++)
	{
		if(x[i]==post) {
		x.splice(i,1);
		setCookie(x,'note');
		y.splice(i,1);
		setCookie(y,'noteh');
		added=1;
		break;
		}
	}

	note[0]=x;
	note=note.concat(post);
	noteh[0]=y;
	noteh=noteh.concat(s);
}
else {
	note[0]=post;
	noteh[0]=s;

}

if (added!=1)
{
setCookie(note,'note');
setCookie(noteh,'noteh');
}
x=getCookie('note');
y=0;
if(x) {
	x=x.split(",");
	y=x.length;
} 
	jQuery('#wished').text(y);
}

function del_from_note(post) {

x=getCookie('note');
y=getCookie('noteh');
if(x) {
	x=x.split(",");
	y=y.split(",");
	if (x.indexOf(post+"")>-1) 
	{
		n=x.indexOf(post+"");
		x.splice(n,1);
		y.splice(n,1);
	}
	setCookie(x,'note');
	setCookie(y,'noteh');
	location.reload();
}

}

function setCookie(value,name)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + 365);
var c_value=escape(value) + "; expires="+exdate.toUTCString()+";path=/";
document.cookie= name + "=" + c_value;
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}
