if (document.getElementById('anim-box')) {
var ul = document.getElementById('anim-box').getElementsByTagName('li');
var count = ul.length;
var n=0;
var paused = false;
for (i=0;i<ul.length;i++)
{
	ul[i].onmouseover = function() {paused = true};
	ul[i].onmouseout = function() {paused = false};
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity == 100)?99.999:opacity;
	object.filter = "alpha(opacity=" + opacity + ")";
	object.KhtmlOpacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	object.opacity = opacity / 100;

	if (opacity == 0) {
		if (n>0) {
			ul[n-1].className = '';
		} else {
			ul[count-1].className = '';
		}
	ul[n].className = 'showing';
	}
}

function changeInfo(){
	if (paused){
		setTimeout("changeInfo()", 3000);
		return false;
	}
opacity('anim-box', 100, 0, 1000);
setTimeout("opacity('anim-box', 0, 100, 1000)", 1000);
if (n<count-1){
	n = n+1;
} else {
	n = 0;
}
setTimeout("changeInfo()", 7000);
}
}

/**
 * Cezary Tomczyk JSCode
 */

/**
 * Twitter API
 *
 */

var Twitter = {

    init : function()
    {
        var twitterjs = document.createElement('script'); twitterjs.type = 'text/javascript'; twitterjs.async = "async";
        twitterjs.src = 'http://platform.twitter.com/widgets.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(twitterjs, s);
    }
};

/**
 * Google Analytics API
 *
 * If the async attribute is set on an external script (one with src=),
 * browsers that support it will download that script in the background
 * without blocking the rest of the content on the page. The script will
 * execute whenever it is finished downloading.
 * http://dev.w3.org/html5/spec/Overview.html#attr-script-async
 *
 */

var _gaq = _gaq || [];
var GA = {

    init : function()
    {
        if(document.location.href.indexOf("www.ekb") != -1)
        {
        	_gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
        	_gaq.push(['_trackPageview']);

        	(function() {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = "async";
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        	})();
        }
    }
};

/**
 * Google Plus Button API
 *
 */

var GPlus = {

    init : function()
    {
        if(document.location.href.indexOf("www.ekb") != -1)
        {
            var box = document.getElementById('bookmarks'),
                btn = document.createElement('g:plusone'),
                plusBox = document.createElement('div');
                
            plusBox.id = 'GooglePlusBox';
            plusBox.appendChild( btn );
                
            box.appendChild( plusBox );
            
        	(function() {
                var gp = document.createElement('script'); gp.type = 'text/javascript'; gp.async = "async";
                gp.src = 'https://apis.google.com/js/plusone.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gp, s);
        	})();
        }
    }
};

/**
 * Facebook API
 *
 */

var facebookAPI = {
    
    lang : function()
    {
        var slash = location.href.split('/'),
            lang = slash[3],
            lang_code = 'pl_PL';

        if( lang == 'de' )
        {
            lang_code = 'de_DE';
        }
        else if( lang == 'en' )
        {
            lang_code = 'en_US';
        }
        
        return lang_code;
    },

    init : function()
    {
        var lang = facebookAPI.lang();

        window.fbAsyncInit = function()
        {
            FB.init({
                appId: null,
                status: true,
                cookie: true,
                xfbml: true
            });
        };

        (function()
        {
            var box = document.getElementById('bookmarks');
            if(box)
            {
                // Create Facebook root box
                var fbroot = document.createElement('div');
                    fbroot.id = 'fb-root';
                box.appendChild( fbroot );

                // Create LIKE button
                var fblike = document.createElement('fb:like');
                   fblike.setAttribute('layout', 'standard');
                   //fblike.setAttribute('show_faces', 'true');
                   //fblike.setAttribute('width', '290');
                   fblike.setAttribute('action', 'like');
                   fblike.setAttribute('colorscheme', 'light');
                   fblike.setAttribute('href', 'http://www.ekb.szczecin.pl/');
                fbroot.appendChild(fblike);

                // Init scripts from Facebook
                var e = document.createElement('script');
                e.async = 'async';
                e.src = document.location.protocol + '//connect.facebook.net/' + lang + '/all.js#xfbml=1';
                document.getElementById('fb-root').appendChild(e);
            }
        }());
        }

};

    // Google Analytics
    //GA.init();
    // Twitter
    Twitter.init();
    // Google Plus
    GPlus.init();
    // Facebook API
    facebookAPI.init();
    
	var contentLoaded = function (win, fn)
	{
		var	done = false, top = true,
			doc = win.document, root = doc.documentElement,
		
		add = doc.addEventListener ? 'addEventListener' : 'attachEvent',
		rem = doc.addEventListener ? 'removeEventListener' : 'detachEvent',
		pre = doc.addEventListener ? '' : 'on',
		
		init = function(e)
		{
			if (e.type == 'readystatechange' && doc.readyState != 'complete') return;
			(e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
			if (!done && (done = true)) fn.call(win, e.type || e);
		},
		
		poll = function()
		{
			try { root.doScroll('left'); } catch(e) { setTimeout(poll, 50); return; }
			init('poll');
		};
		
		if (doc.readyState == 'complete') fn.call(win, 'lazy');
		else
		{
			if (doc.createEventObject && root.doScroll)
			{
				try { top = !win.frameElement; } catch(e) { }
				if (top) poll();
			}
			doc[add](pre + 'DOMContentLoaded', init, false);
			doc[add](pre + 'readystatechange', init, false);
			win[add](pre + 'load', init, false);
		}
	};
    
contentLoaded( window, function(){

    if(document.getElementById('anim-box'))
    {
		window.setTimeout( function(){
			changeInfo();
		}, 8000);
    }

});
