function rerender(){

	$("div.addressblock").corner({
		  tl: {radius: 6},
		  tr: false,
		  bl: false,
		  br: {radius: 6}});
	
	$("#hoggmap").hover(function(){
		var cw = $(this).width()+"px";
		
		$(this).animate({"opacity":0.9},500);
		$(this).animate({"width":"480px"}, "slow");
		},
		function(){
		while($(this).queue().length){
			$(this).stop();
			$(this).dequeue();
		}
		$(this).stop();
		$(this).css({opacity:1.0});
		$(this).animate({"width":"320px"}, "slow");
		}
	);
	// round the border of the mainouter div
//	$("div.mainouter").corner("remove");
        var tlr = 36;
//	$("div.shadow").css("top", (tlr + 12) + 'px');

	$("div.mainouter").corner({
		  tl: false,
		  tr: false,
		  bl: false,
		  br: { radius: 14 }});
	$("div.border").css("zIndex", 1);
	$("div.border").corner({
		  tl: { radius: tlr },
		  tr: false,
		  bl: false,
		  br: { radius: 16 }});
	$("div.shadow").corner({
		  tl: { radius: tlr },
		  tr: false,
		  bl: false,
		  br: { radius: 20 }});
	$("div.border").css("zIndex", 11);
	//other animations of main content area blocks?

	// adjust shadow margin for top rounded corner
//	var mt = parseInt($("div.shadow").css("top"));
//	$("div.header").css("marginTop", (3 - tlr + 8) + "px");
	var hbgh = 181; // parseInt($("div.headerbg").css("height"));
//	$("div.headerbg").css({'marginTop':"-8px", 'height':hbgh+8+'px'});
        $("div.page").css("top", (tlr + 16) + "px");
        $("div.border").css("top", "6px");
        $("body").css('margin-bottom', (tlr + 20) + 'px');
}

function clearTypeFix(container){
    function hex(s) {
        var s = parseInt(s).toString(16);
        return s.length < 2 ? '0'+s : s;
    };
    function getBg(e) {
        for ( ; e && e.nodeName.toLowerCase() != 'html'; e = e.parentNode) {
            var v = $.css(e,'background-color');
            if (v.indexOf('rgb') >= 0 ) { 
                var rgb = v.match(/\d+/g); 
                return '#'+ hex(rgb[0]) + hex(rgb[1]) + hex(rgb[2]);
            }
            if (v && v != 'transparent')
                return v;
        }
        return '#ffffff';
    };
    $(container).each(function() { $(this).css('background-color', getBg(this)); });
};

var menuprops = new Array();

$(document).ready(function(){

// set header image
var numimages = 1;
var inum = Math.floor(Math.random()*numimages) + 1;
$("div.headerbg").css(
	{backgroundImage:"url('images/hbg"+inum+".jpg')",
	 backgroundRepeat:"no-repeat"});

// make the corners of the logo div rounded
//{ radius: 12 },
/*
$("div.logoname").corner({
	  tl: false, 
	  tr: false,
	  bl: false,
	  br: false,
	  antiAlias: true,
	  autoPad: true,
	  validTags: ["div"] });
*/
if($.browser.msie){
	$('.logonamecontent, .logonamebar').each(function(){
		var op = this.style.opacity;
		$(this).css('opacity', op);
//		alert('opacity is \''+op+'\'');
	});	
}
// add behaviours and AJAX to the menu links

$("a.menuitemlink").each(function(){
	var a = new String($(this).attr("href"));
	if(a){
		a = a.replace("?p=", "").replace(".xml", "");
	}
	var c = $(this).html();
	
	var ha = "<span class='hs_' style='display:none;'>"+a+"</span>";
	var p = $(this).parent("li");
	$(this).replaceWith(ha+c);
	var margin = "<div style='margin-left:5px;padding:0;border:0;'></div>";
	$(p).children(".menuitemspan").wrap(margin); //css("marginLeft", "5px");
});

$("ul.menu").children("li").click(function(){
	var page = $(this).children("span.hs_").text();
	load_page(page);
	
	return false;
});

$("ul.menu").children("li").hover(
	function(){
/*		var id = $(this).attr("id");
		if(menuprops[id] == 'undefined' || menuprops[id].length == 0){
			menuprops[id] = new Array();
			menuprops[id]['bcol'] = $(this).attr("borderRightColor");
			menuprops[id]['fw'] = $(this).attr("fontWeight");
			if(!menuprops[id]['fw'])menuprops[id]['fw'] = 'normal';
		} */
                var id = $(this).attr("id");
		$(this).attr("class", "menuover menuover_"+id);
//		$(this).animate({borderRightColor:"#F3F355"},300);
		$(this).css("font-weight", "bold");
	},

	function(){
/*		var id = $(this).attr("id");
		var mp = menuprops[id];
		$(this).animate({borderRightColor:mp['bcol']},300);
		$(this).css("fontWeight", mp['fw']);

*/
                var id = $(this).attr("id");
		$(this).attr("class", "menuout_"+id);
//		$(this).animate({borderRightColor:"#FFFFBF"}, 300).css("class", "menuout_"+id); //, function(){ $(this).css('borderRight', "0");}
		$(this).css("fontWeight", "normal");
	}
);

function load_page(page){

	// load the main content // can use GET p= to allow bookmarks
	if(!page){
		page = location.search.match(/p=([^&]*)(&|$)/);
		if(!page)page = "home.xml";
		else page = escape(page[1]) + ".xml";
	}else page += ".xml";
	//$("div.main").load(page+".xml#content");
	 $.ajax({
	   type: "GET",
	   url: page,
	   success: function(xml){
//		$("div.main").hide();
		$("div.main").css("opacity","0.0");
//		$("div.footer").css("opacity","0.0");
		var content = $("content", xml).text();
		if(content.length < 1)$(".main").text("sorry, the requested page was not found..");
		else $(".main").html(content);
		
		clearTypeFix("div.main");
		clearTypeFix("div.footer");
		rerender();
		$("div.main").animate({opacity:"1.0"},600);
//		$("div.footer").animate({opacity:"1.0"},600);
//		$("div.main").fadeIn(600);
	   },
	   failure: function(xmlreq, textStatus, errorThrown) {
		//   $(".main").html("ajax request error: XMLHttpRequest: '"+xmlreq.getAllResponseHeaders()+"', textStatus: '"+textStatus+"', errorThrown: '"+errorThrown+"'");
	   }
	 });
}

load_page();
/*
// action for the map image
$("#hoggmap").hover(function(){
	$(this).animate({"width":"480px"}, "slow");
	alert("hovering!");
},
function(){
	$(this).animate({"width":"320px"}, "slow");
});
*/

});

