// 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];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}

function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        cursor.x = e.clientX + 
            (document.documentElement.scrollLeft || 
            document.body.scrollLeft) - 
            document.documentElement.clientLeft;
        cursor.y = e.clientY + 
            (document.documentElement.scrollTop || 
            document.body.scrollTop) - 
            document.documentElement.clientTop;
    }
    return cursor;
}

function doPopover(obj, viz, event) { 
	
	var obj = document.getElementById(obj);
//	alert(cursor.x + ':' + cursor.y);
	switch(viz) {
		
		case 'show':

			var cursor = getPosition(event);

			obj.style.position = 'absolute';
			obj.style.top = cursor.y + 10 +'px';
			obj.style.left = cursor.x + 25 +'px';
			
			obj.style.display = 'block';
			break;

		case 'hide':
			obj.style.display = 'none';
			break;
		}
}

function debugObj(obj) {
	document.getElementById('debug').innerHTML += '<hr />';
 	for (items in obj) {
      	document.getElementById('debug').innerHTML += items + ': ' + obj[items] + '<br />';
 	}
	document.getElementById('debug').innerHTML += '<hr />';
}


// ***************************************************
//  	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 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 = 'pei';
	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 = "#B57462";
	}

}

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

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

//--><!]]>

//  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';
	}
}

