/*document.write('<script src="/js/prototype.js" type="text/javascript"></script>');*/
document.write('<script type="text/javascript" src="/js/datepickercontrol.js"></script>');
document.write('<script type="text/javascript" src="/js/swfobject.js"></script>');
/*if (navigator.platform.toString().toLowerCase().indexOf("linux") != -1){
	document.write('<link type="text/css" rel="stylesheet" href="/js/datepickercontrol_lnx.css">');
}else{
	document.write('<link type="text/css" rel="stylesheet" href="/js/datepickercontrol.css">');
}
document.write('<script type="text/javascript" src="/js/jq.js"></script>');*/
document.write('<script type="text/javascript" src="/js/ui.core.js"></script>');
document.write('<script type="text/javascript" src="/js/jq-ui.js"></script>');

//НЕ ЛАЗИЙ СЮДА!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

var pdf_params = {
  menu: "false",
  bgcolor: '#efefef',
  allowFullScreen: 'true'
};
var pdf_attributes = {
	id: 'website'
};


function MM_openBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}


function getElementsByClassName(classname,tag) {
	 if(!tag) tag = "*";
	 var anchs =  document.getElementsByTagName(tag);
	 var total_anchs = anchs.length;
	 var regexp = new RegExp('\\b' + classname + '\\b');
	 var class_items = new Array()
	 
	 for(var i=0;i<total_anchs;i++) {
	  var this_item = anchs[i];
	  if(regexp.test(this_item.className)) {
	   class_items.push(this_item);
	  }
	 }
	 return class_items;
	}
	function toggleEl(elem, anc) {
		var t_el = document.getElementById(elem);
		if (t_el.style.display == 'none') {
		for (var i = 0, j = getElementsByClassName('inner_ul').length; i < j; i++) {
		   getElementsByClassName('inner_ul')[i].style.display = 'none';
		}
		for (var i = 0, j = getElementsByClassName('active').length; i < j; i++) {
		   getElementsByClassName('active')[i].className = '';
		}	
		t_el.style.display = 'block';
		}
		else t_el.style.display = 'none';
		anc.className = anc.className == '' ? 'active' : '';
	}
	function getBrowserWidth(){
		if (window.innerWidth){
			return window.innerWidth;}  
		else if (document.documentElement && document.documentElement.clientWidth != 0){
			return document.documentElement.clientWidth;    }
		else if (document.body){return document.body.clientWidth;}      
			return 0;
	}
	function getBrowserHeight(){
		if (window.innerHeight){
			return window.innerHeight;}  
		else if (document.documentElement && document.documentElement.clientHeight != 0){
			return document.documentElement.clientHeight;    }
		else if (document.body){return document.body.clientHeight;}      
			return 0;
	}
	function hideBigLayer(divId){
		var div=document.getElementById(divId);
		var dwrap=document.getElementById('bigImgWrap');
		dwrap.style.visibility='hidden';
		div.style.display='none';
	}
	function animWidth(divId, start, finish){
		var div=document.getElementById(divId);
		var currWidth=start+10;
		div.style.width=currWidth+'px';
		if(currWidth<finish){
			setTimeout(function(){animWidth(divId, currWidth, finish);}, 0.5);
		}else{
			return currWidth;
		}
	}
	function animHeight(divId, start, finish){
		var div=document.getElementById(divId);
		var currHeight=start+10;
		div.style.height=currHeight+'px';
		if(currHeight<finish){
			setTimeout(function(){animHeight(divId, currHeight, finish);}, 0.5);
		}else{
			return currHeight;
		}
	}
	function showBigLayer(divId, w, h, bigimg){
		var l=(getBrowserWidth()/2)-(w/2);
		var t=(getBrowserHeight()/2)-(h/2);
		var div=document.getElementById(divId);
		var dwrap=document.getElementById('bigImgWrap');
		dwrap.style.visibility='visible';
		div.style.left=l.toFixed(0)+'px';
		div.style.top=t.toFixed(0)+'px';
		div.style.display='block';
		animWidth(divId, 10, w);
		animHeight(divId, 10, h);
		div.innerHTML='<img class="galleryBigImg" src="'+bigimg+'" onclick="hideBigLayer(\'bigImg\')">';
	}
	

