$(document).ready(function() {
	
	$('.link').click(function() {
		//pobiera index z rodzica linka
//		var parentInd = $(this).parent().attr('id').toString().substr(1);
		var parentInd = $(this).parent().attr('id');
		//pobiera index z id obrazka
		var ind = $(this).attr('id').toString().split('_');
		ind = ind[1];
		//szerokosc okna zeby oblicyc pozycje galerii
		var windwidth = $('body').width();
		//klonujemy galerie (ukryta jest na poczatku) zeby pozniej wyswietlic na lightboxie
		var clone = $('.ad-gallery#ad_gallery_'+parentInd).clone();
		
		var size = _getPageSize_();
		var scroll_ = _getPageScroll_();
		
		//overlay lighboxa
		var wrapper = $('<div class="galeria_wrapper"></div>');
		var docHeight = document.documentElement.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight; 
		wrapper.css('height', docHeight);
		//to co sie dzieje po kliknieciu na szarym
		wrapper.click(function() {
			clone.remove();
			wrapper2.remove();
			$(this).remove();
		});
		//lightbox
		var wrapper2 = $('<div class="wrapper2"></div>');
		
		//ustawienie pozycji
		var left = (windwidth/2 - 365)+'px';
		$('body').append(wrapper).append(wrapper2);
		wrapper2.css({
			left: left,
			top: scroll_[1] + (size[3] / 30)
		});
		//dodanie galerii do lightboxa
		wrapper2.append(clone);
		//wczesniej klon nie byl widoczny, tutaj juz jest
		clone.css({
			display: 'block'
		});
		
		//tutaj ustawiasz opcje galerii te co masz tam na stronie
		clone.adGallery({
			start_at_index: ind,
			loader_image: 'jquery.ad-gallery.1.2.4/loader.gif'
		});
	});
	
	
	$('a.lightbox').lightBox();
	
	
	
	$('img#lin_wyb_miast').click(function() {
	
			 $('div#miasta').slideDown('slow');
		
		});

	$('img#close').click(function() {
	
			 $('div#miasta').slideUp('slow');
		
		});


	$(function() {
	
	 $(".produkty_oferta_1").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		  visible: 1	
			
    });
	
    $(".produkty_oferta").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		  visible: 3	
			
    });
	 
	
    $(".produkty_oferta_glowna").jCarouselLite({
        btnNext: ".nextg",
        btnPrev: ".prevg"
    });
	 
	});

	
});

//pobiera rozmiary okna, wyciagniete z lightboxa
function _getPageSize_(){
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    }
    else 
        if (document.body.scrollHeight > document.body.offsetHeight) {
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        }
        else {
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
    var windowWidth, windowHeight;
    if (self.innerHeight) {
        if (document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        }
        else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    }
    else 
        if (document.documentElement && document.documentElement.clientHeight) {
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        }
        else 
            if (document.body) {
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
            }
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    }
    else {
        pageHeight = yScroll;
    }
    if (xScroll < windowWidth) {
        pageWidth = xScroll;
    }
    else {
        pageWidth = windowWidth;
    }
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
    return arrayPageSize;
};
//kolejna funkcja wyciagnieta z lightboxa
function _getPageScroll_(){
    var xScroll, yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    }
    else 
        if (document.documentElement && document.documentElement.scrollTop) {
            yScroll = document.documentElement.scrollTop;
            xScroll = document.documentElement.scrollLeft;
        }
        else 
            if (document.body) {
                yScroll = document.body.scrollTop;
                xScroll = document.body.scrollLeft;
            }
    arrayPageScroll = new Array(xScroll, yScroll);
    return arrayPageScroll;
};

function googleMap(x,y,s) {
	var latlng = new google.maps.LatLng(x,y);
	var myOptions = {
	  zoom: 14,
	  center: latlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("MapaHere"), myOptions);
	var marker = new google.maps.Marker({
        position: latlng, 
        map: map,
        title: s
    });
}
