/*
 * Programmierung 2008 (c) 08 MEDIA de
 * http://www.08media.de
 * tipmanager@08media.de
 * Datei:   js/collection.js
 * Autor:   Thomas Schlicker
 * Version: 08/2010
 */


/*function showCollection(league_id, team_id, team2_id) {

	initCollectionLayer();
	reqTeam(league_id,team_id,team2_id);
}

function initCollectionLayer() {

	document.getElementById("layer-collection-bg").style.display = "block";
	document.getElementById("layer-collection").style.display = "block";
	document.getElementById("collection-home").style.display = "block";
}

function closeCollection() {

	document.getElementById("layer-collection-bg").style.display = "none";
	document.getElementById("layer-collection").style.display = "none";
	document.getElementById("collection-home").style.display = "none";
	document.getElementById("collection-guest").style.display = "none";
	document.getElementById("collection-home").innerHTML = "<img src=\"images/ajax-loader.gif\" alt=\"\">";
	document.getElementById("collection-guest").innerHTML = "<img src=\"images/ajax-loader.gif\" alt=\"\">";
}*/

var xpos;
var ypos;
function getPageScroll(){
    var yScroll;
    if(self.pageYOffset) {
        yScroll = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop){ 
       // Explorer 6 Strict
       yScroll = document.documentElement.scrollTop;
    }
    else if (document.body) {
        // all other Explorers
        yScroll = document.body.scrollTop;
    }
    arrayPageScroll = new Array('',yScroll)
    return arrayPageScroll;
}
function getPageSize(){
    var xScroll, yScroll;
    if(window.innerHeight && window.scrollMaxY) { 
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight){
        // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    }
    else {
        // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    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;
    } 
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    }
    else {
        pageHeight = yScroll;
    }
    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){ 
        pageWidth = windowWidth;
    }
    else {
        pageWidth = xScroll;
    }
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
}
function showCollection(league_id, team_id, team2_id) {
    
	reqTeam(league_id,team_id,team2_id);
	
    var objOverlay = document.getElementById('layer-collection-bg');
    var objLightbox = document.getElementById('layer-collection');
	document.getElementById("collection-home").style.display = "block";
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();
    // set height of Overlay to take up whole page and show
    objOverlay.style.height = (arrayPageSize[1] + 'px');
    objOverlay.style.display = 'block';
    // center lightbox and make sure that the top and left values are not negative
    // and the image placed outside the viewport
    var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 520) / 2);
    objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
    objLightbox.style.display = "block";
}
function closeCollection() {

	document.getElementById("layer-collection-bg").style.display = "none";
	document.getElementById("layer-collection").style.display = "none";
	document.getElementById("collection-home").style.display = "none";
	document.getElementById("collection-guest").style.display = "none";
	document.getElementById("collection-home").innerHTML = "<img src=\"images/ajax-loader.gif\" alt=\"\">";
	document.getElementById("collection-guest").innerHTML = "<img src=\"images/ajax-loader.gif\" alt=\"\">";
}


/* REQUEST TEAM */
var league;
var idGuest;

function reqTeam(league_id,team_id,team2_id) {

	if(!initRequest())
		return false;
	
	league = league_id;
	idGuest = team2_id;
	
	http_request.onreadystatechange = handleTeam;
	http_request.open("GET", "tpl/selectCollection.php?league_id="+league_id+"&team_id="+team_id+"&no="+1, true);
	http_request.send(null);
}
function handleTeam() {

	if(http_request.readyState == 4) {
		if(http_request.status == 200) {
			document.getElementById("collection-home").innerHTML = http_request.responseText;	
			if(idGuest)
				reqTeam2(league,idGuest);
		}		
	}
}
function reqTeam2(league_id,team_id) {

	if(!initRequest())
		return false;
	
	document.getElementById("collection-guest").style.display = "block";
	
	http_request.onreadystatechange = handleTeam2;
	http_request.open("GET", "tpl/selectCollection.php?league_id="+league_id+"&team_id="+team_id+"&no="+2, true);
	http_request.send(null);
}
function handleTeam2() {

	if(http_request.readyState == 4) {
		if(http_request.status == 200) {
			document.getElementById("collection-guest").innerHTML = http_request.responseText;	
		}		
	}
}


/* OPPOSER */
var nr;
function handleOpposerLayer() {

	if(http_request.readyState == 4) {
		if(http_request.status == 200) {

			document.getElementById("team-opposer-layer-"+nr).innerHTML = http_request.responseText;
		}
	}
}
function showOpposerLayer(league,team,r,no) {

	if(!initRequest())
		return false;
		
	nr = no;
	http_request.onreadystatechange = handleOpposerLayer;
	http_request.open("GET", "tpl/selectOpposer.php?league_id="+league+"&team_id="+team+"&repertoire_id="+r+"&no="+no, true);
	http_request.send(null);
}
function hideOpposerLayer(no) {
	
	document.getElementById("team-opposer-layer-"+no).innerHTML = "&nbsp;";
}

