function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { 
		window.onload = func; 
	} else { 
		window.onload = function() { 
			if (oldonload) { 
				oldonload(); 
			} 
			func(); 
		} 
	} 
}

addLoadEvent(init_webkit);

//var iWebkit;
//if (!iWebkit && typeof(IPHONE) != 'undefined') {	
//if (!iWebkit) {	
//	iWebkit = window.onload = function () {

function init_webkit() {	
	var iWebkit = Array();
//	var iWebkit = function() {
		iWebkit.checkboxHeight = "25";
		iWebkit.radioHeight = "25";
		iWebkit.autolistNumVisible = 10;
	
		function url() {
			var a = document.getElementsByTagName("a");
			for (var i = 0; i < a.length;i++) {
				if (a[i].className.match("noeffect")) {
				}
				else {
					a[i].onclick = function () {
						window.location = this.getAttribute("href");
						return false;
					};
				}
			}
		}
		
		function hideURLbar() {
			window.scrollTo(0, 0.9);
		}
		
	    iWebkit.popup = function () {
	        window.scrollTo(0, 9999);
	        var o_popup = document.getElementById(arguments[0]);
	        var o_frame = o_popup.getElementsByClassName('confirm_screen')[0];
	        o_frame.className = 'confirm_screenopen'; 
	        var b = document.getElementById("cover");
	        b.className = "cover";
			b.style.height = document.height + "px";
        };

        iWebkit.closepopup = function () {
	        var o_parent = arguments[0].toElement;
	        var b_found = false;
	        do {
		        o_parent = o_parent.parentNode;
		        if (o_parent.tagName.toLowerCase() == 'div' && o_parent.className.toLowerCase() == 'popup') {
			        b_found = true;
			        break;
   	         }
	        } while (o_parent.parentNode);
	
	        if (b_found === false) {
                return false;
	        }
	        
            var o_frameclose = o_parent.getElementsByClassName('confirm_screenopen')[0];
            o_frameclose.className = 'confirm_screenclose';    	
	        var b = document.getElementById("cover");
			b.className = "nocover";
		    b.style.height = 0;		
        };        

        function initAutoLists() {
	
	        var ul = document.getElementsByTagName('ul');
	        for (var i = 0; i < ul.length; i++) {
		        var list = ul[i];
	        	if (list.getAttribute('class').search(/(autolist)/) === -1) {
			        continue;
		        }		
		        var items = list.getElementsByTagName('li');
		        if (items.length <= iWebkit.autolistNumVisible) {
                    continue;
	        	}		
		        list.numitems = items.length;
	        	list.visibleitems = 0;
	        	var button = list.getElementsByClassName('autolisttext')[0];
		        button.onclick = function (event) {
		        	var list = this.parentNode;
		        	list.showItems(list.visibleitems + iWebkit.autolistNumVisible);
		        	return false;
	        	};
		        list.showItems = function (numItems) {
			        var items = this.getElementsByTagName('li');
			        var count = 0;
			        for (var i = 0; i < items.length; i++) {
				        items[i].className = items[i].className.replace(/hidden/g, '');
			        	if (i >= numItems) {
				        	items[i].className = items[i].className + ' hidden';
				        } 
				        else {
					        count += 1;
			        	}
			        }
        			this.visibleitems = count;
		        	button.className = button.className.replace(/hidden/g, '');
	        		if (count >= (items.length - 1)) {
	        			button.className = button.className + ' hidden';
	        		}
	        	};
	        	list.showItems(iWebkit.autolistNumVisible);
        	}
        }		
		
		iWebkit.init = function () {
			url();
			hideURLbar();
			initAutoLists();
			var inputs = document.getElementsByTagName("input"), span = [], textnode, option, active;
			for (var a = 0;a < inputs.length;a++) {
				if (inputs[a].type === "checkbox" || inputs[a].type === "radio") {
					span[a] = document.createElement("span");
					span[a].className = inputs[a].type;
					if (inputs[a].checked) {
						if (inputs[a].type === "checkbox") {
							var position = "0 -" + (iWebkit.checkboxHeight * 2) + "px";
							span[a].style.backgroundPosition = position;
						} else {
							position = "0 -" + (iWebkit.radioHeight * 2) + "px";
							span[a].style.backgroundPosition = position;
						}
					}
					inputs[a].parentNode.insertBefore(span[a], inputs[a]);
					inputs[a].onchange = iWebkit.clear;
					span[a].onmouseup = iWebkit.check;
					document.onmouseup = iWebkit.clear;
				}
			}
			/*
			inputs = document.getElementsByTagName("select");
			for (a = 0;a < inputs.length; a++) {
				if (inputs[a]) {
					option = inputs[a].getElementsByTagName("option");
					active = option[0].childNodes[0].nodeValue;
					textnode = document.createTextNode(active);
					for (var b = 0;b < option.length;b++) {
						if (option[b].selected) {
							textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
						}
					}
					span[a] = document.createElement("span");
					span[a].className = "select";
					span[a].id = "select" + inputs[a].name;
					span[a].appendChild(textnode);
					inputs[a].parentNode.insertBefore(span[a], inputs[a]);
					inputs[a].onchange = iWebkit.choose;
				}
			}
			*/
		};
		
		iWebkit.pushed = function () {
			var element = this.nextSibling;
			if (element.checked && element.type === "checkbox") {
				this.style.backgroundPosition = "0 -" + iWebkit.checkboxHeight * 3 + "px";
			} else {
				if (element.checked && element.type === "radio") {
					this.style.backgroundPosition = "0 -" + iWebkit.radioHeight * 3 + "px";
				} else {
					if (!element.checked && element.type === "checkbox") {
						this.style.backgroundPosition = "0 -" + iWebkit.checkboxHeight + "px";
					} else {
						this.style.backgroundPosition = "0 -" + iWebkit.radioHeight + "px";
					}
				}
			}
		};
		
		iWebkit.check = function () {
			var element = this.nextSibling;
			if (element.checked && element.type === "checkbox") {
				this.style.backgroundPosition = "0 0";
				element.checked = false;
			} else {
				if (element.type === "checkbox") {
					this.style.backgroundPosition = "0 -" + iWebkit.checkboxHeight * 2 + "px";
				} else {
					this.style.backgroundPosition = "0 -" + iWebkit.radioHeight * 2 + "px";
					var group = this.nextSibling.name;
					var inputs = document.getElementsByTagName("input");
					for (var a = 0;a < inputs.length;a++) {
						if (inputs[a].name === group && inputs[a] !== this.nextSibling) {
							inputs[a].previousSibling.style.backgroundPosition = "0 0";
						}
					}
				}
				element.checked = true;
			}
		};
		
		iWebkit.clear = function () {
			var inputs = document.getElementsByTagName("input");
			for (var b = 0;b < inputs.length;b++) {
				if (inputs[b].type === "checkbox" && inputs[b].checked) {
					inputs[b].previousSibling.style.backgroundPosition = "0 -" + iWebkit.checkboxHeight * 2 + "px";
				} else {
					if (inputs[b].type === "checkbox") {
						inputs[b].previousSibling.style.backgroundPosition = "0 0";
					}
					else {
						if (inputs[b].type === "radio" && inputs[b].checked) {
							inputs[b].previousSibling.style.backgroundPosition = "0 -" + iWebkit.radioHeight * 2 + "px";
						} else {
							if (inputs[b].type === "radio") {
								inputs[b].previousSibling.style.backgroundPosition = "0 0";
							}
						}
					}
				}
			}
		};
		
		iWebkit.choose = function () {
			var option = this.getElementsByTagName("option");
			for (var d = 0;d < option.length; d++) {
				if (option[d].selected) {
					document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
				}
			}
		};
		
		iWebkit.init();
//	};
}

