$(document).ready(function() {
	$("p a.show-text").toggle(
		function () {
			$(this).text("UKRYJ");
			$(this).parent().next().slideDown("slow");			
		},
		function () {
			$(this).text("NASZA STRUKTURA ORGANIZACYJNA");
			$(this).parent().next().slideUp("slow");
		}
	);
	
	$( ".bg-strip" ).css({ 'opacity': 0.8 });
	
	$("h3 a.show-text").toggle(
		function () { $(this).parent().next().slideDown("slow") },
		function () { $(this).parent().next().slideUp("slow") }
	);
	
	$("li a.show-text").toggle(
		function () { $(this).parent().next().slideDown("slow") },
		function () { $(this).parent().next().slideUp("slow") }
	);
		

	   
	$('#gallerymain li, #gallery li').hover(
		function(){ $(".cover", this).stop().animate({bottom:'0px'},{queue:false,duration:300}) }, 
		function() { $(".cover", this).stop().animate({bottom:'-60px'},{queue:false,duration:300}) }
	);
	
	$( "#bg-strip" ).css({ 'opacity': '80%' });

	/*
	$( "#navmenu" ).accordion({
		autoheight: false,
		header:		'.title',
		active: 	'.selected'
	});
	*/
	   
	$('#gallery a, .gallery a, a.lightbox').lightBox({
		imageLoading:		'/media/images/lightbox-ico-loading.gif',		
		imageBtnPrev:		'/media/images/lightbox-btn-prev.gif',			
		imageBtnNext:		'/media/images/lightbox-btn-next.gif',			
		imageBtnClose:		'/media/images/lightbox-btn-close.gif',		
		imageBlank:			'/media/images/lightbox-blank.gif'	
	});
  
	
	$("#link")
		.click( function() { $("#more").toggle(); })
		.toggle(	
				function() { $(this).text('schowaj'); }, 
				function() { $(this).text("więcej"); }
		);

});

var MyUI = {

	start: function() { this.maps.start() },

	maps: {
		start: function() { MyUI.maps.render() },
		map: undefined,	  		
		positions: {},
		
		descriptions: {	        
		    kazun:     '<h6>Autivox</h6>'
		                + '<p>05-152 Czosnów k.Warszawy,</p>'
		                + '<p>Kazuń Nowy 19a </p>'		   
		   	           
		},
		
		render: function() {
	        
		    this.positions.kazun	= new google.maps.LatLng(52.410162, 20.694187);
		           
		    this.map = new google.maps.Map(document.getElementById("map_canvas"), {
		        scaleControl:           false,
		        zoom:                   15,
		        center:                 this.positions.kazun,
		        mapTypeId:              google.maps.MapTypeId.ROADMAP,
		        streetViewControl:      false,
		        mapTypeControlOptions:  {
		            mapTypeIds: [
		                google.maps.MapTypeId.ROADMAP,
		                google.maps.MapTypeId.HYBRID
		            ]
		        }
		    });
		               
		    this.goToPositionButton(
		        MyUI.maps.positions.kazun,
		        'Autivox - Kazuń Nowy',
		        'Pokaż adres siedziby Autivox w Kazuniu Nowym',
		        MyUI.maps.setHomeKazun
		    );		          
		   		               
		    this.addMarkers(
		        MyUI.maps.positions.kazun,
		        this.descriptions.kazun,
		        'Autivox'
		    );		   
		           
		},
		
		addMarkers: function(position, text, title) {

		    if (!text) return false;
		           
		    var marker = new google.maps.Marker({
		        map:        this.map,
		        position:   position || this.map.getCenter(),
		        title:      title || 'punkt docelowy'
		    });
		    		    		               
		    var infowindow = new google.maps.InfoWindow();
		        infowindow.setContent(text);
		        
		               
		    google.maps.event.addListener(marker, 'click', function() {
		        infowindow.open(this.map, marker);
		    });		           
		},
		
		goToPositionButton: function(position, text, title, callback) {
	        
		    var controlDiv = document.createElement('DIV');
		        controlDiv.style.margin = '2px 5px';

		    var controlUI = document.createElement('DIV');
		        controlUI.style.backgroundColor = 'white';
		        controlUI.style.borderStyle = 'solid';
		        controlUI.style.borderWidth = '1px';
		        controlUI.style.borderColor = 'gray';
		        controlUI.style.cursor = 'pointer';
		        controlUI.style.width = '120px';
		        controlUI.style.textAlign = 'center';
		        controlUI.style.padding = '2px 8px';
		        controlUI.title = title || 'Wyświetl pierwotny adres';
		               
		    controlDiv.appendChild(controlUI);
		   
		    var controlText = document.createElement('DIV');
		        controlText.style.fontFamily = 'Arial,sans-serif';
		        controlText.style.fontSize = '12px';
		        controlText.style.paddingLeft = '4px';
		        controlText.style.paddingRight = '4px';
		        controlText.innerHTML = text;
		        controlUI.appendChild(controlText);
		   
		    google.maps.event.addDomListener(controlUI, 'click', function() {		               
		        MyUI.maps.map.setCenter(position);		                       
		        if (callback) callback();		                   
		    });
		               
		    controlDiv.index = 1;
		    this.map.controls[google.maps.ControlPosition.RIGHT].push(controlDiv);
		           
		},
		
		setHomeKazun: function() { MyUI.maps.map.setZoom(15) }
	}
}


