/*Load the widget parser*/

dojo.addOnLoad(function(){
	var addthis_config = {
		     pubid: "canondlc"
		};

	//hide URL bar
	var zoomPageCheck = document.getElementById("checkIfZoomPage");
	if (zoomPageCheck == null) {
		setTimeout(function () {
         window.scrollTo(0, 1);
		}, 10);
	}
	
	dojo.require("dojo.fx");
	/*home page toggle section control*/
	dojo.query("#toggleNavigation .toggleTitle").connect("click", function(e){
		e.preventDefault();
		//var to capture + and - 
		var currentState= this.innerHTML;
		var updtSt;
		var thisToggleId = dojo.attr(this, "id").substring(2,3);
		var targetNode = "tS"+thisToggleId;
		if(dojo.hasClass(this, "openState")){
			dojo.addClass(this, "closedState");
			dojo.removeClass(this, "openState");
			wipeOut(targetNode);
			updtSt= currentState.replace("-", "+");		
		}
		else{
			dojo.addClass(this, "openState");
			dojo.removeClass(this, "closedState");
			wipeIn(targetNode);
			updtSt= currentState.replace("+", "-");
		}
		this.innerHTML = updtSt;
	});
	/*choose a section select */
	//dojo.query("#header #sectionSelect").connect("onchange", function(e){
	//	window.location = this.value;
	//});
	
	/*search functionality*/
	dojo.query("#searchLabel").connect("click", function(e){
		if(dojo.style("mobileSearchForm", "display") == "none"){
			dojo.style("mobileSearchForm", "display","block");
			wipeIn("searchCont");
			//document.getElementById('searchValue').focus;
			//dojo.query('#searchValue').focus().click();
		}
		else{
			wipeOut("searchCont");
			dojo.style("mobileSearchForm", "display","none");
		}
	});
	
	var tmpValue="";
	dojo.query("#searchValue").connect("focus", function(e) {
		tmpValue= this.value;
		this.value = "";
    });
	/*on blur if input is empty,reset label */
	dojo.query("#searchValue").connect("blur", function(e) {
		if (this.value == ""){
			this.value = tmpValue;
		}
	});
	

	/*reusable toggle for various pages*/
	dojo.query(".jsToggleLink").connect("click", function(e) {
		e.preventDefault();
		var curTggl = this.innerHTML;
		
		dojo.query(".jsToggleLink").forEach(function(thisToggle){
		    var tmpStr = thisToggle.innerHTML;
		    var updtStr;
		    //update other open toggles to close
		    if (tmpStr.indexOf("-") != -1 && tmpStr != curTggl){
				updtStr= tmpStr.replace("-", "+");
				thisToggle.innerHTML = updtStr;
		    } 
		    //set clicked toggle to open
		    else if (tmpStr.indexOf("+") != -1 && tmpStr == curTggl){
				updtStr= tmpStr.replace("+", "-");
				thisToggle.innerHTML = updtStr;
		   }
		    else if (tmpStr.indexOf("-") != -1 && tmpStr == curTggl){
				updtStr= tmpStr.replace("-", "+");
				thisToggle.innerHTML = updtStr;
		   }
		});

		
		
		
		var targetContainerId = dojo.attr(this, "target");
		
		
		allCollapse(targetContainerId);
		if(dojo.hasClass(targetContainerId,'toggleOpened')){
			wipeOut(targetContainerId);
		}
		else{
			wipeIn(targetContainerId);
		}
    });
	
	
	dojo.query(".closeLink").connect("click", function(e) { 
		window.close();
	});
	
	
	
});
/*end addOnLoad*/
function toggleNarrow(type) {
	if (type == 'expand') {
		dojo.style('narrowPlus','display','none');
		dojo.style('narrowMinus','display','block');
	} else {
		dojo.style('narrowMinus','display','none');
		dojo.style('narrowPlus','display','block');
	}
}

function wipeIn(targetNode){
	dojo.addClass(targetNode, "toggleOpened");
	dojo.fx.wipeIn({
        node: targetNode,
        duration: 200
    }).play();

}
function wipeOut(targetNode){
	dojo.fx.wipeOut({
        node: targetNode,
        duration: 200
    }).play();
	
	setTimeout(function(){dojo.removeClass(targetNode, "toggleOpened")},300);
}


function allCollapse(tgId){
	dojo.query(".toggleOpened").forEach(function(curElem){
		var curId = dojo.attr(curElem, "id");
		if(curId != tgId){
			wipeOut(dojo.attr(curElem, "id"));
		}
	});

		
}

function get_url_parameters( name )	 {
 	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}



