﻿function delayer(){
    window.location = "default.aspx"
}



function wbosRedirect(url, msg)
{
   var TARG_ID = "wbos_redirect";
   var DEF_MSG = "radio 92.9 more music. less blah blah blah";

   if( ! msg )
   {
      msg = DEF_MSG;
   }

   if( ! url )
   {
      throw new Error('You didn\'t include the "url" parameter');
   }


   var e = document.getElementById(TARG_ID);

   if( ! e )
   {
      throw new Error('"wbos_redirect" element id not found');
   }

   var cTicks = parseInt(e.innerHTML);

   var timer = setInterval(function()
   {
      if( cTicks )
      {
         e.innerHTML = --cTicks;
      }
      else
      {
         clearInterval(timer);
         document.body.innerHTML = msg;
         location = url;	  
      }

   }, 950);
}




function pop_page(the_URL,page_name,pop_width,pop_height) {
    var doPopUpX = 0;
    var doPopUpY = 0;
    var pop_resize = "yes";
    var location = "no";
    var mbar = "no";

    var pos = "left="+doPopUpX+",top="+doPopUpY;
    open( the_URL ,page_name,"location="+location+",toolbar="+mbar+",resizable="+pop_resize+",scrollbars=yes,width="+pop_width+",height="+pop_height+"," + pos);

} 

//-----------------Random image rotation -----------------------------------//
var interval = 8.0; // delay between rotating images (in seconds)
var random_display = 1; // 0 = no, 1 = yes
interval *= 1000;

var image_index = 0;
image_list = new Array();
image_list[image_index++] = new imageItem("i/earthfest1.jpg");
image_list[image_index++] = new imageItem("i/earthfest2.jpg");
image_list[image_index++] = new imageItem("i/earthfest3.jpg");
image_list[image_index++] = new imageItem("i/earthfest4.jpg");
image_list[image_index++] = new imageItem("i/earthfest5.jpg");
image_list[image_index++] = new imageItem("i/earthfest6.jpg");
var number_of_image = image_list.length;
function imageItem(image_location) {
this.image_item = new Image();
this.image_item.src = image_location;
}
function get_ImageItemLocation(imageObj) {
return(imageObj.image_item.src)
}
function generate(x, y) {
var range = y - x + 1;
return Math.floor(Math.random() * range) + x;
}
function getNextImage() {
if (random_display) {
image_index = generate(0, number_of_image-1);
}
else {
image_index = (image_index+1) % number_of_image;
}
var new_image = get_ImageItemLocation(image_list[image_index]);
return(new_image);
}
function rotateImage(place) {
var new_image = getNextImage();
document[place].src = new_image;
var recur_call = "rotateImage('"+place+"')";
setTimeout(recur_call, interval);
}



// new timer
function cdtime(container, targetdate){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.currentTime=new Date()
this.targetdate=new Date(targetdate)
this.timesup=false
this.updateTime()
}

cdtime.prototype.updateTime=function(){
var thisobj=this
this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

cdtime.prototype.displaycountdown=function(baseunit, functionref){
this.baseunit=baseunit
this.formatresults=functionref
this.showresults()
}

cdtime.prototype.showresults=function(){
var thisobj=this


var timediff=(this.targetdate-this.currentTime)/1000 //difference btw target date and current date, in seconds
if (timediff<0){ //if time is up
this.timesup=true
this.container.innerHTML=this.formatresults()
return
}
var oneMinute=60 //minute unit in seconds
var oneHour=60*60 //hour unit in seconds
var oneDay=60*60*24 //day unit in seconds
var dayfield=Math.floor(timediff/oneDay)
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))

sec = (secondfield == 1) ? " Second" : " Seconds";
minute = (minutefield == 1) ? " Minute | " : " Minutes | ";
hr = (hourfield == 1) ? " Hour | " : " Hours | ";
dy = (dayfield == 1)  ? " Day | " : " Days | "

if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
hourfield=dayfield*24+hourfield
dayfield="n/a"
}
else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
minutefield=dayfield*24*60+hourfield*60+minutefield
dayfield=hourfield="n/a"
}
else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
var secondfield=timediff
dayfield=hourfield=minutefield="n/a"
}
this.container.innerHTML=this.formatresults(dayfield, hourfield, minutefield, secondfield)
setTimeout(function(){thisobj.showresults()}, 1000) //update results every second
}

/////CUSTOM FORMAT OUTPUT FUNCTIONS BELOW//////////////////////////////

//Create your own custom format function to pass into cdtime.displaycountdown()
//Use arguments[0] to access "Days" left
//Use arguments[1] to access "Hours" left
//Use arguments[2] to access "Minutes" left
//Use arguments[3] to access "Seconds" left

//The values of these arguments may change depending on the "baseunit" parameter of cdtime.displaycountdown()
//For example, if "baseunit" is set to "hours", arguments[0] becomes meaningless and contains "n/a"
//For example, if "baseunit" is set to "minutes", arguments[0] and arguments[1] become meaningless etc


function formatresults(){
if (this.timesup==false){//if target date/time not yet met
var displaystring= "<div align=center>Earthfest 2009 starts in <font color=red>" +arguments[0]+"</font>"+dy+"<font color=red>"+arguments[1]+"</font>"+hr+"<font color=red>"+arguments[2]+"</font>"+minute+"<font color=red>"+arguments[3]+"</font>"+ sec + "</div>";
}
else{ //else if target date/time met
var displaystring="Earthfest 2009 is on!"
}
return displaystring
}
