function popwin(url,nam,w,h,resizable,scrollbars,toolbar,locationbar,directories,status,menubar){
  var attr="";
	if(w>0){
		attr=(attr=="") ? "" : attr+",";
		attr+="width="+w;
	}
	attr=(attr=="") ? "" : attr+",";
	attr+="height="+h;
	if(resizable!=""){
		attr=(attr=="") ? "" : attr+",";
		attr+="resizable="+resizable;
	}
	if(scrollbars!=""){
		attr=(attr=="") ? "" : attr+",";
		attr+="scrollbars="+scrollbars;
	}
	if(toolbar!=""){
		attr=(attr=="") ? "" : attr+",";
		attr+="toolbar="+toolbar;
	}
	if(locationbar!=""){
		attr=(attr=="") ? "" : attr+",";
		attr+="location="+locationbar;
	}
	if(directories!=""){
		attr=(attr=="") ? "" : attr+",";
		attr+="directories="+directories;
	}
	if(status!=""){
		attr=(attr=="") ? "" : attr+",";
		attr+="status="+status;
		attr=(attr=="") ? "" : attr+",";
		attr+="statusbar="+status;
	}
	if(menubar!=""){
		attr=(attr=="") ? "" : attr+",";
		attr+="menubar="+menubar;
	}
	if(window.screen&&w>0&&h>0){
		var x=(screen.width-w)/2;
		var y=(screen.height-h)/2;
		attr+=",top="+y+",left="+x;
	}
	var winchild=window.open(url,nam,attr);
	if(winchild){
		winchild.focus();
	}
	return winchild;
}


function imgRollOverInit(){
  $('a.ro').hover(
    function(){
      $(this).children("img").attr("src", $(this).children("img").attr("src").replace("_off.","_on."));
    }
  , function(){
      $(this).children("img").attr("src", $(this).children("img").attr("src").replace("_on.","_off."));
    }
  );
}

function showDate(){
  var today = new Date();
  var year = today.getFullYear();
  var month = today.getMonth() + 1;
  var day = today.getDate();
  $('span.date').text(day + "/" + month + "/" + year);
}

function localSitesInit(){
  $('select#localSites').change(
    function(){
      var selected = $(this).children("option:selected");
      if(selected.attr("value") != ""){
        if( selected.hasClass("alert") ) {
          var alertWin = popUpObject(selected.attr("value"),"alert",710,178);
        } else {
          var mywin= ( selected.hasClass("disclaimerPop") ) ? (popwin(selected.attr("value"),"popWinDisclaimer",659,525,"no","yes","no","no","no","no","no") ) : (popwin(selected.attr("value"),"popWin",1024,768,"yes","yes","yes","yes","yes","yes","yes") );        
        }
      }
    }
  );
}

function popUpObject(href,name,width,height){
  return popwin(href,name,width,height,"no","no","no","no","no","no","no");
}

function popInFlash(href){
  popwin(href,"disclaimer",659,525);
}

function popConstructionInFlash(href){
  popwin(href,"construction",710,178);
}

function popCalendarInFlash(href){
  popwin(href,"caldenar",566,246);
}


function popUpInit(){
  $('a.constructionPop').click(
    function(event){
      var constructionWin = popUpObject($(this).attr("href"),"construction",710,178);
      event.preventDefault();
    }
  );
  $('a.disclaimerPop').click(
    function(event){
      var disclaimerWin = popUpObject($(this).attr("href"),"disclaimer",659,545);
      event.preventDefault();
    }
  );
  $('a.videoPop').click(
    function(event){
      var videoWin = popUpObject($(this).attr("href"),"video",432,407);
      event.preventDefault();
    }
  );
  $('a.glossaryPop').click(
    function(event){
      var glossaryWin = popwin($(this).attr("href"),"glossary",720,720,"yes","yes","no","no","no","no","no");
      event.preventDefault();
    }
  );
  $('a.wideVideoPop').click(
    function(event){
      var wideVideoWin = popUpObject($(this).attr("href"),"wideVideo",720,269);
      event.preventDefault();
    }
  );
  $('a.alert').click(
    function(event){
      var alertWin = popUpObject($(this).attr("href"),"alert",710,178);
      event.preventDefault();
    }
  );  
  $('a.imgPop').click(
    function(event){
      var alertWin = popUpObject($(this).attr("href"),"image",390,570);
      event.preventDefault();
    }
  ); 
}

$(document).ready(
  function(){
    showDate();
    imgRollOverInit();
    localSitesInit();
    popUpInit();
  }
);
