var points = new Array();
function initialize() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map-box"));
        map.setCenter(new GLatLng(center_point['lat'], center_point['lng']), scale);
        map.setUIToDefault();
        var mapControl = new GOverviewMapControl();
        map.addControl(mapControl);

        for (var i = 0; i < points.length; i++) {
            var data = points[i];
            var point = new GLatLng(data['lat'], data['lng']);

            map.addOverlay(createMarker(point, map, data['html']));
        }
    }
}

function createMarker(latlng, map, msg) {
    var marker = new GMarker(latlng);
    GEvent.addListener(marker,"click", function() {
        map.openInfoWindowHtml(latlng, msg);
    });
    return marker;
}

$(document).ready(function(){
    //odpalamy mape
    if($('#map-box').length)
        initialize();
	
    //zakładeczki
    $('#tabs a').click(function(){
        $('#tabs').find('a').removeClass('selected');
        $(this).addClass('selected');
        var content_id = $(this).attr('id').split('_', 2)[0];
        $('.tab-content').hide();
        $('#'+content_id).show();
    });
	
	
    //ustawienie wysokości panoramy
    if($('#panorama-box').length){
        
		
		
		var h  = $(window).height()- 20;
		var w  = $(window).width()-17;
                $('#pano').height(h);
                $('#pano').width(w);
				
		var swf = createswf(app_path, "krpanoSWFObject", "100%", "100%");
		swf.addVariable("xml", xml_path);
		swf.embed("pano");	
		
        $(window).resize(function() {
            var h  = $(window).height()- 20;
			var w  = $(window).width()-17;
            $('#pano').height(h);
            $('#pano').width(w);
			$(document).find('#krpanoSWFObject').height(h);
        });
		
		$(document).find('#krpanoSWFObject').height(h);
		
    }
	
    //auto height dokumentu
    var setDocumentHeight = function(){
        var s = $('#banner').height() +
        $('#content').height() +
        $('#footer').height();
				
        var d = $(window).height();
        var c = $('#content').height();

        if(s < d){
            var r = d - s;
            $('#content').height(c+r);
        }
    }
	
    setDocumentHeight();
	
    $(window).resize(function(){
        setDocumentHeight();
    });
	
    //rotator
    var bn_count = $('.rotator-banner').size();
    if(bn_count){
        var active = parseInt($('.act').attr('id').split('-')[1]);
        var set_time = banner_time;
        var set_time2 = banner_time;
        var time_step = banner_time_step;
        var getNext = function(a){
            if(a < bn_count){
                a++;
            }
            else {
                a = 1;
            }
            return a;
        }
        //                var bannerRotate = function(active){
        //                    $('#b-'+active).fadeOut(set_time2,function(){
        //                        $(this).removeClass('act');
        //                    }); //0
        //                    active = getNext(active);
        //                    $('#b-'+active).fadeIn(set_time,function(){ //1
        //                        $('#b-'+active).fadeOut(set_time2); //0
        //                        active = getNext(active);
        //                        $('#b-'+active).fadeIn(set_time,function(){ //1
        //
        //                                bannerRotate(active);
        //                        });
        //                    });
        //                }

        var step1 = function(active){
            $('#b-'+active).fadeOut(set_time2,function(){
                $(this).removeClass('act');
            }); //0
            active = getNext(active);
            $('#b-'+active).fadeIn(set_time,function(){ //1
                setTimeout ( function(){
                    step2(active);
                }, time_step );
            });
        }

        var step2 = function(active){
            $('#b-'+active).fadeOut(set_time2); //0
            active = getNext(active);
            $('#b-'+active).fadeIn(set_time,function(){ //1
                setTimeout ( function(){
                    step1(active);
                }, time_step );
            });
        }

      
        if(bn_count >= 2) step1(active);
            //bannerRotate(active);
    }
});