
// SCRIPT by Tomasz 'tommy4' Klapsia
// ALL RIGHTS RESERVED
// http://tommy4.gtacartel.pl



var ahigh = 0;
var rolled = 1;
var k = 0;



function roll()
{
	if(rolled == 1)
	{
		document.getElementById('roll_table').style.display = 'none';
		rolled = 0;
	}
	else
	{
		document.getElementById('roll_table').style.display = 'block';
		rolled = 1;
	}
}
function prepare(th)
{
	if(th.id != 'main' + ahigh)
	{
		th.className = 'topmenulinkhover';
		var id = th.id.substr(4);
		document.getElementById('amain' + id).className = 'topmenulinkhover';
	}
}

function prepareout(th)
{
	if(th.id != 'main' + ahigh)
	{
		th.className = 'topmenulink';
		var id = th.id.substr(4);
		document.getElementById('amain' + id).className = 'topmenulink';
	}
}

function preparesel(th)
{
	document.getElementById('main' + ahigh).className = 'topmenulink';
	document.getElementById('amain' + ahigh).className = 'topmenulink';
	document.getElementById('links' + ahigh).className = 'menuhide';
	document.getElementById('activel' + ahigh).className = 'activelh';
	document.getElementById('activer' + ahigh).className = 'activerh';
	ahigh = th.id.substr(4);
	th.className = 'topmenulinkactive';
	document.getElementById('amain' + ahigh).className = 'topmenulinkactive';
	document.getElementById('links' + ahigh).className = 'menushow';
	document.getElementById('activel' + ahigh).className = 'activelv';
	document.getElementById('activer' + ahigh).className = 'activerv';
}

function checkregister()
{
	var error = document.getElementById('error');
	if(document.getElementById('login').value.length >= 3 && document.getElementById('login').value.length <= 20)
	{
		if(document.getElementById('pass').value.length >= 6 && document.getElementById('pass').value.length <= 20)
		{
			if(document.getElementById('pass').value == document.getElementById('passr').value)
			{
				if(document.getElementById('mail').value.search(/@/) >= 2 && document.getElementById('mail').value.search(/\./) > -1 && document.getElementById('mail').value.search(/\./) < document.getElementById('mail').value.length-2)
				{
					return true;
				}
				else
				{
					error.innerHTML = 'Niepoprawny adres e-mail!';
					gotop();
				}
			}
			else
			{
				error.innerHTML = 'Podane hasła nie są identyczne!';
				gotop();
			}
		}
		else
		{
			error.innerHTML = 'Hasło powinno składać się z conajmniej 6 znaków, natomiast nie powinno być dłuższe niż 20 znaków!';
			gotop();
		}
	}
	else
	{
		error.innerHTML = 'Login powinien zawierać od 3 do 20 znaków!';
		gotop();
	}
	return false;
}

function gotop()
{
	var href = document.location.href;
	if(href.substr(href.length-1) != "#")
	{
		href += "#";
	}
	document.location.href = href;
}

