function loadFoto(img) {
//        alert(img)
	document.getElementById('big_foto').style.display='';   
	path = "/files/"+img;
    $("#big_foto").animate({opacity: 0},1000,function(){
      $(this).html("<img src=" + path + " />").find("img").bind("load",function(){
        $(this).parent().animate({opacity: 1},1000);
      });
    });
//  return false;
}


function slideShow() {

$("#btnSlideShow").text("остановить слайд-шоу");
$("#btnSlideShow").attr({onClick: "stopSlideShow();"});

	document.getElementById('big_foto').innerHTML = document.getElementById('all_imgs').innerHTML;   
	document.getElementById('big_foto').style.display='';   
		$(function(){
			var rotator = new Utils.ImageRotator("big_foto");
			setTimeout(function(){
				rotator.startRotation(2000);
			}, 1000);
		});

}

function stopSlideShow() {

$("#btnSlideShow").text("показ слайд-шоу");
$("#btnSlideShow").attr({onClick: "slideShow();"});

document.getElementById('big_foto').style.display='none';   
document.getElementById('big_foto').innerHTML = '';
   
}

/* ______________ код для линейки превью на главной морде v2 ______________*/
// Сокращаем запись document.getElementById
function gebi(obj) { return document.getElementById(obj); }

var PMoveObjects_photo_new = {};
function getPMove_photo_new(id) {
	if (typeof(PMoveObjects_photo_new[id]) == "undefined") {
		PMoveObjects_photo_new[id] = new PMove_photo_new(id);
	}
	return PMoveObjects_photo_new[id];
}

function PMove_photo_new(id) {
	this.id = id;
	this.previewWidth = false;
	this.previewHeight = false;
	this.containerWidth = 300;
	this.containerWidthMin = 300;
	this.previewCount  = 0;
	
	this.marginLeft = false;
	this.scriptURL = "";
	this.xmlEnable = false;
	this.initFlag = 0;
	this.nameItemEnable = false;
	
	this._container = "cont_";
	this._leftAngle = "left_";
	this._rightAngle = "right_";
	
	this.defaultArray = [];
	this.casheImages = [];
	this.curPos = 0;
	this.isRight = 0;
	this.isLeft = 0;
	
	this.container = null;
	this.leftAngle = null;
	this.rightAngle = null;
	
	// Scroll
	this.initTimeout = 100;
	this.stepTimeout = 100;
	this.stepDirection = "";

	this.init = function(w, h, m, e, u, d) {
		if (
			typeof w == "undefined" ||
			typeof h == "undefined" ||
			typeof m == "undefined" ||
			typeof u == "undefined" ||
			typeof d == "undefined"
		) return;
		this.previewWidth = w;
		this.previewHeight = h;
		this.marginLeft = m;
		this.scriptURL = u;
		this.defaultArray = d;
		this.container = this.gebi(this._container + this.id);
		if (this.container == null) {
			// Error. Do nothing
			return;
		}
		this.leftAngle = this.gebi(this._leftAngle + this.id);
		if (this.leftAngle == null) {
			// Error. Do nothing
			return;
		}
		this.rightAngle = this.gebi(this._rightAngle + this.id);
		if (this.rightAngle == null) {
			// Error. Do nothing
			return;
		}
		if (this.defaultArray.length >= 1) {
			// Mix preview
			this.mixPreview();
			// Draw preview & angles
			this.drawPreview();
			this.drawAngles();
			// Add rezize-event handler
			var id = this.id;
			this.addHandler(
				window,
				"resize",
				function() {
					try {getPMove_photo_new(id).drawPreview();} catch(e) {}
				}
			);
			this.addHandler(
				document, 
				"mouseup", 
				function() {getPMove_photo_new(id).mouseUpHandler()}
			);
			this.addHandler(this.leftAngle, "mousedown", function(evt) {
				evt = evt || window.event;
				if (evt.preventDefault) evt.preventDefault();
			});
			this.addHandler(this.rightAngle, "mousedown", function(evt) {
				evt = evt || window.event;
				if (evt.preventDefault) evt.preventDefault();
			});
			this.addHandler(this.leftAngle, "dragstart", function() {return false;});
			this.addHandler(this.rightAngle, "dragstart", function() {return false;});
			this.initFlag = 1;
		} else {
			// Error. Do nothing
			return;
		}
	}
}

