/*$(window).load(function () {
	initIntro();
})*/

function initNivo(o) {
$("#slider").nivoSlider({
				effect: "sliceDown",
				slices: 15,
				boxCols: 8,
				boxRows: 4,
				animSpeed: 500,
				pauseTime: 6000,
				startSlide: 0,
				directionNav: false,
				directionNavHide: true,
				controlNav: true,
				controlNavThumbs: false,
				controlNavThumbsFromRel: true,
				keyboardNav: true,
				pauseOnHover: false,
				manualAdvance: false,
				onChange: function(t) {
					
					$('#slider-title').stop().animate({left: '+=30px', opacity: 0}, 350, function () {
						$('#slider-title').attr('href', $('#slider .slide').eq(t).attr('href')).css({'left': '-30px', 'opacity': 0, 'background-image': 'url(/static/label/medium/210/26/18/ffffff/ea9113/0/0/'+$('#slider .slide').eq(t).attr('title')+')'}).stop().animate({left: '0px', opacity: 1})
					})
				},
				afterChange: function() {
					
				},
				afterLoad: function() {
					$('.nivo-controlNav a').hover(function () { $(this).addClass('hover') }, function () { $(this).removeClass('hover') })
					var a = $('<a>', {'id': 'slider-catalog','href': o.catalog_href}).appendTo('#intro')
					$('<img>', {src: o.cat}).appendTo(a)

					var el = $('#slider .slide').eq(0);
					var title = el.attr('title')

					if (typeof(title) == 'undefined') { title = ''; }
					
					$('<a>', {
						'id': 'slider-title',
						//'html': $('#slider .slide').eq(0).attr('title'),
						'href': title
						})
						.css({'left': '-30px', 'opacity': 0, 'background-image': 'url(/static/label/medium/210/26/18/ffffff/ea9113/0/0/'+title+')'})
						.appendTo('#intro')
						.stop()
						.animate({left: '0px', opacity: 1})
				}
			});
}

function initIntro() {
	if ($('#intro.flash-update').size() == 0) { return false; }

	$('#intro').empty()
	$('<div>', {'id': 'slider'}).appendTo('#intro')
	
	var o = {
		xml: '/autopromo/flash?l='+CONST_LANGUAGE['locale']+'&s='+CONST_LANGUAGE['symbol'],
		mLoading: _T['Trwa ładowanie...'],
		mWait: _T['proszę czekać'],
		cat: _T['/static/images/katalog.png'],
		//catalog_href: CONST_APP_URL+'katalog'
		catalog_href: '/public/Katalogi%20i%20Ulotki/KATALOG_PRODUKTOW_AKTUALNY_2012.pdf'
	}
	

	$('<div>', {'class': 'mask'}).appendTo('#intro')
	$.ajax({
		url: o.xml,
		success: function (result) {
			var toLoad = $('img', result).size();
			$('img', result).each(function () {
				var link = $('<a>', {'class': 'slide', 'href': $(this).attr('href'), 'title': $(this).attr('title')}).appendTo('#slider')
				$('<img>', {'src': $(this).attr('src')}).hide().load(function () {
					toLoad--;
					if (toLoad <= 0) {
						initNivo(o)
					}
				}).appendTo(link)
			})
			
			
		}
	})
	
}

