function urlwork(){
	return (dle_root?dle_root:url_to_main) + 'engine/photo/flash.php';
}

var noshow = '';
var ignork = '';
var cache_ = new Array();
var cache_count = 70;
var cache_edits = new Array();

function TOutf(url)
{

	url = url.toString();
	var regcheck = url.match(/[\x90-\xFF]/g);
	if( regcheck )
	{
		for( var i = 0; i < i.length; i++)
		{
			url = url.replace(regcheck[i], '%u00' + (regcheck[i].charCodeAt(0) & 0xFF).toString(16).toUpperCase());
		}
	}
	return escape(url).replace(/\+/g, "%2B");
}

function photo_win( url, name, w, h)
{
	if(!w) var w = 600;
	if(!h) var h = 500;
	window.open( url, name, 'scrollbars,resizable,width=' + w + ',height=' + h );
}

function rp( id , activ )
{
	var ajax = new dle_ajax();
	ajax.execute = true;
	ajax.onShow ('');
	var varsString = "";
	ajax.setVar( "command", 'R' );
	if( activ==1 ) ajax.setVar( "M", id );
	else ajax.setVar( "P", id );
	ajax.requestFile =  urlwork();
	ajax.method = 'GET';
	ajax.element = 'rp-' + id;
	ajax.sendAJAX(varsString);
}

function onPhoto(i, on)
{	var o = document.getElementById(i);
	if(o.style.background!='#e6f1ff')
	if(!o.style.background && on == 'over')
	o.style.background='#F9FCFF';
	else o.style.background='';
}

function editPhotoComm(id)
{
	var obg = document.getElementById('comm-'+id);
	if( obg ) cache_edits[id] = obg.innerHTML;
	var ajax = new dle_ajax();
	ajax.execute = true;
	ajax.onShow ('');
	var varsString = "";
	ajax.setVar( 'command', 'BA' );
	ajax.setVar( 'cid', id );

	var obj = document.getElementById('ephotocomms'+id);
	if( obj ){		ajax.setVar( 'text', TOutf( obj.value ) );
	}

	ajax.requestFile =  urlwork();
	ajax.method = 'POST';
	ajax.element = 'comm-'+id;
	ajax.sendAJAX(varsString);
}

function cancelPhotoCommEdit(id)
{	var obg = document.getElementById('comm-'+id);
	if( obg && cache_edits[id] ) obg.innerHTML = cache_edits[id];
}

function nextphotol( pid, albom , start )
{
	var ajax = new dle_ajax();
	ajax.execute = true;
	ajax.onShow ('');
	var varsString = "";
	ajax.setVar( 'command', 'AA' );
	ajax.setVar( 'act', 'next' );
	ajax.setVar( 'pid', pid);
	ajax.setVar( 'albom', albom );
	ajax.setVar( 'start', start );
	ajax.requestFile =  urlwork();
	ajax.method = 'POST';
	ajax.element = 'photoline';
	ajax.sendAJAX(varsString);
}

function backphotol( pid, albom , start )
{
	var ajax = new dle_ajax();
	ajax.execute = true;
	ajax.onShow ('');
	var varsString = "";
	ajax.setVar( 'command', 'AA' );
	ajax.setVar( 'act', 'back' );
	ajax.setVar( 'pid', pid );
	ajax.setVar( 'albom', albom );
	ajax.setVar( 'start', start );
	ajax.requestFile =  urlwork();
	ajax.method = 'POST';
	ajax.element = 'photoline';
	ajax.sendAJAX(varsString);
}

/*Нижи приведенный код собственность Dle-news.ru*/

var horizontal_offset="9px";
var vertical_offset = "0";
var ie = document.all;
var ns6 = document.getElementById &&!document.all;

function getposOffset(what, offsettype)
{
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null)
	{
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function iecompattest()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge)
{
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1;

	if (whichedge=="rightedge")
	{

		var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
		{
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset);
	    }
	}else{
		var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
		{
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight;
		}
	}
	return edgeoffset;
}

function showhint_photo(menucontents, obj, e, tipwidth){	if( ( ie || ns6 ) && document.getElementById("hintbox_photo") )
	{

		dropmenuobj=document.getElementById("hintbox_photo");
		dropmenuobj.innerHTML=menucontents;
		dropmenuobj.style.left=dropmenuobj.style.top=-500;
		if (tipwidth!="")
		{
			dropmenuobj.widthobj=dropmenuobj.style;
			dropmenuobj.widthobj.width=tipwidth;
		}
		dropmenuobj.x=getposOffset(obj, "left");
		dropmenuobj.y=getposOffset(obj, "top");
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px";
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px";
		dropmenuobj.style.visibility="visible";
		obj.onmouseout=hidetip;
	}
}

function hidetip(e)
{
	dropmenuobj.style.visibility="hidden";
	dropmenuobj.style.left="-500px";
}

