// JavaScript Document

function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// ***************************************************
//  	BEGIN ARCHIVE RELATED JAVASCRIPT 
//  	Contact:  Malte Wendlandt for help
// 	Use the following snippet in the page that has the archive:
//		The first Option is the path to the shows archive, relative from cbc.ca/
//		The second Option can be either monthly or weekly, depending on which type of archive is used
//		the third Option is the start year of the archive.
//		the fourth Option is the first month of the start year which has an archive.  Must be entered in Numerical form, ie 5 for may.
//
//			<script type="text/javascript">
//				document.write(makeArchive ('/showname/path_to_archives/', 'weekly', '2005', '5'))
//			</script>
//
// ***************************************************

function y2k(number)    { return (number < 1000) ? number + 1900 : number; }		//  Deal with Javascripts y2k problem

function makeArray0() {
    for (i = 0; i<makeArray0.arguments.length; i++)
        this[i] = makeArray0.arguments[i];
}

function makeArchive (archivePath, archiveType, baseYear, baseMonth) {   

		var archive = '';
		var shortMonths = new makeArray0('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');
		var longMonths = new makeArray0('January','February','March','April','May','June','July','August','September','October','November','December');
		var dateObject = new Date();
		var thisYear = y2k(dateObject.getYear());
//		var baseYear = 2004;
		
		if (baseMonth > 0) {
			baseMonth = baseMonth - 1;	
		} else {
			baseMonth = 0;	
		}
		
		for (var i = thisYear; i >= baseYear; i--){

			archive += '<p><strong>' + i + '</strong><br>\n<div class="dotsDivider2">&nbsp;</div><ul>';

			if (i == baseYear){
				var startMonth = baseMonth;
			} else {
				var startMonth = 0;
			}

			if (i == thisYear){
				var endMonth = dateObject.getMonth();
			} else {
				var endMonth = 11;
			}
		
			for (j = endMonth; j >= startMonth; j--){

				archive += ('<li><a href=\"' + archivePath + i + '_' + shortMonths[j]);
				
				if (archiveType == 'weekly'){
					archive += ('_w1');
				}

				archive += ('.html\">' + longMonths[j] + ' ' + i + '</a></li>');
			}

			archive += '</ul></p>'

		}
		
		return (archive);
}

//  END ARCHIVE RELATED JAVASCRIPT 

// ***************************************************
//  	BEGIN WEEKEND NEWS RELATED JAVASCRIPT 
//		MHW Time Based Reveal Script v0.4
// ***************************************************

function revealItem (revealThis, revealStart, revealEnd, currentTime) {   

	var longDays = new Array(
		'sunday',
		'monday',
		'tuesday',
		'wednesday',
		'thursday',
		'friday',
		'saturday'
	);
	
	revealStart 	= revealStart.split(', ');
	revealEnd 		= revealEnd.split(', ');
	currentTime		= currentTime.split(', ');


	
var thisDayStr = currentTime[0].toLowerCase();
	var hours		= currentTime[1].split('+');
	var thisHour	= eval(hours[0]) + eval(hours[1]);
//	var thisHour 	= eval(currentTime[1]);

	for ( var counter = 0; counter < longDays.length; counter++ ) {
		if ( longDays[counter] == thisDayStr ) {
			thisDay = counter;	
		}
	}


	if ( thisHour <= 0) {		//  Adjust Day and Time for those instances when the timezone adjustment sets the hour below the valid range of 1 - 24
		thisHour = thisHour + 24;
		thisDay = thisDay - 1;
		if ( thisDay < 0 ) {
			thisDay = 6;	
		}
		thisDayStr = longDays[thisDay];
	}


	if ( thisHour > 24) {		//  Adjust Day and Time for those instances when the timezone adjustment sets the hour above the valid range of 1 - 24
		thisHour = thisHour - 24;
		thisDay = thisDay + 1;
		if ( thisDay > 6 ) {
			thisDay = 0;	
		}
		thisDayStr = longDays[thisDay];
	}

	for ( var counter = 0; counter <= 6; counter++ ){		//	Find the numeric value of the Start and End days

		if ( revealStart[0].toLowerCase() == longDays[counter] ) {
			revealStart[2] = counter;
		} else if ( revealEnd[0].toLowerCase() == longDays[counter] ) {
			revealEnd[2] = counter;
		}	

	}

	if ( thisHour >= revealStart[1] && longDays[thisDay] == revealStart[0].toLowerCase() ) {
		document.getElementById(revealThis).style.display = 'block';
	}


	if ( thisHour < revealEnd[1] && longDays[thisDay] == revealEnd[0].toLowerCase() ) {
		document.getElementById(revealThis).style.display = 'block';
	}

	if ( revealStart[2] < revealEnd[2] ) {			//	The Start Day is before the End Day in the sequence sun - sat

		if ( (thisDay > revealStart[2]) && (thisDay < revealEnd[2]) ) {
				document.getElementById(revealThis).style.display = 'block';
		} 
	
	} else if ( revealStart[2] > revealEnd[2] ) {		//	The End Day is before the Start Day, ie next week.

		if ( thisDay > revealStart[2] && thisDay <= 6 ) {
				document.getElementById(revealThis).style.display = 'block';
		} else if ( thisDay >= 0 && thisDay < revealEnd[2] ) {
				document.getElementById(revealThis).style.display = 'block';
		}
	
	}

}

