/* COMMON BANNER FUNCTIONS */
function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie6=((navigator.appName.indexOf("Microsoft")!=-1 || this.ver.indexOf("MSIE 6")>-1) && this.dom)?1:0;
	this.ie5=((navigator.appName.indexOf("Microsoft")!=-1 || this.ver.indexOf("MSIE 5")>-1) && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.gecko=(navigator.userAgent.indexOf("Gecko")!=-1)?1:0;
	this.mac=((navigator.appName.indexOf("Mac")!=-1 || this.ver.indexOf("Mac")>-1) && this.dom)?1:0;

    //var test_cookie = setBannerCookie( 'test_cookie', 5 * 1000 );
    //this.cookie=getBannerCookie( 'test_cookie' )?1:0;

	return this
}
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}



/* BANNER INIT FUNCTIONS */


/* Scrolling banner */
var scrollingStepPx = 1;
var scrollingStepMs = 50;
var scrollingInterval;

function scrollingStart(bannerSrc,bannerHref,bannerName,bannerId,width,height,altText){
    if(!altText) altText='Spied šeit';
    //var browser = checkBrowser();
    var scrollingShowed = false;
    //var scrollingShowed = getBannerCookie( bannerName );
    /* eriks -- nav vajadziigs uz iipashiem browseriem */
    /*( !scrollingShowed && ( browser.ie5 || browser.ie6 ) && browser.dom && 1==1 ){ */
    if ( !scrollingShowed )
    {
        /*var cookieExpire = 12 * 60 * 60 * 1000;
        var bust = Math.floor(89999999*Math.random()+10000000);
        var millis = new Date().getTime();*/

        // izveidojam ifreimu, anchoru un img objektus ar visiem parametriem
        var scrollingIframe = document.createElement('iframe');
        scrollingIframe.setAttribute('src',bannerSrc);
        scrollingIframe.setAttribute('id',bannerName);
        scrollingIframe.setAttribute('marginwidth','0');
        scrollingIframe.setAttribute('marginheight','0');
        scrollingIframe.setAttribute('width','1');
        scrollingIframe.setAttribute('height','1');
        var scrollingA = document.createElement('a');
        scrollingA.setAttribute('href',bannerHref);
        scrollingA.setAttribute('target','_blank');
        var scrollingImg = document.createElement('img');
        scrollingImg.setAttribute('src',bannerSrc);
        scrollingImg.setAttribute('alt',altText);
        scrollingImg.setAttribute('width',width);
        scrollingImg.setAttribute('height',height);

        // ievietojam izveidotos objektus scrolling-content div elementaa
        var scrollingContent = document.getElementById('scrolling-content');
        scrollingImgA = scrollingImg.cloneNode(true);
        scrollingImgB = scrollingImg.cloneNode(true);
        scrollingImgC = scrollingImg.cloneNode(true);
        scrollingImgD = scrollingImg.cloneNode(true);
        scrollingA.appendChild(scrollingImg);
        scrollingA.appendChild(scrollingImgA);
        scrollingA.appendChild(scrollingImgB);
        scrollingA.appendChild(scrollingImgC);
        scrollingA.appendChild(scrollingImgD);
        scrollingA.style.width = width * 6 + 5 + 'px';
        scrollingA.style.height = height + 'px';
        scrollingContent.appendChild(scrollingA);
        scrollingContent.appendChild(scrollingIframe);
        // uzliekam scrolling-contentam augstumu platumu un poziiciju
        scrollingContent.style.width = width * 6 + 5 + 'px';
        scrollingContent.style.height = height + 'px';
        scrollingContent.style.left = '0px';
        scrollingContent.style.top = '0px';

        // uztaisam bannera aizveershanas pogu
        var scrolling = document.getElementById('scrolling-banner');
        /*var button = document.createElement( "a" );
	    button.className = "hide-banner";
	    button.setAttribute( "cookieexpire", cookieExpire );
        button.setAttribute( "bannername", bannerName );
	    button.onclick = function()
        {
          setBannerCookie(this.getAttribute('bannername'), this.getAttribute('cookieexpire') )
          scrollingStop();
        }
	    var buttonText = document.createTextNode( "" );
	    buttonText.nodeValue = "SlÄ�pt Å”o reklÄ�mu";
	    button.appendChild( buttonText );
	    scrolling.appendChild( button );*/

        scrolling.style.left = "0px";
        var agt=navigator.userAgent.toLowerCase();
    var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
        if ( is_ie)
        {
		    // ie
            scrolling.style.position='absolute';
            scrolling.style.top = ( document.body.scrollTop + document.body.clientHeight - height ) + "px";
        }
	    else
        {
		    // paareejiem browseriem
            scrolling.style.top = ( window.innerHeight - height ) + "px";
        }
	    scrolling.style.width = document.body.clientWidth + "px";
        scrolling.style.height = height + 'px';
        if ( window.attachEvent )
        {
		    window.attachEvent( "onscroll", scrollingRePosition );
		    window.attachEvent( "onresize", scrollingRePosition );
	    }
        else
        {
		    window.addEventListener( "resize", scrollingRePosition, 1 );
	    }
	    scrolling.style.visibility = 'visible';
        scrollingInterval = setInterval( "scrollingMove(" + width + ")", scrollingStepMs );
	    //setBannerCookie( bannerName, cookieExpire );
    }

}
function scrollingRePosition(){
    var scrolling = document.getElementById('scrolling-banner');
    var height = parseInt(scrolling.style.height);

    // nochekojam vai sestais jo sestajam gljuks
    var agt=navigator.userAgent.toLowerCase();
    var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie6 = (is_ie && (agt.indexOf("msie 6.")!=-1) );
    if (is_ie)
    {
        scrolling.style.top = ( document.body.scrollTop + document.body.clientHeight - height ) + "px"; //ie6
    }
    else
    {
        scrolling.style.top = ( window.innerHeight - height ) + "px"; //other
    }
	scrolling.style.width = document.body.clientWidth + "px";
}
function scrollingMove(width) {
	var scrollingContent = document.getElementById( 'scrolling-content' );
	var scrollingContentPosition = parseInt( scrollingContent.style.left );
	scrollingContent.style.left = scrollingContentPosition - scrollingStepPx + 'px';
	if ( Math.abs(scrollingContentPosition) >= width ) {
		scrollingContent.style.left = ( - scrollingStepPx ) + 'px';
	}
}
function scrollingStop() {
	var scrolling = document.getElementById( 'scrolling-banner' );
	scrolling.style.visibility = 'hidden';
	clearInterval(scrollingInterval);
}
function openUrl_banner(url){
    window.location=url;
}
