//tankboys development

var d = document;


//watch

function Watch(url){
	var postUrl = 'watch.php?file='+url;
	window.open(postUrl,'videoplayer','width=512, height=580, scrollbars=no,resizable=no,status=no, top=0, left=450');
}


//rate
function rate(){
	var postUrl = 'rate.php';
	window.open('rate.php','rate','width=400, height=554, scrollbars=no,resizable=no,status=no, top=0, left=0');
}



//open close
var timer=null;

function openClose(Id, min, max) {
var obj = document.getElementById(Id);
if(obj.style.height == '') now = 1; 
else now = parseInt(obj.style.height);

if((obj.style.height == '') || (now == min)) Open(Id, min, max);
else if (now >= max) close(Id, min, max);

}

function Open(Id, min, max){
var obj = document.getElementById(Id);
if(obj.style.height == '') now = 1; 
else now = parseInt(obj.style.height);

if(now < max){
	var delta = (min+now/10); 
	obj.style.height = (now+delta) + 'px'; 
	}	
else {
		obj.style.height = max + 'px';
		clearTimeout(timer);
	}
	if (timer) clearTimeout(timer);
 	if(now != max) timer=window.setTimeout(function () {Open(Id, min, max)}, 8);
	
}

function close(Id, min, max){
var obj = document.getElementById(Id);
now = parseInt(obj.style.height);

if(now > min){
	obj.style.height = (now-now/12) + 'px'; 
	}	
else {
		obj.style.height = min + 'px';
		clearTimeout(timer);
	}
	if (timer) clearTimeout(timer);
 	if(now != min) timer=window.setTimeout(function () {close(Id, min, max)}, 8);
	
}

//open closemenu
var timer=null;

function openCloseMenu(Id, min, max) {
var obj = document.getElementById(Id);
if(obj.style.height == '') now = 1; 
else now = parseInt(obj.style.height);

if((obj.style.height == '') || (now == min)) Open(Id, min, max);
else if (now >= max) close(Id, min, max);

}


//ajax
function ajax(url, divId, flag) { //alert(url);
		if(divId=='docs' && flag==1) openCloseMenu('docControll',3,240); 
        var http_request = false;
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function() { rateContents(http_request, divId); };
        http_request.open('GET', url, true, flag);
        http_request.send(null); 
    }

    function rateContents(http_request, divId, flag) {
        if (http_request.readyState == 4) {

	
            if (http_request.status == 200) {			
                document.getElementById(divId).innerHTML = http_request.responseText; 
				if(flag!=0) {
					if(divId=='docs') initOpenClose(); 
					initFadeBox();
					}//alert(document.getElementById(divId).innerHTML);
            }
					else {
                document.getElementById(divId).innerHTML = "No match found. Try again.";
            }
        }
		else if	(http_request.readyState == 1)	{
			document.getElementById(divId).innerHTML = "loading data...";
			}

    }

//openclose init
//
function initOpenClose()
{
	if (!document.getElementsByTagName){ return; }
	var divs = document.getElementsByTagName("div");

	// loop through all div tags
	for (var i=0; i<divs.length; i++){
		var div = divs[i];

		if (div.className == "closed"){ 
			var max = div.offsetHeight; 
			div.style.height = '1px';
			var aId = 'anc'+div.id; 
			var min = 1;
			d.getElementById(aId).setAttribute('href','javascript:openClose(\''+div.id+'\','+min+','+ max+')'); 	

		}
	}
}


function gObj(id){
	return d.getElementById(id);
}

function show(id){
	gObj(id).style.display = 'block';	
}

function hide(id){
	gObj(id).style.display = 'none';	
}


//-------------------------------------------------------------------------------------------------

var d = document;

function gObj(id){
	return d.getElementById(id);
}

function show(id){
	gObj(id).style.display = 'block';	
}

function hide(id){
	gObj(id).style.display = 'none';	
}


//fade background
//
var colors = new Array("#ffffff","#FAFAFA","#F2F2F2","#E8E8E8","#D9D9D9","#C9C9C9","#B5B5B5","#757575","#626262","#555555","#494949","#3D3D3D","#303030");

function initFadeBox(){

	var objBody = d.getElementsByTagName("body").item(0);
	var objImg = d.createElement("img");
	objImg.style.border = '10px white solid';
	stylize(objImg);
	objImg.setAttribute('id', 'fadeBoxImg');
	objImg.onclick = function () {fadeBox();}
	objBody.insertBefore(objImg, objBody.firstChild);
	var objLoading = d.createElement("span");
	objLoading.innerHTML = 'Loading...';
	stylize(objLoading);
	objLoading.id = 'loading';
	objLoading.style.display = 'none';
	objLoading.style.color = 'white';
	objBody.insertBefore(objLoading, objBody.firstChild);

	if (!document.getElementsByTagName){ return; }
	var anchs = document.getElementsByTagName("a");

	// loop through all div tags
	for (var i=0; i<anchs.length; i++){
		var anch = anchs[i];

		if (anch.rel == "fadeBox"){ 
			anch.onclick = function () {fadeBox(this); return false;}
		}
	}
}

function stylize(obj){
	obj.style.display = 'none';
	obj.style.position = 'absolute';
	//obj.style.position = 'fixed';
	obj.style.left = '50%';
	obj.style.top = '50%';
}

var bgi = 0;
var timer = null;

function fadeBg(){
	if(bgi==0) fadeIn();
	else if(bgi==12) fadeOut();
}

function fadeIn(){
	bgi++;
	document.bgColor = colors[bgi];
	if(bgi<12)	timer=window.setTimeout('fadeIn()', 40);
}
function fadeOut(){
	bgi--;
	document.bgColor = colors[bgi];
	if(bgi>0)	timer=window.setTimeout('fadeOut()', 60);
}

function fadeBox(obj){
	var fbi = gObj('fadeBoxImg')
	if(fbi.style.display == 'block'){
		hide(fbi.id);
		fadeBg();
	}
	else {
		if (fbi.src == obj.href) {
			timer=window.setTimeout(function () {show(fbi.id)}, 480);
			fadeBg();
			}
		else {
			fadeBg();
			show('loading');
			fbi.src = obj.href;
			fbi.onload=function(){
				hide('loading');
				show(fbi.id);
				//fbi.style.marginTop = -(fbi.height/2);
				fbi.style.top = document.body.scrollTop + 10 + 'px';
				fbi.style.left = ((window.innerWidth-fbi.width)/2) + 'px';

				}
			}
	}
}

window.onload = function () {
	initOpenClose(); 
	initFadeBox();
}