//  END WEEKEND NEWS RELATED JAVASCRIPT 

// ***************************************************
//		MHW Dropdown Menu Script v0.4

<!--//--><![CDATA[//><!--

sfHover = function() {
//	var menuClasses = new Array('topmenu', 'regionalMenu');		//  Might as well make it flexible enough to deal with other menus too
	var menuClasses = new Array('regionalMenu');		//  Might as well make it flexible enough to deal with other menus too
	for (var j=0; j<menuClasses.length; j++) {

		if(sfEls = document.getElementById(menuClasses[j]).getElementsByTagName("LI")){		//	Make sure the menu exists before trying to fiddle with it

			for (var i=0; i<sfEls.length; i++) {
				sfEls[i].onmouseover=function() {
					this.className+=" hover";
				}
				sfEls[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" hover\\b"), "");
				}
			}

		}

	}
}


function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}

cPage = function () {

	var region = 'nb';
	var path = window.location.pathname;

	if ((path.indexOf('features') > 0) || path.indexOf('cgi-bin') > 0)  {
		element = document.getElementById('features');
	} else
	if (path.indexOf('programs') > 0)  {
		element = document.getElementById('programs');
	} else
	if (path.indexOf('community') > 0) {
		element = document.getElementById('community');
	} else 
	if (path.indexOf('weather') > 0)  {
		element = document.getElementById('weather');
	} else 
	if (path.indexOf('audio') > 0)  {
		element = document.getElementById('audio');
	} else
	if (path.indexOf('/contact/') > 0)  {
		element = document.getElementById('contact');
	} else 
	if (path.indexOf('story') > 0) {
		element = null;
	} else 
	if (path == '/' + region + '/' || path == '/' + region + '/index.html')  {
		element = document.getElementById('main');

	} else { 
		element = document.getElementById('programs');
	} 
	
	if(element) {
		element.childNodes[0].style.color = "#D9D5B9";
	}

}

addEvent(window,'load',cPage,false);
if (window.attachEvent) window.attachEvent("onload", sfHover);



//--><!]]>

//  END DROPDOWN MENU RELATED JAVASCRIPT 


//	HIDE AND REVEAL LISTEN AND WATCH

 function toggleVisibility (obj, type) {
     var obj = document.getElementById(obj);
	switch(obj.className) {
     case 'Hide':
		obj.className = 'Reveal';
     	break;
	default:
     	obj.className = 'Hide';
	}
}
//	END HIDE AND REVEAL LISTEN AND WATCH




//	SHOW MEDIA ICON


 function showIcon (linkType,mediaContainer) {
	

	var children = document.getElementById(mediaContainer).childNodes;
	var linkTypes = linkType;
	var mediaType = [];
		mediaType[0] = "ram";
		mediaType[1] = "wmv";
		mediaType[2] = "mov";
		mediaType[3] = "asx";
		mediaType[4] = "mp3";
		mediaType[5] = "wav";
		mediaType[6] = "avi";


	for ( i in children ) {  // Loop through all the children of the container
	
		if ( children[i].nodeName == 'A') {  //  See if it's an anchor
	
			var hrefs = children[i].href;	// dump the anchor's href into a variable
			var extension = hrefs.slice(hrefs.lastIndexOf(".")+1);  // Find's the last . in the href and returns everything from the next character to the end		
			
			var targets = children[i].target;

			for ( types in mediaType) {

				if (extension == mediaType[types]  && linkTypes == "audioIcon") { // sees if it matches the mediaType and the variable passed is an audio icon
					children[i].className = "audioIcon"; 
					break;
;		
				}

				else if (extension == mediaType[types]  && linkTypes == "videoIcon") { // sees if it matches the mediaType and the variable passed is an video icon
					children[i].className = "videoIcon"; 		
					break;
				}

				else if (extension != mediaType[types] && targets == "_blank") { // sees if it does not match the mediaType and the target is set to blank
					children[i].className = "externalIcon";
					break;
				
				}

				else if (extension != mediaType[types]) { // sees if it does not match the mediaType 
					children[i].className = "arrowIcon"; 		
				}

			}


		}


	}

}

//	END SHOW MEDIA ICON



// ***************************************************

//  ADS FOR REGION

// ***************************************************


// <![CDATA[
		advertising_zone = 'nb';
// ]]>

//--><!]]>