function get_location_updater() {

	if (navigator.geolocation) {
		updateLocationId = navigator.geolocation.watchPosition(	get_location_success_updater, 
																															get_location_fail,
																															{ timeout: 3000, maximumAge:0, enableHighAccuracy: true } );
	} else {
		geolocation = google.gears.factory.create('beta.geolocation');
		updateLocationId = geolocation.watchPosition(	get_location_success_updater, 
																									  get_location_fail,
																									  { timeout: 3000, maximumAge:0, enableHighAccuracy: true } );		
	}
	
	$('location_overlay').style.display = 'block';
	$('location_span').style.display = 'block';
	$('location_progress').innerHTML = '';
	$('location_accuracy').innerHTML = '';
	timer_locate = setTimeout(function () {				
		if (global_position['accuracy'] != null && global_position['accuracy'] <= RADIUS_CHECKIN_MIN) {
			locate_me();
			stop_location(true);	
		} else {
			stop_location(false);
		}
		}, 10000);
	if (typeof(IPHONE) != 'undefined') {
		timestamp = new Date().getTime();
		timer_refresh = setTimeout('timer()', 1000);
	}
}

var global_position = Array();
global_position['latitude']=0;
global_position['longitude']=0;
global_position['accuracy']=null;
global_position['timestamp']=0; 
var timestamp = new Date().getTime();
var base_location = Array();
var bases_no = 0;
var geolocation = null;
var updateLocationId = null;
var updateLocationCount = 0;
var timer_refresh = null;
var timer_locate = null;
var RADIUS_CHECKIN_MIN = 600;
var RADIUS_CHECKIN_GOOD = 250;
var RADIUS_CHECKIN_PERFECT = 250;
var spinner = '<div style="width:16px;margin-left:auto;margin-right:auto;padding: 20px 0px 200px 0px;"><img src="/img/progress.gif"/></div>';

