
// javascript - code to make the div container 'horizontal_slide' move


// All <a> tag hrefs in the main page container 'PageBox' are prefixed
// with the current URL and '#?redirect=' to allow the code to be able
// to close the slider pane before making the new page call

// Exceptions to this are elements with their id starting with 'dnn_'
// which signify DNN control links, and the active button link 'buttonmenuCurrentLink'
// also any href beginning with 'javascript:'
 
var width = 484;
var slideDuration = 500;

function setPaneOpen(){
//        document.write("<style type='text/css'>.sliderbox{margin-left:0;}</style>");
        $('dnn_RightPaneTop').className = 'snazzy rightpanetop rightpanetopfill';
}

function setPaneClosed(){
        document.write("<style type='text/css'>.sliderbox{margin-left:" + width + "px;}</style>");
//        $('dnn_RightPaneTop').className = 'snazzy rightpanetop';
}

function openPane(){
//        $('dnn_RightPaneTop').className += ' rightpanetopfill'; 
        $('dnn_RightPaneTop').className = 'snazzy rightpanetop rightpanetopfill';
        hideiframes();
        sideBarSlide(0, 0, 0, width);
        // wait until the slide has finished before showing
        window.setTimeout("showiframes();", slideDuration+10);
}

// parameter newPage contains the modified url with query string
function closePane(newPage){

        // first check for the cufflink query string and remove it
        var n= newPage.indexOf('?CuffLink');
        if (n > -1){
            newPage = newPage.substr(n+14);
        }  
        
        // next check for our special redirect query string
        var n= newPage.indexOf('#?redirect=');
        //check to see if this is a new page
        if (newPage.substr(n+1) != document.location){
            // close the pane
            hideiframes();
            sideBarSlide(0, 0, width, 0);
            // no need to show again, we're off to a new page

            // wait 'til it's closed then remove the coloured infill
            window.setTimeout("$('dnn_RightPaneTop').className = $('dnn_RightPaneTop').className.replace(' rightpanetopfill','');", slideDuration+10);

            // wait a bit longer then goto new page
            window.setTimeout("document.location = '" + newPage.substr(n+11) + "';", slideDuration+100);
        } else {
            // goto new page immediately
            document.location = newPage.substr(n+11);
        }
}

function sideBarSlide(fromHeight, toHeight, fromWidth, toWidth){
		var myEffects = new Fx.Styles('horizontal_slide', {duration: slideDuration, transition: Fx.Transitions.linear});
		myEffects.custom({
			 //'height': [fromHeight, toHeight],
			 //'width': [fromWidth, toWidth]
			 'margin-left': [toWidth, fromWidth]
		});
}


function init(){
    // modify the href of all the <a> tags inside PageBox
    // except those with id containing 'dnn_' and 'buttonmenuCurrentLink' and href containing 'javascript:'
	var e=$('PageBox').getElementsByTagName('a');
	for(var i=0;i<e.length;i++){
	    if (e[i].id.indexOf('dnn_') && e[i].id.indexOf('buttonmenuCurrentLink') && e[i].href.indexOf('javascript:')){
	        $(e[i]).addEvent('click', function(){closePane(this.href)});
	            e[i].href = '#?redirect=' + e[i].href;
	    }
	}
	// disable this button link
	$('buttonmenu').getElementById('buttonmenuCurrentLink').href = 'javascript:void(0)';
}


// When using bing maps in embedded iframes, this causes flickering problems
// on Firefox during the slide operation. It is therefore necessary to 'hide'
// these iframes during the slide and show them again afterwards.
function hideiframes(){
	var e=$('horizontal_slide').getElementsByTagName('iframe');
	for(var i=0;i<e.length;i++){
        $(e[i]).style.visibility = 'hidden';
    }
}   

function showiframes(){
	var e=$('horizontal_slide').getElementsByTagName('iframe');
	for(var i=0;i<e.length;i++){
        $(e[i]).style.visibility = 'visible';
    }
}
