var GrRek_Flash = 0, GrRek_TL_Aktywna = 0, GrRek_TL_Margines = 20, GrRek_TL_oknoSzerokosc = 0, GrRek_TL_oknoWysokosc = 0, GrRek_TL_selekty = 0, GrRek_TL_Czas = 0, GrRek_Domena;

function GrRek_TL_selektyWidoczne(tryb) {
	tryb = tryb ? 'visible' : 'hidden';

	if (!GrRek_TL_selekty) {
		GrRek_TL_selekty = document.getElementsByTagName ? document.getElementsByTagName('SELECT')
			: document.all.tags('SELECT');
	}
	for (i = 0; i < GrRek_TL_selekty.length; i++) {
		if (GrRek_TL_selekty[i].style) {
			GrRek_TL_selekty[i].style.visibility = tryb;
		}
	}
}

function GrRek_URL(clientId, bannerId, zoneId, source) {
	return '?bannerid=' + bannerId +
		'&clientid=' + clientId +
		'&zoneid=' + zoneId +
		'&source=' + source +
		'&block=0&cb=' + (new Date()).getTime();
}


function GrRek_FlashTworz(plik, url, szerokosc, wysokosc) {
	if (GrRek_Flash) {
		var log = '';

		if (url.indexOf('?') == 0) {
			plik += '?clickTAG=' + GrRek_Domena + 'adclick.php' + url;
			log += '<img src="' + GrRek_Domena + 'adlog.php' + url +
				'" alt="" style="width: 0; height: 0;" />';
		} else if (url) {
			plik += '?clickTAG=' + url;
		}
		return '<object id="GrRek_TL_element" data="' + plik +
			'" type="application/x-shockwave-flash" border="0" width="' + szerokosc + '" height="' + wysokosc + '">' +
			'<param name="movie" value="' + plik + '"><param name="quality" value="high">' +
			'<param name="wmode" value="transparent"><param name="bgcolor" value="transparent">' +
			'<embed name="movie" src="' + plik +
			'" quality="high" wmode="transparent" menu="false" swliveconnect="true" '+
			'allowscriptaccess="samedomain" type="application/x-shockwave-flash" '+
			'pluginspage="http://www.macromedia.com/go/getflashplayer" height="' + wysokosc + '" width="' + szerokosc + '">'+
			'</object>' + log;
	}
}


function GrRek_TL_oknoRozmiar() {
	if (self.innerHeight) {
		GrRek_TL_oknoSzerokosc = self.innerWidth;
		GrRek_TL_oknoWysokosc = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		GrRek_TL_oknoSzerokosc = document.documentElement.clientWidth;
		GrRek_TL_oknoWysokosc = document.documentElement.clientHeight;
	} else if (document.body) {
		GrRek_TL_oknoSzerokosc = document.body.clientWidth;
		GrRek_TL_oknoWysokosc = document.body.clientHeight;
	}

	if (GrRek_TL_oknoSzerokosc > 0) {
		GrRek_TL_oknoSzerokosc -= 2 * GrRek_TL_Margines;
		GrRek_TL_oknoWysokosc -= 2 * GrRek_TL_Margines;
	} else {
		GrRek_TL_oknoSzerokosc = 100;
		GrRek_TL_oknoWysokosc = 100;
	}
}

function GrRek_TL_Dostosuj() {
	if (GrRek_TL_Aktywna == 1) {
		GrRek_TL_oknoRozmiar();

	   document.getElementById('GrRek_TL_div').style.width = GrRek_TL_oknoSzerokosc+'px';
	   document.getElementById('GrRek_TL_div').style.height = GrRek_TL_oknoWysokosc+'px';
	   document.getElementById('GrRek_TL_div').style.top = GrRek_TL_Margines+'px';
	   document.getElementById('GrRek_TL_div').style.left = GrRek_TL_Margines+'px';
	   document.getElementById('GrRek_TL_element').style.width = GrRek_TL_oknoSzerokosc+'px';
	   document.getElementById('GrRek_TL_element').style.height = GrRek_TL_oknoWysokosc+'px';

	}
}

function GrRek_TL_Stop() {
	if (GrRek_TL_Aktywna == 1) {
	    document.getElementById('GrRek_TL_div').style.visibility = 'hidden';
	    document.getElementById('GrRek_TL_element').style.visibility = 'hidden';
		GrRek_TL_selektyWidoczne(1);
		GrRek_TL_Aktywna = 0;
	}
}

