// JavaScript Document
function pokaz_baner_wysw(obj,sc){

if(obj.value!=""){
	var swf=obj.find(":selected").text().indexOf(".swf");
	
	if(sc==""){
		var width_i=200;
		var width_s=260;	
	}else {
		var width_i=260;	
		var width_s=340;	
	}
	
	if(swf==-1){
		var baner="<img src='"+sc+"banery"+obj.find(":selected").text()+"' style='width:"+width_i+"px; height:auto; max-height:' />";
	}else {
		var baner=flash(width_s,"auto",sc+"banery"+obj.find(":selected").text());
	}
}else {
	var baner="";	
}

$('#baner').html(baner);
	
}

function baner_animate(){
	var ile=$(".baner_intro").length;
	var speed=1000*2;
	
	setInterval(function(){
		var act=$("img[active=1]").index();
		if((act+1)<=(ile-1)){
			$(".baner_intro:eq("+act+")").css({"z-index" : "1"}).fadeOut(speed).attr('active',0);
			$(".baner_intro:eq("+(act+1)+")").css({"z-index" : "10"}).fadeIn(speed).attr('active',1);
		}else{
			$(".baner_intro:eq("+act+")").css({"z-index" : "1"}).fadeOut(speed).attr('active',0);
			$(".baner_intro:eq(0)").css({"z-index" : "10"}).fadeIn(speed).attr('active',1);
		}
	},1000*6);	
}

function baner_import(jezyk,strona,polozenie){
	$.ajax({
		url: 'panel/a/aBaneryIntro.php', //wzgledna sciezka do skryptu php
		type: 'POST', //metoda POST/GET
		dataType: 'json', //typ transferu xml/json/javascript/html
		data: {
			'jezyk' : jezyk,
			'strona' : strona,
			'polozenie' : polozenie
			
		}, //dane wysylane do skryptu
		async: false,
		//error: function(){}, //co ma sie dziac jak wystapi blad
		success: function(data){ //funkcja odpowiedzialna za odpowiedz skryptu
			var ile_banerow=data.length;
			if(ile_banerow>0){
				zamien_baner(data[0].sciezka,0);
				
				
				$('#ui-slider').slider({
					'step' : 1,
					'max' : ile_banerow-1,
					'min' : 0,
					'animate' : true,
					'slide' : function(event,ui){
						index=ui.value;
						zamien_baner(data[index].sciezka,index);
					},
					'change': function(event,ui){
						index=ui.value;
						zamien_baner(data[index].sciezka,index);
					}
					
				});
				
				var slider_width=$('#slider_center').width()-56;
				var slide_w=slider_width/ile_banerow;
							
				$('#ui-slider').css('width',slider_width);
				$('#ui-slider a').css('width',slide_w.toFixed(1)+'px');
				$('#ui-slider a').removeClass('ui-state-default')
				.removeClass('ui-corner-all');

				$('#ui-slider a').mouseover(function(){$(this).removeClass('ui-state-hover').removeClass('ui-state-focus');});
				$('#ui-slider a').click(function(){$(this).removeClass('ui-state-hover').removeClass('ui-state-focus');});

			}
		}
		
	})
	
}

function przesun_slider(krok){
	var index=$('#ui-slider').slider('value');
	var s_max=$('#ui-slider').slider('option','max');
	
	//console.log(index,s_max);
	if(s_max>1){
		if(index+krok>s_max){
			$('#ui-slider').slider('value',0);
		}else if(index+krok<0){
			$('#ui-slider').slider('value',s_max);
		}else{
			$('#ui-slider').slider('value',index+krok);
		}
	}
	
}


function zamien_baner(baner,index){
	var old_img=$('#baner').find('img');
	
	old_img.animate({
		opacity : 0
		},1000,function(){
			old_img.remove();
		}
	);
	
	var img=$(document.createElement('img'));
	img.attr('src','banery'+baner);
	
	if(navigator.appName=="Microsoft Internet Explorer" && (gup('p')==20 || gup('p')==33)){
		var el_width=parseFloat($('#baner').parent().width())-3;
	}else{
		var el_width=$('#baner').parent().width();
	}
	img.css({
		'opacity' : 0,
		'position' : 'absolute',
		'display' : 'block',
		'top' : 0,
		'left' : 0,
		'z-index' : 10+parseInt(index),
		'width' : el_width,
		'height': "auto",
		'max-height' : $('#baner').parent().height(),
		'margin' : 'auto'
			
	});
	
	setTimeout(function(){
		$('#baner').prepend(img);
		img.animate({opacity: 1},1300);
	},200);
	
}


function pokaz_pause(){
	var div = $('#pause')
	.attr('active','true');
	
	div.animate({
		'opacity' : 0.8
		
	},200)
}


