function offerquest()
{
	var id = $(this).attr('id');
	var prod = $(this).attr('prod');
	var o = $('<div id="questbox" />').appendTo('body');
	var b = $('<div id="questback" />').appendTo('body');
	var w = o.outerWidth();
	var h = o.outerHeight();
	
	var ol = $(this).offset().left - $(document).scrollLeft();
	var ot = $(this).offset().top - $(document).scrollTop();
	var ww = $(window).width();
	var wh = $(window).height();

	o.css({position:'fixed',top:ot,left:ol,width:0,height:0,zIndex:300}).animate({top:(wh - h)/2,left: (ww - w) /2, width: w, height: h},function () {
			var d = $('<h1>Pytanie o '+prod+'</h1><form>\
					<label for="nazwisko">Imie i nazwisko (firma)</label>\
						<input type="text" name="nazwisko" id="nazwisko" class="input" />\
						<br style="clear: both;" />\
					<label for="email">E-mail</label>\
						<input type="text" name="email" id="email" class="input" />\
					<br style="clear: both;" />\
					<label for="tresc">Pytanie</label>\
						<textarea name="tresc" id="tresc" class="textarea" ></textarea>\
					<br style="clear: both;" />\
					<a href="javascript:;" id="close">zamknij</a>\
					<a href="javascript:;" id="send">wyślij</a>\
					</form>').appendTo('#questbox').hide().fadeIn();
			$('#questback,#questbox #close').click(offerboxclose);
	});
	b.css({position:'fixed',top:0,left:0,width:ww,height:wh,zIndex:299,opacity:0,cursor: 'pointer'}).animate({opacity:0.7});

}

function offerboxclose(e)
{
	e.preventDefault();
	$('#questbox,#questback').animate({opacity:0},function () { $(this).remove(); });
}

function sitebodycont() {
	var o = $('#sitebodycont');
	var t = o.offset().top;
	var dh = $(document).height();
	var mfh = $('#mainfoot').outerHeight();
	var oh = o.outerHeight()-o.height();
	var aim = (dh-t-oh-mfh > 0) ? dh-t-oh-mfh : 0;
	o.height(aim);
	
	$('.offerquest').click(offerquest);
}

$(window).load(sitebodycont);

function gallery(arr) {
	$('<div id="galleryBack" />').appendTo('body').css({width: $(window).width(),height: $(window).height(), opacity: 0}).click(galleryClose).animate({opacity: 0.7},300);
	$('<div id="gallery"><div id="galleryStripe" /><a href="javascript:galleryClose();" id="galleryClose">zamknij</a></div>').appendTo('body').css({width: $(window).width(), height: $(window).height(), top: $(window).scrollTop(), left: $(window).scrollLeft()});
	$('#galleryStripe').height($(window).height()).css({opacity:0.8}).hide().fadeIn();
	$(window).scroll(galleryMove).resize(galleryMove);
	galleryMove();
	galleryImage(arr[0]);
	for (i in arr)
		$('<a href="javascript:galleryImage('+arr[i]+');"><img src="/g,'+arr[i]+',120,120.jpg" /></a>').appendTo('#galleryStripe');
	var i = 2;
	while ($('#galleryStripe')[0].scrollHeight > $('#galleryStripe').height() && i <= 3)
	{
		$('#galleryStripe').css({ width: 150*i});
		i++;
	}
}

function galleryMove() {
	$('#galleryBack').css({width: $(window).width(), height: $(window).height(), top: $(window).scrollTop(), left: $(window).scrollLeft()});
	$('#gallery').css({width: $(window).width(), height: $(window).height(), top: $(window).scrollTop(), left: $(window).scrollLeft()});
	$('#galleryStripe').height($(window).height());
		var w = $('#galleryMainImage').width();
		var h = $('#galleryMainImage').height();
	$('#galleryMainImage').css({top: ($(window).height() - h)/2, left: ($(window).width() - w + $('#galleryStripe').outerWidth() + 20) / 2});
	if ($('#galleryMainImage').width() > $(window).width() - $('#galleryStripe').outerWidth() - 20)
		$('#galleryMainImage').width($(window).width() - $('#galleryStripe').outerWidth() - 20);
	$('#galleryStripe').css({ width: 150});
	var i = 2;
	while ($('#galleryStripe')[0].scrollHeight > $('#galleryStripe').height() && i <= 3)
	{
		$('#galleryStripe').css({ width: 150*i});
		i++;
	}
}

function galleryImage(n) {
	$('#galleryMainImage').remove();
	$('<img src="/g,'+n+'.jpg" id="galleryMainImage">').appendTo('#gallery').hide().load(function () {
		var w = $(this).width();
		var h = $(this).height();
		$(this).fadeIn().css({top: ($(window).height() - h)/2, left: ($(window).width() - w + $('#galleryStripe').outerWidth() + 20) / 2});
		if ($('#galleryMainImage').width() > $(window).width() - $('#galleryStripe').outerWidth() - 20)
			$('#galleryMainImage').width($(window).width() - $('#galleryStripe').outerWidth() - 20);
	});
	
}

function galleryClose() {
	$(window).unbind();
	$('#gallery,#galleryBack').fadeOut(function () { $(this).remove(); });
}
///

var imgzoom = {
	init : function () {
		$('a.screenzoom').fancybox();
		
	}}
