window.addEvent('domready', function() { 
	if(Browser.Engine.trident4){
		ie6Resize();
		window.addEvent('resize',ie6Resize); 
	}
	if ($('semmodel')) semModel();
	if ($('preventionmodel')) ppmodel();
	if ($('Scroller')) scroller();
	moopop.captureByRel('popup');
	if ($('btnhelpfulwritingtips')) pauseSetup();
});

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
function pauseFlash() {
	getFlashMovie("flashwelcome").pauseMovie();
}

function pauseSetup() {
	var btn = $('btnhelpfulwritingtips');
	btn.onclick = function() {
		pauseFlash();
		return false;
	}
}

function scroller() {
	scroller  = new jsScroller(document.getElementById("Scroller"), 430, 240);
	scrollbar = new jsScrollbar (document.getElementById("Scrollbar-Container"), scroller, false);	
}

function ppmodel() {
	var links = $('preventionmodel').getChildren('a');
	links.each(function(el) {
		var id = el.get('id');
		
		el.onmouseover = function() {
			var rollcopy = $('rollcopy').getChildren('div');
			rollcopy.each(function(el) {
				if (el.hasClass(id)) {
					if (el.hasClass('hidden')) el.removeClass('hidden');
				} else {
					if (!el.hasClass('hidden')) el.addClass('hidden');
				}
			});
		}
		
		el.onmouseout = function() {
			var rollcopy = $('rollcopy').getChildren('div');
			rollcopy.each(function(el) {
				if (!el.hasClass('hidden')) el.addClass('hidden');
			});
		}
	});
}

function ie6Resize(){
	size = window.getSize();
	$$('#navigation ul span').each(function(el){
		el.setStyle("width",size.x);
	});
}

function semModel() {
	var ind = $('semIndividual');
	var rel = $('semRelationship');
	var com = $('semCommunity');
	var soc = $('semSociety');
	
	$$('a.semlink').each(
		function(el) {
			el.onmouseover = function() {
				var id = el.get('id');
				var targetid = id+'Text';
				$(targetid).removeClass('hidden');
			}
			el.onmouseout = function() {
				var id = el.get('id');
				var targetid = id+'Text';
				$(targetid).addClass('hidden');
			}
		}
	);
}


/*
  moopop: unobtrusive javascript popups via late binding using mootools 1.2
  copyright (c) 2007-2008 by gonchuki - http://blog.gonchuki.com
  version:	1.1
  released: June 23, 2008
  This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
    http://creativecommons.org/licenses/by-sa/3.0/
*/

/*
  Basic usage:
    add a rel attribute to your <a> tags to be like this:
      <a href="http://blog.gonchuki.com" rel="popup">foobar</a>
      or
      <a href="http://blog.gonchuki.com" rel="popup[600,400]">foobar</a>
      
    where:
      "popup" is the default string token to match against so the popup behavior
              can be attached.
      "[600,400]" is the (optional) size of the newly created window.
      
    optionally, you can specify an "r" parameter like this:
      "[600,400,r]" that will allow the window to be resizable.
*/

var moopop = {
  width: 0,
  height: 0,

  captureByRel: function(attrVal, parent) {
    this.capture((parent || document).getElements('a[rel*=' + (attrVal || 'popup') +']'));
  },
  
  capture: function(el, width, height) {
    if ($defined(width) && $defined(height)) {
      this.width = width;
      this.height = height;
    }

    switch ($type(el)) {
      case 'string':
        el = $$(el);
      case 'element':
      case 'array':
        $splat(el).each(this.add_pop_to, this);
    }

    this.width = null;
    this.height = null;
  },
  
  add_pop_to: function(el) {
    el.addEvent('click', function(e){ e.stop(); this.popup(el); }.bind(this));

    var size = el.get('rel').match(/\[(\d+),\s*(\d+)/) || ['', this.width, this.height];
    var resizable = el.get('rel').match(/,(r)/) || [];

    if (size[1]) el.store('popupprops', 'width=' + size[1] + ', height=' + size[2] + (resizable[1] ? ', scrollbars=yes, resizable=yes' : '') );
  },
  
  popup: function(el) {
    window.open(el.get('href'), el.get('name') || '', el.retrieve('popupprops') || '');
  }
};


sfHover = function() {
	var sfEls = document.getElementById("primaryNavigation").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);