function timer() {
	timestamp_new = new Date().getTime();
	if (timestamp_new - timestamp > 3000) {
		timestamp = timestamp_new;
		get_location_updater();
	}	
	timestamp = new Date().getTime();	
	setTimeout('timer()',1000);
}


function switch_visible(id) {
	if ($(id).style.display == 'none')
		$(id).style.display = 'block';
	else
		$(id).style.display = 'none';
}

function gps_indicator(visible) {
	if (visible)
		$('gps').style.display = 'block';
	else {
		$('gps').style.display = 'block';
		//if (typeof(IPHONE) != 'undefined')
		//	Effect.Fade('gps', { duration: 2.0 });
		//else
			$('gps').style.display='none';
	}
}

function friends() {
	document.location.href = '#friends';
	$('content_friends').style.display = 'block';
	$('content_events').style.display = 'none';
	$('content_locate').style.display = 'none';
	$('content_base').style.display = 'none';
	$('content_base_create').style.display = 'none';
	$('content_checkin').style.display = 'none';
	
	$('menu_events').className = 'inactive';
	$('menu_tickets').className = 'inactive';
	$('menu_locate').className = 'inactive';
	$('menu_friends').className = 'active';
}

function events() {
	document.location.href = '#events';
	$('content_friends').style.display = 'none';
	$('content_events').style.display = 'block';
	$('content_locate').style.display = 'none';
	$('content_base').style.display = 'none';
	$('content_base_create').style.display = 'none';
	$('content_checkin').style.display = 'none';
	
	$('menu_events').className = 'active';
	$('menu_tickets').className = 'inactive';
	$('menu_locate').className = 'inactive';
	$('menu_friends').className = 'inactive';
}

function tickets() {
	document.location.href = '#tickets';
	$('content_friends').style.display = 'none';
	$('content_events').style.display = 'none';
	$('content_locate').style.display = 'none';
	$('content_base').style.display = 'none';
	$('content_base_create').style.display = 'none';
	$('content_checkin').style.display = 'none';
	
	$('menu_events').className = 'inactive';
	$('menu_tickets').className = 'active';
	$('menu_locate').className = 'inactive';
	$('menu_friends').className = 'inactive';
}

function check_in_cancel() {
	document.location.href = '#locate';
	$('content_locate').style.display = 'block';
	$('content_events').style.display = 'none';
	$('content_friends').style.display = 'none';
	$('content_base').style.display = 'none';
	$('content_base_create').style.display = 'none';
	$('content_checkin').style.display = 'none';
	
	$('menu_events').className = 'inactive';
	$('menu_tickets').className = 'inactive';
	$('menu_locate').className = 'active';
	$('menu_friends').className = 'inactive';
}

function base_create() {
	document.location.href = '#create';
	$('content_locate').style.display = 'none';
	$('content_events').style.display = 'none';
	$('content_friends').style.display = 'none';
	$('content_base').style.display = 'none';
	$('content_base_create').style.display = 'block';
	$('content_checkin').style.display = 'none';
}

function check_in_display(base_id,li_id,base_title) {
	document.location.href = '#checkin';
	$('content_locate').style.display = 'none';
	$('content_events').style.display = 'none';
	$('content_friends').style.display = 'none';
	$('content_base').style.display = 'none';
	$('content_base_create').style.display = 'none';
	$('content_checkin').style.display = 'block';
	$('content_checkin_base').innerHTML = base_title;
	$('checkin_base_id').value = base_id;
	$('checkin_li_id').value = li_id;
	return;
}