document.write('<script src="/js/JsHttpRequest/lib/JsHttpRequest/JsHttpRequest.js"></script>');

function getNextPrev(id, cat){
 var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('arrows').innerHTML = req.responseText;
        }
    }
    req.open(null, '/js/nextprev.php', true);
    req.send( { currid: id, currcat: cat } );
}

function reportError(request){
	alert('Ошибка соединения с сервером!\nПроверьте соединение с интернетом или обновите страницу.');
}

// This Script was written by Benjamin Meier, b2m@gmx.de
// The DHTML-function for creating a overlaying div-layer uses parts of the Dynamic Image Mambot, written by Manuel Hirsch
// and Lightbox => core code quirksmode.org
var pg_ffwrong = "red";
var pg_padding = "5";
var pg_filenamewithjs = "1";
var pg_dhtml_border = "gray";
var pg_openjs_background = "white";
var pg_disableclick = "1";
var pg_use_code = "1";
var pg_show_title_in_dhtml = "1";
var pg_show_description_in_dhtml = "1";
var ponygallery_image = "Фото";
var ponygallery_of = "из";
var ponygallery_close = "Закрыть";
var ponygallery_prev = " Назад";
var ponygallery_next = "Дальше";
var ponygallery_press_esc = "(Esc)";
var resizeJsImage = "1";
function opendhtml(id, cat, imgsource, imgtitle, imgtext, imgwidth, imgheight) {
  imgwidth = parseInt(imgwidth);
  imgheight = parseInt(imgheight);
	//var dwrap=document.getElementById('bigImgWrap');
		//dwrap.style.visibility='visible';
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	//dwrap.style.height=(document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight+'px';
	var yScroll, xScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
	var fullHeight=(document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
	//Create wrap layer
	var bodyObj = document.getElementsByTagName('BODY')[0];
  if(!document.getElementById("bigImgWrap")) {
    divObjWrapper = document.createElement("div");
    divObjWrapper.setAttribute("id", "bigImgWrap");
    bodyObj.appendChild(divObjWrapper);
  } else {
    divObjWrapper = document.getElementById("bigImgWrap");
  }
  with(divObjWrapper.style){
	position='absolute'; 
	backgroundColor='#000000'; 
	top='0px'; 
	left='0px'; 
	zIndex='90'; 
	width='100%';
	height=fullHeight+'px'; 
	filter='alpha(opacity=60)'; 
	mozOpacity='0.6';	
	opacity='0.6';
	visibility='visible';
  }

  if(resizeJsImage==1) {
   if((imgwidth+3*pg_padding)>windowWidth) {
     imgheight = (imgheight * (windowWidth-2*pg_padding))/imgwidth;
     imgwidth = windowWidth-2*pg_padding;
   }
   if((imgheight+2*pg_padding+80)>windowHeight) {
     imgwidth = (imgwidth * (windowHeight-2*pg_padding-80))/imgheight;
     imgheight = windowHeight-2*pg_padding-80;
   }
  }
  var postop =(windowHeight/2)-(imgheight/2)+yScroll+document.body.style.padding-10;
  var posleft =(windowWidth/2)-(imgwidth/2)+xScroll+document.body.style.padding;
  if(postop >= 30) { 
   postop = postop-30;
  }
 // var bodyObj = document.getElementsByTagName('BODY')[0];
  if(!document.getElementById("pg_photocontainer")) {
    divObjContainer = document.createElement("div");
    divObjContainer.setAttribute("id", "pg_photocontainer");
    bodyObj.appendChild(divObjContainer);
  } else {
    divObjContainer = document.getElementById("pg_photocontainer");
  }

  var closeimg = new Image();
  closeimg.src = "/images/close.gif";

  var dhtmltext, dhtmltext2="";

  divObjContainer.style.display = "block";
  dhtmltext  = "<div class=\"pg_photocontainer\" style=\"top:"+postop+"px; left:"+posleft+"px; position: absolute; display:block;z-index:99999;\">";
  dhtmltext += "<div class=\"photoborder\" style=\"background-color: "+pg_openjs_background+"; padding: "+pg_padding+"px; border: solid 1px "+pg_dhtml_border+";\">";
  dhtmltext += "<img onclick=\"pg_photocontainershut()\" style=\"cursor:pointer;border: solid 1px #000;width:"+imgwidth+"px;height:"+imgheight+"px;\" src=\""+imgsource+"\" alt=\""+imgtitle+"\" width=\""+imgwidth+"px\" height=\""+imgheight+"px\" class=\"pngfile\" \/>";
  dhtmltext += "<div id='arrows' style='text-align:center'></div><img onclick=\"pg_photocontainershut()\" style=\"cursor:pointer;position:absolute;bottom:"+pg_padding+"px;right:"+pg_padding+"px;width:"+closeimg.width+"px;height:"+closeimg.height+"px;\" src=\""+closeimg.src+"\" title=\"Закрыть\" id=\"dhtml_close\" class=\"pngfile\" />";  
  dhtmltext += "<br /><div id=\"pony_dhtml_imgtext\" style=\"color:#000000; margin-top:"+pg_padding+"px;text-align: justify; width:"+imgwidth+"px;\">&nbsp;<br />&nbsp;</div>";
  //dhtmltext += "<\/div></div>";
  divObjContainer.innerHTML = dhtmltext;
     document.getElementById("pony_dhtml_imgtext").style.width2 = document.getElementById("pony_dhtml_imgtext").style.width-document.getElementById("dhtml_close").style.width;
  if (pg_show_title_in_dhtml==1) {
   dhtmltext2 += "<strong>"+imgtitle+"</strong><br />";
  }
  if (pg_show_description_in_dhtml==1) {
   dhtmltext2 += imgtext;
  }
  dhtmltext2 += "<\/div></div>";
  if (dhtmltext2!="") {
   document.getElementById("pony_dhtml_imgtext").innerHTML = dhtmltext2;
  }

  if (pg_disableclick==1) { 
    divObjContainer.oncontextmenu = function(){return false;}
  }
  getNextPrev(id, cat);
}

function pg_photocontainershut() {
  document.getElementById("pg_photocontainer").style.display = "none";
  var dwrap=document.getElementById('bigImgWrap');
		dwrap.style.visibility='hidden';
}

function showdiv(obj, parent){  
	var div=document.getElementById('divmenu'+obj);
	if(div.style.display=="none"){
	   document.cookie = "divmenu="+obj+"; expires=Thu, 31 Dec 2100 23:59:59 GMT; path=/;";
	  div.style.display="block";
	}else{
	   if(parent==0){
		  document.cookie = "divmenu=N; expires=Thu, 31 Dec 2100 23:59:59 GMT; path=/;";
		  div.style.display="none";
	   }
	}return true;
}

function setID(id){
	$('#currid').val(id);
	$.ajaxSetup({cache: false});
	$.get('/linkcode.php', { 'id': id, 'mode':'title' }, function (data){ document.title=data; });
	$('#block_comment').html('<img src="/images/loading.gif" align=left>&nbsp; Идет загрузка...');
	$.get('/modules/comments.php', { 'id': id }, function (data){ $('#block_comment').html(data); });
	$.get('/linkcode.php', { 'id': id, 'mode':'comments' }, function (data){ $('#a_comments').text(data); });
	if($('#showlink').css('display')=='block'){
		$('#showlink').slideUp('normal');
		$('#videocode').text('Получить код');
		$('#videolink').text('Прямая ссылка');
	}
}

function getLink(){
	var videoID=$('#currid').val();
	$('#videolink').blur();
	$.ajaxSetup({cache: false});
	$.get('/linkcode.php', { 'id': videoID, 'mode':'link' }, function (data){ $('#showlink').html(data); });
	$('#showlink').slideToggle('fast', function(){
		var txt=($('#showlink').css('display')=='none')?'Прямая ссылка':'Скрыть';
		$('#videolink').text(txt);
		$('#videocode').text('Получить код');	
	});
}

function getCode(){
	var videoID=$('#currid').val(); 
	$.ajaxSetup({cache: false});
	$.get('/linkcode.php', { 'id': videoID, 'mode':'code' }, function (data){ $('#showlink').html(data); });
	$('#videocode').blur();
	$('#showlink').slideToggle('fast', function(){
		var txt=($('#showlink').css('display')=='none')?'Получить код':'Скрыть';
		$('#videocode').text(txt);
		$('#videolink').text('Прямая ссылка');
	});
}

function sendComment(){ 
	var rnd_no = Math.floor(Math.random());
	var bodyObj = document.getElementById('comments_list');
    divObjContainer = document.createElement("div");
    divObjContainer.setAttribute("id", "last_comment"+rnd_no);
    bodyObj.appendChild(divObjContainer);
	$.ajaxSetup({cache: false});
	$('#alert_area').hide('fast');
	$('#alert_area').html('');
	$.post('/modules/comments.php', {'show_comments':1, 'show_comments_list':1, 'id':document.addcomm.id.value, 'MM_insert':'addcomm', 'text':document.addcomm.text.value, 'autor':document.addcomm.autor.value, 'rating':$('#rating').val(), 'ip':document.addcomm.ip.value, 'pagepath':document.addcomm.pagepath.value, 'securityCode':document.addcomm.securityCode.value }, function (data){ $('#last_comment'+rnd_no).append(data); $('#last_comment'+rnd_no).effect("pulsate", { times:2 }, 500);});

	document.addcomm.reset();
}

function show_alert(txt){
	$('#alert_area').html(txt);
	$('#alert_area').slideUp('fast');
	$('#alert_area').effect("pulsate", { times:5 }, 200);
	setTimeout("$('#alert_area').fadeOut('slow')", 5000);
}

function editComment(id){
	$.post('/modules/comments.php', {'edit_comment':1, 'show_comments_list':1, 'id':id}, function(data){ $('#commenttext'+id).html(data)});
}

function saveComment(id){
	$('#commenttext'+id).prepend('<img src="/images/loading.gif" align=left>&nbsp; Пожалуйста, подождите...<br>');
	$.post('/modules/comments.php', {'update_comment':1, 'show_comments_list':1, 'id':id, 'text':$('#textcomment'+id).val()}, function(data){ $('#commenttext'+id).html(data)});
}

function unsaveComment(id){
	$.post('/modules/comments.php', {'get_comment':1, 'show_comments_list':1, 'id':id}, function(data){ $('#commenttext'+id).html(data)});
}

function delComment(id){
	$('#alert'+id).html('Уверены, что хотите удалить именно этот комментарий? <input class="button" type=button onclick="deleteComment('+id+')" value="Да"> &nbsp;&nbsp;<input class="button" type=button onclick="undeleteComment('+id+')" value="Нет">');
	$('#alert'+id).slideDown('fast');
}

function deleteComment(id){
	$.post('/modules/comments.php', {'del_comment':1, 'id':id}, function(data){$('#commenttext'+id).html(data)});
	$('#comment'+id).slideUp('fast');
}

function undeleteComment(id){
	$('#alert'+id).slideUp('fast');
}

function scroll_div(control, slider, obj, params){
	$('#'+obj).scrollTo( params, { 
						duration:500, easing:'swing', queue:true, axis:'y', 
						onAfter:function(){
									var bh=$(window).height();
									var vish=(bh/100)*72;
									var k=$.scrollTo.max(this, 'y')/ vish;
									$('#'+slider).slider('value', Math.round(vish-$(this).scrollTop()/k)); 
									
									if($(this).scrollTop()<=0){
										$('#'+control+' > .up_arrow').css({visibility:'hidden', cursor:'default'});
									}else{
										$('#'+control+' > .up_arrow').css({visibility:'visible', cursor:'pointer'});
									}
									if($(this).scrollTop()>=$.scrollTo.max(this, 'y')){
										$('#'+control+' > .down_arrow').css({visibility:'hidden', cursor:'default'});
									}else{
										$('#'+control+' > .down_arrow').css({visibility:'visible', cursor:'pointer'});
									}
								} 
							} 
						);
}

function refresh_random(obj){
	obj.blur();
	$('#random_img').attr('src','/images/randomimage.php?'+Math.random());
}

function printPage(cat){
	openWindow('/print_kiosk.php?p='+cat,'print','scrollbars=yes,resizable=yes', '800', '700', 'true');
	
	//$('#print_frame').attr('src', '/print_kiosk.php?p='+cat);
}

