// Uses AJAX to fetch and replace the current content
function switchContentAJAX(url, div) {
	var div = $(div);
	$('loader-img').toggle();
	var ajaxUrl = url + '/ajax/1';
    new Ajax.Request(ajaxUrl, {
        method: 'get',
        onLoading: function() {
        	// So fast! We do nothing here...
        },
        onSuccess: function(transport) {
        	// Toggle the link-class to highlight active link
            var anchors = $('children-links-menu').getElementsByTagName('a');
			for (var i=0; i<anchors.length; i++){
				if (anchors[i].href == url) {
					anchors[i].className = 'childmenu-link-on';
				} else {
		            anchors[i].className = 'childmenu-link';
				}
			}
			// Switch the content using the blindUp/Down effects
        	new Effect.BlindUp(div, {
        		duration: .4,
        		afterFinish: function() {
        			div.update(transport.responseText);
        			new Effect.BlindDown(div, {
        				duration: .4,
        		        afterFinish: function() { $('loader-img').toggle(); }
        		    });
        		}
        	});
        }
    });
}

function startDivSlideshow(divPrefix, startDiv, endDiv, delay) {
    setTimeout(switchSlideDivs(divPrefix, startDiv,startDiv,endDiv, delay), delay);
}

function switchSlideDivs(divPrefix, div, startDiv, endDiv, delay) {
    return (function() {
         if (div == endDiv) { var newDiv = startDiv; } else { var newDiv = div + 1; }
         Effect.Fade(divPrefix + div, { duration: 4 });
         Effect.Appear(divPrefix + newDiv, { duration: 4 });
         setTimeout(switchSlideDivs(divPrefix, newDiv, startDiv, endDiv, delay), delay + 850);
    })
}

var newWin = null; 
function popUp(strURL, strType, strHeight, strWidth) { 
  if (newWin != null && !newWin.closed) 
    newWin.close(); 
  var strOptions=""; 
  if (strType=="console") 
    strOptions="resizable,scrollbars,height="+ 
      strHeight+",width="+strWidth;  
  if (strType=="fixed") 
    strOptions="status,height="+ 
      strHeight+",width="+strWidth; 
  if (strType=="elastic") 
    strOptions="toolbar,menubar,scrollbars,"+ 
      "resizable,height="+ 
      strHeight+",width="+strWidth; 
  newWin = window.open(strURL, 'newWin', strOptions); 
  newWin.focus(); 
}