function base_display(base_id) {
	pleasewait(1);
	if($('content_locate'))
		$('content_locate').style.display = 'none';
	if($('content_friends'))
		$('content_friends').style.display = 'none';
	if($('content_base')) {
		$('content_base').style.display = 'block';
	}
	if($('content_checkin'))
		$('content_checkin').style.display = 'none';
	
	var myAjax = new Ajax.Request('/base/'+base_id+'?ajax=1',
	        {method: 'post', 
	         parameters: null,
			 onSuccess: function (response) {			 		
					$('content_base').innerHTML = response.responseText;
					pleasewait(0);
			 }
	        });
}

function refresh_events(type_id) {
	$('events_container').innerHTML=spinner;
	var myAjax = new Ajax.Request('/events/list/'+$('event_date').value+'/'+type_id+'?ajax=1',
	        {method: 'post', 
	         parameters: null,
			 onSuccess: function (response) {
				$('events_container').innerHTML = response.responseText;
			 }
	        });
}

function check_in(base_id,li_id) {
	pleasewait(1);
	checkin_twitter = $('checkin_twitter').value;
	checkin_facebook = $('checkin_facebook').value;
	checkin_foursquare = $('checkin_foursquare').value;
	checkin_gowalla = $('checkin_gowalla').value;
	
	var myAjax = new Ajax.Request('/ajax/checkin',
	        {method: 'post', 
	         parameters: { 'data[Checkin][base_id]': base_id,
	         			   'data[Checkin][twitter]':  checkin_twitter,
	         			   'data[Checkin][facebook]': checkin_facebook,
	         			   'data[Checkin][foursquare]': checkin_foursquare,
	         			   'data[Checkin][gowalla]': checkin_gowalla,
	         			   'data[Checkin][comment]':  $('checkin_comment').value },
					 onSuccess: function (response) {
					 	
					 	pleasewait(0);							 	
					 	buffer = eval('('+response.responseText+')'	);					 	 
					 	
					 	for (i=0; i<bases_no; i++) {
					 		if (i != base_id) {
					 			$('base_arrow_'+i).style.display = 'block';
						 		$('base_check_'+i).style.display = 'none';
					 		}
					 	}
					 	
					 	if (buffer['result'] == 'ok') {
					 		if ('li_id') {
						 		$('base_arrow_'+li_id).style.display = 'none';
						 		$('base_check_'+li_id).style.display = 'block';
						 	}
					 		alert('You\'ve checked in! '+buffer['points']);
					 	} else if (buffer['result'] == 'already') {
					 		if ('li_id') {
					 			$('base_arrow_'+li_id).style.display = 'none';
					 			$('base_check_'+li_id).style.display = 'block';
					 		}
					 		alert('You\'re already checked in here!');
					 	} else {
					 		alert('There was an error :(');
					 	}
						//check_in_cancel();
						//locate_me();
						document.location.href = '/#locate';
					 }
	         });	
}

function found() {
	pleasewait(1);
	//base_title = prompt('Name this Base!',base_location);	
//	if (base_title != '' && base_title != null) {
	if ($('base_title').value!= '') {
//		if (title) {
			var myAjax = new Ajax.Request('/ajax/found',
			        {method: 'post', 
			         parameters: { 'data[Base][title]': $('base_title').value,
			         							 'data[Base][description]': $('base_description').value,
			         							 'data[Base][latitude]': global_position['latitude'],
			         							 'data[Base][longitude]': global_position['longitude'],
			         							 'data[Base][accuracy]': global_position['accuracy'] },
							 onSuccess: function (response) {	
							 	
							 	pleasewait(0);
							 	buffer = eval('('+response.responseText+')'	);					 	 
							 	if (buffer['result'] == 'ok') {
							 		alert('Base was created! '+buffer['points']);
							 		if (confirm('Do you want to checkin at '+$('base_title').value+'?')) {
							 			check_in(buffer['id'],'');
							 		}
							 		check_in_cancel();
							 		locate_me();
							 	} else {
							 		alert('There was an error :(');
							 	}
							 }
			         });	
//		}
	} else {
		pleasewait(0);
	}
}

function progress(val) {
	if (val)
		$('progress').style.display='block';
	else
		$('progress').style.display='none';
}

