// JavaScript Document
document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
}
function pixscr(){
	var pixs = [];
	var alldocimgs = document.images;
	for (var i=0; i<alldocimgs.length; i++){
		if (/thumbs/.test(alldocimgs[i].src)) pixs.push(alldocimgs[i]);
	}
	if (document.getElementById("remtext").value == "remove texts"){
		document.getElementById("remtext").value = "with texts";
		document.getElementsByClassName("text")[0].style.display = "none";
	}
	else{
		document.getElementById("remtext").value = "remove texts";
		document.getElementsByClassName("text")[0].style.display = "";
	}
	var desc = document.getElementsByClassName("desc");
	var sg = document.getElementsByClassName("sg");
	var cat = document.getElementsByClassName("cat");
	for(var i=0; i<pixs.length; i++){
		if(desc[i].style.display == "none"){
			desc[i].style.display = "";
			sg[i].style.display = "";
			cat[i].style.display = "";
		}
		else{
			desc[i].style.display = "none";
			sg[i].style.display = "none";
			cat[i].style.display = "none";
		}
	}
}
function narrow(){
	var pixcol = document.getElementsByClassName("pix");
	var imgw = pixcol[0].getElementsByTagName("img")[0].clientWidth*0.9+"px";
	var imgh = pixcol[0].getElementsByTagName("img")[0].clientHeight*0.9+"px";
	var pixw = pixcol[0].clientWidth*0.9+"px";
	var pixh = pixcol[0].clientHeight*0.9+"px";
	for (var i=0; i<pixcol.length; i++){
		var img = pixcol[i].getElementsByTagName("img")[0];
		img.style.width = imgw;
		img.style.height = imgh;
		pixcol[i].style.width = pixw;
		pixcol[i].style.height = pixh;
	}
}
function enlarge(){
	var pixcol = document.getElementsByClassName("pix");
	var imgw = pixcol[0].getElementsByTagName("img")[0].clientWidth/0.9+"px";
	var imgh = pixcol[0].getElementsByTagName("img")[0].clientHeight/0.9+"px";
	var pixw = pixcol[0].clientWidth/0.9+"px";
	var pixh = pixcol[0].clientHeight/0.9+"px";
	for (var i=0; i<pixcol.length; i++){
		var img = pixcol[i].getElementsByTagName("img")[0];
		img.style.width = imgw;
		img.style.height = imgh;
		pixcol[i].style.width = pixw;
		pixcol[i].style.height = pixh;
	}
}
function resetimgs(){
	document.getElementById("remtext").value = "remove texts";
	document.getElementsByClassName("text")[0].style.display = "";
	var pixs = [];
	var alldocimgs = document.images;
	for (var i=0; i<alldocimgs.length; i++){
		if (/thumbs/.test(alldocimgs[i].src)) pixs.push(alldocimgs[i]);
	}
	var desc = document.getElementsByClassName("desc");
	var sg = document.getElementsByClassName("sg");
	var cat = document.getElementsByClassName("cat");
	for(var i=0; i<pixs.length; i++){
			desc[i].style.display = "";
			sg[i].style.display = "";
			cat[i].style.display = "";
	}
	var pixcol = document.getElementsByClassName("pix");
	for (var i=0; i<pixcol.length; i++){
		var img = pixcol[i].getElementsByTagName("img")[0];
		img.style.width = "";
		img.style.height = "";
		pixcol[i].style.width = "";
		pixcol[i].style.height = "";
	}
}
$(document).ready(function(){
$("center").prepend('<input name="test" type="button" id="remtext" onClick="pixscr();" value="remove texts" style="position:fixed; top:0px; right:0px; z-index:5; width:100px; height:25px;"><input name="narrow" type="button" onClick="narrow();" value="narrow imgs" style="position:fixed; top:25px; right:0px; z-index:5; width:100px; height:25px;"><input name="enlarge" type="button" onClick="enlarge();" value="enlarge imgs" style="position:fixed; top:50px; right:0px; z-index:5; width:100px; height:25px;"><input name="resetimgs" type="button" onClick="resetimgs();" value="reset page" style="position:fixed; top:75px; right:0px; z-index:5; width:100px; height:25px;">');
archives();
})
function addToFavorites() {
	var urlAddress = "http://www.u-18.com/"; 
	var pageName = "u-18.com"; 
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(pageName, urlAddress,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite(urlAddress, pageName); 
	} else { 
		alert("Sorry! Your browser doesn't support this function. Press CTRL+D to manual bookmark"); 
	}  		
} 
function getXmlHttp(){
	var xmlhttp;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
i = 0;
var adres = window.location.toString();
if (/archives/.test(adres)) {
	var spn = adres.replace(/.+\/(.+)\d+.html/,"$1");
	i = parseInt(adres.replace(/.+\/.+(\d+).html/,"$1"));
	var basearc = '/st/archives/'+spn;
	var metka = "isarc";
	}else var basearc = '/st/archives/archive';
function archives(){
	if (metka == "isarc") i++;
	else i = Math.floor(Math.random() * 398);
	if (document.getElementById("tempdiv") != null){
		var tempdiv = document.getElementById("tempdiv");
		tempdiv.parentNode.removeChild(tempdiv);
		}
	var archpage = basearc + i + '.html';
	var xmlhttp = getXmlHttp();
	xmlhttp.open('GET', archpage, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if(xmlhttp.status == 200) {
				var gotit = xmlhttp.responseText;
				gotit = gotit.replace(/[\s\S]+?<span class="top">/,'<div onMouseOver="archives()" style="width:100%; height:500px; left:0px; z-index:5;" id="tempdiv"></div><span class="top">');
				gotit = gotit.replace(/<span class="arclink">[\s\S]+/,'');
				gotit = gotit + '<br><br>';
				document.body.appendChild(document.createElement("center"));
				document.body.lastChild.innerHTML = gotit;
			}
		}
	}
	xmlhttp.send(null);
}