function addcomment(i)
{
	var ajax = new dle_ajax();
	ajax.onShow ('');
	ajax.execute = true;
	var varsString = "";
	if (document.getElementById('com-email'))
	{
		ajax.setVar("n", TOutf(document.getElementById('com-name').value) );
		ajax.setVar("e", TOutf(document.getElementById('com-email').value) );
	}
	ajax.setVar( "command", 'G' );
	ajax.setVar( "comments", TOutf( document.getElementById('comments').value ) );
	ajax.setVar( "id", i);
	ajax.setVar( "ajax", i);
	if(document.getElementById('comseccod')) ajax.setVar( "seccod", document.getElementById('comseccod').value );
	ajax.requestFile =  urlwork();
	ajax.method = 'POST';
	ajax.element = 'newcomm';
	ajax.sendAJAX(varsString);
}

/* Code by DLE (c) */

function dle_copy_quote_(qname)
{
	dle_txt= '';
	if (window.getSelection)
	{
	 dle_txt=window.getSelection();
	}
	else if (document.selection)
	{
	 dle_txt=document.selection.createRange().text;
	}
	if (dle_txt != "")
	{
	 dle_txt='[quote='+qname+']'+dle_txt+'[/quote]\n';
	}
};

function dle_ins_(name)
{
	if ( !document.getElementById('photo-comm-add') ) return false;
	var input=document.getElementById('photo-comm-add').message;
	var finalhtml = "";
	if (dle_wysiwyg == "no") {
		if (dle_txt!= "") {
			input.value += dle_txt;
		}
		else {
			input.value += "[b]"+name+"[/b],"+"\n";
		}
	} else {
		if (dle_txt!= "") {
			finalhtml = dle_txt;
		}
		else {
			finalhtml = "<b>"+name+"</b>,"+"<br />";
		}
	tinyMCE.execInstanceCommand('comments', 'mceInsertContent', false, finalhtml, true)
	}
}

/* / */

function next_alboms( i )
{
	var ajax = new dle_ajax();
	ajax.onShow ('');
	ajax.execute = true;
	var varsString = "";
	ajax.setVar( "command", 'AL' );
	ajax.setVar( "page", i );
	ajax.requestFile =  urlwork();
	ajax.method = 'POST';
	ajax.element = 'alboms';
	ajax.sendAJAX(varsString);
}

/* Thanks to ManHunter ( site http://www.manhunter.ru ) */

function hookEvent(hElem, eventName, callback) {
  if (typeof(hElem) == 'string') {
    hElem = document.getElementById(hElem);
  }
  if (!hElem) { return false; }

  if (hElem.addEventListener) {
    if (eventName == 'mousewheel') {

      hElem.addEventListener('DOMMouseScroll', callback, false);
    }

    hElem.addEventListener(eventName, callback, false);
  }
  else if (hElem.attachEvent) {

    hElem.attachEvent('on' + eventName, callback);
  }
  else { return false; }
  return true;
}

function unhookEvent(hElem, eventName, callback) {
  if (typeof(hElem) == 'string') {

    hElem = document.getElementById(hElem);
  }

  if (!hElem) { return false; }

  if (hElem.removeEventListener) {
    if (eventName == 'mousewheel') {

      hElem.removeEventListener('DOMMouseScroll', callback, false);
    }

    hElem.removeEventListener(eventName, callback, false);
  }
  else if (hElem.detachEvent) {

    hElem.detachEvent('on' + eventName, callback);
  }
  else { return false; }
  return true;
}

function cancelEvent(e) {
  e = e ? e : window.event;
  if (e.stopPropagation) {
    e.stopPropagation();
  }
  if (e.preventDefault) {
    e.preventDefault();
  }
  e.cancelBubble = true;
  e.cancel = true;
  e.returnValue = false;
  return false;
}

function setHook(obj, act ) {
  act ? hookEvent(obj.id, 'mousewheel', MouseWheelFunction) : unhookEvent(obj.id, 'mousewheel', MouseWheelFunction);
}

function MouseWheelFunction(e) {
  e = e ? e : window.event;
  var wheelElem = e.target ? e.target : e.srcElement;
  var wheelData = e.detail ? e.detail * -1 : e.wheelDelta / 40;
  if (Math.abs(wheelData)>100) { wheelData=Math.round(wheelData/100); }
  if( wheelData > 0 )
  {  	if( left_ )
	{
	  	cache_count = cache_count + 1;
	  	if( cache_[ cache_count ] )
	  	{	  		document.getElementById( 'photoline' ).innerHTML = cache_[ cache_count ];
	  	}else{	  		nextphotol(pid, albom, start);	  		cache_[ cache_count ] = document.getElementById( 'photoline' ).innerHTML;
	  	}
	}
  }else{  	if( right_ )
  	{
	  	cache_count = cache_count - 1;
	  	if( cache_[ cache_count ] )
	  	{
	  		document.getElementById( 'photoline' ).innerHTML = cache_[ cache_count ];
	  	}else{
	  		backphotol(pid, albom, start);
	  		cache_[ cache_count ] = document.getElementById( 'photoline' ).innerHTML;
	  	}
	}
  }
  return cancelEvent(e);
}

function ref()
{
	window.opener.location = window.opener.location;
}
