// JavaScript Document
var narrowCss="css/IW_Narrow.css";  //Path to the narrow design CSS file
var wideCss="css/IW_wide.css"; //Path to the wide design CSS file
var isWide=false;  //Determines the default layout. Setting this variable to true, will set the default layout to the wide layout, setting it to false, will cause the narrow design to be the default.

//Loading a css or js file at runtime
function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

//Removing a css or js file at runtime
function removejscssfile(filename, filetype){
 var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist from
 var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
 var allsuspects=document.getElementsByTagName(targetelement)
 for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
  if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1)
   allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
 }
}

//Loading a startup layout (based on the value of the variable 'isWide')
function initiateCssW(){
	if(isWide){
		loadjscssfile(wideCss, "css");
	}else{
		loadjscssfile(narrowCss, "css");
	}
}


//function switch
function goNarrow(){
	loadjscssfile(narrowCss, "css");
	removejscssfile(wideCss, "css");
	isWide=false;
}
function goWide(){
	loadjscssfile(wideCss, "css");
	removejscssfile(narrowCss, "css");
	isWide=true;
}



function switchLayout(){
	if(isWide){
		goNarrow();
	}else{
		goWide();
	}
} 
