$(document).ready(function () {
	
	$('ul#topMenu li')
		.mouseover(function(){
			if(!$(this).hasClass('chosen')) {
				
				$(this).find('a').stop().animate({color:"#fffa6e"}, {duration:200});
			}
		})
		.mouseout(function(){
			if(!$(this).hasClass('chosen')) {
				$(this).find('a').stop().animate({color:"#fcfcfc"}, {duration:200});
			}			
		});
		
	$('div#upperLeft a,div.promocjeBigBanner a,div.promocjeSmallBanner a')
		.mouseover(function(){
			var rel=$(this).find('img').attr('rel');
			$(this).find('img').attr('rel',$(this).find('img').attr('src'));
			$(this).find('img').attr('src',rel);
		})
		.mouseout(function(){
			var rel=$(this).find('img').attr('rel');
			$(this).find('img').attr('rel',$(this).find('img').attr('src'));
			$(this).find('img').attr('src',rel);
		});		
			
		
	$('div#upperRightLink')
		.mouseover(function(){
			$(this).css({backgroundImage: "url('./images/upperRightLinkHover.jpg')"});
		})
		.mouseout(function(){
			$(this).css({backgroundImage: "url('./images/upperRightLink.jpg')"});
		});		
				
		
	$('div.moreLink')
		.mouseover(function(){
			$(this).css({backgroundImage: "url('./images/upperRightLinkHover.jpg')"});
		})
		.mouseout(function(){
			$(this).css({backgroundImage: "url('./images/upperRightLink.jpg')"});
		});		
		
	$('div.moreLink2')
		.mouseover(function(){
			$(this).css({backgroundImage: "url('./images/upperRightLinkHover.jpg')"});
		})
		.mouseout(function(){
			$(this).css({backgroundImage: "url('./images/upperRightLink.jpg')"});
		});				
	
	$('div.bodyLowerNewsItem h2').each(function(index) {
		var fontS=20;
		while($(this)[0].offsetHeight>44) {
			fontS--;
			$(this).css({fontSize: fontS+"px", lineHeight: (fontS+2)+"px"});
		}
		
		//alert($(this)[0].offsetHeight);
	});
	
	$('img#wyslijWiadomosc')
		.mouseover(function(){
			$(this).attr('src','./images/btn_wyslijWiadomosc_2.jpg');
		})
		.mouseout(function(){
			$(this).attr('src','./images/btn_wyslijWiadomosc_1.jpg');
		});			
	
	$('div.pagination img.wstecz')
		.mouseover(function(){
			if(!$(this).hasClass('szary'))
				$(this).attr('src','./images/btn_wstecz_2.jpg');
		})
		.mouseout(function(){
			if(!$(this).hasClass('szary'))
				$(this).attr('src','./images/btn_wstecz_1.jpg');
		});		
		
	$('div.pagination img.dalej')
		.mouseover(function(){
			if(!$(this).hasClass('szary'))
				$(this).attr('src','./images/btn_dalej_2.jpg');
		})
		.mouseout(function(){
			if(!$(this).hasClass('szary'))
				$(this).attr('src','./images/btn_dalej_1.jpg');
		});		
	
	$('div.cennik img')
		.mouseover(function(){
			
				$(this).attr('src','./images/btn_cennik_2.jpg');
		})
		.mouseout(function(){
			
				$(this).attr('src','./images/btn_cennik_1.jpg');
		});			
	
	$('div#footerRightRight img')
		.mouseover(function(){
			$(this).attr('src','./images/btn_wyslij_2.jpg');
		})
		.mouseout(function(){
			$(this).attr('src','./images/btn_wyslij_1.jpg');
		});		
		
	$('table#kontaktTable input')
		.focus(function(){
			if($(this).val()=='...') {
				$(this).val('');
			}
		})
		.blur(function() {
			if($(this).val()=='') {
				$(this).val('...');
			}
		});
		
		
	$('table#kontaktTable textarea')
		.focus(function(){
			if($(this).val()=='treść wiadomości...') {
				$(this).val('');
			}
		})
		.blur(function() {
			if($(this).val()=='') {
				$(this).val('treść wiadomości...');
			}
		});		
		
	$('ul.asortymentListaLi1 li')
		.click(function(){			
	
			
				
				var rel=$(this).attr('rel');
				//style="width: 40px; background-position: 30px 3px;"
		
				$('div.asortymentListaDiv2').each(function(index) {
					if($(this).attr('rel')==rel) {
						$(this).find('a').css({color: "#e1280f"});
						$(this).slideToggle('fast');
					} else {
						$(this).find('a').css({color: "#434343"});
						$(this).slideUp('fast');
					}
				});
  			
			return false;
		})			
	
	$('div.asortymentCategory div.moreLink2')
		.click(function(){
			if($(this).find('a').html()=='rozwiń') {
				
				//style="width: 40px; background-position: 30px 3px;"
				if($(this).find('div.asortymentLista')) {
					$(this).find('a').html('zwiń');
					$(this).css({width: "40px", backgroundPosition: "30px 7px"});
					$(this).parent().find('div.asortymentLista').slideDown('fast');
				}
			} else {
				
				if($(this).find('div.asortymentLista')) {
					$(this).find('a').html('rozwiń');
					$(this).css({width: "50px", backgroundPosition: "40px 7px"});
					$(this).parent().find('div.asortymentLista').slideUp('fast');
				}			
			}
		})	
		
	var fixHelper = function(e, ui) {
		ui.children().each(function() {
			$(this).width($(this).width());
		});
		return ui;
	};
		
		
	$( "#newsySortable tbody" ).sortable({
		helper: fixHelper,
		revert: true,
		opacity: 0.5, 
		update: function() {
			serial = $('#newsySortable tbody').sortable('serialize');
			
			$.ajax({
			url: "ajax.gateway.php?req=sortujNewsy",
			type: "post",
			data: serial,
			error: function(){
					alert("theres an error with AJAX");
				}
			});
		}
	});
	$( "#newsySortable tbody" ).disableSelection();		

	$( "#maleZamowieniaId" ).sortable({
		//helper: fixHelper,
		revert: true,
		opacity: 0.5, 
		update: function() {
			serial = $('#maleZamowieniaId').sortable('serialize');
			$.ajax({
			url: "ajax.gateway.php?req=sortujMaleZamowienia",
			type: "post",
			data: serial,
			error: function(){
					alert("theres an error with AJAX");
				}
			});
		}
	});
	//$( "#maleZamowieniaId" ).disableSelection();		
	
	$( "#duzeZamowieniaId" ).sortable({
		//helper: fixHelper,
		revert: true,
		opacity: 0.5, 
		update: function() {
			serial = $('#duzeZamowieniaId').sortable('serialize');
			
			$.ajax({
			url: "ajax.gateway.php?req=sortujDuzeZamowienia",
			type: "post",
			data: serial,
			error: function(){
					alert("theres an error with AJAX");
				}
			});
		}
	});
	//$( "#duzeZamowieniaId" ).disableSelection();			
	
	$( "#asortymentId tbody" ).sortable({
		helper: fixHelper,
		revert: true,
		opacity: 0.5, 
		update: function() {
			serial = $('#asortymentId tbody').sortable('serialize');
		
			$.ajax({
			url: "ajax.gateway.php?req=sortujAsortyment",
			type: "post",
			data: serial,
			error: function(){
					alert("theres an error with AJAX");
				}
			});
		}
	});
	$( "#asortymentId tbody" ).disableSelection();		
	
		

});

