/* Determine scroll  */
	function getScrollXY() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	    scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	  }
	  return {scrX: scrOfX, scrY: scrOfY };
	}
	
	
	
	/*  Determine the user's window width and height  */
	function width_height() {      
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    w = window.innerWidth;
	    h = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    w = document.documentElement.clientWidth;
	    h = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    w = document.body.clientWidth;
	    h = document.body.clientHeight;
	  }
	 // w = $(window).width();    /* Ширина экрана на момент загрузки страницы */
	 // h = $(window).height();   /* Высота экрана на момент загрузки страницы */
	  return {width: w, height: h}; 
	}
	
	
	
//---------------------------------------------------------------------------------

	$("body").ready(function() {
		
	    /*var hr_width = width_height() ['width'];
	    $("#hr").width(hr_width);*/
		
		$("#toggle").mouseover(function(){ 
		
			$("#header-hidden").slideToggle();	
			var t = $(this).css('textAlign');
			if (t == "left") {
				$(this).css({textAlign: "right"})
					.css({backgroundImage: "url('images/btn_close.png')"});
					$("#about, #contacts").animate({opacity: 1}, 800);
			}
			else  {
				$(this).css({textAlign: "left"})
					.css({backgroundImage: "url('images/btn_open.png')"});
					$("#about, #contacts").animate({opacity: 0}, 200);
			}		 
			return false;
		});
		
		$("#contacts").mouseover(function(){ 
			$(this).css({backgroundImage: "url('images/btn_over_contact.jpg')"}) }).
			mouseout(function(){
			$(this).css({backgroundImage: "url('images/btn_contact.jpg')"});
			return false;
		});
		
		$("#about").mouseover(function(){ 
			$(this).css({backgroundImage: "url('images/btn_over_about.jpg')"}) }).
			mouseout(function(){
			$(this).css({backgroundImage: "url('images/btn_about.jpg')"});
			return false;
		});
		
		$("#go-home").mouseover(function(){ 
			$(this).css({backgroundImage: "url('images/icon_over_home.png')"}) }).
			mouseout(function(){
			$(this).css({backgroundImage: "url('images/icon_home.png')"});
			return false;
		});
			
		$(".menus").mouseover(function(){ 	
				$(this).css({color: '#AEAEAE'});
				return false;
		}).mouseout(function(){ 	
				var a = $(this).attr('id');
				var id = /\d+/.exec(a);
					if (id == present_color) $(this).css({color: '#EE4580'}); else	$(this).css({color: '#7A7A7A'});
				return false;
		});
		
		$(".menus").click(function(){ 	
			var id = $(this).attr('id');
				if (id == "item0") window.open('/index.php?t=1', '_self');
				if (id == "item1") window.open('/index.php?t=2', '_self');
				if (id == "item2") window.open('/index.php?t=3', '_self');
				if (id == "item3") window.open('/index.php?t=4', '_self');
				if (id == "item4") window.open('/index.php?t=5', '_self');
				if (id == "item5") window.open('/index.php?t=6', '_self');
				if (id == "item6") window.open('/index.php?t=7', '_self');
				return false;
		});
	
		$(".thumb img").mouseover(function(){ 
			$(this).animate({opacity: 1}, 200)
		}).mouseout(function(){ 
			$(this).animate({opacity: 0}, 2000);
			return false;
		});
		
		$(".thumb").click(function(){
			var a = $(this).attr('id');
			var id = /\d+/.exec(a);
			$("#content").load("img_change.php", {id: id});
			$("#years").load("year_change.php", {id: id});
			$("#describtion").load("desc_change.php", {id: id});
			return false;
		});
		
		function left_press() {
			// $("#nav-left").css({backgroundImage: "url('images2/gallery_over_left.jpg')"});		
			$("#nav-left").css({backgroundImage: "url('images2/btn_left.jpg')"});
			$("#nav-right").css({backgroundImage: "url('images2/btn_right.jpg')"});
			if (len <= 0) return false;
			var left_pos = $("#slider").css('left');
			var l_pos = /^-?\d+/.exec(left_pos);
			if (l_pos > -81) {
					$(this).css({backgroundImage: "url('images2/no_left.jpg')"});
					return false;
			}
			if (l_pos > -1) return false;
			
			var l_pos = /^-?\d+/.exec(left_pos);
			l_pos = parseInt(l_pos) + 100;
			//alert(l_pos);
			$("#slider").animate({left: l_pos}, 500);
			$("#nav-left").css({backgroundImage: "url('images2/btn_left.jpg')"});
			
			return false;
		}
		
		function right_press()  {
			// $("#nav-right").css({backgroundImage: "url('images2/gallery_over_right.jpg')"});
			$("#nav-right").css({backgroundImage: "url('images2/btn_right.jpg')"});
			$("#nav-left").css({backgroundImage: "url('images2/btn_left.jpg')"});
			if (len <= 0) return false;
			var left_pos = $("#slider").css('left');
			var l_pos = /^-?\d+/.exec(left_pos);
			l_pos = parseInt(l_pos) - 100;
			
			var d = parseInt(l_pos) + len*100 - 460;
			if (d < 80) {
					$(this).css({backgroundImage: "url('images2/no_right.jpg')"});
					return false;
			}
			if (d < 0) return false;
			$("#slider").animate({left: l_pos}, 500);
			$("#nav-right").css({backgroundImage: "url('images2/btn_right.jpg')"});
			
			return false;
		}
		
		/* change event to "mouseover" */
		$("#nav-left").mousehold(501, left_press);
		$("#nav-right").mousehold(501, right_press);


		/*
		$("#nav-left").hover(
			function() {
				$(this).addClass('pretty-hover');
			}, 
			function() {
				$(this).removeClass('pretty-hover');
			});


		$("#nav-left").mouseover(css({backgroundImage: "url('images2/gallery_over_left.jpg')"}));		
		$("#nav-right").mouseover(css({backgroundImage: "url('images2/gallery_over_right.jpg')"}));	
		*/

		
		$(".del-mark").click(function(){
			var a = $(this).attr('id');
			var id = /\d+/.exec(a);
			var flag=confirm("Are you sure you would like to delete this record?","Yes","No");
			if (!flag) return false;
			$("#del-div").load("../admin/delete_it.php", {id: id, del: "1"});
			return false;
		});
		
		$("#deltable img").click(function(){
			var a = $(this).attr('id');
			var id = /\d+/.exec(a);
			var left = width_height()['width'];
			var height = width_height()['height'] + getScrollXY()['scrY'];
			var top = getScrollXY()['scrY'] + 30;
			var img_left = (left-460) / 2;
			$("#modal").css({display: 'block', width: left, height: height});
			$("#img-preview").css({display: 'block', left: img_left, top: top});
			$("#img-preview").load("../admin/delete_it.php", {id: id, show: "1"});
			return false;
		});
		
		$(".desire").click(function(){
			var a = $(this).attr('id');
				if (a == "new")  window.open('index.php', '_self');
				if (a == "look") window.open('/index.php', '_self'); 
			return false;
		});
		
		
		$("#top-logo-right").click(function(){
			window.open('plotter.php', '_self'); 
			return false;
		});


		$("#modal, #img-preview").click(function(){
			$("#modal, #img-preview").css({display: 'none'});
			return false;
		});
		
		$("#submit-event").click(function(){
		
			var f1=""; var f2=""; var f3=""; var f4=""; var f5=""; var f6="";
			var attention = false;
			
			var year = $("#year").attr('value');
			var desc = $("#desc").attr('value');
			var client = $("#client").attr('value');
			var thumb = $("#thumb").attr('value');
			var thumb_bw = $("#thumb_bw").attr('value');
			var image = $("#image").attr('value');
			
			
			if (!year) { f1="Год "; attention = true; }
			if (!desc) { f2="Описание "; attention = true; }
			if (!client) { f3="Заказчик "; attention = true; }
			if (!thumb) { f4="Уменьшенное изображение цветное "; attention = true; }
			if (!thumb_bw) { f5="Уменьшенное изображение ч/б "; attention = true; }
			if (!image) { f6="Картинка"; attention = true; }
		
			if (attention)	{ alert("Не заполнены поля: " + f1+f2+f3+f4+f5+f6); return false;  }
			
			var jpg1 = /\.jpe?g$/i.exec(thumb);
			var jpg2 = /\.jpe?g$/i.exec(thumb_bw);
			var jpg3 = /\.jpe?g$/i.exec(image);
			
			if (!jpg1)  {alert("Неправильный формат в поле: Уменьшенное изображение цветное"); return false; }
			if (!jpg2)  {alert("Неправильный формат в поле: Уменьшенное изображение ч/б"); return false; }
			if (!jpg3)  {alert("Неправильный формат в поле: Картинка"); return false; }
			return;
		});
		
		
		
	});	
	
	
	
