var smallCurrFoto = false; //Содержит текущую выбранную фотографию

var objFotoCount = 0; // количество изображений в массиве 
var objFotoCurrent = 0; // Текущее изображение 
var maxNumFoto = 4;
var numNext = 0; //Количество фотографий, на которое мы перемотали

var idFotoName = "smallFoto";
var idCommentName = "commentFoto";
var defImage = "default.jpg";

//VIDE VARS

var smallCurrVideo = false; //Содержит текущее выбранное видео
var objVideoCount = 0; // количество видеороликов в масиве 
var objVideoCurrent = 0;
var maxNumVideo = 3;
var numVideoNext = 0; //Количество видео, на которое мы перемотали
var idVideoName = "smallVideo";

function preloadFoto(name_obj, big_photo, small_photo, comment_photo, photo_orig) 
{  
  if (browserOK) {
   
    pics[objFotoCount] = new Array(5);
    pics[objFotoCount][0] = new Image();
    pics[objFotoCount][0].src = big_photo;
    pics[objFotoCount][1] = new Image();
    pics[objFotoCount][1].src = small_photo;
    pics[objFotoCount][2] = name_obj;
    pics[objFotoCount][3] = comment_photo;
    pics[objFotoCount][4] = new Image();
    pics[objFotoCount][4].src = photo_orig;
    

    objFotoCount++;
  }
}

function reloadFoto()
{
	for( var i=0; i<maxNumFoto; i++)
	{
		var lnumNext = i + numNext;
		
		var oImgDiv = document.getElementById(idFotoName+i);
		oImgDiv.src = pics[lnumNext][1].src;
		oImgDiv.width = pics[lnumNext][1].width;
		oImgDiv.height = pics[lnumNext][1].height;

//max		var oCommentSpan = document.getElementById(idCommentName+i);
//		oCommentSpan.text = '1';
//max    oCommentSpan.innerHTML = '';
//    oCommentSpan.firstChild.replaceNode(document.createTextNode(pics[lnumNext][3]));
//max		oCommentSpan.appendChild( document.createTextNode(pics[lnumNext][3]) );

	}
}

//Выводик кнопочки прокрутки вперед-назад
function setVisFoto()
{
  //alert('tut');
	objNext = document.getElementById("next_foto");
	objPrev = document.getElementById("prev_foto");
	if( (maxNumFoto + numNext ) < objFotoCount )
	{
//		objNext.className = "visObj";
		objNext.src = '/images/'+fotoNext_a;
	}
	else	
	{
//		objNext.className = "hiddenObj";
		objNext.src = '/images/'+fotoNext;
	}

	if( numNext > 0 )
	{
//		objPrev.className = "visObj";
		objPrev.src = '/images/'+fotoPrev_a;
	}
	else
	{
//		objPrev.className = "hiddenObj";
		objPrev.src = '/images/'+fotoPrev;
	}
}

function getNext( obj )
{
	if(objFotoCount > maxNumFoto && (maxNumFoto + numNext ) < objFotoCount )
	{
		numNext ++;
		reloadFoto();
	}
	setVisFoto();
}

function getPrev( obj )
{
	if( numNext > 0 )
	{
		numNext --;
		reloadFoto();
	}
	setVisFoto();
}

//Выводит текущую фотографию в окно просмотра
function fotoClick()
{
	var oCurrFoto = document.getElementById("currFoto");
	var oCurrFotoLink = document.getElementById("currFotoLink");
//	oCurrFoto.src = this.src;
	var numFoto = this.id;
	numFoto = numFoto.substr(idFotoName.length,numFoto.length - idFotoName.length);
	var lnumNext = parseInt(numFoto) + numNext;

	if( lnumNext < objFotoCount )
	{
		oCurrFoto.src = pics[lnumNext][0].src; //Соответствующая большая фотография
		oCurrFoto.parentNode.href = pics[lnumNext][4].src; //Соответствующая большая фотография
		oCurrFotoLink.href = pics[lnumNext][4].src;
	}
	else
		oCurrFoto.src = defImage; //Соответствующая большая фотография
		
	
	if( smallCurrFoto == false)
		smallCurrFoto = document.getElementById("smallFoto0");

	smallCurrFoto.className = "imgFoto";
	smallCurrFoto = this;
	smallCurrFoto.className = "imgFoto_curr";
}

