$(function(){
	preload = new Array();
	preload[0] = 'static/images/menu-stronaglowna-hover.gif';
	preload[1] = 'static/images/menu-ofirmie-hover.gif';
	preload[2] = 'static/images/menu-oferta-hover.gif';
	preload[3] = 'static/images/menu-portfolio-hover.gif';
	preload[4] = 'static/images/menu-kontakt-hover.gif';
	preload[5] = 'static/images/h-mysliszo.gif';
	preload[6] = 'static/images/h-twojwybor.gif';
	preload[7] = 'static/images/h-naszamisja.gif';
	preload[8] = 'static/images/h-spokojnie.gif';
	preload[9] = 'static/images/h-pozwol.gif';
	preload[10] = 'static/images/h-udowodnimy.gif';
	preload[11] = 'static/images/h-najpierw.gif';
	for( var i=0; i<preload.length; i++ ) {
		var foo = new Image();
		foo.src = preload[i];
	}
	
	$('#js-on').remove();

	$('.about-submenu a').click(function(){
		$('.about-submenu a.active').removeClass('active');
		$(this).addClass('active');
		var tokens = $(this).attr('class').split(' ');
		if( tokens.length == 1 )  page = tokens[0];
		else {
			for( var i=0; i<tokens.length; i++ ) {
				if( tokens[i] != 'active' ) {
					page = tokens[i];
					break;
				}
			}
		}
		var html = $.ajax({
			url: 'static/templates/pages/o-firmie/'+page+'.tpl',
			async: false
		}).responseText;
		html = '<div class=\'subpage\'>'+html+'</div>';
		$('.subpage').slideUp('fast',function(){
			$(this).remove();
			$('.subpage-inner').hide().html(html).slideDown('fast');
		});
		return false;
	});
	
	$('.offermenu a').click(function(){
		$('.offermenu a.active').removeClass('active');
		$(this).addClass('active');
		var title = $(this).attr('title');
		$('.right-big div.block:visible').slideUp('fast',function(){
			$('.right-big div.'+title).slideDown('fast');
		});
		return false;
	});
	
	if( GBrowserIsCompatible() ) {
		if( $('#map_lodz').length > 0 ) {
			var map = new GMap2(document.getElementById('map_lodz'));
			map.setCenter(new GLatLng(37.4419, -122.1419), 13);
			map.setUIToDefault();
			geocoder = new GClientGeocoder();
			geocoder.getLatLng(
				'Łódź, Tadeusza Kościuszki 23/25',
				function(point) {
					map.setCenter(point, 13);
					var marker = new GMarker(point);
					map.addOverlay(marker);
				}
			);
		}
		if( $('#map_lask').length > 0 ) {
			var map2 = new GMap2(document.getElementById('map_lask'));
			map2.setCenter(new GLatLng(37.4419, -122.1419), 13);
			map2.setUIToDefault();
			geocoder2 = new GClientGeocoder();
			geocoder2.getLatLng(
				'Łask, Pułaskiego 3/47',
				function(point2) {
					map2.setCenter(point2, 14);
					var marker = new GMarker(point2);
					map2.addOverlay(marker);
				}
			);
		}
	}
	
	if( $('.lodz_bank').length > 0 ) {
		$('.lodz_bank').change(function(){
			var show = $(this).val();
			$('.accounts_lodz').find('div:visible').hide();
			$('.accounts_lodz').find('div.'+show).show();
		});
	}
	
	$('.contactform').submit(function(){
		var err = '';
		$(this).find('.error').remove();
		if( $(this).find('input[name="name"]').val() == '' ) 
			err += 'Nie podano imienia i nazwiska<br />';
		if( $(this).find('input[name="phone"]').val() == '' ) 
			err += 'Nie podano numeru telefonu<br />';	
		if( $(this).find('input[name="email"]').val() == '' ) 
			err += 'Nie podano adresu e-mail<br />';
		if( $(this).find('textarea[name="content"]').val() == '' ) 
			err += 'Nie podano treści zapytania<br />';
		
		if( err == '' )  return true; 
		else {
			$(this).find('.buttons').before( $('<div class=\'error\'>'+err+'</div>') );
			return false;
		}
	});
}); 
