/**
* Function to submit a HTML form into a Highslide iframe popup.
*/
var pageID = null;
function submitToHighslide(form) {
    // identify the submit button to start the animation from
    var anchor;
    for (var i = 0; i < form.elements.length; i++) {
    	if (form.elements[i].type == 'submit') {
			anchor = form.elements[i];
			break;
		}
	}

	// open an expander and submit our form when the iframe is ready
	hs.overrides.push('onAfterExpand');
	hs.htmlExpand(anchor, {
		objectType: 'iframe',
		src: 'about:blank',
		width: 800,
		height: 600,
		objectHeight: 565,
		onAfterExpand: function(expander) {
			form.target = expander.iframe.name;
			form.submit();
			$('iframe').attr('id', 'searchResults');
			$('iframe').attr('class', 'iframe');
		}
	});
	hs.Expander.prototype.onAfterClose = function (sender) {
		if(pageID != null){
			//scroll to searchresult-page
			$('#slidingContent').stop().scrollTo('#page'+pageID, 1000, function(){
				top.window.location.hash = "#page"+pageID;
				top.window.scrollTo(0, 0);
				pageID = null;			
			});
			var activeLi = null; 
			//find all links in the menu
			$("#menu li.levelOne").find("a").each(function(){
				//find the menu-point, which has to be active now
				if ( $(this).attr("href") == "#page"+pageID){
					if($(this).attr("class") == "lvlTwoLink"){
						activeLi = $(this).parents("li.levelOne:first");
					}else{
						activeLi = $(this).parents("li:first");
					}
					$(this).parents("li.levelOne").attr("class", "active");
				}	
			});

			refresh_page(pageID);
			getActiveNavpoint(activeLi);
		}
	};
	// return false to delay the sumbit until the iframe is ready
	return false;
}
