function WysokoscKolumny() {
	lewa = $('#Left').height();
	prawa = $('#Right').height();
	//alert("lewa: "+lewa+" Prawa: "+prawa);
	if (lewa < prawa) {
//									$('#Left div:last-child').height(prawa - 9);
									lewa_lc = $('#Left .textBox:last-child').height();
									roznica = prawa - lewa;
									$('#Left .textBox:last-child').height(lewa_lc + roznica);
	} 
	/*
	else if (lewa > prawa) {
		roznica = lewa - prawa;
		if ($('.rTextBox').height()) $('.rTextBox').height($('.rTextBox').height() + roznica);
		if ($('.rTextBox2').height()) $('.rTextBox2').height($('.rTextBox2').height() + roznica);
	}
	*/
}

function KlikWybor() {
				$('.pole1_link > a').click(function(){
					$(this).prev().click();
				});
				
				$('#pole1_send').click(function(){
					wartosc = $('input[name="v1"]').val() + '|' + $('input[name="v2"]').val();
					$('.pole1_link').each(function(){
						$(this).children('input').each(function(){
							if($('input[name="v2"]').val()=='1')
							{
								if (this.checked == true) wartosc+= '|'+$(this).parent().parent().attr('rel')+'_' + ($(this).val());
							}
							else
							{
								if (this.checked == true) wartosc+= '|' + ($(this).val());
							}
						});
					});
					//alert(wartosc);
					Pole2_write(wartosc);
				});
}

function Pole1_write(d1, d2) {
					$.ajax({
						type: "POST",
						url : "inc/pole1.php",
						data: "v1=" + d1 + "&v2=" + d2,
						success: function(odp){
							$("#pole1").html(odp);
							$("#pole1").parent().css('height', 'auto');
							KlikWybor();
							WysokoscKolumny();
						}
					});
}

function Pole2_write(d1) {
					$.ajax({
						type: "POST",
						url : "inc/pole2.php",
						data: "v1=" + d1,
						success: function(odp){
							$("#pole2").css('display', 'block');
							$("#pole2").html(odp);
							$("#pole2").parent().css('height', 'auto');
//							KlikWybor();
							WysokoscKolumny();
						}
					});
}

function HoverSubMenu2() {
				$('.rSub').children('A').each(function(){
					$(this).hover(function(){
							alert($(this).attr['name']);
							$(this).css('background-position', '-300px, -50px');
						}, function(){
					});
				});
}

function HoverSubMenu() {
					$('.rSubMenu').hover(function(){$(this).css('background-position', '-300px -' + $(this).attr('name') + 'px');},
												function(){$(this).css('background-position', '0px -' + $(this).attr('name') + 'px');}
					);
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getScreenSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ parseInt(myWidth), parseInt(myHeight) ];
}

function getMousePosition(ev) {
	function processEvent(e) { // catches and processes the mousemove event 
		if (isIE) { // for IE
			y = window.event.y+document.body.scrollTop;
			x = window.event.x+document.body.scrollLeft;
		} else { // for Navigator
			y = e.pageY;
			x = e.pageX;
		}
	}
var isIE = false,isNav = false
if (document.all) {
	isIE = true
}
					
	processEvent(ev);
	return [ parseInt(x) , parseInt(y) ];
}


$(document).ready(function(){
				/* LightBox */
				
				$("#All A IMG").parent().not(".NaZewnatrz").lightBox();
				$("#All A IMG").parent().attr("title", "Kliknij z boku zdjęcia aby zobaczyć następne.");
				
				/* -------- */
				Pole1_write(1,0);
//				WysokoscKolumny();

				$('#form1 INPUT').click(function(){
					$("#pole1").html('proszę czekać...');
					$('input[name="typ"]').each(function(){
						if (this.checked == true) typ = $(this).val();
						}
					);
					$('input[name="podzial"]').each(function(){
						if (this.checked == true) podzial = $(this).val();
						}
					);

					Pole1_write(typ, podzial);
					
				});
				
				if ($('#Top') != undefined) {
					var so = new SWFObject("fla/main.swf", "mymovie", "960", "305", "8", "#19396D");
				   so.addParam("wmode", "transparent");
				   so.write("Flash");
				}

				if ($('#pioro1').attr('id') != undefined) {
					var so = new SWFObject("fla/pioro1.swf", "mymovie", "300", "281", "8", "#19396D");
				   so.addParam("wmode", "transparent");
				   so.write("pioro1");
				}
				
				if ($('#pioro2').attr('id') != undefined) {
					var so = new SWFObject("fla/pioro2.swf", "mymovie", "300", "281", "8", "#19396D");
				   so.addParam("wmode", "transparent");
				   so.write("pioro2");
				}
				
				if ($('#pioro3').attr('id') != undefined) {
					var so = new SWFObject("fla/pioro3.swf", "mymovie", "300", "281", "8", "#19396D");
				   so.addParam("wmode", "transparent");
				   so.write("pioro3");
				}
				
/* 				$('#FlagaBox A').click(function(e){
					var poz = getMousePosition(e);
					poz[0] = poz[0] - (parseInt($('#EngInfo').width()) + 10);
					poz[1] = poz[1] - (parseInt($('#EngInfo').height()) + 20);
						$('#EngInfo').css('left', poz[0] + 'px');
						$('#EngInfo').css('top', poz[1] + 'px');
				});
				
				$('#FlagaBox A').hover(function(){
				}, function(){
						$('#EngInfo').css('left', '-2000px');
						$('#EngInfo').css('top', '-2000px');
				}); */
});

if (window.addEventListener) {
	window.addEventListener("load", function(){
//		WysokoscKolumny();
		HoverSubMenu();
		}, false);
}else if (window.attachEvent) {
	window.attachEvent("onload", function(){
//		WysokoscKolumny();
		HoverSubMenu();
		});
}


Cufon.DOM.ready(function() {
	Cufon.replace('.mplc',{
		fontFamily: 'Myriad Pro Light Cond',
		hover: true
	});
});