function locate_me() {
	progress(true);
	$('debug').innerHTML='';

	var myAjax = new Ajax.Request('/ajax/locate',
	        {method: 'post', 
	         parameters: { 'data[Base][latitude]': global_position['latitude'],
	         							 'data[Base][longitude]': global_position['longitude'],
	         							 'data[Base][accuracy]': global_position['accuracy'] },
					 onSuccess: function (response) {

					 	progress(false);
					 	$('locations_container').innerHTML='';
					 	$('debug').innerHTML = response.responseText;	
					 	buffer = eval('('+response.responseText+')'	);					 	 
					 	if (buffer['bases'].length < 1) {
					 	
					 		base_location = buffer['address']['full'];
					 		
					 		li = Builder.node('li', { });
							li.innerHTML = '<small>'+buffer['address']['full']+'</small>';
							$('locations_container').appendChild(li);
					 	} else {
					 		base_location = buffer['address']['full'];

							li = Builder.node('li', { });
							li.innerHTML = '<small>'+buffer['address']['full']+'</small>';
							$('locations_container').appendChild(li);
							bases_no = buffer.bases.no;

							markers = '';
					 		for (i=0; i<buffer.bases.no; i++) {

					 			li = Builder.node('li', { className: 'menu', onclick: 'check_in_display('+buffer.bases[i].id+','+i+',\''+js_string(buffer.bases[i].title)+'\');' });
					 			if (i<35) {
					 				markers += '|';
									markers += buffer.bases[i].latitude+','+buffer.bases[i].longitude+',mid'+buffer.bases[i].color+buffer.bases[i].no;
								}
								
								bullet = '<span style="background-color:'+buffer.bases[i].html_color_background+';">&nbsp;'+buffer.bases[i].no.toString().toUpperCase()+'&nbsp;</span>&nbsp;&nbsp;';
								
					 			if (buffer.bases[i].checkedin == true) {
					 				li.innerHTML = '<span class="name">'+bullet+buffer.bases[i].title+'</span><span class="arrow" id="base_arrow_'+i+'" style="display:none;"></span><span class="check" id="base_check_'+i+'"></span>';	
					 			} else {
					 				li.innerHTML = '<span class="name">'+bullet+buffer.bases[i].title+'</span><span class="arrow" id="base_arrow_'+i+'"></span><span class="check" id="base_check_'+i+'" style="display:none;"></span>';
					 			}
								$('locations_container').appendChild(li);								
					 		}					 	
					 		
							if (markers == '') {
							
							} else {
								
							}
							markers += '&zoom=16&center='+buffer.latitude+','+buffer.longitude;
							markers = global_position['latitude']+','+global_position['longitude']+',red' + markers;
					 		img_url = 'http://maps.google.com/staticmap?'+
									  '&size=305x229&maptype=mobile&markers='+markers+
									  '&key=ABQIAAAAnzRnUlaX3MHCmhkhnnwDVhTrmsBnPWYquP4VlmSq6hL7CCkCfBT-3WdCVV7OoLdrFH8Gf0lcoQg7ag&sensor=false';
						
							$('img_current_position').style.display='block';
							$('img_current_position').src = img_url;	
					 	}
					 	
					 	li = Builder.node('li', { className: 'menu', id: 'button_found' });
						li.innerHTML = '<div class="button_active" onclick="base_create();">'+lbl['lbl_create_new_base']+'</div>';
						$('locations_container').appendChild(li);
					 }
	         });	
}

function stop_location(found) {
	updateLocationCount = 0;
	
	if (navigator.geolocation) {
		navigator.geolocation.clearWatch(updateLocationId);
	} else {
		geolocation.clearWatch(updateLocationId);
	}
	if (!found) {
		$('location_accuracy').innerHTML = 'Sorry, couldn\'t locate you accurately!<br/><a class="white" href="#locate" onclick="get_location_updater();">Try again!</a>';	
	} else {
		$('location_accuracy').innerHTML = 'Got you!';	
	}
		
	$('location_span').style.display = 'none';	
	
	if (found) {
		//if (typeof(IPHONE) != 'undefined')
		//	Effect.Fade('location_overlay', { duration: 2.0 });
		//else
			$('location_overlay').style.display='none';			
	}
}

