/* Accordion Maker */
/*******************/
var Accordion = {
	currentToggle : null,
	Load: function () { var blendOut = '<style type="text/css">\n'; blendOut += '#Accordion .slide { display: none; }\n'; blendOut += '#Accordion .toggle { background: url('+ cssPath +'box_Accordian_header-down.gif); cursor:pointer;}\n'; blendOut += '</style>'; document.write(blendOut); },

	Init: function () {
		if( !document.getElementById('Accordion') ) return;
		var aNode = document.getElementById('Accordion');
		var h3_els = aNode.getElementsByTagName('H3');
		for( var i=0; i< h3_els.length; i++) {
			if( h3_els[i].className=='toggle') {
				var h3_el=h3_els[i];
				var hide_el=h3_el.nextSibling;

				while(hide_el.nodeType != 1 && hide_el.tagName != 'DIV' && hide_el.className != 'slide') {
					hide_el=hide_el.nextSibling;
				}

				if(hide_el) {
					hide_el.style.display='none';
					h3_el.getElementsByTagName('SPAN')[0].className = 'close';
					h3_el.togglePanel=hide_el;
					h3_el.onclick= function(){
						Accordion.Toggle(this); return false;
					};
					h3_el.isOpen=false;
					h3_el.id='Accordion_'+i;
					if(h3_el.getAttribute('rel') == 'open') {
						Accordion.Toggle(h3_el);
					}
				}
			}
		}

		//if(document.getElementById('bbMap')) setTimeout("GetECMap()", 1500);
	},
	Toggle: function (node) {
		//alert("toggle");
		/*
		if(this.currentToggle && this.currentToggle.id != node.id){
			this.currentToggle.isOpen=false;
			//this.currentToggle.style.backgroundImage='url('+ cssPath +'/box_Accordian_header-down.gif)';
			this.currentToggle.togglePanel.style.display='none';
		}
		*/

		node.isOpen = !node.isOpen;
		//node.getElementsByTagName('SPAN')[0].style.backgroundImage = (node.isOpen) ? 'url('+ cssPath +'/box_Accordian_header-up.gif)' : 'url('+ cssPath +'/box_Accordian_header-down.gif)';
		if(node.isOpen) {
			node.getElementsByTagName('SPAN')[0].className = 'open';
			node.togglePanel.style.display = 'block';
		} else {
			node.getElementsByTagName('SPAN')[0].className = 'close';
			node.togglePanel.style.display = 'none';
		}

		//if(node.isOpen) this.currentToggle = node;
		//else this.currentToggle = null;
		return false;
	}
};


