/**************************************************************************************************	zasada-rowery.pl**************************************************************************************************//*************************************************	Init*************************************************/window.addEvent('domready', function() {	// Distributors page map.	/*	if ($('distributors-google-map')) {		createDistributorsGoogleMap('distributors-google-map');	}	*/		// Distributors dropdowns	if ($$('ul.county-list').length) {		manageDistributorsDropdowns();	}	// Contact page map.	if ($('contact-google-map')) {		parentId = $('contact-google-map').getParent().get('id');		createContactGoogleMap(parentId);	}	// Scrolls	if ($('simple-container-scroll')) {		simpleSlider();	}	// Popups	checkPopups();	// External links	externalLinks();});/***************************************************************************************************	Slider	***************************************************************************************************/function simpleSlider() {	containerElement = $('simple-container-scroll');	containerElementHeight = containerElement.getSize().y;	containerElementFullHeight = containerElement.getScrollSize().y;	// Is slider needed?	if (containerElementFullHeight <= containerElementHeight) {		return;	}	containerElement.setStyle('overflow', 'hidden');		// Create slider elements	simpleSliderContainer = new Element('div', {		'class': 'simple-slider-container'	});	simpleSliderKnob = new Element('div', {		'class': 'simple-slider-knob'	});	simpleSliderArrowUp = new Element('a', {		'href':'',		'class': 'simple-slider-arrow-up',		'events': {			'click':function(e) {				e.stop();				currentSliderStep = mySlider.step;				mySlider.set(currentSliderStep - 100);				mySlider.fireEvent('onChange()');			}		}	});	simpleSliderArrowDown = new Element('a', {		'href':'',		'class': 'simple-slider-arrow-down', 		'events': {			'click':function(e) {				e.stop();				currentSliderStep = mySlider.step;				mySlider.set(currentSliderStep + 100);				mySlider.fireEvent('onChange()');			}		}	});	// Add slider elements	simpleSliderContainer.inject(containerElement);	simpleSliderKnob.inject(containerElement);	simpleSliderArrowUp.inject(containerElement);	simpleSliderArrowDown.inject(containerElement);	// Calculate knob step	st = containerElementFullHeight - containerElementHeight;	// Init slider	var mySlider = new Slider(simpleSliderContainer, simpleSliderKnob, {		offset:0,		wheel: true,		snap: true,		mode: 'vertical',		initialStep: 0,		steps:st,		onTick: function(pos){			this.knob.setStyle(this.property, pos);		},		onChange:function(step) {			containerElement.scrollTo(0, step);		},		onComplete: function(step){		}	});}/***************************************************************************************************	Distributors dropdowns	***************************************************************************************************/function manageDistributorsDropdowns() {	countySwitch = $$('a.county-switch');	countyList = $$('ul.county-list')[0];	countyDefaultSwitchText = 'Wybierz województwo';	countyCurrentSwitchText = countySwitch[0].get('text');	citySwitch = $$('a.city-switch');	cityList = $$('ul.city-list')[0];	cityDefaultSwitchText = 'Wybierz miasto';	cityCurrentSwitchText = citySwitch[0].get('text');	countySwitch.each(function(el, i) {		el.addEvent('click', function(e) {			e.stop();			if (countyList.getStyle('display') == 'none') {				countySwitch[0].set('html', countyDefaultSwitchText);				countyList.setStyle('display', 'block');				cityList.setStyle('display', 'none');			} else {				countySwitch[0].set('html', countyCurrentSwitchText);				countyList.setStyle('display', 'none');			}		});	});	citySwitch.each(function(el, i) {		el.addEvent('click', function(e) {			e.stop();			if (cityList.getStyle('display') == 'none') {				citySwitch[0].set('html', cityDefaultSwitchText);				cityList.setStyle('display', 'block');				countyList.setStyle('display', 'none');			} else {				citySwitch[0].set('html', cityCurrentSwitchText);				cityList.setStyle('display', 'none');			}		});	});}/***************************************************************************************************	Google Maps	***************************************************************************************************//*************************************************	Contact page*************************************************/function createContactGoogleMap(mapContainerId){	if (GBrowserIsCompatible()) {		var map = new GMap2(document.getElementById(mapContainerId));		map.addControl(new GLargeMapControl3D());		map.addControl(new GScaleControl());        map.addControl(new GMapTypeControl());		map.setMapType(G_NORMAL_MAP);			map.setCenter(new GLatLng(51.2293546, 18.582148), 14);		}	var zasadaIcon = new GIcon();	zasadaIcon.image = "img/gmap_icon_zasada.png";	zasadaIcon.shadow = "img/gmap_icon_zasada_shadow.png";	zasadaIcon.iconSize = new GSize(791, 236);	zasadaIcon.shadowSize = new GSize(791, 236);	zasadaIcon.iconAnchor = new GPoint(206,219);	markerOptions = { icon:zasadaIcon };	var point = new GPoint(18.582148, 51.2263546);	map.addOverlay(new GMarker(point, markerOptions));}/*************************************************	Create distributors map*************************************************/function createDistributorsGoogleMap(mapContainerId) {	if (GBrowserIsCompatible()) {		// Create map		map = new GMap2(document.getElementById(mapContainerId));		map.addControl(new GLargeMapControl3D());		map.addControl(new GScaleControl());		map.addControl(new GOverviewMapControl(new GSize(160,100)));        map.addControl(new GMapTypeControl());		map.setMapType(G_NORMAL_MAP);			map.setCenter(new GLatLng(52.2263546, 19.082148), 6);		// Add points		markerPoints = [];		markerTexts = [];		distributorsLinks = $$('div.header a[href]');		distributorsLinks.each(function(el, i) {			locationString = el.toString();			locationString = locationString.split(',');			distributorId = locationString[0].split('(');			var distributorId = distributorId[1];			var pointLat = locationString[1].substring(0, 100);			var pointLng = locationString[2].substring(0, locationString[2].length - 2);			point = new GPoint(pointLng, pointLat);			markerPoints[distributorId] = new GMarker(point);			map.addOverlay(markerPoints[distributorId]);			text1 = $('distributor-' + distributorId + '-info-1').get('html');			text1 = '<b style="font-weight:bold">' + text1 + '</b>';			text2 = $('distributor-' + distributorId + '-info-2').get('html');			text2 += '<br />';			text3 = $('distributor-' + distributorId + '-info-3').get('html');			text = '<div style="padding:13px 25px;">' + text1 + text2 + text3 + '</div>';			markerTexts[distributorId] = text;			GEvent.addListener(markerPoints[distributorId], "click", function() {				markerPoints[distributorId].openInfoWindowHtml(markerTexts[distributorId]);			});		});	}}/*************************************************	Move marker to a new location*************************************************/function moveToLocation(distributorId, lat, lng) {	mainDiv = $('main');	if (mainDiv.getStyle('display') == 'none') {		mainDiv.setStyle('display', 'block');		createDistributorsGoogleMap('distributors-google-map');	}	// Prepare scroll	var scroll = new Fx.Scroll(window, {		wait: false,		duration: 250,		transition: Fx.Transitions.Quad.easeInOut	});	// Set new center point, move marker there and open infoWindow	pointLocation = new GLatLng(lat, lng);	map.setCenter(pointLocation, 12);	markerPoints[distributorId].openInfoWindow(markerTexts[distributorId]);	// Scroll to top and open marker window	scroll.toElement(document.body);}/***************************************************************************************************	Popup window	***************************************************************************************************/function checkPopups() {	if (!$$('a[rel=popup]').length) {		return;	}	$$('a[rel=popup]').each(function(el) {		el.addEvents({			'click':function(e) {				e.stop();				href = el.get('href');				openPopup(href, 800, 600);			}		});	});}/*************************************************	Popup*************************************************/function openPopup(filename, w ,h) {	win = null;	aw = window.screen ? screen.availWidth : 800;	ah = window.screen ? screen.availHeight : 600;	opt="width="+w+",height="+h+",left="	+(aw-w)/2+",top="	+(ah-h)/2	+",toolbar=no,location=no,directories=no,"	+"status=no,menubar=no,"	+"scrollbars=yes,resizable=no";	win=window.open(filename, '' , opt);}/***************************************************************************************************	External links	***************************************************************************************************/function externalLinks() {	$$('a[rel=external]').each(function(el) {		el.set('target', '_blank');	});}
