

$(function(){

Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
	//set defaults
	settings = jQuery.extend({
		scope: 'body',
		reverse: false
	}, settings);
	
	var pxVal = (this == '') ? 0 : parseFloat(this);
	var scopeVal;
	var getWindowWidth = function(){
		var de = document.documentElement;
		return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};	
	
	/* When a percentage-based font-size is set on the body, IE returns that percent of the window width as the font-size. 
		For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size. 	
		When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size) 
		to get an accurate em value. */
				
	if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
		var calcFontSize = function(){		
			return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
		};
		scopeVal = calcFontSize();
	}
	else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };
			
	var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
	return result;
};


$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};

/*
 var h1 = $("#tresc").outerHeight({'margin': true});
 var h2 = $("#promocje").outerHeight({'margin': true});
 var wys = Math.max(h1, h2);

$("#tresc, #promocje").css('min-height', wys+"px");
$("#promocje").css('min-height', wys+15+"px");
*/
$('#content').equalHeights();
var a = $("#promocje").height();
//$("#promocje").height(a+15+"px");

//mouseover
$("#tresc, #promocje").bind('click', function(){


   /*
    var h1 = $("#tresc").outerHeight(true);
    var h2 = $("#promocje").outerHeight(true);
    var wys = Math.max(h1, h2);
    $("#tresc, #promocje").css('max-height', wys+"px");
    $("#promocje").css('height', wys+15+"px");
    */ 
    
    /*
    var dzieci = $("#tresc").children();
    var height = 0;
    $.each(dzieci, function(i, obj){
        height += $(obj).outerHeight({'margin': true});
    });
    var dzieci2 = $("#promocje").children();
    var height2 = 0;
    $.each(dzieci2, function(i, obj){
        height2 += $(obj).outerHeight({'margin': true});
    });
   
    var h = Math.max(height, height2);
    $("#tresc").css('min-height',h+"px");
    $("#promocje").css('min-height', h+15+"px");
   */
   
    $('#content').equalHeights();
    var a = $("#promocje").height();
    

    //$("#promocje").height(a+15+"px");
    return;
});


if(!jQuery.browser.msie)
{

   // Kod opowiedzialny za podświetlanie tekst po najechaniu na link
   var color =  $("#menu #glMenu li .menu").css("color");
   var newColor = "#f2f2f2";
   $("#menu #glMenu li a.menu").hover(
       function () {
           $(this).animate( {
               'color' : newColor
           }, 600);
           $("#menu #glMenu li ul").slideUp(800);
       },
       function () {
           $(this).animate( {
               'color' : color
           }, 800);
       }
       );
   // Koniec kodu odpowiedzialnego za zmiane koloru tekstu po najechaniu na hiperłącze!

//    $("#menu ul li").mouseover(function() {
//        $(this).find('ul:first').show();
//    });
//
//    $("#menu ul li").mouseleave(function() {
//        $("#menu ul li ul").hide();
//    });
//
//    $("#menu ul li ul").mouseleave(function() {
//        $("#menu ul li ul").hide();
//    });

}

     $("#menu #glMenu li").click(function() {
         $(this).find("ul:first").slideToggle(800);
     });

     $("#menu #glMenu li ul").mouseleave(function() {
         $(this).slideUp(800);
     });


 


});