//создать элементы с фотографиями
function getDivFoto()
{
	var oFragment = document.createDocumentFragment();
	var first = true;
	for( var i=0; i<maxNumFoto; i++)
	{ 
	  //alert('ins');
		var oDiv = document.createElement('div');
		oDiv.className = "fotoGalery";
		oDiv.id = "foto"+i;

		var oDivMiddle = document.createElement('div');
		oDivMiddle.className = "fotoMiddle";

		var oDivMiddleBottom = document.createElement('div');
		oDivMiddleBottom.className = "fotoMiddleBottom";
		
	  var oComment = false;
    
		var oImgDiv = document.createElement('img');
		var lnumNext = i + numNext;
		var xxx;
		var photo_orig;
		if( lnumNext < objFotoCount ){
			xxx=pics[lnumNext][0].src;
			oImgDiv.src = pics[lnumNext][1].src;
			photo_orig = pics[lnumNext][4].src; //Соответствующая большая фотография


  		oComment = document.createTextNode(pics[lnumNext][3]);
		}
		else	
			oImgDiv.src = defImage;
		
		oImgDiv.id = idFotoName+i;
		if( first )
		{
			//alert(oImgDiv.src);	
			var oCurrFoto = document.getElementById("currFoto");;
			var oCurrFotoLink = document.getElementById("currFotoLink");
			//oCurrFoto.src=oImgDiv.src;
			oCurrFoto.src=xxx;
			oCurrFoto.parentNode.href = photo_orig;
			oCurrFotoLink.href = photo_orig;
			oImgDiv.className = "imgFoto_curr";
		}
		else
			oImgDiv.className = "imgFoto";
		oImgDiv.onclick = fotoClick;

		oDivMiddleBottom.appendChild(oImgDiv);
  	oDivMiddle.appendChild(oDivMiddleBottom);
		oDiv.appendChild(oDivMiddle);
/*		if( oComment )
		{
  		var oSpan = document.createElement('span');
		  
  	  oSpan.className = "commentFoto";
  		oSpan.id = "commentFoto"+i;
  		
    	oSpan.appendChild(oComment);
    	oDiv.appendChild(oSpan);
  	}*/
		oFragment.appendChild(oDiv);
		first = false;
	}
	return oFragment;
}

//Вывести элементы с фотографиями
function setDivFoto()
{  //alert('11');
	//Заполняем список фоток
	var oDivAllFoto = document.getElementById("allFoto");
	var oNextFoto = document.getElementById("nextFoto");
	if(!objFotoCount )
	{
		oDivAllFoto.parentNode.removeChild(oDivAllFoto);
		return;
	}

	if(objFotoCount < maxNumFoto)
	   maxNumFoto = objFotoCount;
	   //alert('maxNumFoto'+maxNumFoto);
//	oDivAllFoto.appendChild( getDivFoto() );
	//oDivAllFoto.insertBefore( getDivFoto(), oNextFoto );
	var divfoto = document.getElementById("divfoto");
	//oDivAllFoto.insertBefore( getDivFoto(), oNextFoto );
	divfoto.appendChild(getDivFoto());
	//alert('22');
	setVisFoto();

}

// VIDEO PART

function reloadVideo()
{

	
		for( var i=0; i<maxNumVideo; i++)
	{
		var lnumVideoNext = i + numVideoNext;
		
		var oImgDiv = document.getElementById(idVideoName+i);
		oImgDiv.src = mvideo[lnumVideoNext][1].src;
		oImgDiv.width = mvideo[lnumVideoNext][1].width;
		oImgDiv.height = mvideo[lnumVideoNext][1].height;
	}
}


function setVisVideo()
{

	objNext = document.getElementById("next_video");
	objPrev = document.getElementById("prev_video");
	if( (maxNumVideo + numVideoNext ) < objVideoCount )
	{
//		objNext.className = "visObj";
		objNext.src = '/images/'+fotoNext_a;
	}
	else	
	{
//		objNext.className = "hiddenObj";
		objNext.src = '/images/'+fotoNext;
	}

	if( numVideoNext > 0 )
	{
//		objPrev.className = "visObj";
		objPrev.src = '/images/'+fotoPrev_a;
	}
	else
	{
//		objPrev.className = "hiddenObj";
		objPrev.src = '/images/'+fotoPrev;
	}
}


/*function getVideoNext( obj )
{
	if(objVideoCount > maxNumVideo && (maxNumVideo + numVideoNext ) < objVideoCount )
	{
		numVideoNext ++;
		reloadVideo();
	}
	setVisVideo();
}

function getVideoPrev( obj )
{
	if( numVideoNext > 0 )
	{
		numVideoNext --;
		reloadVideo();
	}
	setVisVideo();
}
*/

function getVideoNext( obj )
{
	if(objVideoCount > maxNumVideo && (maxNumVideo + numVideoNext ) < objVideoCount )
	{
		numVideoNext ++;
		reloadVideo();
	}
	setVisVideo();
}