var stepTimer = {};
PMove_photo_new.prototype = {
	// ----------- Default -----------
	gebi : function(id) {
		return document.getElementById(id);
	},
	newImg : function(path) {
		var image = new Image();
		image.src = path;
		return image;
	},
	addHandler : function(object, event, handler, useCapture) { 
		if (object.addEventListener) { 
			object.addEventListener(event, handler, useCapture ? useCapture : false); 
		} else if (object.attachEvent) { 
			object.attachEvent('on' + event, handler); 
		} 
	},
	screenSize : function() { 
		var w, h;
		w = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth)); 
		h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight)); 
		return {w:w, h:h}; 
	},
	// ----------- Funcs -----------
	scrollInit : function(order) {
		if (this.xmlEnable) this.ajaxLoad();
		this.stepDirection = order;
		var id = this.id;
		if (stepTimer[id] == null || typeof stepTimer[id] == "undefined")
		stepTimer[id] = setInterval("getPMove_photo_new('" + id + "').scrollRepeat()", 100);
	},
	scrollRepeat : function() {
		this.showNext(this.stepDirection);
		var id = this.id;
		if (typeof stepTimer[id] == "undefined" || stepTimer[id] != null) {
			clearInterval(stepTimer[id]);
			stepTimer[id] = null;
			stepTimer[id] = setInterval("getPMove_photo_new('" + id + "').scrollRepeat()", this.stepTimeout);
		}
	},
	mouseUpHandler : function() {
		var id = this.id;
		if (typeof stepTimer[id] == "undefined" || stepTimer[id] == null) return;
		clearInterval(stepTimer[id]);
		stepTimer[id] = null;
		this.showNext(this.stepDirection);
	},
	mixPreview : function() {
		if (this.defaultArray.length > 1) {
			var randKey = 0;
			var bufer = [];
			for (i = 0; i <= 3; i++) {
				randKey = parseInt(Math.random() * this.defaultArray.length);
				if (typeof this.defaultArray[i] == "undefined") continue;
				bufer = this.defaultArray[i];
				this.defaultArray[i] = this.defaultArray[randKey];
				this.defaultArray[randKey] = bufer;
			}
		}
	},
	drawNameItem : function(valueNameItem, urlNameItem) {
		if (this.nameItemEnable) {
			var nameItem = '' +
				'<div class="nameItem">' +
					'<div><span></span></div>' +
					'<div class="bodyNameItem"><a href="' + urlNameItem + '" title="' + valueNameItem + '">' + valueNameItem + '</a></div>' +
					'<div><span></span></div>' +
				'</div>';
		} else {
			var nameItem = '';
		}
		return nameItem;
	},
	drawPreview : function() {
		this.containerWidthDetect();
		var html = [];
		try {
			html[html.length] = '<table><tr>';
			var j;
			for (i = 0; i < this.previewCount; i++) {
				j = (this.curPos + i) % this.defaultArray.length;
				this.casheImages[j] = this.newImg(this.defaultArray[j][1]);

				if (!(document.all && !window.opera && parseInt(/msie\s([^;]+)/i.exec(navigator.appVersion)[1]) <= 6)) {
					var watermark_src = 'http://img.mail.ru/r/watermark_80.png';
				} else {
					var watermark_src = 'http://img.mail.ru/0.gif';
				}

				var nameItem = (this.nameItemEnable && (this.defaultArray[j][2] != undefined)) ? this.defaultArray[j][2] : '';
				
				var preview_unit = '<td><a href="' + this.defaultArray[j][0] + '" title="' + nameItem + '"><img id="preview_' + this.id + i + '_Id" src="' + this.defaultArray[j][1] + '"' + (this.previewWidth ? ' width="' + this.previewWidth + '"' : '') + (this.previewHeight ? ' height="' + this.previewHeight + '"' : '') + ' alt="' + nameItem + '" /></a></td>';

				html[html.length] = preview_unit;
			}
			html[html.length] = '</tr></table>';
			html = html.join('');
		} catch (e) {
			// Error. Do nothing
			alert("Error");
			return;
		}
		this.container.innerHTML = html;
	},
	showPreview : function() {
		var j;
		for (i = 0; i < this.previewCount; i++)
		{
			var itemMain = this.gebi('preview_' + this.id + i + '_Id');

			j = (this.curPos + i) % this.defaultArray.length;
			itemMain.src = this.defaultArray[j][1];
			itemMain.parentNode.href = this.defaultArray[j][0];

		}
	},
	containerWidthDetect : function() {
		this.containerWidth = this.screenSize().w * 0.9 * 0.26;
		this.containerWidth = this.containerWidth < this.containerWidthMin ? this.containerWidthMin : this.containerWidth;
		this.previewCount = 3; //parseInt(this.containerWidth / (this.previewWidth + this.marginLeft));
	},
	showNext : function(side) {
		if (side == "right") this.curPos++;
		else this.curPos--;
		if (this.curPos < 0) this.curPos = this.defaultArray.length - 1;
		if (this.curPos > this.defaultArray.length - 1) this.curPos = 0;
		this.showPreview();
		this.drawAngles();
		if (side == "left" && !this.isLeft) {
			clearInterval(stepTimer[this.id]);
			stepTimer[this.id] = null;
		}
		return false;
	},
	drawAngles : function() {
		this.define();
		var i = a = img = 0, node, nodes = {};
		for (i = 0; i < this.leftAngle.childNodes.length; i++) {
			node = this.leftAngle.childNodes[i];
			if (node.nodeType != 1) continue;
			nodes[node.nodeName.toLowerCase()] = node;
		}
		if (typeof nodes["a"] != "undefined" && typeof nodes["img"] != "undefined") {
			nodes["a"].style.display = this.isLeft ? "" : "none";
			nodes["img"].style.display = this.isLeft ? "none" : "";
			if (!this.initFlag) nodes["img"].style.backgroundColor = "#FFFFFF";
		}
		for (i = 0; i < this.rightAngle.childNodes.length; i++) {
			node = this.rightAngle.childNodes[i];
			if (node.nodeType != 1) continue;
			nodes[node.nodeName.toLowerCase()] = node;
		}
		if (typeof nodes["a"] != "undefined" && typeof nodes["img"] != "undefined") {
			nodes["a"].style.display = this.isRight ? "" : "none";
			nodes["img"].style.display = this.isRight ? "none" : "";
			if (!this.initFlag) nodes["img"].style.backgroundColor = "#FFFFFF";
		}
		//this.loadPreview();
	},
	define : function() {
		/*
		//this.isLeft = this.curPos ? true : false;
		this.isLeft = true;
		this.isRight = true;
		*/
		this.isLeft = this.curPos ? true : false;
		this.isRight = true;
	},
	loadPreview : function() {
		if (this.casheImages.length != this.defaultArray.length) {
			for (i = 0; i < this.previewCount * 2; i++) {
				j = (this.curPos + i) % this.defaultArray.length;
				if (typeof this.casheImages[j] == "undefined") this.casheImages[j] = this.newImg(this.defaultArray[j][1]);
			}
		}
	},
	ajaxLoad : function() {
		var _this = this;
		this.scriptURL = (this.scriptURL.indexOf('http://') == -1) ? ('http://' + window.location.hostname + this.scriptURL) : this.scriptURL;
		//this.scriptURL = 'http://' + 'mail.ru' + this.scriptURL;//window.location.hostname
		//alert(this.nameItemEnable);
		ajax_call_static(
			this.scriptURL,
			function(arr) {
				var item = new Array();
				var str = '';
				if (arr.length) {
					for (var i = 0; i < arr.length; i++) {
						if (arr[i]["PhotoName"] != 'undefined') {
							try
							{// if contain &#8470;, for conversion to №
								var result = arr[i]["PhotoName"].match(/&#\d+;/g);
								if (result != null) {
									for (var j = 0; j < result.length; j++) {
										result[j] = result[j].replace(/[&#;]/g, '');
										arr[i]["PhotoName"] = arr[i]["PhotoName"].replace(/&#\d+;/g, String.fromCharCode(result[j]));
									}
								}
							} catch(e) {}

							item = [arr[i]["url"], arr[i]["prevurl"], arr[i]["PhotoName"]];//
						}
						else item = [arr[i]["url"], arr[i]["prevurl"]];

						_this.defaultArray[_this.defaultArray.length] = item;
					}
				}
			}
		);
		this.xmlEnable = false;
	}
}
/* ______________ код для линейки превью на главной морде v2 ______________*/