function get_location_success_updater(position) {	

	updateLocationCount++;
	
	gps_indicator(false);
	
	timestamp_new = new Date().getTime();
	if (navigator.geolocation) {
		global_position['latitude'] = position.coords.latitude;
		global_position['longitude'] = position.coords.longitude;
		global_position['accuracy'] = position.coords.accuracy;		
		global_position['timestamp'] = timestamp_new - position.timestamp;
	} else {
		global_position['latitude'] = position.latitude;
		global_position['longitude'] = position.longitude;
		global_position['accuracy'] = position.accuracy;
		global_position['timestamp'] = timestamp_new - position.timestamp.getTime(); //timestamp_new - position.timestamp;
	}
	
	$('debug_location').innerHTML = 'Acc: '+Math.round(global_position['accuracy'])+
																				' Lat: '+Math.round(global_position['latitude']*10)/10+
																				' Long: '+Math.round(global_position['longitude']*10)/10+ 
																				' Time: '+global_position['timestamp']+'s';	
	
	$('location_progress').innerHTML += '.';
	$('location_accuracy').innerHTML = '('+Math.round(global_position['accuracy'])+'m accuracy)';

	img_url = 'http://maps.google.com/staticmap?center='+global_position['latitude']+','+global_position['longitude']+
			  '&zoom=16&size=285x229&maptype=mobile&markers=&key=ABQIAAAAnzRnUlaX3MHCmhkhnnwDVhTrmsBnPWYquP4VlmSq6hL7CCkCfBT-3WdCVV7OoLdrFH8Gf0lcoQg7ag&sensor=false';

	$('img_current_position').style.display='block';
	$('img_current_position').src = img_url;	
	if (global_position['accuracy'] <= RADIUS_CHECKIN_PERFECT) {

		locate_me();
		stop_location(true);
		
	} else {		
		
		if (global_position['accuracy'] <= RADIUS_CHECKIN_GOOD) { 
			locate_me();			
			stop_location(true);
		} else if (global_position['accuracy'] <= RADIUS_CHECKIN_MIN) { 
			
		} else {
			//$('button_found').style.display = 'none';
			//if (updateLocationCount == 10) {
			//	stop_location(false);
			//}
		}
	}
}

function get_location_fail(positionError) {
	//alert('fail');
	//alert (positionError.message+' ('+positionError.code+')');
	$('debug_location').innerHTML = positionError.message+' ('+positionError.code+')';
	if (positionError.code == 1) {		
		stop_location(false);
		$('location_accuracy').innerHTML = 'Sorry, your GPS seems turned off!<br/><a class="white" href="#locate" onclick="get_location_updater();">Try again!</a>';
		clearTimeout(timer_locate);
		clearTimeout(timer_refresh);
	}
	//$('debug_location').style.display='block';
}	

function set_location(latitude,longitude,accuracy) {
	img_url = 'http://maps.google.com/staticmap?center='+latitude+','+longitude+
 					  '&zoom=16&size=285x229&maptype=mobile&markers=&key=ABQIAAAAnzRnUlaX3MHCmhkhnnwDVhTrmsBnPWYquP4VlmSq6hL7CCkCfBT-3WdCVV7OoLdrFH8Gf0lcoQg7ag&sensor=false';
	
	$('img_current_position').style.display='block';
	$('img_current_position').src = img_url;
	$('button_found').style.display = 'none';
}

function js_string(str) {
	str = str.replace(/\'/g, "\\'");
	return str;
}

function load_url(url) {
	pleasewait(1);	
	document.location.href = url;
}

function pleasewait(visible) {
	if (visible) {
		document.location.href = '#top';
		$('pleasewait').style.display='block';
	} else {
		$('pleasewait').style.display='none';
	}
}

function checkbox(id) {
	if ($(id).value == 0) {
		$(id).value = 1;
		$(id+'_button').className='checkbox';
	} else {
		$(id).value = 0;
		$(id+'_button').className='checkbox_inactive';
	}
}

var lastHash = null;
function poll_hash() {

	if(lastHash !== document.location.hash || lastHash==null) {
  	lastHash = document.location.hash;

		if (lastHash == '#locate') {
			check_in_cancel();
			$('menu_locate').className = 'active';
			$('menu_events').className = 'inactive';
			$('menu_friends').className = 'inactive';
		} else if (lastHash == '#checkin') {
		
		} else if (lastHash == '#tickets') {
			
		} else if (lastHash == '#friends') {
			friends();
			$('menu_locate').className = 'inactive';
			$('menu_events').className = 'inactive';
			$('menu_friends').className = 'active';
		} else if (lastHash == '#create') {
			$('content_base_create').style.display='block';	
			$('menu_locate').className = 'inactive';
			$('menu_events').className = 'inactive';
			$('menu_friends').className = 'inactive';			
		} else if (lastHash == '#base') {
			$('content_base').style.display='block';	
			$('menu_locate').className = 'inactive';
			$('menu_events').className = 'inactive';
			$('menu_friends').className = 'inactive';			
		} else {
  		if ($('content_events')) {
				events();
				//$('content_events').style.display='block';
				//$('menu_events').className = 'active';
			}	
			$('menu_locate').className = 'inactive';			
			$('menu_friends').className = 'inactive';					
		}      
	}
}
addLoadEvent(function() {
  setInterval(poll_hash, 100);
});
