var currF = {};
var mv = {};
var lStep = 1;

function init(){
	$('img_slide_01').show();
	$('img_slide_02').show();
	playStart('images');
	playStart('text');
	loadURL($('content'), 'home.html');
}

function playStart(scene){
    if(!currF[scene]){
        currF[scene] = 1;
    }
    playFrame(scene, currF[scene]);
}

function playFrame(scene, f){

    switch(scene){
            
        case 'text':
            switch(f){
                case 1:
                    var n = texts[Math.floor(Math.random()*texts.length)].toUpperCase();
                    n = n.replace(/ /g, '&nbsp;');
                    mv = moves[Math.floor(Math.random()*moves.length)];
                    $('overlay').insert('<div id="slideframe01" style="position:absolute;top:' + mv.top + 'px;left:' + mv.left + 'px;display:none;">' + n + '</div>');
                    setTimeout(function(){incFrame(scene)},1000);                    
                    break;
                case 2:
                    new Effect.Move('slideframe01', {duration:7, x:mv.x, y:mv.y});
                    new Effect.Appear('slideframe01', {duration:4, from:0, to:0.3, afterFinish: function(){incFrame(scene)}});
                    break;
                case 3:
                    new Effect.Fade('slideframe01', {duration:3, from:0.3, to:0, afterFinish: function(){incFrame(scene)}});
                    break;
                case 4:
                    $('slideframe01').remove();
                    setTimeout(function(){currF.text=1;playStart('text');},5000);
                    break;
            }
            break;
            
        case 'images':
            switch(f){
                case 1:
                    if($('img_pri').getOpacity() == 0.01){
                    
                        //$('img_pri').select('img')[0].src = images[Math.floor(Math.random()*images.length)];
                        $('img_pri').select('img')[0].src = images[lStep];
                        new Effect.Appear('img_pri', {duration:1, from:0.01, to:1, afterFinish: function(){incFrame(scene)}});
                        new Effect.Fade('img_sec', {duration:1, from:1, to:0.01});
                        
                    } else {
                    
                        //$('img_sec').select('img')[0].src = images[Math.floor(Math.random()*images.length)];
                        $('img_sec').select('img')[0].src = images[lStep];
                        new Effect.Fade('img_pri', {duration:1, from:1, to:0.01, afterFinish: function(){incFrame(scene)}});
                        new Effect.Appear('img_sec', {duration:1, from:0.01, to:1});
                        
                    }
                    break;
                case 2:
                	if(lStep < images.length - 1){
	                	lStep++;
	                } else {
	                	lStep = 0;
	                }

                    setTimeout(function(){currF.images=1;playStart('images');},10000);
                    break;
            }
            break;
    }
    
}

function incFrame(scene){
    currF[scene]++;
    if(currF[scene] < 100){
        setTimeout(function(){
            playFrame(scene, currF[scene]);
        }, 100);
    }
}

function mOver(o){
    new Effect.Fade(o, {from: 1.0, to: 0.5, duration: 0.3});
}

function mOut(o){
    new Effect.Fade(o, {from: 0.5, to: 1, duration: 0.3});
}

function loadURL(o, url, t){
	if(t && !Prototype.Browser.IE){
		$('highlight').morph('position:relative;top:30px;left:' + t.getAttribute('s') + 'px;z-index:1000;width:' + t.getAttribute('w') + 'px;height:32px;border:solid 1px red;');
	}

	var ts = new Date().getTime() + '';
    new Ajax.Request(url + '?ts=' + ts , {
        onSuccess: function(r){
            o.update(r.responseText);
            if($$('.blackbox')[0]){
            	var boxHeight = $$('.blackbox')[0].getAttribute('boxHeight');
			} else {
				var boxHeight = $$('.blacklong')[0].getAttribute('boxHeight');
			} 
            $('pano').style.height = boxHeight;
            $('footer').style.top = boxHeight - 50;
        }
    });

}

var texts = [
    'najwyższy poziom obsługi prawnej',
    'bezpośrednia dostępność',
    'dostosowana pomoc prawna',
    'priorytetowe znaczenie',
    'szybkie podejmowanie czynności'
];

var moves = [
    {'top':'10', 'left':'10', 'x':'250', 'y':'25'},
    {'top':'10', 'left':'450', 'x':'-250', 'y':'25'},
    {'top':'300', 'left':'10', 'x':'250', 'y':'-25'},
    {'top':'300', 'left':'450', 'x':'-250', 'y':'-25'},
    {'top':'10', 'left':'10', 'x':'400', 'y':'40'},
    {'top':'10', 'left':'450', 'x':'-400', 'y':'40'},
    {'top':'300', 'left':'10', 'x':'400', 'y':'-40'},
    {'top':'300', 'left':'450', 'x':'-400', 'y':'-40'}
];

var images = [
    'slide07.png',
    'slide01.png',
    'slide02.png',
    'slide03.png',
    'slide04.png',
    'slide05.png'
];
