function getAccordion(header, entry)
{
        var acc = new Accordion(header, entry, {
                            onActive: function(toggler, element){
                                toggler.setAttribute('id', 'header_active');
                                var alist = toggler.getChildren();
                                setHref(alist[0]);
                            },
                            onBackground: function(toggler, element){
                                toggler.setAttribute('id', 'header_inactive');
                                var alist = toggler.getChildren();
                                alist[0].href = 'javascript:void(0);';
                                alist[0].target = '_self';
                            },
                            height: true,
                            fixedHeight: 135
                        });
}

function setHref(item)
{
    (function(){ item.setAttribute('href', item.title); item.setAttribute('target', item.rel); } ).delay(1000);
}

function setImage(id)
{
    if (id == undefined || id == '' ) return;
    $$('div.photo_new').each(function(element) { element.setStyle('display', 'none'); });
    $('photo'+id).setStyle('display', '');
}


var scroll = Array();
var counterScroll = Array();
var countScroll = Array();
var itemsScroll = Array();

function setScroll(id, it, len)
{
    if ( $('scroll_'+id) == null ) return;
    if ( $('scroll_content_'+id) == null ) return;
    
    counterScroll[id] = 0;
    itemsScroll[id] = it;
    countScroll[id] = $$('div.item_'+id).length;
    $('scroll_content_'+id).setStyle('width', countScroll[id]*len);

    scroll[id] = new Fx.Scroll('scroll_'+id);
}

function scrollSelect(id, it)
{
    counterScroll[id] = it;
	scroll[id].toElement('item_'+id+'_'+counterScroll[id]);
    selectLink(id, it);
}

function selectLink(id, it)
{
    $$('a.item_select_realgallery').each(function(element, index){
        element.setAttribute('id', '');
        if (index == it)
            element.setAttribute('id', 'active');

    });
}

function scrollNext(id)
{
    if (scroll[id] == null) return;

	counterScroll[id]++;

	if ( counterScroll[id] > countScroll[id] - itemsScroll[id])
        counterScroll[id] = 0;

	scroll[id].toElement('item_'+id+'_'+counterScroll[id]);
}

function scrollPrev(id)
{
    if (scroll[id] == null) return;

    counterScroll[id]--;

	if ( counterScroll[id] < 0 )
        counterScroll[id] = countScroll[id] - itemsScroll[id];

    if ( counterScroll[id] < 0 )
        counterScroll[id] = 0;
        
	scroll[id].toElement('item_'+id+'_'+counterScroll[id]);
}

function randNumb(zakres){
var rn;
var z = 1;
    while(z){
        rn = Math.floor(Math.random() * 20) + 1;
        if(rn>zakres) z = 1;
        if(rn<=zakres) {
            z = 0;
        }
    }
    return rn;
}

var fx = [];
var rotateTime = 1200;
var counter = 4;

function rotateImgs(){
    var logimgs = $$('.logo_img');
    if(counter < (imgsTab.length-1)){
        loadImg(logimgs[randNumb(4)-1],imgsTab[counter]);
        counter ++;
        timer = $clear(timer);
        timer = rotateImgs.delay(rotateTime);
        return;
    }

    if(counter == (imgsTab.length-1)){
        counter = 0;
        timer = $clear(timer);
        timer = rotateImgs.delay(rotateTime);
        return;
    }
    //logimgs[randNumb(12)].src = imgsTab[randNumb((imgsTab.length-1))];

}

var timer;

function rotator(){
    timer = $clear(timer);
    timer = rotateImgs.delay(rotateTime);
}

var imgload = [];
imgload[0]=0;
var dd = 0;
var imgloadfadecmplt = [];
imgloadfadecmplt[0]=0;
var newImg = [];

function loadImg(img,newSrc){
     dd ++;
     newImg[dd] = new Image();
     newImg[dd].src = newSrc;
     imgloadfadecmplt[dd] = 0;

     fx[dd] = new Fx.Style(img,'opacity',{
        onComplete: function(){
			if(imgload[dd]!=1){
				imgloadfadecmplt[dd] = 1;
			}
            if(imgload[dd] == 1){
                imgload[dd]=0;
                img.src = newImg[dd].src;
                fx[dd].stop();
                fx[dd].start(0.1,1);
            }
        }
     });
     fx[dd].start(1,0.1);
     newImg[dd].onload = function(){
            imgload[dd] = 1;
			if(imgloadfadecmplt[dd] == 1){
				img.src = newImg[dd].src;
				fx[dd].start(0.1,1);
				imgload[dd] = 0;
			}
     }
     if (newImg[dd].complete)
    	{
    		imgload[dd] = 1;

    	}

}

var kwicks;
var szNormal = 169, szSmall  = 44, szFull   = 547;
function init_menu(option){

    kwicks = $$("#offer .offer_entry");
    var fx = new Fx.Elements(kwicks, {wait: false, duration: 600, transition: Fx.Transitions.Cubic.easeOut});
    kwicks.each(function(kwick, i) {
    	kwick.addEvent("mouseenter", function() {
    	    //event.stopPropagation();
    		var o = {};
    		o[i] = {width: [kwick.getStyle("width").toInt(), szFull]}

            $$('div.offer_bg0').setStyle('background-position', 'bottom right');
            $$('div.offer_bg1').setStyle('background-position', 'bottom right');
            $$('div.offer_bg2').setStyle('background-position', 'bottom right');
            $$('div.offer_bg3').setStyle('background-position', 'bottom right');

            $('offer_entry_small'+i).setStyle('display', 'none');
            $('offer_entry_normal'+i).setStyle('display', '');
            $('offer_lid_normal'+i).setStyle('display', 'none');
            $('offer_lid_big'+i).setStyle('display', '');

    		kwicks.each(function(other, j) {
    			if(i != j) {
    				var w = other.getStyle("width").toInt();
    				if(w != szSmall)
                    {
                        o[j] = {width: [w, szSmall]};                        
                        $('offer_entry_normal'+j).setStyle('display', 'none');                        
                        $('offer_lid_normal'+j).setStyle('display', 'none');
                        $('offer_lid_big'+j).setStyle('display', '');
                        $('offer_entry_small'+j).setStyle('display', '');
                    }
    			}
    		});
    		fx.start(o);
    	});
    });

    $("offer").addEvent("mouseleave", function() {
        //.stopPropagation();\

            $$('div.offer_bg0').setStyle('background-position', 'bottom left');
            $$('div.offer_bg1').setStyle('background-position', 'bottom left');
            $$('div.offer_bg2').setStyle('background-position', 'bottom left');
            $$('div.offer_bg3').setStyle('background-position', 'bottom left');

    	var o = {};
    	kwicks.each(function(kwick, i) {
    		o[i] = {width: [kwick.getStyle("width").toInt(), szNormal]}
            $('offer_lid_normal'+i).setStyle('display', '');
            $('offer_lid_big'+i).setStyle('display', 'none');
            $('offer_entry_normal'+i).setStyle('display', '');
            $('offer_entry_small'+i).setStyle('display', 'none');
    	});
    	fx.start(o);
    	if(option==0) kwicks[0].fireEvent('mouseenter');
    	if(option==1) kwicks[1].fireEvent('mouseenter');
    	if(option==2) kwicks[2].fireEvent('mouseenter');
    	if(option==3) kwicks[3].fireEvent('mouseenter');
    })
       if(option>=0 && option <=3){
        setKwicks(option);
       }
}

function setKwicks(nr){
    kwicks.each(function(item,i){
        if(i==nr){
            item.setStyles({'width':szFull});
        }
        if(i!=nr){
            item.setStyles({'width':szSmall});
        }
    })
}
