var newWindow;

function openWindow(url, name) {
	newWindow = window.open(url, name, "width=" + screen.availWidth + ",height=" + (screen.availHeight - 30));
	newWindow.focus();
}

function openLoginWindow() {
	loginWindow = window.open(BASE + "/app/login.php","loginWindow", "width=" + screen.availWidth + ",height=" + (screen.availHeight - 30) + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,screenX=0,screenY=0,left=0,top=0");
	loginWindow.focus();
}

function openRegistrationWindow() {
	loginWindow = window.open(BASE + "/registration/studentRegistration.php","loginWindow", "width=" + screen.availWidth + ",height=" + (screen.availHeight - 30) + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,screenX=0,screenY=0,left=0,top=0");
	loginWindow.focus();
}

function openMailboxWindow() {
	var windowName = 'newMailboxWindow' + Math.floor(Math.random() * 100);
	loginWindow = window.open(BASE + "/app/cmsFrameset.php", windowName, "width=" + screen.availWidth + ",height=" + (screen.availHeight - 30) + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,screenX=0,screenY=0,left=0,top=0");
	loginWindow.focus();
}

function newWindow(url, width, height, windowName) {
	var left = (screen.availWidth / 2) - (width / 2);
	var top = (screen.availHeight / 2) - (height / 2);
	var newWindow;
	if(!windowName) {
		var windowName = 'newWindow' + Math.floor(Math.random() * 100);
	}
	newWindow = window.open(url, windowName, 'top=' + top + 'px,left=' + left + 'px,screenX=' + left + 'px,screenY=' + top + 'px,width=' + width + 'px,height=' + height + 'px,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no');
	newWindow.focus();
}

function newPrintWindow(url, windowName) {
	var width = 850;
	var height = 580;
	var left = (screen.availWidth / 2) - (width / 2);
	var top = (screen.availHeight / 2) - (height / 2);
	var newWindow;
	if(!windowName) {
		var windowName = 'newWindow' + Math.floor(Math.random() * 100);
	}
	newWindow = window.open(url, windowName, 'top=' + top + 'px,left=' + left + 'px,screenX=' + left + 'px,screenY=' + top + 'px,width=' + width + 'px,height=' + height + 'px,menubar=yes,resizable=yes,scrollbars=yes,status=no,toolbar=no');
	newWindow.focus();
}

function newUserPageWindow(url, windowName) {
	var width = 780;
	var height = 580;
	var left = (screen.availWidth / 2) - (width / 2);
	var top = (screen.availHeight / 2) - (height / 2);
	var newWindow;
	if(!windowName) {
		var windowName = 'newWindow' + Math.floor(Math.random() * 100);
	}
	newWindow = window.open(url, windowName, 'top=' + top + 'px,left=' + left + 'px,screenX=' + left + 'px,screenY=' + top + 'px,width=' + width + 'px,height=' + height + 'px,menubar=yes,resizable=yes,scrollbars=yes,status=no,toolbar=no');
	newWindow.focus();
}

function newMailWindow(url, width, height) {
	//url = BASE + url;
	newWindow(url, width, height);
}

function printSituation(e,div,image,text) {
	!e ? e = window.event : null;
	window.document.getElementById( div ).style.display = '';
	window.document.getElementById( div ).style.position = 'absolute';
     var thisScrollTop = Math.max(window.document.documentElement.scrollTop, window.document.body.scrollTop);
	window.document.getElementById( div ).style.top = e.clientY + thisScrollTop + 35 + 'px';
	window.document.getElementById( div ).style.left = e.clientX   + 20 + 'px';
	window.document.getElementById( div ).style.background = "rgb(64,98,131) center bottom no-repeat";
	//window.document.getElementById( div ).innerHTML = text;
	setOpacity(window.document.getElementById( div ),94);
}
function hiddenSituation(e,div) {
	!e ? e = window.event : null;
	window.document.getElementById(div).style.display = "none";
}

function setOpacity(thisElement, opacity) {
 thisElement.style.filter = "alpha(opacity:"+opacity+",style=0)";
 thisElement.style.KHTMLOpacity = opacity/100;
 thisElement.style.MozOpacity = opacity/100;
 thisElement.style.opacity = opacity/100;
}





// Vraci nahodne cislo x, kde 0<=x<num
function randNum (num) {
var rnd1 = Math.round( (num-1) * Math.random() )
    return rnd1;
}

// Snezeni
var items = [ "snow4.gif", "snow4.gif", "snow6.gif" ];
//var items = [ "snow1.gif", "snow2.gif", "snow3.gif" ];
var itemsCount=30;
var screenLeft = 50;
var screenTop = 50;
var screenWidth = screen.availWidth - 150;
var screenHeight = screen.availHeight - 180;
var moveamountY = 3;
var moveamountX = 0;
var randomizeX = 2;
var randomizeY = 3;
var fCycleX = false;
var fCycleY = true;
var fRandomXwhenYCycles = true;
var fRandomYwhenXCycles = false;
var fCycleImages = false;
var speed = 130;


var i;
var Xs = new Array();
var Ys = new Array();
var Is = new Array();

function Animate() {
var y;
    for(i=0; i<itemsCount; i++ ) {

        Ys[i] += moveamountY + ( randNum(2) ? (1) : (-1) ) * randNum(randomizeY);
        Xs[i] += moveamountX + ( randNum(2) ? (1) : (-1) ) * randNum(randomizeX);

        if( Xs[i] > screenLeft + screenWidth )  {
            Xs[i] = fCycleX ? screenLeft : screenLeft + screenWidth;
            Ys[i] = fRandomYwhenXCycles ? screenTop + randNum(screenHeight) : Ys[i];
        }
        if( Ys[i] > screenTop + screenHeight )  {
            Ys[i] = fCycleY ? screenTop : screenTop + screenHeight;
            Xs[i] = fRandomXwhenYCycles ? screenLeft+ randNum(screenWidth) : Xs[i];
        }
        if (fCycleImages) {
            Is[i]++;
            if(Is[i]>=items.length) Is[i]=0;
            document.getElementById('animitem'+i).src = items[ Is[i] ];
        }

        document.getElementById('animitem'+i).style.top = Ys[i] + 'px';
        document.getElementById('animitem'+i).style.left = Xs[i] + 'px';
    }                                                            
}

function hviezdicky(){
    if(document.getElementById) {
       for(var i=0; i<itemsCount; i++ ) {
           Xs[i] = screenLeft + randNum(screenWidth);
           Ys[i] = screenTop + randNum(screenHeight);
           Is[i] = randNum(items.length);
           DOM.gI("main").innerHTML = DOM.gI("main").innerHTML + '<img id="animitem'+i+'" style="position:absolute; left:'+Xs[i]+'px; top:'+Ys[i]+'px" src="'+ items[Is[i]] +'">';
       }
       setInterval("Animate()",speed);
    }
}

DOM.aE(window, "load", hviezdicky, false);
