$(document).ready(function(){
	
	if($('#carousel').length){
		$('#carousel').jcarousel({
			scroll: 1,
			auto: 10,
			wrap: 'both',
			buttonNextHTML: null,
			buttonPrevHTML: null,
			initCallback: carousel_initCallback,
			itemLoadCallback: carousel_itemLoadCallback
		});
	}
	
	$('#login form').submit(function(e){
		var field = $(this).find('input[name=email]');
		if($.trim(field.val()) == ''){
			alert('Wpisz swój e-mail i hasło podane podczas rejestracji.\nJeśli jesteś nowym klientem, zarejestruj się najpierw.');
			e.preventDefault();
			field.focus();
		}
	});
	
	$('input[name=quantity]').focus(function(){
		$(this).select();
		$(this).attr('autocomplete', 'off');
	});
	
	$('img.hover').bind({
		mouseover:function(){
			var tmp = $(this).attr('src').substr(-6,6);
			if(tmp != '_a.jpg'){
				$(this).attr('src', $(this).attr('src').replace('.jpg','_a.jpg'));
			}
		},
		mouseout:function(){
			$(this).attr('src', $(this).attr('src').replace('_a.jpg', '.jpg'));
		}
	});
	
	$('a').bind('focus',function(){
		$(this).blur();
	});
	
	$('input[type=submit]').css('cursor', 'pointer');
	
});

$(window).load(function(){
	
	if($('#fb_widget').length){
		$('#fb_widget').mouseenter(function(){
			$(this).animate({right:'0'},{queue:false,duration:300});
		});
		$('#fb_widget').mouseleave(function(){
			$(this).animate({right:'-292px'},{queue:false,duration:500});
		});
	}
	
});

var carousel_initCallback = function(carousel){
	$('.jcarousel-control a').css('cursor', 'pointer');
	$('.jcarousel-control a').click(function(){
		var txt = $(this).text();
		if(txt == '<'){
			carousel.prev();
		} else if(txt == '>'){
			carousel.next();
		} else {
			carousel.scroll($.jcarousel.intval(txt));
		}
		return false;
	});
}
var carousel_itemLoadCallback = function(carousel, state){
	$('#carousel-control a').removeClass('act');
	$('#carousel-control a').eq(carousel.first).addClass('act');
}

function show_pic(path, w, h) {
	if(window.winny) winny.close();
	l=(window.screen.width-w)/4; t=(window.screen.height-h)/4;
	winny=window.open('', 'pic', 'width='+w+', height='+h+', left='+l+', top='+t+', scrollbars=no');
	winny.document.write('<html><head><title>[::]</title></head><body style="background-color:black; margin:0px"><a href="javascript:window.close()"><img src="'+path+'" width="'+w+'" height="'+h+'" border="0"></a></body></html>');
	winny.focus();
}
function tr_mouse_over(where, flag) {
	if(flag==1) {
		memClass=where.className;
		where.className="tr_bkg0";
	} else {
		where.className=memClass;
	}
}

