function flash(id, url, w, h) {
	$('#player'+id).flash(url, {
		version: '8.0.24',
		params: {
			allowfullscreen: true
		},
		attr: {
			width: w+'px',
			height: h+'px'
		}
	});
};

function introleave() {
	$('#naglosnienie, #scena').stop();
	$("#technika").css({"background": "url(/images/i_menu.png)"});
	$("#naglosnienie").animate({'top': '0px'}, 400);
	$("#scena").animate({'top': '0px'}, 400);
};
function intro(){
	$("#technika").css({"background": "url(/images/i_menu.png)"});
	$("#naglosnienie").css({"margin-top": "160px"});
	$("#scena").css({"margin-top": "160px"});
	$("#technika, #naglosnienie, #scena").mouseenter(function(){
		$('#naglosnienie, #scena').stop();
		$("#technika").css({"background": "url(/images/i_menu.png) -480px -320px"});
		//$("#technika:hover").css({"background": "url(/images/i_menu.png) -160px -160px"});
		if ($(this).attr('id') == 'technika') {
			$(this).css({"background": "url(/images/i_menu.png) -160px -160px"});
		} else {
			$('#technika').css({"background": "url(/images/i_menu.png) -480px -320px"});
		}
		$("#naglosnienie").animate({'top': '-160px'}, 400);
		$("#scena").animate({'top': '160px'}, 400);
	});
	$(".pion").mouseleave(introleave);
};

function minimenu(){
	$('#naglosnienie').css({'top': '40px'});
	$('#scena').css({'top': '40px'});
	$('#technika').css({'background': 'url(/images/minimenu.png) -160px 0px'});
	$('#technika, #naglosnienie, #scena').mouseenter(function(){
		$('#technika, #naglosnienie, #scena').stop();
		$('#technika').css({'background': 'url(/images/minimenu.png) -160px -40px'});
		//$('#technika:hover').css({'background': 'url(/images/minimenu.png) -160px -120px'});
		if ($(this).attr('id') == 'technika') {
			$(this).css({'background': 'url(/images/minimenu.png) -160px -120px'});
		} else {
			$('#technika').css({'background': 'url(/images/minimenu.png) -160px -40px'});
		}
		$("#naglosnienie").animate({'top': '0px'}, 400);
		$("#scena").animate({'top': '80px'}, 400);
	});
	$(".pion").mouseleave(function(){
		$('#technika, #naglosnienie, #scena').stop();
		$("#technika").css({"background": "url(/images/minimenu.png) -160px 0px"});
		$("#naglosnienie").animate({'top': '40px'}, 400);
		$("#scena").animate({'top': '40px'}, 400);
	});
};

function pageWidth(){
	return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;
}

function miernik(element){
	return document.getElementById(element).offsetHeight
}

function zaslona(zaslaniany, zaslaniajacy){
	var wielkosc = miernik(zaslaniany);
	$(zaslaniajacy).css({'height': wielkosc});
}

var myriad = {
	src: '/images/myriad.swf'
};
sIFR.activate(myriad);
sIFR.replace(myriad, {
	selector: '.baner h2',
	wmode: 'transparent',
	css: '.sIFR-root { font-size: 50px; color: #ffffff; }'
});
sIFR.replace(myriad, {
	selector: '.baner h3',
	wmode: 'transparent',
	css: '.sIFR-root { font-size: 30px; color: #aeaeae; }'
});

var timeoutbaner = 5000;
var obecnybaner;
var docelowybaner;
var jedziebaner = false;
var timebaner;
$.fn.wlaczbaner = function() {
	var plik = $('span:last', this).text();
	if (plik != '') {
		$('span:last', this).html('');
		$(this).css({'background': '#000000 url('+plik+') no-repeat'});
	}
};
$.fn.nastepnybaner = function(callback) {
	jedziebaner = true;
	$(this).animate({'left': '-600px'}, 1000, function() {
		$('li', this).eq(0).insertAfter($('li', this).eq($('li', this).length - 1));
		$(this).css({'left': '0px'});
		$('.baner .kolejka li').eq(1).wlaczbaner();
		obecnybaner = $('.baner .kolejka li:first').attr('id');
		$('.guziki li').each(function(){
			if($(this).text() == obecnybaner) {
				$(this).css({'background': '#ffffff'})
				$(this).fadeTo('normal', 1);
			} else {
				$(this).css({'background': '#cdcdcd'})
				$(this).fadeTo('normal', 0.6);
			}
		});
		jedziebaner = false;
		if ($.isFunction(callback)) {
			callback();
		}
		clearTimeout(timebaner);
		timebaner = setTimeout('czasowkabaner()', timeoutbaner);
	});
};
$.fn.ustawbaner = function(baner) {
	if (obecnybaner != baner) {
		docelowybaner = baner;
		$(this).nastepnybaner(function() {
			$('.baner .kolejka').ustawbaner(docelowybaner);
		});
	}
};
$.fn.guzikbaner = function() {
	return $(this).each(function() {
		$(this).click(function() {
			docelowybaner = $(this).text();
			if (!jedziebaner) {
				$('.baner .kolejka').ustawbaner(docelowybaner);
			}
		});
	});
}
function czasowkabaner() {
	if (!jedziebaner) {
		$('.baner .kolejka').nastepnybaner();
	}
}

$.okno = function() {
	//window.scroll(0,0);
	$('.okno_wraper').fadeOut('fast');
	//$('body').css({'overflow': 'hidden'});
	$('#zaslona').show();
	$('#zaslona, .tekst').fadeTo('fast', 0.01, function(){
		$('#zaslona').css({'background': '#000000'});
		$('#zaslona').fadeTo('fast', 0.7, function(){
			$('.okno_wraper').fadeIn('fast', function(){
				sIFR.replace(myriad, {
					selector: 'h3',
					wmode: 'transparent',
					css: '.sIFR-root { font-size: 40px; color: #ffffff; }'
				});
				$('#mapa', this).googleMaps({
					latitude: 50.01774,
					longitude: 21.985308,
					depth: 15,
					markers: {
						latitude: 50.01774,
						longitude: 21.985308
					}
				});
				$('.tekst').fadeTo('fast', 1);
			});
		});
	});
	$('.off').click(function(){
		$('.tekst').fadeTo('fast', 0.1, function(){
			$('.okno_wraper').fadeOut('fast', function(){
				$('#zaslona').fadeTo('fast', 0.01, function(){
					$('#zaslona').hide();
					//$('body').css({'overflow': 'visible'});
				});
			});
		});
	});
};

function okn() {
	zaslona('miernik', '#zaslona');
	$.okno();
}

$.fn.przelaczanie = function() {
	return $(this).each(function() {
		if ($(this).attr('target') != '_blank' && !$(this).is('.lightbox')) {
			$(this).click(function() {
				$('#content').load($(this).attr('href')+' #content > *', function() {
					var cont2 = $('#content').html();
					if (cont2 != '') {
						$('.okno .tekst').html(cont2);
						$('.okno .tekst').scrollTop(0);
						$('#content').html('');
					}
					sIFR.replace(myriad, {
						selector: 'h3',
						wmode: 'transparent',
						css: '.sIFR-root { font-size: 40px; color: #ffffff; }'
					});
					$('.lightbox').lightBox();
					$('.okno .main a').przelaczanie();
				});
				return false;
			});
		}
	});
}
