// JavaScript Document


var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
var play_pause = 'pause';

$(document).ready(function(){
    headline_count = $("div.headline").size();
	
    // setup the first headline
    $("div.headline:eq("+current_headline+")").css('top', '5px');
    
    // setup the counter text
    //$("#scroll_counter").text('1 of ' + headline_count);
    
    // call the rotate function at regular intervals
    headline_interval = setInterval(headline_rotate,10000);
/*  
    $('#scrollup').hover(
        function() {
        clearInterval(headline_interval);
        }, 
        function() {
            headline_interval = setInterval(headline_rotate,5000);
            headline_rotate();
        }
    );
*/
    $('#scroll_play_pause').click(function(){
        if( play_pause == 'pause' ) {
            clearInterval(headline_interval);
            $(this).text('play');
            play_pause = 'play';
        } else {
            headline_interval = setInterval(headline_rotate,10000);
            headline_rotate();
            $(this).text('pause') ;
            play_pause = 'pause';
        }
    });
    
    $('#scroll_next').click(function(){
            clearInterval(headline_interval);
            headline_interval = setInterval(headline_rotate,10000);
            headline_rotate();
    });
});

function headline_rotate() {
  current_headline = (old_headline + 1) % headline_count;
  

  $("div.headline:eq(" + old_headline + ")")
	.animate({top: -410},"slow", function() {
	  $(this).css('top', '420px');				/* zmena z 210 na 800*/
	});

  $("div.headline:eq(" + current_headline + ")")
	.animate({top: 5},"slow");
  
  old_headline = current_headline;  
  
  // incriment the headline text
  $("#scroll_counter").text( (current_headline+1) + ' of ' + headline_count);
  
}

var headline_count2;
var headline_interval2;
var old_headline2 = 0;
var current_headline2 = 0;
var play_pause2 = 'pause';
var direction = 'up';
var movedC = 0;
var overlayed = false;

$(document).ready(function(){
    headline_count2 = $("div.headline2").size();
	
    // setup the first headline
    $("div.headline2:eq("+current_headline2+")").css('top', '0px');
    
    // setup the counter text
    //$("#scroll_counter").text('1 of ' + headline_count);
    
    // call the rotate function at regular intervals
    headline_interval2 = setInterval(headline_rotate2,3500);
/*  
    $('#scrollup').hover(
        function() {
        clearInterval(headline_interval);
        }, 
        function() {
            headline_interval = setInterval(headline_rotate,5000);
            headline_rotate();
        }
    );
*/
    $('#scroll_play_pause').click(function(){
        if( play_pause == 'pause' ) {
            clearInterval(headline_interval2);
            $(this).text('play');
            play_pause2 = 'play';
        } else {
            headline_interval2 = setInterval(headline_rotate2,3500);
            headline_rotate2();
            $(this).text('pause') ;
            play_pause2 = 'pause';
        }
    });
    
    $('#scroll_next').click(function(){
            clearInterval(headline_interval2);
            headline_interval2 = setInterval(headline_rotate2,3500);
            headline_rotate2();
    });
});

function headline_rotate2() {
  //current_headline2 = (old_headline2 + 1) % headline_count2;

if(direction == 'up' & movedC < ((overlayed) ? 4 : 3)){
	current_headline2 = (current_headline2+67);
	movedC++;
	if(movedC == ((overlayed) ? 4 : 3)){
		direction = 'down';	
	}
}else{
   current_headline2 = (current_headline2-67);
   movedC--;
   	if(movedC == 0){
		direction = 'up';
	}


}

//if(current_headline2 < 150){
//	current_headline2 = (current_headline2+65);
//}else{
//   current_headline2 = (current_headline2-65);
//}


  $("div.headline2:eq(" + old_headline2 + ")")
	.animate({top: -current_headline2},"slow", function() {
	  $(this).css('top', '-'+ current_headline2 +'px');				/* zmena z 210 na 800*/
	});

//  $("div.headline2:eq(" + current_headline2 + ")")
//	.animate({top: 0},"slow");
  
  //old_headline2 = (current_headline2-65);  
  
  // incriment the headline text
  //$("#scroll_counter").text( (current_headline2+1) + ' of ' + headline_count2);
  
}


function establishTopPosition() {
var slidebar = document.getElementById('slidebar');
var y = 0;
while (slidebar!=null) {
y += slidebar.offsetTop
slidebar = slidebar.offsetParent;
}
return y;
}

function establishLeftPosition() {
var slidebar = document.getElementById('slidebar');
var x = 0;
while (slidebar!=null) {
x += slidebar.offsetLeft
slidebar = slidebar.offsetParent;
}
return x;
}

function pushMyCart() {
	var access = document.getElementById('access');
	var slide = document.getElementById('slide2');
	//var scroll_wrapper = document.getElementById('scroll_wrapper'); 
	if(access != null) {
		var topPos = establishTopPosition();
		if( window.XMLHttpRequest ) { // IE 6 doesn't implement position fixed nicely...
			if (document.documentElement.scrollTop > topPos || self.pageYOffset > topPos) {
				access.style.position = 'fixed';
				access.style.top = '0';
 /*			//access.style.width = '150';
			//scroll_wrapper.style.top = '0'; */ 
				slide.style.position = 'relative';
				slide.style.top = '-67px';
				overlayed = true;
			} else {
				access.style.position = '';
				slide.style.top = '0';
				overlayed = false;
			}
		}
	}
}

function establishTopPosition2() {
	var slidebar2 = document.getElementById('slidebar2');
	var y2 = 0;
	while (slidebar2!=null) {
		y2 += slidebar2.offsetTop
		slidebar2 = slidebar2.offsetParent;
	}
	return y2;
}

function pushMyCart2() {
	var access2 = document.getElementById('access2');
	
	if(access2 != null) {
		var free = document.getElementById('freespace');
		free.style.height = access2.offsetHeight + 'px';
		var topPos2 = establishTopPosition2();
		
		if( window.XMLHttpRequest ) { // IE 6 doesn't implement position fixed nicely...
			if (document.documentElement.scrollTop > topPos2 || self.pageYOffset > topPos2) {
				access2.style.position = 'fixed';
				access2.style.top = '0px';
				free.style.position = 'relative';
				
				//access2.style.width = '172';
			} else {
				access2.style.position = '';
				free.style.position = 'absolute';
			}
		}
	}
}
