mbm.glowna = 0;
mbm.imgArray = new Array('/media/pokaz/zdjecie1.jpg','/media/pokaz/zdjecie2.jpg','/media/pokaz/zdjecie3.jpg','/media/pokaz/zdjecie4.jpg'); // images array
mbm.currentImg = 0;	// starting index
mbm.time = 5;	// execution time

/* Event.observe.defer(window, 'load', function(pokaz) { if (mbm.imgArray.length > 0 && $('mainContent') !== null && mbm.glowna == 1) {
	updateImage();
	mbm.pokaz = new PeriodicalExecuter(updateImage, mbm.time);
}}); */

setTimeout(function() { if (mbm.imgArray.length > 0 && $('mainContent') !== null && mbm.glowna == 1) {
	updateImage();
	mbm.pokaz = new PeriodicalExecuter(updateImage, mbm.time);
}},500);
	
function updateImage() {
	var next = mbm.currentImg + 1;
	if (mbm.imgArray[next] === undefined)	next = 0;
	var prev = mbm.currentImg;
	a = document.createElement('img');
	Element.extend(a);
	a.style.display = 'none';
	$('mainContent').appendChild(a);
	a.src = mbm.imgArray[next];
	a.id = 'm'+next;
	a.addClassName('pokazGlowna');
	if($('m'+mbm.currentImg) !== null) $('m'+mbm.currentImg).fade();
	$('m'+next).appear();
	mbm.currentImg = next;
	if($('m'+prev) !== null)
		setTimeout("$('m" + prev+ "').remove()",1010);
}

function clearImage() {
	$$('img.pokaz').each(function(item) {item.remove()});
}

mbm.gTime = 2.7;
mbm.gCurrent = 0;
Event.observe.defer(window, 'load', function() { if ($('logo') !== null) {
	gwiazdki();
	new PeriodicalExecuter(gwiazdki, mbm.gTime);
}});
	
function gwiazdki() {
	return;
	var gnext = mbm.gCurrent+1
	if (gnext > 3)	gnext = 1;
	var prev = mbm.gCurrent;
	$('g'+gnext).appear();
	setTimeout("$('g"+gnext+"').fade()",1210);
	mbm.gCurrent = gnext;
}

//Event.observe.defer(window, 'load', function() { logotypy(); });
setTimeout(function() { logotypy(); },500);
mbm.lCurrent = 0;
mbm.lTime = 6;
function logotypy() {
	mbm.logotypyCount = $$('div.logotypy').size();
	mbm.lmax = mbm.logotypyCount - 1; 
	if(mbm.logotypyCount > 1) {
		logotypyUpdate();
		new PeriodicalExecuter(logotypyUpdate, mbm.lTime);
	} else if(mbm.logotypyCount == 1) {
		$('l0').appear();
	}
}

function logotypyUpdate() {
	$('l'+mbm.lCurrent).style.top = "-82px";
	$('l'+mbm.lCurrent).show();
	new Effect.Move($('l'+mbm.lCurrent), { x: 0, y: 82 });
	mbm.lnext = mbm.lCurrent+1
	if (mbm.lnext > mbm.lmax)	mbm.lnext = 0;
	logotypyHide(mbm.lCurrent);	
	mbm.lCurrent = mbm.lnext;
}

function logotypyHide(id) {
	setTimeout("new Effect.Move($('l"+id+"'), { x: 0, y: 82 })",5900);
	setTimeout("$('l"+id+"').hide()",6900);
}

