
$(document).ready(function($){
startup();
});

function startup() {
	// if ($.browser.msie) {
		// $("#panel_logowania").delay(800).css("position","relative");
	// } else {
		// $("#panel_logowania").css("position","relative");
	// }
	if ($('.mod_catalogfilter').length) {
		$('.mod_catalogfilter .filter_field_product_category h3').remove();
	}
	var heightCon = $('.content').height();
	if (heightCon < 670) {
		$('.content').css({'height': 670 + 'px'});
	}
	if ($('#map').length) {
		$("#map").gMap({ markers: [{ latitude: 50.02703495221942,
						  longitude: 19.934756755828857,
						  html: "<strong>Action Energy Sp z o.o.</strong>, <br />Adres siedziby:<br />ul. Zakopiańska 9<br />30-418 Kraków",
						  popup: true }],
				  zoom: 15 });
	}
	
	if ($('#f2').length){
		//console.log($('tr.row_27 td.col_0, tr.row_28 td.col_0, tr.row_29 td.col_0'));
		$('input#opt_29_0').live("click",function() {
			if ($(this).attr('checked') == true) {
				$('#f2 table .row_8, #f2 table .row_9, #f2 table .row_10, #f2 table .row_11').show();
			} else {
				$('#f2 table .row_8, #f2 table .row_9, #f2 table .row_10, #f2 table .row_11').hide();
			}
		});
		$('input#opt_30_0').live("click",function() {
			if ($(this).attr('checked') == true) {
				$('#f2 table .row_13, #f2 table .row_14, #f2 table .row_15, #f2 table .row_16').show();
			} else {
				$('#f2 table .row_13, #f2 table .row_14, #f2 table .row_15, #f2 table .row_16').hide();
			}
		});
		$('.row_24 .col_1 div span:last').append($('.row_25 input'));
		$('tr.row_27 td.col_0, tr.row_28 td.col_0, tr.row_29 td.col_0').remove();
		$('tr.row_27 td.col_1, tr.row_28 td.col_1, tr.row_29 td.col_1').attr('colspan',2);
		
		$('label#lbl_26_0').html('Akceptuję <a href="regulamin" rel="#overlay" style="text-decoration:none">Regulamin</a>');
		
		if ($('#f2').length){
			$("#overlay").appendTo("body");
			$("#lbl_26_0 a[rel]").overlay({
										// one configuration property
										//color: '#fff',
										// another property
										//top: 50
										effect: 'apple'
									});
		}
		
	}
	if ($('#f3').length){
		//$('input#ctrl_50, input#ctrl_51, input#ctrl_53').attr('readonly', 'readonly');
		var lato = $('tr.row_16 td.col_1').html();
		//console.log(lato);
		var calyRok = 'Przyjmuje się, że średnia dzienna ilość godzin słonecznych<br>w okresie zimowym wynosi ok. 0,5 godziny';
		$('#ctrl_145 input').change(function() {
			if ($("#ctrl_145 input[type='radio']:checked").val() == 'wiosna-lato') {
				$('tr.row_16 td.col_1').html(lato);
				fotowoltaika();
			} else {
				$('tr.row_16 td.col_1').html(calyRok);
				fotowoltaika();
			}
		});
		$('#ctrl_46,#ctrl_47,#ctrl_48').change(function() {
			fotowoltaika();
		});
	}
	if ($('#f4').length){
		//console.log($('label[for=ctrl_98]').next());
		$('#ctrl_117 span input.radio').each(function(){
			$(this).parent().addClass($(this).attr('id'));
		});
		$('#ctrl_90').appendTo('#ctrl_89');
		$('#ctrl_98,#ctrl_99,#ctrl_101,#ctrl_102,#ctrl_104,#ctrl_106,#ctrl_108,#ctrl_110').addClass('short');
		$('label[for=ctrl_58],label[for=ctrl_59],label[for=ctrl_60],label[for=ctrl_61],label[for=ctrl_62],label[for=ctrl_63],label[for=ctrl_64],label[for=ctrl_65],label[for=ctrl_66],label[for=ctrl_75],label[for=ctrl_76],label[for=ctrl_77],label[for=ctrl_78],label[for=ctrl_91],label[for=ctrl_92]').addClass('labeq');
		$('label[for=ctrl_98]').insertAfter($('label[for=ctrl_98]').next());
		$('label[for=ctrl_99]').insertAfter($('label[for=ctrl_99]').next());
		$('label[for=ctrl_104]').insertAfter($('label[for=ctrl_104]').next());
		$('label[for=ctrl_106]').insertAfter($('label[for=ctrl_106]').next());
		$('label[for=ctrl_108]').insertAfter($('label[for=ctrl_108]').next());
		$('label[for=ctrl_110]').insertAfter($('label[for=ctrl_110]').next());
		$('#ctrl_89,#ctrl_82').next('br').remove();
	}
	if ($('#tlhp').length){
		var api = $("#tlhp").overlay({oneInstance: false, api: true}); 
		api.load();
	}
	if ($('html.newsy').length){
		//console.log($("h3:contains('Fotowoltaika')").next().find('.list_container'));
		$('ul.kolek-prog-dob').appendTo($("h3:contains('Kolektory')").next().find('.list_container'));
		$('ul.foto-prog-dob').appendTo($("h3:contains('Fotowoltaika')").next().find('.list_container'));
		accord();
	}
}
function fotowoltaika() {
	var a = $('#ctrl_46').val();
	var b = $('#ctrl_47').val();
	var c = $('#ctrl_48').val();
	var bc = Math.round(b*c);
	if ($("#ctrl_145 input[type='radio']:checked").val() == 'wiosna-lato') {
		$('input#ctrl_50').val(bc);
		var d = $('#ctrl_50').val();
		$('input#ctrl_51').val(Math.round((4*d)/a));
		var f = Math.round(d/3);
		$('input#ctrl_53').val(Math.round(f,2));
	} else {
		$('input#ctrl_50').val(bc);
		var d = $('#ctrl_50').val();
		$('input#ctrl_51').val(Math.round((8*d)/a));
		var f = Math.round(d/0.56);
		$('input#ctrl_53').val(Math.round(f,2));
	}
}
// akordeon w bocznym menu
function accord() {
$(".mod_catalogfilter h3").click(function (event) {
		//console.log($('.left'));
		//event.preventDefault();
		//$(this).parent();
		$(this).parent().siblings('div.mod_catalogfilter').children('div.filter_group').slideUp();
		//$(this).next().toggleClass('open');
		$(this).next().slideToggle("slow");
	});
};
Math.round = (function() {
  var oldRound = Math.round;
  return function(number, precision) {
    precision = Math.abs(parseInt(precision)) || 0;
    var coefficient = Math.pow(10, precision);
    return oldRound(number*coefficient)/coefficient;
  };
})();