function updateContent(url, what, post, special)
{
	// FIX IE UPDATE PROBLEM
	var d = new Date;
	if(url.search(/\?/) > -1)
	{
		url = url + '&time=' + d.getTime();
	}
	else
	{
		url = url + '?time=' + d.getTime();
	}
	// INITIALIZE REQUEST
	var httpRequest;
	if(window.XMLHttpRequest)
	{
		httpRequest = new XMLHttpRequest();
	} 
	else if(window.ActiveXObject)
	{
		try
		{
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(e)
		{
			try
			{
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(e)
			{
			}
		}
	}
	if(!httpRequest)
	{
		document.getElementById(what).innerHTML = "Nie można zainicjować AJAXa!";
		return false;
	}
	// OVERRIDE CHARSET
	if(httpRequest.overrideMimeType)
	{
		httpRequest.overrideMimeType('text/html;');
	}
	// CALLBACK FUNCTION
	httpRequest.onreadystatechange = function()
	{
		updateCallback(httpRequest, what, special);
	};
	// SEND REQUEST
	if(post.length > 0)
	{
		httpRequest.open('POST', url, true);
		httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		httpRequest.setRequestHeader("Content-length", post.length);
		httpRequest.setRequestHeader("Connection", "close");
		httpRequest.send(post);
	}
	else
	{
		httpRequest.open('GET', url, true);
		httpRequest.send(null);
	}
}
function updateCallback(httpRequest, what, special)
{
	if(httpRequest.readyState == 4)
	{
		if(httpRequest.status == 200)
		{
			var rt = httpRequest.responseText;
			if(rt != null && rt.length > 0)
			{
				if(special == 'online')
				{
					var pos = rt.search(/:/);
					var rtx = rt.substr(0, pos);
					rt = rt.substr(pos+1, rt.length-pos);
					document.getElementById('online_count').innerHTML = rtx;
				}
				if(special == 'relation')
				{
					document.getElementById('ajax_relation_status').innerHTML = '_auto.refresh.status: waiting;';
				}
				document.getElementById(what).innerHTML = rt;
			}
		}
		else
		{
			document.getElementById(what).innerHTML = "Błąd podczas pobierania danych przez AJAX!";
		}
	}
	httpRequest = null;
}

function showhide(what)
{
	if(document.getElementById(what).style.display == 'none')
	{
		document.getElementById(what).style.display = 'block';
		document.getElementById('amorestats').innerHTML = 'mniej statystyk';
	}
	else
	{
		document.getElementById(what).style.display = 'none';
		document.getElementById('amorestats').innerHTML = 'więcej statystyk';
	}
}

function get_height(object)
{
 	if(object.offsetHeight)
 	{
 	 	return object.offsetHeight;
 	}
 	if(object.clip.height)
 	{
 	 	return object.clip.height;
 	}
	return null;
}

function set_height(object, height)
{
	if(object.height)
	{
		object.height = height;
	}
	else if(object.style)
	{
		object.style.height = height;
	}
}
function set_width(object, width)
{
	if(object.width)
	{
		object.width = width;
	}
	else if(object.style)
	{
		object.style.width = width;
	}
}

function updateHeight()
{
	set_height(document.getElementById('content_in'), get_height(document.getElementById('menu')) + 'px');
}

function preparevote(th)
{
	var id = th.id.substr(4);
	for(var i = 1; i <= id; i++)
	{
		document.getElementById('vote' + i).src = 'images/vote.png';
	}
}

function preparevoteout(th)
{
	for(var i = 1; i <= 6; i++)
	{
		document.getElementById('vote' + i).src = 'images/voteno.png';
	}
}

function vote(vote, wid)
{
	updateContent('ajax/vote.php?id=' + wid, 'voteform', 'vote=' + vote + '&wid=' + wid, null);
}

function show(img, id)
{
	document.getElementById('preview').src = img;
	document.getElementById('preview').style.visibility = 'visible';
	idx = document.getElementById(id);
	idx.style.position = 'relative';
	set_left(document.getElementById('preview'), get_left(idx) + 120 + 'px');
	set_top(document.getElementById('preview'), get_top(idx) + 100 + 'px');
}
function show2(img)
{
	var imgx = new Image();
	imgx.src = img;
	var iWidth = imgx.width + 100;
	var iHeight = imgx.height + 100;
	document.getElementById('click_preview_img').src = imgx.src;
	document.getElementById('click_preview_bg').style.visibility = document.getElementById('click_preview').style.visibility = 'visible';
	set_height(document.getElementById('click_preview'), iHeight + 'px');
	set_height(document.getElementById('click_preview_bg'), iHeight + 'px');
	set_width(document.getElementById('click_preview'), iWidth + 'px');
	set_width(document.getElementById('click_preview_bg'), iWidth + 'px');
	var wHeight = 0;
	var wWidth = 0;
	if(window.innerHeight != null)
	{
		wHeight = window.innerHeight;
		wWidth = window.innerWidth;
	}
	else if(document.body.clientHeight != null)
	{
		wHeight = document.body.clientHeight;
		wWidth = document.body.clientWidth;
	}
	var sHeight = 0;
	if(window.pageYOffset != null)
	{
		sHeight = window.pageYOffset;
	}
	else if(document.body.scrollHeight != null)
	{
		sHeight = document.body.scrollTop;
	}
	set_top(document.getElementById('click_preview'), Math.round((wHeight-iHeight)/2) + sHeight + 'px');
	set_top(document.getElementById('click_preview_bg'), Math.round((wHeight-iHeight)/2) + sHeight + 'px');
	set_left(document.getElementById('click_preview'), Math.round((wWidth-iWidth)/2) + 'px');
	set_left(document.getElementById('click_preview_bg'), Math.round((wWidth-iWidth)/2) + 'px');
}
function hide2()
{
	document.getElementById('click_preview_bg').style.visibility = document.getElementById('click_preview').style.visibility = 'hidden';
}
function hide()
{
	document.getElementById('preview').src = 'images/delete.gif';
	document.getElementById('preview').style.visibility = 'hidden';
}

function get_left(object)
{
 	var left = null;
	if(object.style.left)
	{
	 	left = object.style.left;
	}
	if(object.style.pixelLeft)
	{
	 	left = object.style.pixelLeft;
	}
	if(object.offsetLeft)
	{
	 	left = object.offsetLeft;
	}
	left = left.toString();
	if(left.charAt(left.length-1) == 'x')
	{
	 	left = left.slice(0, left.length-3);
	}
	return left*1;
}
function set_left(object, left)
{
	if(object.style.left)
	{
	 	object.style.left = left;
	}
	else if(object.style.pixelLeft)
	{
	 	object.style.pixelLeft = left;
	}
	else if(object.offsetLeft)
	{
	 	object.offsetLeft = left;
	}
}
function set_top(object, top)
{
	if(object.style.top)
	{
	 	object.style.top = top;
	}
	else if(object.style.pixelTop)
	{
	 	object.style.pixelTop = top;
	}
	else if(object.offsetTop)
	{
	 	object.offsetTop = top;
	}
}
function get_top(object)
{
 	var top = null;
	if(object.style.top)
	{
	 	top = object.style.top;
	}
	else if(object.style.pixelTop)
	{
	 	top = object.style.pixelTop;
	}
	else if(object.offsetTop)
	{
	 	top = object.offsetTop;
	}
	top = top.toString();
	if(top.charAt(top.length-1) == 'x')
	{
	 	top = top.slice(0, top.length-3);
	}
	return top*1;
}

var timeoutid;

function showheader(arr1, arr2)
{
	var str = '';
	for(var i = 0; i < arr1.length; i++)
	{
		str += '<img src="images/point.png" class="point" alt="-" /><a href="' + arr2[i] + '" class="topmenudlink">' + arr1[i] + '</a>';
	}
	document.getElementById('submenu_out').style.display = 'block';
	document.getElementById('submenu_in').innerHTML = str;
}

function setHide()
{
	timeoutid = window.setTimeout("hideSubmenu()", 1000);
}

function unsetHide()
{
	window.clearTimeout(timeoutid);
}

function hideSubmenu()
{
	document.getElementById('submenu_out').style.display = 'none';
}
function resizeSite()
{
	if(get_height(document.getElementById('menu')) > get_height(document.getElementById('content_in')))
	{
		updateHeight();
	}
}

function showcat(name)
{
	var divs = document.getElementsByName(name);
	for(var i = 0; i < divs.length; i++)
	{
		if(divs.item(i).style.display != 'block')
		{
			divs.item(i).style.display = 'block';
		}
		else
		{
			divs.item(i).style.display = 'none';
		}
	}
}

var seconds = 21;
function updateRelation()
{
   seconds--;
   if(seconds < 0)
   {
      seconds = 20;
      document.getElementById('ajax_relation_status').innerHTML = '_auto.refresh.status: loading;';
      updateContent('ajax/relation.php?roll=' + rolled, 'ajax_relation', '', 'relation');
   }
   document.getElementById('ajax_relation_counter').innerHTML = '_auto.refresh.count: ' + seconds;
}

function activetab(tab)
{
	document.getElementById(tab + 'tab').className = "atab";
	document.getElementById(tab + 'tabl').src = "images/atabl.jpg";
	document.getElementById(tab + 'tabr').src = "images/atabr.jpg";
	document.getElementById(tab + '_content').style.display = 'block';
}

function deactivetab(tab)
{
	document.getElementById(tab + 'tab').className = "tab";
	document.getElementById(tab + 'tabl').src = "images/tabl.jpg";
	document.getElementById(tab + 'tabr').src = "images/tabr.jpg";
	document.getElementById(tab + '_content').style.display = 'none';
}

function ie_fix()
{
	if(navigator.appName.substring(0,9) == 'Microsoft') // only for shit
	{
		var elements = document.getElementsByTagName('img');
		for(var i = 0; i < elements.length; i++)
		{
			elements[i].setAttribute('vspace', '0');
			elements[i].setAttribute('hspace', '0');
		}
	}
}



$(document).ready(function() {
$("#next").click(function(event){
   if(document.getElementById('adsflash'+(k+1)))
{
$('#adsflash'+k).slideUp('slow');
k+=1;
$('#adsflash'+k).slideDown('slow');
}
});

$("#prev").click(function(event){
if(document.getElementById('adsflash'+(k-1)))
{
$('#adsflash'+k).slideUp('slow');
k-=1;
$('#adsflash'+k).slideDown('slow');
}
});
});



function bookmarkit(){
if(navigator.appName.substring(0,9) == 'Microsoft') { 
window.external.addFavorite('http://gooner.pl','Arsenal Polish Supporters Club');

}
else { alert('Tylko w IE!'); } 


}


