var scrolldelta = 1;
var scrolling = true;
var scrollspeed = 120;

$(document).ready(function() {
	// preload images to speed menus, etc
	preloadimages();  
	
	var regexS = "^(/(cloudbase/)?)([a-z]*)";
	var regex = new RegExp(regexS, "i");
	var results = regex.exec(window.location.pathname);
	var root;
	var page;
	root = results[1];
	if (results[3] == null || results[3] == "") {
		page = "home";
	} else {
		page = results[3];
	}
	if (page == "home") {
		// fix the home link on the staging site
		$("#menu li#home a").attr("href", "")
	} else {
		// append current section to title
	 	document.title +=  window.location.pathname.split('/').join(" : ");
	}
	// and set the bullet images
	var b = $("#menu li");
	for (i = 0; i < b.length; i++) {
		b.eq(i).css("list-style-image", "url("+root+"images/bullet_"+i+".gif)").data("i", i);
	}
	$("#menu li#"+page).css("list-style-image", "url("+root+"images/bullet_dkgrn.gif)").find("a").css("color","#99A167");
	// change menu bullets on mouse over
	$("#menu li").not("#"+page).mouseover(function(){
		$(this).css("list-style-image", "url("+root+"images/bullet_grey.gif)");
	});
	// change menu bullets on mouse out
	$("#menu li").not("#"+page).mouseout(function(){
		$(this).css("list-style-image", "url("+root+"images/bullet_"+$(this).data("i")+".gif)");
	});
	
	// load photo thumbs and bullets
	preloadimages();  
	preloadphotos();  
});



function getpagename(root) {
	var regexS = "//[a-z\.]+/(cloudbase/)?([a-z]+)/";
	var regex = new RegExp(regexS, "i");
	var results = regex.exec(window.location.href);
	//alert (results.toString());
	root = "/" + results[1];
	if ((results == null) || (results[2] == 'cloudbase'))
		return "home";
	else
		return results[2];
}


// get a URL parameter
function get(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}

function preloadphotos() {
	var n_images = 25;
	var a = new Array();
	for (n = 1; n <= n_images; n++) {
		s = n;
		if (n < 100) {
			s = '0' + s;
		}
		if (n < 10) {
			s = '0' + s;
		}
		a[n] = new Image;
		a[n].src = "flying/slovenia2009/photos/t/slovenia" + s + ".jpg"; 
	}
}

function preloadimages() {
	var n_bullets = 9;
	var a = new Array();
	for (n = 0; n < n_bullets; n++) {
		a[n] = new Image;
		a[n].src = "images/bullet_" + n + ".gif"; 
	}
	a[++n] = new Image;
	a[n].src = "images/bullet_grey.gif";
	a[++n] = new Image;
	a[n].src = "images/bullet_dkgrn.gif";
}

// 
// Display a URL in a popup window
//
var popup_window = 0;
function popup(url, width, height) {
  if(popup_window)
  {
    if(!popup_window.closed) popup_window.close();
  }
  if (!width) width = 550;
  if (!height) height = 400;
  popup_window = open(url, 'popup', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height);
  return false;
}