function GrRek_TL_Start() {
	if (document.getElementById('GrRek_TL_div')) {
        GrRek_TL_Aktywna = 1;
	   GrRek_TL_Dostosuj();

	   GrRek_TL_selektyWidoczne(0);
	   document.getElementById('GrRek_TL_div').style.visibility = 'visible';
	   document.getElementById('GrRek_TL_element').style.visibility = 'visible';
	   if (GrRek_TL_Czas > 0) {
		   setTimeout('GrRek_TL_Stop()', GrRek_TL_Czas);
	   }
	}
}

// jak url zaczyna się od znaku zapytania to dotyczy naszego serwera reklam
function GrRek_TL_Inicjuj(domena, plik, url, czas) {
	if (GrRek_Flash) {
		GrRek_Domena = domena;
		GrRek_TL_Czas = czas;
		GrRek_TL_Dostosuj();
		document.write('<div id="GrRek_TL_div" ' +
			'style="visibility:hidden;position:absolute;overflow:hidden;top:' + GrRek_TL_Margines + 'px;left:' +
				GrRek_TL_Margines + 'px;width:' + GrRek_TL_oknoSzerokosc + 'px;height:' + GrRek_TL_oknoWysokosc +
				'px;z-index:9900;" >' +
			GrRek_FlashTworz(plik, url, GrRek_TL_oknoSzerokosc, GrRek_TL_oknoWysokosc) +
			'</div>');
		window.onload = GrRek_TL_Start;
	}
}

document.write(
	'<sc' + 'ript type="text/javasc' + 'ript">\n' +
	'<!--\n' +
	'if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]\n' +
	'		&& navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {\n' +
	'	GrRek_Flash = 1;\n' +
	'}\n' +
	'//-->\n' +
	'</sc' + 'ript>\n' +
	'<sc' + 'ript language="VBScript" type="text/vbsc' + 'ript">\n' +
	'<!--\n' +
	'on error resume next\n' +
	'GrRek_Flash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash")))\n' +
	'//-->\n' +
	'</sc' + 'ript>\n');

// kompatebilność wstecz (do usunięcia)
function NMAdToplayerInit(plik, clientId, bannerId, zoneId, source) {
	GrRek_TL_Inicjuj('http://ads.gratka.pl/', plik, GrRek_URL(clientId, bannerId, zoneId, source), 0);
}

function NMAdToplayerStop() {
	GrRek_TL_Stop();
}

brandmark_ukryj = function() {
    var brandmark_div = document.getElementById("brandmark");
    
    brandmark_div.style.top = 0;
    brandmark_div.style.left = 0; 
    brandmark_div.style.width = 0;
    brandmark_div.style.height = 0;
    brandmark_div.style.visibility = 'hidden';
    brandmark_div.style.display = 'none';
}
brandmark_wyswietl = function() {
    var brandmark_div = document.getElementById("brandmark");
    var body_tag = document.getElementById('body');
    
    var szerokosc_okna = body_tag.offsetWidth;
    var wysokosc_okna = body_tag.offsetHeight;
    
    var blokWidth = 0;
    var blokHeight = 0;
    
    if (brandmark_div) {
        var divTags = body_tag.getElementsByTagName('div');
        var links = brandmark_div.getElementsByTagName('a');
        var obiektTag = brandmark_div.getElementsByTagName('object');
        
        if (links.length > 0) {
            imageObj = new Image();
        
            for (var i = 0; i < links.length; i++) {
                var link = links[i];
                        
                if (link.childNodes[0].width == 0) {
                    imageObj.src=link.childNodes[0].src;                
                    var tmpWidth = parseInt(imageObj.width);
                    var tmpHeight = parseInt(imageObj.height);
                }
                else {
                    var tmpWidth = parseInt(link.childNodes[0].width);
                    var tmpHeight = parseInt(link.childNodes[0].height);
                }
                if ( tmpWidth > blokWidth) {
                    blokWidth = tmpWidth;
                    blokWidth = tmpHeight;
                }        
            } 
        }
        
        if (obiektTag.length > 0) {
            for (var i = 0; i < obiektTag.length; i++) {
                var tmpWidth = parseInt(obiektTag[i].width);
                var tmpHeight = parseInt(obiektTag[i].height);
                        
                if ( tmpWidth > blokWidth) {
                    blokWidth = tmpWidth;
                    blokHeight = tmpHeight;
                }     
            }
        }
        var top  = ((wysokosc_okna/2)-blokWidth);
        var left = ((szerokosc_okna/2)-blokHeight);
        //alert(wysokosc_okna+' '+szerokosc_okna);
        brandmark_div.style.top = top +'px';
        brandmark_div.style.left = left + 'px'; 
        
        brandmark_div.style.width = blokWidth+'px';
        brandmark_div.style.height = blokHeight+'px';
        brandmark_div.style.visibility = 'visible';
        brandmark_div.style.display = 'block';
        
        setTimeout('brandmark_ukryj()', 10000);       
    }
}

