//konfiguracja
Config = new Hash ({
	devmode: false, //developer mode - tworzy konsole pod IE
	Flashes: { //flasze do oosadzenia
		banner: { 
			container: 'banner-wrapper',
			swf: '/flash/baner-350x144-dealer.swf',
			required_version: 9, 
			bg_color: '#fff', 
			width: 350, 
			height: 144
		},
		player: {
			container: 'player-wrapper',
			swf: '/flash/player.swf',
			required_version: 9, 
			bg_color: '#3D3D3D', 
			width: 464, 
			height: 265
		},
		logoflash: {
			container: 'logo',
			swf: '/flash/logo.swf',
			required_version: 9, 
			bg_color: '#fff', 
			width: 328, 
			height: 144
		}
	},
	Forms: { //klasy formularzy wylaczonych z walidacji i kolorowania
		noValidateClass: 'noValidate',
		noRecolorClass: 'noRecolor'
	},
	Images: { 
		preload: [ //obrazki do preloadowania
		]
	},
	Tables: { //klasa tabel wylaczonych z kolorowania
		noRecolorClass: 'noRecolor'
	}
})


// ----------- do not edit below this line ---------- //

if (!window.console){
	var console = { log:function(comm){ if (Config.devMode == true && $('consoleDiv')) $('consoleDiv').innerHTML = $('consoleDiv').innerHTML+"<br />\n"+comm;/*alert(comm);*/} }
}

String.implement({ 
	toHash: function(){ 
		var hash = new Hash(); 
		this.split('&').each(function(el){
			var t = el.split('=');
			t[0] = t[0].replace("http://maps.google.com/staticmap?center", 'latlng');
			hash.include(t[0].replace(/amp;/, ''), t[1]);  
		});
		return hash; 
	}
});


window.addEvent("domready", function() {

	var likeHomepageButton = '<div class="facebook-like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FAAT-RenKar-Sp-Z-oo%2F106479972714806&amp;layout=button_count&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:70px; height:35px;" allowTransparency="true"></iframe></div>'
	var likeCurrentPageButton = '<div class="facebook-like"><iframe src="http://www.facebook.com/plugins/like.php?href=' + escape(location.href) + 'layout=button_count&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:250px; height:38px;" allowTransparency="true"></iframe></div>'
	
	// Facebook like button - for page and products
	$('header').set('html',$('header').get('html') + likeHomepageButton);

	$('productitem').getElements('h1').each(function(h1)
	{
		// current page button
		var likeCB = new Element('div');
		likeCB.set('class','facebook-like').set('html')
		likeCB.set('html', '<iframe src="http://www.facebook.com/plugins/like.php?href=' + escape(location.href) + 'layout=button_count&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:250px; height:38px;" allowTransparency="true"></iframe>');
		likeCB.inject($('productitem').getElement('.cartbox'), 'bottom');
		
		//h1.set('html', h1.get('html') + likeCurrentPageButton);
	});
	
	
	//tworzenie #consoleDiv
	if (Browser.Engine.trident && Config.devMode == true) new Element('div',{'id':'consoleDiv'}).setStyles({'position':'absolute','z-index':'13','top':'0','left':'0','background':'#fff','color':'#000'}).inject($('container'), 'before').appendText('consoleDiv');

	// ie bg fix 
	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
	
	//ukrywanie formularzy negocjacji
	$$('form.negotiation').each(function(form, i){
		//wstawianie przycisku do pokazywania
		var container = form.getPrevious('div.cartbox').getPrevious();
		if (container.get('class') == 'top') container = container.getLast();
		var lub = new Element('p', {
			'class': 'lub_negocjuj',
			html: ' &middot; '
		}).inject(container);
		//ukrywanie
		var h = form.getSize().y;
		if (form.getElements('span.error').length == 0) form.setStyle('height', 0);
		form.setStyle('overflow', 'hidden');
		var negocjuj = new Element('span', {
			text: 'Negocjuj cenę',
			events: {
				'click': function() { 
					var myEffect = new Fx.Morph(form);
					if (form.getSize().y == 0) myEffect.start({ 'height': h, 'opacity': 1 });
					else myEffect.start({ 'height': 0, 'opacity': 0 });
				}
			}
		}).inject(lub);
	})
	
	//kolorowanie formularzy
	$('content').getElements('form').each(function(form) {
		if (!form.hasClass(Config.Forms.noRecolorClass)) form.getElements('li:odd').addClass('odd');	
	})
	
	//kolorowanie tabel
	$('content').getElements('table').each(function(table) {
		if (!table.hasClass(Config.Tables.noRecolorClass)) {
			table.getElements('tr:odd').addClass('odd');	
			//table.getElements('tr').getLast().addClass('last');
		}
	})	
	
	//policz rate - nowe okno
	$$('.policz-rate a').each(function(el) {
		el.addEvent('click', function(ev){
			new Event(ev).stop();
			window.open(el.get('href'), 'Policz_raty','width=630,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
		})
	}) 
	
	//seo
	$('seo4').addEvent('click', function(event) {
    	location.href = "http://seo4.net/";
    	new Event(event).stop();
	})
	
}); //koniec ondomready

window.addEvent("load", function() {

	$each(Config.Flashes, function(props, id) { //osadzanie flaszy
		
		if ($(props.container) && Browser.Plugins.Flash.version >= props.required_version) {
			window[id] = new Swiff(props.swf, {
				container: props.container,
				id: id,
				name: id, //pozwala na dzialanie setVariable!
				width: props.width,
				height: props.height,
				params: {
					'bgcolor': props.bg_color,
					'allowFullScreen': true,
					'wmode': 'opaque'
				}
			})
		}
	})
	
	//osadzanie map googla
	var Gmap = $$('img[src^=http://maps.google.com/staticmap]')[0];
	if (Gmap && Gmap.getParent().get('id') == 'Gmap') {
		var src = Gmap.get('src');
		//var Gmap = new Element('div', {'class': 'Gmap'}).replaces(Gmap); //usuwamy static map
		//new Element('div', {'class': 'Gmap'}).wraps(Gmap);
		Gmap = Gmap.getParent();
		
		window.onunload = GUnload; // przy wyjsciu ze strony zwalniamy pamiec 
		if (GBrowserIsCompatible()) {  
			//obrabiamy zrodlo mapy statycznej
			var h = src.toHash();
			console.log(h);
			var size = h.size.split('x');
			var latlng = h.latlng.split(',');
						
			var map = new GMap2(Gmap, { 
				size: new GSize(size[0], size[1]) 
			});  
			map.addControl(new GLargeMapControl());  
			map.addControl(new GMapTypeControl());  
			var point = new GLatLng(latlng[0], latlng[1]);
			map.setCenter(point, h.zoom.toInt(), G_NORMAL_MAP);  
			map.addOverlay(new GMarker(point/*, icon*/));
		}
	}
	
	
}); //koniec onload