function getVideoPrev( obj )
{
	if( numVideoNext > 0 )
	{
		numVideoNext --;
		reloadVideo();
	}
	setVisVideo();
}
//Выводит текущее видео в окно просмотра
function videoClick()
{
	
//	oCurrFoto.src = this.src;
	var numVideo = this.id;
	numVideo = numVideo.substr(idVideoName.length,numVideo.length - idVideoName.length);
	var lnumVideoNext = parseInt(numVideo) + numVideoNext;

	if( lnumVideoNext < objVideoCount )
	{
		to_swf(mvideo[lnumVideoNext][0],mvideo[lnumVideoNext][2].src);
	}
	else
		oCurrFoto.src = defImage; //Соответствующая большая фотография
		
	
	if( smallCurrVideo == false)
		smallCurrVideo = document.getElementById("smallVideo0");

	smallCurrVideo.className = "imgVideo";
	smallCurrVideo = this;
	smallCurrVideo.className = "imgVide_curr";
}


//создать элементы с фотографиями
function getDivVideo()
{
	var oFragment = document.createDocumentFragment();
	var firstV = true;
	for( var i=0; i<maxNumVideo; i++)
	{ 
	  //alert('ins');
		var oDiv = document.createElement('div');
		oDiv.className = "videGalery";
		oDiv.id = "video"+i;
     
		var oImgDiv = document.createElement('img');
		var lnumVideoNext = i + numVideoNext;
		var xxx;
		if( lnumVideoNext < objVideoCount )
		{
			xxx=mvideo[lnumVideoNext][0];
			minipic = mvideo[lnumVideoNext][1].src;
			oImgDiv.src = mvideo[lnumVideoNext][1].src;
		}
		else	
			oImgDiv.src = defImage;
		
		oImgDiv.id = idVideoName+i;
		if( firstV )
		{
			//alert(oImgDiv.src);	

			//oCurrFoto.src=oImgDiv.src;
			to_swf(xxx,minipic);
			oImgDiv.className = "imgVideo_curr";
		}
		else
			oImgDiv.className = "imgVideo";
		oImgDiv.onclick = videoClick;

		oDiv.appendChild(oImgDiv);
		oFragment.appendChild(oDiv);
		firstV = false;
	}
	return oFragment;
}


function preloadVideo(file_name,thumb, thumbBig) 
{  
  if (browserOK) {
    mvideo[objVideoCount] = new Array(1);
    mvideo[objVideoCount][0] = file_name;
    mvideo[objVideoCount][1] = new Image();
    mvideo[objVideoCount][1].src = thumb;
    mvideo[objVideoCount][2] = new Image();
    mvideo[objVideoCount][2].src = thumbBig;
    objVideoCount++;
  }
}

function setDivVideo()
{  //alert('11');
	//Заполняем список видео
	var oDivAllVideo = document.getElementById("allVideo");
	var oNextVideo = document.getElementById("nextVideo");
	if(!objVideoCount )
	{
		oDivAllVideo.parentNode.removeChild(oDivAllVideo);
		return;
	}

	if(objVideoCount < maxNumVideo)
	   maxNumVideo = objVideoCount;
	   //alert('maxNumFoto'+maxNumFoto);
//	oDivAllFoto.appendChild( getDivFoto() );
	//oDivAllFoto.insertBefore( getDivFoto(), oNextFoto );
	var divvideo = document.getElementById("divvideo");
	//oDivAllFoto.insertBefore( getDivFoto(), oNextFoto );
	divvideo.appendChild(getDivVideo());
	//alert('22');
	setVisVideo();

}

function runSwf(args,small_pic)
{
	var s1 = new SWFObject("/images/mediaplayer.swf","mediaplayer","430","350","8");
	s1.addParam("allowfullscreen","true");
	s1.addVariable("width","430");
	s1.addVariable("height","350");
	s1.addVariable("file",args); 
	s1.addVariable("image",small_pic);
	s1.write("currVideo");
	
//	var oVideo = document.getElementById("currVideoObj");
//	oVideo.SetVariable('file', args);
//	window.document.currVideoObj.addVariable("file",args);
//	window.document.currVideoObj.SetVariable('file', args);
}

function to_swf(args,small_pic)
{
	isFoto = false;
	setBlockFull();
	var tm = setTimeout( "runSwf('" + args + "','"+small_pic+"')", 100	);
//	clearTimeout(tm);
//	window.document.tuz.SetVariable('file', args);
}

function setBlockFull()
{
	/*objFoto = document.getElementById("currFoto");
	objVideo = document.getElementById("currVideo");
	if( isFoto == true  )
	{
		if( objFoto.style.display != "block" )
		{
			objFoto.style.display = "block";
			objVideo.style.display = "none";
		}
	}
	else
	{
		if(objFoto.style.display != "none")
		{
			objFoto.style.display = "none";
			objVideo.style.display = "block";
		}
	}*/
}

if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;