var firstSlider;

$(document).ready(function(){

/*
	// main sliders
	if($('div.multicontent-main').size() > 0){
		$('div.multicontent-main').each(function(){
			var slidesCount = $(this).find('div.visual').size();
			if(slidesCount > 1){
				$(this).append('<ul class="page"></ul>');
				for(i = 1; i <= slidesCount; i++){
					$(this).find('ul').append('<li' + (i == 1 ? ' class="first active"' : '') + '><a href="#">'+ i +'</a></li>');
				}
				$(this).find('div.visual').gt(0).hide();
			}
			$(this).find('ul.page li').click(function(){
				$(this).parents('ul.page').find('li.active').removeClass('active');
				$(this).addClass('active');
				$(this).parents('div.multicontent-main').find('div.visual:visible').hide();
				$(this).parents('div.multicontent-main').find('div.visual').eq(parseInt($(this).text())-1).show();
				return false;
			});

		});
	}
*/
	var currentSlider;
	var slideWidth = 675;
	var slideHeight = 240;

	var rotateInterval;
	var rotateIntervalTime = 20000;
	
	// main sliders
	if($('div.multicontent-main').size() > 0){
		$('div.multicontent-main').each(function(){
			var slidesCount = $(this).find('div.visual').size();
			if(slidesCount > 1){
				if(firstSlider == null || firstSlider < 0 || firstSlider > slidesCount-1) {
					firstSlider = 0;
				}
				currentSlider = firstSlider+1;
				$(this).append('<ul class="page"></ul>');
				for(i = 1; i <= slidesCount; i++){
					$(this).find('ul').append('<li' + (i == firstSlider+1 && i == 1 ? ' class="first active"' : (i == firstSlider+1 ? ' class="active"' : '') + (i == 1 ? ' class="first"' : '') ) + ' ><a href="#">'+ i +'</a></li>');
				}
				$('div.multicontent-main ol li').each(function(i){
					$(this).css({ position: "absolute", left: (slideWidth * (i-firstSlider)), top: "0" });
				});
				$(this).find('ul.page li').click(function(){
					$(this).parents('ul.page').find('li.active').removeClass('active');
					$(this).addClass('active');
					$('div.multicontent-main ol').animate({
						left: (slideWidth - (parseInt(($(this).text())-firstSlider) * slideWidth))
	//					top: (slideHeight - (parseInt($(this).text()) * slideHeight))
					},1200,"easeinout");
					currentSlider = $(this).text();
					return false;				
				});

				function rotateSliders() {
					currentSlider = (currentSlider + 1);
					if(currentSlider > slidesCount)	{
						currentSlider = 1;
					}
					
					$(this).find('ul.page').find('li.active').removeClass('active');
					
					$(this).find('ul.page li').each(function(){
						if($(this).text() == currentSlider) {
							$(this).addClass('active');
							$('div.multicontent-main ol').animate({
								left: (slideWidth - (parseInt(($(this).text())-firstSlider) * slideWidth))
							},1200,"easeinout");							
						}
					});
				}

				rotateInterval = setInterval(rotateSliders,rotateIntervalTime);
				$(this).hover(function() {
					clearInterval(rotateInterval);
				}, function() {
					rotateInterval = setInterval(rotateSliders,rotateIntervalTime);
				});

			}
		});
	}


	// mini sliders
	if($('div.multicontent').size() > 0){
		$('div.multicontent').each(function(){
			var slidesCount = $(this).find('div.content').size();
			if(slidesCount > 1){
				$(this).find('div.boxHeader').append('<ul class="navigation"></ul>');
				for(i = 1; i <= slidesCount; i++){
					$(this).find('ul.navigation').append('<li' + (i == 1 ? ' class="active"' : '') + '><a href="#">'+ i +'</a></li>');
				}
				$(this).find('div.content').gt(0).hide();
			}
			$(this).find('ul.navigation li').click(function(){
				$(this).parents('ul').find('li.active').removeClass('active');
				$(this).addClass('active');
				$(this).parents('div.multicontent').find('div.content:visible').hide();
				$(this).parents('div.multicontent').find('div.content').eq(parseInt($(this).text())-1).show();
				return false;
			});

		});
	}

});

function open_foto(img,fot_a)
{
	var foto_poz_x = (screen.availWidth/2) - (377/2);
	var foto_poz_y = (screen.availHeight/2) - (610/2);
	var foto_win_value = 'scrollbar=no,resize=no,width=377px,height=600px,left=' + foto_poz_x + ',top=' + foto_poz_y;
	
	foto_window=window.open('','foto_window',foto_win_value);
	foto_pop_emiter='<html>\n<head>\n<title>Babyonline.pl<\/title>\n<link rel="stylesheet" type="text\/css" href="http:\/\/www.polki.pl\/webapps\/front\/html\/css\/style.css" media="all">\n<\/head>\n';

	foto_pop_emiter+='<'+'scr'+'ipt type="text/java'+'script">\n';
	foto_pop_emiter+='<'+'!--//-->'+'<![CDATA[//><'+'!--\n';
	foto_pop_emiter+='var gemius_identifier = new String(\'.R.lpqLICUViNb7ypMZCDMPJDkEWA6cwQFBv4OvpwSj.I7\');\n';
	foto_pop_emiter+='//-'+'-><!]]>\n';
	foto_pop_emiter+='<'+'/sc'+'ript>\n';
	foto_pop_emiter+='<'+'scri'+'pt type="text/jav'+'ascript" src="http://www.babyonline.pl/gemius.js"></scr'+'ipt>\n';
	
	foto_pop_emiter+='<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">\n<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">\n<tr width="100%" height="100%">\n<td width="100%" height="100%" VALIGN="middle" align="center">\n<img src="'+img+'" border="0">\n<P ALIGN="LEFT">&nbsp;&nbsp;&nbsp;'+fot_a+'<\/P>\n<\/td>\n<\/tr>\n<\/table>\n<\/body>\n<\/html>';
	foto_window.document.write('');
	foto_window.document.write(foto_pop_emiter);
	foto_window.document.close();
}