mbm.pid = null;
mbm.pos = null;
mbm.json = null;
function showPic(el,pos,id,ad) {
	tlo = $('mainContent').getStyle('background-image');
//	$('mainContent').style.backgroundImage = 'none';
	mbm.pid = id;
	mbm.pos = pos;
	var next = pos+1;
	var prev = pos-1;
	if($('showPicPodpis') !== null)
		$('showPicPodpis').update($('zdj'+pos).title);
	$('showPicZdj').src = '';
	$('showPicZdj').src = ad;
	$('showPicZdj').style.display = 'none';
	$('showPicZdj').style.visibility = 'visible';
	$$('#podpis').each(function(item) {item.hide();});
//	$$('.nextGal').each(function(item) {item.hide();});
//	$$('.prevGal').each(function(item) {item.hide();});
	$$('.'+id).first().fade();
	$('x').show();
	if($('zdj'+next) !== null)
		$('next').show();
	if($('zdj'+prev) !== null)
		$('prev').show();
	$('tloDol').appear();
	$('showPicZdj').appear();
	if($('zdj'+pos).title != '' && $('zdj'+pos).title !== null && $('zdj'+pos).title !== undefined && $('showPicPodpis') !== null)
		$('showPicPodpis').appear();
	
	$('showPicBG').appear();

}

function closePic() {
	$('x').hide();
	$('next').hide();
	$('prev').hide();
	$('tloDol').fade();
	$('showPicZdj').fade();
	$('showPicBG').fade();
	if($('showPicPodpis') !== null)
		$('showPicPodpis').fade();
	$$('.'+mbm.pid).first().appear();
	setTimeout("$$('#podpis').each(function(item) {item.show();})",1010);
//	setTimeout("$$('.nextGal').each(function(item) {item.show();})",1010);
//	setTimeout("$$('.prevGal').each(function(item) {item.show();})",1010);
	setTimeout("$('showPicZdj').src = ''",1010);
	if($('showPicPodpis') !== null)
		setTimeout("$('showPicPodpis').innerHTML = ''",1010);
}

function goNext() {
	var next = mbm.pos+1;
	var next2 = mbm.pos+2;
	if($('zdj'+next2) === null) $('next').hide();
	if($('prev').style.display == 'none') $('prev').show();
//	if(mbm.pid == 'salon') {
		$('showPicZdj').src = $('zdj'+next).href;
		if($('showPicPodpis') !== null) 
			$('showPicPodpis').update($('zdj'+next).title);
		mbm.pos = next;
//	}
}

function goPrev() {
	var prev = mbm.pos-1;
	var prev2 = mbm.pos-2;
	if($('zdj'+prev2) === null) $('prev').hide();
	if($('next').style.display == 'none') $('next').show();
//	if(mbm.pid == 'salon') {
		$('showPicZdj').src = $('zdj'+prev).href;
		if($('showPicPodpis') !== null)
			$('showPicPodpis').update($('zdj'+prev).title);
		mbm.pos = prev;
//	}
}

// ----------------------------------------------------------------------------

//mbm.addr = 'http://dono.fourtka.pl';
mbm.addr = 'http://www.donomoda.pl';
var pgG = null;

function setTitles(m,pm) {
	document.title = '';
	if(m !== null)
		document.title = m;
	if(pm !== null ) document.title = document.title + ', ' + pm;
	if(document.title != '') document.title = document.title + ' | ';
	document.title = document.title + ' Dono';
}


