
var uid = (
	function(){
		var id=0;
		return function(){
			return id++ ;
		};
	}
)();

$(document).ready(function(){
	
	//clear search val?
	$("#site_search input:eq(0)").focus(function(){
		if($(this).val() == 'search')
			$(this).val('');
	});

	if($('#content').height() < 550){
		$('#content').height(550);
	}

	//top and left submenu's
	$("#menu ul li").hover(
		 function(){
			 if($(this).children('ul:eq(0)').is(':hidden'))
				 $(this).children('ul:eq(0)').css('display','block');
		 },
		 function(){
			 if($(this).children('ul:eq(0)').is(':visible'))
				 $(this).children('ul:eq(0)').css('display','none');
		 }
	 );

	//change all popups...
	var img = new Array();
	var i = null;
	$(".article a").each(function(){
		s = "dow.open(this.href,";
		if($(this).attr('onclick'))
			i = $(this).attr('onclick').toString().indexOf(s);

		if(i){
		
			w = 640;
			h = 480;
			
			u = $(this).attr('href');
			var id = u.substring(u.lastIndexOf('/')+1,u.lastIndexOf('.')).toLowerCase() + '_' + uid();
			e = u.substring(u.lastIndexOf('.')+1).toLowerCase();
			
			$(this).attr('id',id);
			if(e == 'png' || e == 'gif' || e == 'jpg'){
				img[id] = new Image();
				img[id].onload = function(){
					img[id].onload = null;
					w = img[id].width;
					h = img[id].height;

					$("a#" + id).attr('onclick',"").addClass('popWindowLink').attr('href',"javascript:popWindow('" + u + "'," + w + "," + h + ");");
				}
				img[id].src = u;
			}
		}
	});

	//set clicked button down
	$("#menu a.buttonID_" + $("#container").attr('class').split('mainButtonID_')[1]).addClass('buttonDown').wrap('<span class="buttonDown"><span></span></span>');

	//make all boxed the same height
	var boxedheight = 0;
	$("#middle div.boxed div.content").each(function(){
		j = $(this).height() + 25;
		if(j > boxedheight)
			boxedheight = j;
	});
	if(!$("div.boxed div.googlemaps_module").html()){
		$("#middle div.boxed div.content").height(boxedheight);
	}
});


//emulate popup function...
function popWindow(u,w,h){
	e = u.substring(u.lastIndexOf('.')+1).toLowerCase();
	if(e == 'png' || e == 'gif' || e == 'jpg')
		popEl = $("<div class=\"popWindowDiv\" style=\"display:block;\"><img src=\""+ u +"\" width=\"" + w + "\" height=\"" + h + "\" border=\"0\" /></div>");
	else
		popEl = $("<div class=\"popWindowDiv\" style=\"display:block;\"><iframe src=\""+ u +"\"  width=\"" + w + "\" height=\"" + h + "\" border=\"0\" frameborder=\"0\"></iframe></div>");
	popEl.modal();
	$("#modalContainer").css('height',h).css('width',w).css('margin-left',(w / 2) * -1); 
}