var bbMap = {
	div: bbMap,
	map: null,
	type: 'GMap',
	cObj: null,

	//keyId: 'ABQIAAAA6CxrjFa-qkfOL0N7RtqSzxTYbvYssaYmgrGs4xxtfrEpL9BzqBQjfkkKQWxlehaXQTqNhRV6xUaN2w',
	keyId: 'ABQIAAAA6CxrjFa-qkfOL0N7RtqSzxRg7Udu05PhOihgDu6AkuetKyTn6BSMEdun6LX3YjSFnB7GZOF0rdbQSA', //bbkult.net

	init: function(type, div) {
		bbMap.type = type;
		bbMap.div = div;
		bbMap.cObj = type == 'GMap' ? bbMap.GMap : bbMap.VEMap;
		document.write('<scr' + 'ipt type="text/javascript" src="'+ bbMap.cObj.init() +'"></src'+ 'ipt>');
	},

	getCity: function(country, city, zip, street, zoom) {
		bbMap.cObj.load();
		//alert(this.type+ ": "+street+", "+zip+" "+city+", "+country);
		if(country.toLowerCase() == 'cz') country = 'Czech Republic';
		if(country.toLowerCase() == 'de') country = 'Germany';
		bbMap.cObj.getCity(street, zip, city, country, zoom, 1);
	},

	load: function () {
		//alert("Load: "+ bbMap.type);
		bbMap.cObj.load();
	},

	GMap: {
		geocoder: null,

		init: function() {
			return "http://maps.google.com/maps?file=api&v=2.x&key="+ bbMap.keyId;
		},
		load: function() {
			if (GBrowserIsCompatible()) {
				bbMap.map = new GMap2(document.getElementById(bbMap.div));
				bbMap.map.setCenter(new GLatLng(49.565681,  12.204274), 7);
				//bbMap.map.setUIToDefault();
				bbMap.map.addControl(new GSmallMapControl());
				bbMap.map.addControl(new GMapTypeControl());
				bbMap.GMap.geocoder = new GClientGeocoder();
			}
		},

		getCity: function(st, zi, ci, co, zoom, call) {
			if(call > 2) return;
			var MapArr = new Array();
			if(st) MapArr.push(st);
			if(zi && ci ) MapArr.push(zi +" "+ ci);
			if(!zi && ci) MapArr.push(ci);
			if(co) MapArr.push(co);

			var MapLoc = MapArr.join(", ");
			//alert(MapLoc);

			if (bbMap.GMap.geocoder) {
				bbMap.GMap.geocoder.getLatLng(
					MapLoc,
					function(point) {
						if (!point) {
							bbMap.cObj.getCity(false, zi, ci, co, zoom, call+=1);
						} else {
							//document.getElementById("linkMap").style.display="block";
							bbMap.map.setCenter(point, zoom);
							var marker = new GMarker(point);
							bbMap.map.addOverlay(marker);
							marker.bindInfoWindowHtml("<b>"+ci+"</b><br/><br/>"+zi+" "+ci+"<br/>"+st);
						}
					}
				);
			}
		}
	},

	VEMap: {
		pinTitle: null,
		pinDesc: null,

		init: function() {
			return "http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&mkt=de-DE";
		},
		load: function() {
			//alert("Load: VEMap");
			bbMap.map = new VEMap(bbMap.div);
			bbMap.map.SetDashboardSize(VEDashboardSize.Small);
			bbMap.map.LoadMap();
		},

		getCity: function (st, zi, ci, co, zoom, call) {
			if(call > 2) return;

			var MapArr = new Array();
			if(st) MapArr.push(st);
			if(zi && ci ) MapArr.push(zi +" "+ ci);
			if(!zi && ci) MapArr.push(ci);
			if(co) MapArr.push(co);

			var MapLoc = MapArr.join(", ");
			//alert(MapLoc);

			bbMap.VEMap.pinTitle = ci;
			bbMap.VEMap.pinDesc = zi +" "+ ci +"<br />"+ st;

			try{
				bbMap.map.Find(null, MapLoc,null,null,0,null,null,null,null,null, bbMap.VEMap.setPin);
			}catch(e) {
				alert(e.message);
				bbMap.map.SetCenterAndZoom(new VELatLong(49.565681,  12.204274), zoom);
			}
		},

		setPin: function(e) {
			var pin = bbMap.map.AddPushpin(bbMap.map.GetCenter());
			pin.SetTitle(bbMap.VEMap.pinTitle);
			pin.SetDescription(bbMap.VEMap.pinDesc);
			bbMap.map.SetZoomLevel(11);

		}
	}
};

var ajax = {
	rpc: '/_includes/ajax.php',
	divH: { event: 0 , address: 0 },
	time: { event: false , address: false },
	getList: function(type, placeId, p1, p2) {
		if( $(type+"Slide") ) {
			$(type+"Slide").update('Loading ...');
			new Ajax.Updater(
				type+'Slide',
				ajax.rpc+'?mod='+type+'List&placeId='+placeId+"&p1="+p1+"&p2="+p2,
				{
					evalScripts: 1,
					method: "get",
					onComplete: ajax.setDivListHeight(type)
				}
			);
		}
		return false;
	},

	getDetail: function(type, placeId, typeId, p1, p2) {
		if( $(type+"Slide") ) {
			$(type+"Slide").update('Loading ...');
			new Ajax.Updater(
				type+'Slide',
				ajax.rpc+'?mod='+type+'Detail&placeId='+placeId+"&p1="+p1+"&p2="+p2+"&"+type+"Id="+typeId,
				{
					evalScripts: 1,
					method: "get",
					onComplete: ajax.setDivDetailHeight(type)
				}
			);
		}
		return false;
	},

	setDivListHeight: function(type) {
		if(!$(type +"ListTables") || !$(type+"ListTables").offsetHeight) {
			ajax.time[type] = window.setTimeout("ajax.setDivListHeight('"+type+"')", 200); return;
		};
		ajax.divH[type] = $(type+"ListTables").offsetHeight;
		$(type+"Slide").style.height = (ajax.divH[type]+10) +"px";
	},

	setDivDetailHeight: function(type) {
		if(!$(type+"Details") || !$(type+"Details").offsetHeight) {
			window.setTimeout("ajax.setDivDetailHeight('"+type+"')", 200); return;
		};
		ajax.divH[type] = 0; $(type+"Slide").style.height = $(type+"Details").offsetHeight +'px';
	}
}