/**
 * 
 * @author: Dariusz Pobożniak, http://pobozniak.pl
 *
 **/

$(function() {
	equalHeight();
	panelSlide();
	$('.lightbox').fancybox();
	googleMap();
	slideMenu();
})

function slideMenu() {
	$('#mainnav ul').css({'display': 'none'});
	$('#mainnav .show').css({'display': 'block'});
	$('#mainnav > li > span').click(function() {
		$(this).next('ul').slideToggle(400);
	})
}

function equalHeight() {
    $('#sidebar').css({'height':''});
    $('#content').css({'height':''});
	$('#sidebar, #content').setEqualHeight();
}

function panelSlide() {
	if ($('#specialbox.toggle ul').hasClass('hide')) {
		$('#specialbox.toggle dt').click(function() {
			//$('#products #sidebar').css({'height':''});
			//$('#products #content').css({'height':''});
			
			$('#close').remove();
			$('#specialbox').append('<span id="close">zamknij</span>');
			$(this).parent().find('ul').slideDown('slow');

			$('#close').click(function() {
				$('#specialbox.toggle ul').slideUp('slow');
				$(this).remove();
			});
			equalHeight();
		}); 
	} 
}

function googleMap() {
    if (GBrowserIsCompatible()) {
        var map = document.getElementById('map');
        if (map) {
            var info = new Array();
			info[0] = '<div style="width:270px; color: #000;"><strong>Przedsiębiorstwo wielobranżowe<br /> FAZI4x4<br /> Aleksander Szandrowski</strong><br />43-220 Tychy <br />ul. Towarowa 11</div>';

			var m = new GMap2(map);
            m.setCenter(new GLatLng(50.10195,19.014374), 14);
            m.addControl(new GLargeMapControl());
       		m.addControl(new GMapTypeControl());
       		m.enableDoubleClickZoom();

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

			var point = new GLatLng(50.10195,19.014374);
			m.addOverlay(createMarker(point, info[0]));
        }
    }
}

jQuery.fn.setEqualHeight=function(o) {
    var maxHeight=0;
    var maxElement=null;
    	jQuery(this).each(function(i) {
      		if((jQuery(this).height()+parseInt(jQuery(this).css("padding-bottom"))+parseInt(jQuery(this).css("padding-top")))>maxHeight) {
    		maxHeight=jQuery(this).height()+parseInt(jQuery(this).css("padding-top"))+parseInt(jQuery(this).css("padding-bottom"));
    		maxElement=this;
    	}
    });
    jQuery(this).not($(maxElement)).each(function() {$(this).height(maxHeight-parseInt(jQuery(this).css("padding-top"))-parseInt(jQuery(this).css("padding-bottom")))})
    //jQuery(this).each(function() {$(this).height(maxHeight-parseInt(jQuery(this).css("padding-top"))-parseInt(jQuery(this).css("padding-bottom")))})
}