function getPage(pg,nGa,par) {
	$$('body').first().addClassName('wait');
	History.Observer.stop();
		
	pg=pg.replace(mbm.addr,'');
 	window.scrollTo(0,0);
	mbm.nmenuId = null;
	mbm.npmenuId = null;
	mbm.nmenuName = null;
	mbm.npmenuName = null;
	if(typeof(mbm.pokaz) != 'undefined') {
		mbm.pokaz.stop();
		clearImage();
	}

	$('mainContent-out').addClassName('noBG');
	$('mainContent').fade({duration: 0.4});
	$('ajax').fade({duration: 0.4});
	$$('#ajax div').each(function(item) {item.fade({duration: 0.4})});
	$('lewaKolumna').fade({duration: 0.4});
	$('prawaKolumna').fade({duration: 0.4});
	$('tloDol').fade({duration: 0.4});

	new Ajax.History.Request(pg, 
	{
		parameters: par,
		history: 
		{
			id: 'page',
			cache: true,
			state: pg.replace(/\//g,'_')
		},
		onSuccess: function(transport) {
			// śledzenie google analytics
			if(_gaq !== 'undefined') _gaq.push(['_trackPageview',pg]);
			$('ajax').style.visibility = "hidden";
			$('ajax').update(transport.responseText);          
			$$('link.added').each(function(item) {item.disabled = true;/* item.remove();*/});
			$('mainContent').update('<table class="zdjC"><tr><td><img id="showPicZdj" src="" alt="" /></td></tr></table><div id="showPicPodpis" style="display: none;"></div><div id="showPicBG" style="display: none;"></div>');
			if(pg == '/pl' || pg == '/' || pg == '/pl/' || pg == '/en' || pg == '/en/' || pg == '/it' || pg == '/it/') {
				mbm.currentImg = 0;
				updateImage();
				mbm.pokaz = new PeriodicalExecuter(updateImage, mbm.time);
//				$('marki').style.visibility = "visible";
			} //else $('marki').style.visibility = "hidden";
			setTimeout(function() {Scroller.setAll();Scroller.updateAll();}, 450);
			setTimeout(function() {
				if(typeof(mbm.pokaz) != 'undefined' && pg != '/pl' && pg != '/en' && pg != '/it' && pg != '/' && pg != '/pl/' && pg != '/en/' && pg != '/it/') {
					mbm.pokaz.stop();
					clearImage();
				}
	
				if(mbm.styleFile !== null && mbm.styleFile != 'undefined') {
					mbm.add = true;
					$$('link.added').each(function(item) {
						if(mbm.add == false) return;
						else if(item.href.replace(mbm.addr,'') == mbm.styleFile) {item.disabled = false; mbm.add = false;}
					});

					if(mbm.add == true) {
						var f = document.createElement('link');
						Element.extend(f);
						f.setAttribute("rel", "stylesheet");
						f.setAttribute("type", "text/css");
						f.setAttribute("href", mbm.styleFile);
						f.setAttribute("class", 'added');
						$$('head').first().appendChild(f);
					}
				}

				$$('#menuTop .active').each(function(item) {item.removeClassName('active')});
				$$('#menuDol .active').each(function(item) {item.removeClassName('active')});

				if(mbm.nmenuId !== null && mbm.nmenuId != 'undefined' && mbm.nmenuId != 0 && mbm.nmenuId != 9) $('menu'+mbm.nmenuId).addClassName('active');
				if(mbm.npmenuId !== null && mbm.npmenuId != 'undefined' && mbm.npmenuId != 0) $('menu'+mbm.npmenuId).addClassName('active');
				setTitles(mbm.nmenuName,mbm.npmenuName);
				if(mbm.nplayItem != mbm.playItem) {
					mbm.playItem = mbm.nplayItem;
					if(!$('player_play').hasClassName('active')) {
						$jq("#ctrl_next").click();
						$jq("#player_stop").click();						
					} else
						$jq("#ctrl_next").click();
				}
				$$('body').first().removeClassName('wait');
			},300);
			setTimeout(function() {$('ajax').style.visibility = "visible"; $('lewaKolumna').appear({duration: 0.4}); $('prawaKolumna').appear({duration: 0.4}); $('tloDol').appear({duration: 0.4}); $('mainContent').appear({duration: 0.4}); $('ajax').appear({duration: 0.4});}, 350);
			setTimeout(function() {$('mainContent-out').removeClassName('noBG');},760);
      	}
	});
}

var pg = null;
var pgG = null;

Event.observe.defer(window,'load',function() {
		if(mbm.ajax == 0) return;
		start = window.location.href;
		start = start.replace(mbm.addr,'');
		start = start.replace(/^(.*)\#(.*)$/,'$1');
		History.Observer.delay = 0.5;
		var pg = History.get('page');

		if(typeof(pg) !== 'undefined') var pgt = pg.replace('_','/');
		else var pgt = null;

		if((typeof pg!='undefined' && pg != '_pl' && pg != '_en' && pg != '_it' && pg != '_' && pg != '_pl_' && pg != '_en_' && pg != '_it_') || pgG)
		{
			if(pgG) getPage(pgG,pgt);
			else if(pg!='_') getPage(pg.replace(/_/g,'/'),pgt);
		}
//		else if (start != '_pl' && start != '_en' && start != '_it' && start != '_' && start != '_pl_' && start != '_en_' && start != '_it_')
//			getPage(start,pgt);
});

function getNodes(className) {
	return $$(className);
}

function validateNws(AForm) {
    reg = /^[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ\-\_\.]{1,60}@[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ\-\_\.]+(\.[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ\-\_\.]+)+$/;
    wyn = AForm.email.value.match(reg);
    if (wyn == null) {
        alert("Proszę podać poprawny adres email.");
        return false;
    }
	else if((AForm.imie.value == '')) {
		alert("Podaj imię.");
        return false;
	}
    else {
		return true;
    }
};

function validateKlub(AForm) {
    reg = /^[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ\-\_\.]{1,60}@[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ\-\_\.]+(\.[a-zA-Z0-9ąćęłńóśżźĄĆĘŁŃÓŚŻŹ\-\_\.]+)+$/;
    wyn = AForm.email.value.match(reg);
    
    reg2 = /^[0-9\-\ \+]+$/;
    wyn2 = AForm.telefon.value.match(reg2);
    
    if (wyn == null) {
        alert("Proszę podać poprawny adres email.");
        return false;
    }
	else if((AForm.imie.value == '')) {
		alert("Podaj imię.");
        return false;
	}
	else if(wyn2 == null) {
		alert("Podaj poprawny numer telefonu.");
        return false;
	}
    else {
		return true;
    }
};

function showPodpis(text) {
	$('podpistxt').innerHTML = text;
}

function hidePodpis() {$('podpistxt').innerHTML = '';}


mbm.currentSet = 0;
function prevSet(set) {
	mbm.countSet = set;
	mbm.nextSetId = mbm.currentSet - 1;
	$('nextGal').style.display = 'block';
	if(mbm.nextSetId < 1) $('prevGal').style.display = 'none';
	else $('prevGal').style.display = 'block';
	
	$$('.set'+mbm.currentSet).each(function(item) {item.style.display = 'none';});
	$$('.set'+mbm.nextSetId).each(function(item) {item.style.display = 'block';});
	
	mbm.currentSet = mbm.nextSetId;	
}

function nextSet(set) {
	mbm.countSet = set;
	mbm.nextSetId = mbm.currentSet + 1;
	$('prevGal').style.display = 'block';
	if(mbm.nextSetId > mbm.countSet-1) $('nextGal').style.display = 'none';
	else $('nextGal').style.display = 'block';
	
	$$('.set'+mbm.currentSet).each(function(item) {item.style.display = 'none';});
	$$('.set'+mbm.nextSetId).each(function(item) {item.style.display = 'block';});
	
	mbm.currentSet = mbm.nextSetId;	
}

// toplayer on main page
Event.observe(window, 'load', function() { 
	$('topLayer').style.display = "block";
	$('topLayer').onclick = function() {
		$('topLayer').fade();
	};
});

$jq(document).ready(function() {

	$jq("#markiWrap").carouFredSel({
		width: 400,
		direction: "down",
		infinite: true,
		circular: true,
		items: {
			visible: 1
		},
		scroll: {
			items: 1,
			fx			: "scroll",
			duration		: 500,
			pauseOnHover: true
		},
		auto : {
			pauseDuration	: 4000,
			play: true
		}
	});

});

