var slideActual = 1;
var slideTotal = 9;
var slideTimer;
var np = 1;
var p, c, c1, bob, bob1, np, np1;

function hp_slidemove() {
  var curr = jQ("#referenceCont a.actual");
  var next = jQ("#referenceCont a").slice(slideActual-1, slideActual);  
  jQ(curr).animate({'opacity':'.0'}, 2000,
                  function() {
                    jQ(this).removeClass('actual');
                  });
  jQ(next).animate({'opacity':'1.0'}, 2000,
                  function() {
                    jQ(this).addClass('actual');
                    slideActual = slideActual < slideTotal ? slideActual+1 : 1;
                    clearTimeout(slideTimer);
                    slideTimer = setTimeout('hp_slidemove()',4000);                    
                  });  

};
function curve(x, y, ax, ay, bx, by, zx, zy) {
	var	path0 = [["M", x, y], ["C", x, y, x, y, x, y]],
		path25 = [["M", x, y], ["C", ax, ay, bx, y, zx, y]],
		path50 = [["M", x, y], ["C", ax, ay, bx, by, zx, zy]],
		path100 = [["M", x, y], ["C", ax, ay, bx, by, zx, zy]],
		curve = p.path(path100).attr({stroke: "#131313", "stroke-width": 1, "stroke-linecap": "round", opacity: 0});		
	return curve;
};
function makeBob(x,y,w,h) {	
	var b = p.image("/pages/tpl/img/bck_pt_bobek.png", x,y,w,h);	
	b.attr({scale: .1, stroke: "none", opacity: 1});
	return b;
}
function clback_aBD() {	
	bob.onAnimation(function(){});
	bob1.onAnimation(function(){});
	np = 1;
	np1 = 1;
	hp_slidemove();	
};
function animBobDown(bb,nn,cc,time) {	
	bb.onAnimation(function() {
		var sp = cc.getSubpath(nn, nn + 10);
		nn = bb.attr("y")-125;	
		if(nn > 105) {
			t = p.path(sp).attr({opacity: 0.6, stroke: "#131313"});			
			t.animate({opacity: 0},1500,function(){this.remove()});
		}		
		
	});	
	bb.animate({scale: 1},500);
	bb.animateAlong(cc, 2000, false, function(){clback_aBD()});	
};
function birdShit() {	
	clearTimeout(slideTimer);	
	if(bob1 != undefined && c1 != undefined) {			
		bob.animate({y: bob.attr('y')+30}, 500, 'backIn', function() {
			bob.remove();				
			bob = makeBob(295, 115, 24, 23);			
			animBobDown(bob,np,c);
		});
		bob1.animate({y: bob1.attr('y')+20}, 800, 'backIn', function() {
			bob1.remove();				
			bob1 = makeBob(295, 115, 16, 15);			
			animBobDown(bob1,np1,c1);
		});
	}else {				
		bob = makeBob(295, 115, 24, 23);
		bob1 = makeBob(295, 115, 16, 15);
		animBobDown(bob,np,c);
		setTimeout('animBobDown(bob1,np1,c1)',400);		
	}	
};
jQ(document).ready(function(){
	jQ("#referenceCont a").slice(slideActual-1, slideActual).addClass('actual');    
	jQ("#referenceCont a.actual").siblings().css('opacity','.0');    
	slideActual++;	

	p = Raphael("ptacek", 500, 355);		
	c = curve(305,125, 360,125, 355,342, 355,342);
	c1 = curve(305,125, 353,125, 347,350, 347,350);
	
	jQ("#ptacek").click(function(){birdShit();});
	birdShit();	
});

