var img_arr = new Array();
img_arr[0] = new Array('http://www.vedrana.lt/images/tit/fot_1.jpg', 'http://www.vedrana.lt/images/tit/1p.jpg', 'http://www.vedrana.lt/images/tit/2p.jpg', 'http://www.vedrana.lt/images/tit/4p.jpg');
img_arr[1] = new Array('http://www.vedrana.lt/images/tit/fot_33.jpg', 'http://www.vedrana.lt/images/tit/1s.jpg', 'http://www.vedrana.lt/images/tit/2s.jpg', 'http://www.vedrana.lt/images/tit/3s.jpg');
img_arr[2] = new Array('http://www.vedrana.lt/images/tit/log_pile.jpg', 'http://www.vedrana.lt/images/tit/3m.jpg', 'http://www.vedrana.lt/images/tit/4m.jpg', 'http://www.vedrana.lt/images/tit/5m.jpg');


var m_1i;
var m_2i;
var m_3i;
var img = 1;

function rotate() {
	$('#slide_image_0').parents('td:first').css({'height': ($('#slide_image_0').find('img').outerHeight()+20)+'px', 'width': ($('#slide_image_0').find('img').outerWidth()+20)+'px'});
	$('#slide_image_0').parents('div.container').css({'height': $('#slide_image_0').find('img').outerHeight()+'px', 'width': $('#slide_image_0').find('img').outerWidth()+'px'});
	
	var m_1 = $('#slide_image_0').find('img');
	
	m_1.css({'position':'absolute', 'left':'0px', 'top':'0px', 'z-index':'10'});
	
	var m_1_new = $('<img/>').attr({'border': '0', 'hspace': '0', 'src': img_arr[0][img], 'width': m_1.outerWidth(), 'height': m_1.outerHeight()}).css({'position':'absolute', 'left':'0px', 'top':'0px', 'z-index':'11', 'opacity':'0'});
	
	m_1.before(m_1_new);
	
	
	$('#slide_image_1').parents('td:first').css({'height': ($('#slide_image_1').find('img').outerHeight()+20)+'px', 'width': ($('#slide_image_1').find('img').outerWidth()+20)+'px'});
	$('#slide_image_1').parents('div.container').css({'height': $('#slide_image_1').find('img').outerHeight()+'px', 'width': $('#slide_image_1').find('img').outerWidth()+'px'});
	
	var m_2 = $('#slide_image_1').find('img');
	
	m_2.css({'position':'absolute', 'left':'0px', 'top':'0px', 'z-index':'10'});
	
	var m_2_new = $('<img/>').attr({'border': '0', 'hspace': '0', 'src': img_arr[1][img], 'width': m_2.outerWidth(), 'height': m_2.outerHeight()}).css({'position':'absolute', 'left':'0px', 'top':'0px', 'z-index':'11', 'opacity':'0'})
	
	m_2.before(m_2_new);
	
	
	$('#slide_image_2').parents('td:first').css({'height': ($('#slide_image_2').find('img').outerHeight()+20)+'px', 'width': ($('#slide_image_2').find('img').outerWidth()+20)+'px'});
	$('#slide_image_2').parents('div.container').css({'height': $('#slide_image_2').find('img').outerHeight()+'px', 'width': $('#slide_image_2').find('img').outerWidth()+'px'});
	
	var m_3 = $('#slide_image_2').find('img');
	
	m_3.css({'position':'absolute', 'left':'0px', 'top':'0px', 'z-index':'10'});
	
	var m_3_new = $('<img/>').attr({'border': '0', 'hspace': '0', 'src': img_arr[2][img], 'width': m_3.outerWidth(), 'height': m_3.outerHeight()}).css({'position':'absolute', 'left':'0px', 'top':'0px', 'z-index':'11', 'opacity':'0'});
	
	m_3.before(m_3_new);
	
	m_1i = m_1;
	m_2i = m_2;
	m_3i = m_3;
	
	
	$(m_1_new).delay(400).animate({opacity: 1}, 1000, function() {
		m_1i.remove();
		$(m_2_new).animate({opacity: 1}, 1000, function() {
			m_2i.remove();
			$(m_3_new).animate({opacity: 1}, 1000, function() {
				m_3i.remove();
				img++;
				if (img > 3) {
					img = 0;
				}
				setTimeout('rotate();', 3000);
			});
		});
	});
	
}


$(window).load(function() {
	rotate();
});