function goto(target) {
	document.location.href=target;
	return false;
}

   function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("googleMap"));
		map.removeMapType(G_HYBRID_MAP);
		map.removeMapType(G_SATELLITE_MAP);
        map.setCenter(new GLatLng(52.855838264608686, 17.759538888931274), 13);

		var marker0 = new GMarker(new GPoint(17.759538888931274,52.855838264608686,1));
		GEvent.addListener(marker0, "click", function() {
		marker0.openInfoWindowHtml("<span style='font-family: tahoma;font-size: 12px;'><b>Hurtownia Nabiałowo-Spożywcza Daro</b><br />ul. Klemensa Janickiego 52<br />88-400 Żnin</span>");		
		});
	
		map.addOverlay(marker0);

		
		var customUI = map.getDefaultUI();
        // Remove MapType.G_HYBRID_MAP
		
       // customUI.maptypes.hybrid = false;
		//customUI.maptypes.satellite = false;
		//customUI.maptypes.physical = false;
        map.setUI(customUI);

      }
    }
	
	
/*
Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

// This file is not required by CKEditor and may be safely ignored.
// It is just a helper file that displays a red message about browser compatibility
// at the top of the samples (if incompatible browser is detected).

if ( window.CKEDITOR )
{
	(function()
	{
		var showCompatibilityMsg = function()
		{
			var env = CKEDITOR.env;

			var html = '<p><strong>Your browser is not compatible with CKEditor.</strong>';

			var browsers =
			{
				gecko : 'Firefox 2.0',
				ie : 'Internet Explorer 6.0',
				opera : 'Opera 9.5',
				webkit : 'Safari 3.0'
			};

			var alsoBrowsers = '';

			for ( var key in env )
			{
				if ( browsers[ key ] )
				{
					if ( env[key] )
						html += ' CKEditor is compatible with ' + browsers[ key ] + ' or higher.';
					else
						alsoBrowsers += browsers[ key ] + '+, ';
				}
			}

			alsoBrowsers = alsoBrowsers.replace( /\+,([^,]+), $/, '+ and $1' );

			html += ' It is also compatible with ' + alsoBrowsers + '.';

			html += '</p><p>With non compatible browsers, you should still be able to see and edit the contents (HTML) in a plain text field.</p>';

			var alertsEl = document.getElementById( 'alerts' );
			alertsEl && ( alertsEl.innerHTML = html );
		};

		var onload = function()
		{
			// Show a friendly compatibility message as soon as the page is loaded,
			// for those browsers that are not compatible with CKEditor.
			if ( !CKEDITOR.env.isCompatible )
				showCompatibilityMsg();
		};

		// Register the onload listener.
		if ( window.addEventListener )
			window.addEventListener( 'load', onload, false );
		else if ( window.attachEvent )
			window.attachEvent( 'onload', onload );
	})();
}
	


