var newsid = 2;

function nswitcher()
{
    $('#main1').css('display', 'none');
    $('#main2').css('display', 'none');
    $('#main3').css('display', 'none');
    $('#main'+newsid+'').show('slow');
    $('#idnews li').removeClass('ons');
    $('#cs'+newsid).addClass('ons');
    
    if(newsid == 2)
    {
        newsid = 3;
    }
    else
    {
        if(newsid == 3)
        {
            newsid = 1;
        }
        else
        {
            newsid = 2;
        }
    }
}

$(function(){
	$('.komentarz:odd', '#komentarze').css('background', '#c2d5ee');
	$('.komentarz:even', '#komentarze').css('background', '#eaf8f4');
	setInterval('nswitcher()', 10000);
    
	$('#menu li').click(function() {				 
			$("#menu ul").css('display', 'none');
			$("ul", this).show('slow');		 
	});
		$('#menu ul').mouseleave(function() {
			$("#menu ul").hide('slow');
			$("#menu .og").css('background-image', 'none');	
			$("#menu .ogs").css('background-image', 'none');	
	});

	
	$('.header a').click(function() {
			var co = $(this).attr('name');	
			$('a', '#'+co+'').css('color', '#0b2e72');
			$(this).css('color', '#fff');
			var links = $(this).attr('name'); 
			
			$('.cp', '#'+links+'p').css('display', 'none');
			var bxop = $(this).attr('title');
			$('#'+bxop+'').show('slow');
	;		 
	});

	$('#idnews li').click(function() {		
				var iad = $(this).attr('value');
				$('#main1').css('display', 'none');
				$('#main2').css('display', 'none');
				$('#main3').css('display', 'none');
				$('#main'+iad+'').show('slow');
				$('#idnews li').removeClass('ons');
				$(this).addClass('ons');
	});
	$('#arrowl').click(function() {	
				var iad = $('#idnews .ons').attr('value');
				var id = iad-1;
				if(id == 0){var id = 3;}
				$('#main1').css('display', 'none');
				$('#main2').css('display', 'none');
				$('#main3').css('display', 'none');
				$('#main'+id+'').show('slow');
				$('#idnews li').removeClass('ons');
				$('#idnews #cs'+id+'').addClass('ons');
	});
	$('#arrowr').click(function() {	
				var iad = $('#idnews .ons').attr('value');
				var id = iad+1;
				if(id > 3){var id = 1;}
				$('#main1').css('display', 'none');
				$('#main2').css('display', 'none');
				$('#main3').css('display', 'none');
				$('#main'+id+'').show('slow');
				$('#idnews li').removeClass('ons');
				$('#idnews #cs'+id+'').addClass('ons');
	});
});

var Marquee = function ( id, opt ){
    if( ! document.getElementById(id) ) throw 'invalid id. [' + id + ']';
    var option = opt || {};
    this.id     = id;
    this.amount = option.amount || 6;
    this.delay  = option.delay  || 100;
    this.position = Number.POSITIVE_INFINITY; // means out of range.
    this._wrap();
    this.start();
}
Marquee.prototype = {
    /* wrap child nodes */
    _wrap : function() {
        var t = document.getElementById( this.id );
        with ( t.style ){
            position = 'relative'; // for ie6.
            overflow = 'hidden';
        }
        var w = document.createElement( 'div' );
        with ( w.style ){
            margin     = '0';
            padding    = '0';
            background = 'transparent';
            border     = 'none';
        }
        t.normalize();
        while( t.firstChild ){
            w.appendChild( t.removeChild( t.firstChild ) );
        }
        t.appendChild(w);
        /* get minimum width. */
        w.style.position = 'absolute';
        this.minWidth = w.offsetWidth;
        /* put back */
        w.style.position = 'relative';
        w.style.width = '100%'; // for ie6.
    },
    start : function() {
        this.stop();
        this._next();
    },
    _next : function() {
        var t = document.getElementById( this.id );
        this.curWidth = Math.min(t.offsetWidth,t.parentNode.offsetWidth); // dirty. (for "overflow:hidden" parent)
        this.position = this.position - this.amount;
        if ( this._isOutOfRange() ) {
            this.position = this._startPosition();
        }
        var w = t.firstChild;
        w.style.left = this.position + 'px';
        var self = this;
        this.tid = window.setTimeout(
            function(){ self._next(); },
            this.delay
        );
    },
    _startPosition : function() {
        return ( this.amount > 0 ) ?  this.curWidth
                                   : -this.minWidth;
    },
    _isOutOfRange : function() {
        return this.position < -this.minWidth || this.curWidth < this.position;
    },
    stop : function() {
        if ( this.tid ) window.clearTimeout( this.tid );
        this.tid = null;
    },
    isMarqueeing : function() {
        return ( this.tid ) ? true : false;
    }
}
