/* -- -- -- -- -- -- --
 * ets.js
 * -- -- -- -- -- -- --
 */

var curve4_settings = { tl: { radius: 4 }, tr: { radius: 4 }, bl: { radius: 4 }, br: { radius: 4 }, antiAlias: true };
var curve6_settings = { tl: { radius: 6 }, tr: { radius: 6 }, bl: { radius: 6 }, br: { radius: 6 }, antiAlias: true };
var curve8_settings = { tl: { radius: 8 }, tr: { radius: 8 }, bl: { radius: 8 }, br: { radius: 8 }, antiAlias: true };
var curve10_settings = { tl: { radius: 10 }, tr: { radius: 10 }, bl: { radius: 10 }, br: { radius: 10 }, antiAlias: true };
var curve12_settings = { tl: { radius: 12 }, tr: { radius: 12 }, bl: { radius: 12 }, br: { radius: 12 }, antiAlias: true };

var now = new Date();
var cya_year = now.getFullYear();

$(document).ready(function(){

	// supply the year at the bottom of the page
	$('#cya-year').text(cya_year + " ");

	$('#center-content ul + ul').css('margin-top','2em');

	// start: nav item cleanup
	$('div#site-nav ul#site-nav-top li::last-child').addClass('last');
	$('div#section-navigation ul#section-nav li:last').addClass('last');
	$('div#section-navigation ul.subnav li:last').addClass('last');
	$('div#corp-links ul li:last').addClass('last');
	$('.important-update p:last-child').addClass('last');
	$('.feature p:last-child').addClass('last');
	$('.ad-banner p:last-child').addClass('last');
	// end: nav item cleanup

	// start: corp-nav-top suckerfish trigger
	$("#site-nav-top li").hover(
		function(){ $("ul", this).fadeIn("fast"); },
		function(){ $("ul", this).fadeOut(""); }
	);
	if (document.all) { $("#site-nav-top li").hoverClass ("sfHover"); }
	// end: corp-nav-top suckerfish trigger

	// start: section-navigation suckerfish trigger
	$("#section-navigation li").hover(
		function(){ $("ul", this).fadeIn("fast"); },
		function(){ $("ul", this).fadeOut("slow"); }
	);
	if (document.all) { $("#section-navigation li").hoverClass ("sfHover"); }
	// end: section-navigation suckerfish trigger

	$('.rounded-border').addClass('{transparent}').corners('4px');
	$('.rounded-noborder').addClass('{transparent}').corners('4px');
	$('.important-update').addClass('{transparent}').corners('10px');
	$('.content-box').addClass('{transparent}').corners('10px');
	$('.banner-box').addClass('{transparent}').corners('10px');
	$('.feature').addClass('{transparent}').corners('10px');
	$('.ad-banner').addClass('{transparent}').corners('10px');

	// start: left (main) navigation
	$('.nav-box').addClass('{transparent}').corners('10px');
	$('#main-navigation li span.has-arrow').parent().addClass('white-bkgrnd').attr('margin','8px 0').addClass('{transparent}').corners('8px');
	$('#main-navigation li span.has-arrow').parent().css('width','185px');
	$('#main-navigation ul.subnav li:last').css('margin-bottom','-1px');
	$('#main-navigation .nav-box ul.subnav:first').prevAll().css('margin-top','5px');
	// end: left (main) navigation

	// start: safari only
	if ($.browser.safari) { $('.go-button').css('padding', '3px'); }
	// end: safari only

	// start: msie only
	if ($.browser.msie) {
		$('a.action-button td').css('font-weight','bold');
		$('a.action-button td').css('line-height','1em');
		try{ curvyCorners( curve12_settings, document.getElementById("promo-wrap-1") ) } catch(error){}
		try{ curvyCorners( curve12_settings, document.getElementById("promo-wrap-2") ) } catch(error){}
	} else {
		$('.promo-wrap').addClass('{transpaernt}').corners('10px');
	}
	// end: msie only

	// work some functionality for anchors with 'class="bookmarkfunction"'
	$('a.bookmarkfunction').each(function (i){
		$(this).click(function(event) {
			event.preventDefault();
			url = window.location;
			title = jQuery('title').html();
			if( window.sidebar ) {
				// Mozilla Firefox Bookmark
				try{
					window.sidebar.addPanel(title, url,"");
				} catch(error){
					alert("To bookmark this page in Mozilla, use CTRL + D");
				}
			} else if( window.external ) {
				// IE Favorite
				try{
					window.external.AddFavorite( url, title);
				} catch(error){
					alert("To bookmark this page in Internet Explorer, use CTRL + D");
				}
			} else if( window.opera && window.print ) {
				// Opera Hotlist
				try{
					return true;
				} catch(error){
					alert("To bookmark this page in Opera, use CTRL + T");
				}
			}

		}); // end this.click
	}); // end: a.bookmarkfunction each

	// work some functionality for anchors with 'class="popup"'
	$('a.popup').each(function (i){
		$(this).click(function(event) {
			event.preventDefault();
			if( $(this).attr('class') ) {
				var pop_width = 800;
				var pop_height = 600;
				var class_info = $(this).attr('class');
				var regexp = /(h-\d+|w-\d+)/gi;
				var info = class_info.match(regexp);
				info.forEach(function(x,idx){
					if( /w-\d+/.test(x) ){ pop_width = x.substr(2); }
					if( /h-\d+/.test(x) ){ pop_height = x.substr(2); }
				});
			}
			pop_url = $(this).attr('href');
			pop_window = window.open( pop_url,
			                          "ets_pop",
			                          "location=1,resizable=1,scrollbars=1,status=1,width="+pop_width+",height="+pop_height
			                        );
		}); // end this.click
	}); // end: a.popup each

}); // end: document.ready

// suckerfish navigation functionality
$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover(
			function() { $(this).addClass(c); },
			function() { $(this).removeClass(c); }
		);
	});
};

// IE has some forEach problems.
if (!Array.prototype.forEach) {
	Array.prototype.forEach = function(fun /*, thisp */) {
		var len = this.length;
		if (typeof fun != "function")
			throw new TypeError();

		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in this)
				fun.call(thisp, this[i], i, this);
		}
	};
}

