////////////////////////////////
// BOOKMARKS
////////////////////////////////

function Bookmark()
{
    var url  = 'http://www.nightearth.com';
    var desc = 'Night satellite images with Google Maps interface!';

    if (window.sidebar)         // Mozilla Firefox Bookmark
    {
        window.sidebar.addPanel(desc, url, "");
    }
    else if (window.external)   // IE Favorite
    {
        window.external.AddFavorite(url, desc);
    }
}

function modifyCssClass(theClass, element, value)
{
    for (var S = 0; S < document.styleSheets.length; S++)   // for each stylesheer
    {
        var stylesheet;
        if (document.styleSheets[S]['rules'])         stylesheet = document.styleSheets[S]['rules'];
        else if (document.styleSheets[S]['cssRules']) stylesheet = document.styleSheets[S]['cssRules'];

        for (var R = 0; R < stylesheet.length; R++) // for each rule
        {
            if (stylesheet[R].selectorText == theClass)
            if (stylesheet[R].style[element]) { stylesheet[R].style[element] = value; break; }
        }
    }
}

// Calculate usable height/width
var frameHeight, frameWidth;
function CalculateHeightWidth()
{
    if (document.documentElement && document.documentElement.clientWidth)
    {
        frameHeight = document.documentElement.clientHeight;
        frameWidth  = document.documentElement.clientWidth;
    }
    else if (self.innerWidth)
    {
        frameHeight = self.innerHeight;
        frameWidth  = self.innerWidth;
    }
    else if (document.body)
    {
        frameHeight = document.body.clientHeight;
        frameWidth  = document.body.clientWidth;
    }
}

// Resizes some elements of the page, so the fit of the page will be better
function resizeElements()
{
	CalculateHeightWidth();
	
	document.getElementById("bannerimg").style.width = (frameWidth < 600) ? "100%" : "600px";
	modifyCssClass(".topmenu", "width",   (frameWidth < 740) ? "100%" : "740px");
}

// Checks if an ad blocking extension is in use    
function checkAdBlock()
{
    if (document.getElementById("adsensecheck").offsetHeight < 15)
        document.getElementById("adsensecheck").innerHTML = "A problem occurred while loading the ads.<br/>Please, don't use any ad blocking extensions on this site.<br/>" +
                                                            "Remember that this website is founded through advertising.";
}

function findPos(objid)
{
    obj = document.getElementById(objid);
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			curtop  += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	return [curleft, curtop];
}

