

function scrollNagrody(where){
	$('html,body').animate({
		scrollTop: $("#"+where).offset().top-50
	}, 2000);
}



//******************************************************************************************************************
// wyrownanie w pionie
//******************************************************************************************************************

(function ($) {

$.fn.vAlign = function() {
	return this.each(function(i){
		var ah = $(this).height();
		var ph = $(this).parent().height();
		var mh = Math.ceil((ph-ah) / 2);
		$(this).css('margin-top', mh);
	});
};
})(jQuery);


$(document).ready(function(){  
	
	
	// skracanie
	$('[class~="shorter"]').each(function() {
		
		var text = $(this).text();
		
		var pThis = $(this);
		$(this).css('overflow','hidden');
		$(this).css('visibility','hidden');
		
		$(this).html('<span>'+text+'</span>');
		
		$(this).children().each(function(id,box) {
			
			$(box).css('overflow','none');
			
			//alert($(box).innerHeight()+' > '+pThis.css('height'));
			
			var breakpoint = -2;
			while($(box).innerHeight() > pThis.innerHeight()) {
				
				breakpoint = text.lastIndexOf(" ");
				if (breakpoint == -1) break;
				
				//alert($(box).innerHeight()+' > '+pThis.innerHeight()+': '+text+' BK:'+breakpoint);
				
				text = text.substring(0,breakpoint);
				$(box).html(text+'...');
			}
			
			if (breakpoint == -2) {
				pThis.html(text);
			}
			
			//alert($(box).innerWidth()+'x'+$(box).innerHeight());
			
		});
		
		$(this).css('visibility','visible');
	});
	
	// wyrownanie w pionie
	$(".valign").vAlign();
	
	
	/////////////////////////////////
	// hover linkow
	$("[class*=link]").hover(function() {
			$(this).attr('class',$(this).attr('class')+'_hover');
		}, function() {
			$(this).attr('class',$(this).attr('class').replace('_hover',''));
		}
	);
	
});




//******************************************************************************************************************
// menu rozwijane
//******************************************************************************************************************

$(document).ready(function(){  
  
	$("ul.rollsubnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)  
  
	$("ul.rollnav li span").click(function() { //When trigger is clicked...  
  
		//Following events are applied to the subnav itself (moving subnav up and down)  
		$(this).parent().find("ul.rollsubnav").slideDown('fast').show(); //Drop down the subnav on click  
		
		$(this).parent().hover(function() {  
		}, function(){  
			$(this).parent().find("ul.rollsubnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up  
		});  
		
		//Following events are applied to the trigger (Hover events for the trigger)  
		}).hover(function() {  
			$(this).addClass("subhover"); //On hover over, add class "subhover"  
		}, function(){  //On Hover Out  
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"  
	});
}); 



//******************************************************************************************************************
// box
//******************************************************************************************************************

function BoxKliknij(id) {
	
	var ajax = makeAJAX('box'+id);
	ajax.open("GET","/box.php?id="+id+"&akcja=kliknij",false);
	ajax.send(null);
	
	if (ajax.responseText != '') {
		location.href = ajax.responseText;
	}
}


//******************************************************************************************************************
// box dzialy
//******************************************************************************************************************


function BoxAnimuj(ul,btn,text_pokaz,text_ukryj) {
	
	if (document.getElementById(ul).style.display == 'none') { btn.innerHTML = text_ukryj; }
	else { btn.innerHTML = text_pokaz; }
	
	$("#"+ul).slideToggle('slow');
}


//******************************************************************************************************************
// box rotacyjny
//******************************************************************************************************************


var BoxRotacyjny_animuj = false;
var BoxRotacyjny_kroki = [];

function BoxRotacyjny(cecha,pozycje,interwal) {
	
	if (typeof(BoxRotacyjny_kroki[cecha]) == "undefined") {
		BoxRotacyjny_kroki[cecha] = 0;
	}
	
	if (BoxRotacyjny_animuj) {
		BoxRotacyjny_zmien(cecha,pozycje);
	}
	
	setTimeout("BoxRotacyjny('"+cecha+"','"+pozycje+"',"+interwal+")",interwal);
}

function BoxRotacyjny_zmien(cecha,pozycje) {
	
	if (pozycje == '') return false;
	
	var box = document.getElementById('BoxRotacyjnyPozycja_'+cecha);
	
	var tabela = pozycje.split(',');

	if (BoxRotacyjny_kroki[cecha] >= tabela.length) { BoxRotacyjny_kroki[cecha] = 0; }
	
	
	$.ajax({
		url: "/box_rotacyjny.php?pozycja="+tabela[BoxRotacyjny_kroki[cecha]]+"&ajax=1",
		success: function(data) {
			$("#"+box.id).fadeOut(100, function() {
				$("#"+box.id).html(data);
				$(this).fadeIn(3000);
			});
			BoxRotacyjny_kroki[cecha]++;
		}
	});
	
	return true;
}


function BoxRotacyjny_start() { 

	BoxRotacyjny_animuj = true; 
	
	var btn_start = document.getElementById('BoxRotacyjnyNav_start');
	var btn_stop = document.getElementById('BoxRotacyjnyNav_stop');
	
	btn_start.style.display = "none";
	btn_stop.style.display = "block";
}

function BoxRotacyjny_stop() { 

	BoxRotacyjny_animuj = false; 
	
	var btn_start = document.getElementById('BoxRotacyjnyNav_start');
	var btn_stop = document.getElementById('BoxRotacyjnyNav_stop');
	
	btn_start.style.display = "block";
	btn_stop.style.display = "none";
}


//******************************************************************************************************************
// ustalanie liczby sztuk ksiazek dodawanych do koszyka
//******************************************************************************************************************

function koszyk_sztuk(id,ile) {
	
	if (!ile.match("^[0-9]+$")) { ile = '1'; }
	
	$("#koszyk_input_"+id).attr('value',ile);
	
	$("#koszyk_radio2_"+id).attr('checked',((ile=='2') ? true : false));
	$("#koszyk_radio3_"+id).attr('checked',((ile=='3') ? true : false));
	
}




//******************************************************************************************************************
// checkboxy w koszyku
//******************************************************************************************************************

function getElementsByClassName(oElm, strTag, strClass) {
var arrElements = (strTag == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTag);
var arrReturnElements = new Array();
strClass = strClass.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClass + "(\\s|$)");
var oElement;
for (var i=0; i<arrElements.length; i++) {
oElement = arrElements[i];
if(oRegExp.test(oElement.className)) {
arrReturnElements.push(oElement);
}
}
return (arrReturnElements);
}


function zaznacz( strClass) {
var set=false;
elmnts = getElementsByClassName(document, "input", strClass);
for(var i=0; i<elmnts.length; i++) {
elmnts[i].checked=true;
}
}
function odznacz( strClass) {
var set=false;
elmnts = getElementsByClassName(document, "input", strClass);
for(var i=0; i<elmnts.length; i++) {
elmnts[i].checked=false;
}
}

