
// launches links in new windows - workaround for strict mode that doesn't support the 'target' attribute
function externalLinks() { 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank"; 
	}
}

// validates urls and adds 'http://' if missing
function validateURL(hrefObject) {
    var url = hrefObject.value;
	var urlPrefix = url.substring(0,7);
	if((urlPrefix != "http://") && (urlPrefix != "https:/")) {
		if(url.length != 0) {
		    hrefObject.value = "http://" + url;
		}
	}
}

// initializes textboxes to remove/replace default text when clicked
function SmartInputTextbox(box) {
	this.defaultValue = box.value;
	var me = this;
	$(box).focus(function(){
		if (this.value == me.defaultValue) {
			this.value = '';
		}
	});
	$(box).blur(function(){
		if (this.value == '') {
			this.value = me.defaultValue;
		}
	});
}

//////////////////////////////////////////////////////////////////////////////////

// manages subnav rollover DHTML menus
function RolloverManager(navId) {
	this.navId = navId;
	this.navLinks = $('#' + navId + ' li a');
	this.subnavs = new Array();
	this.navWidth = $('#' + navId).width();
	this.navLeft = ($('#' + navId).offset()).left;
	for (var i=0; i < this.navLinks.length; i++) {
		this.navLinks[i] = new RolloverMenuItem(this.navLinks[i],this);
	}
}
function RolloverMenuItem(menuItem, rolloverMgr) {
	this.menuItem = menuItem;
	this.mgr = rolloverMgr;
	if (this.subnav = $('#sub' + this.menuItem.id).get(0)) {	
		var me = this;
		this.mgr.subnavs.push(this.subnav);
		// set primary nav mousover event
		$(this.menuItem).mouseover(function(){
			me.showNav();
		});
		// set primary nav mouseout event
		$(this.menuItem).mouseout(function(){
			me.hideNav();
		});
	}
}
RolloverMenuItem.prototype.showNav = function() {
	var me = this;
	clearTimeout(this.mgr.navTimer);
	// hide any visible subnav before displaying a new one
	$(this.mgr.subnavs).each(function(){
		$(this).hide();
	});
	// set mouseover/mouseout events for subnav (b/c it will disappear when you leave the primary nav)
	$(this.subnav).mouseover(function(){
		clearTimeout(me.mgr.navTimer);
		$(this).show();
	});
	$(this.subnav).mouseout(function(){
		me.hideNav();
	});
	$(this.subnav).show();
}
RolloverMenuItem.prototype.hideNav = function(){
	var me = this;
	clearTimeout(this.mgr.navTimer);
	// set a slight delay on hiding the nav
	this.mgr.navTimer = setTimeout( function() {
		$(me.subnav).hide();
	}, 200)
}

//////////////////////////////////////////////////////////////////////////////////

$(document).ready(function() {
	
	externalLinks();
	
	// initialize nav rollovers
	var navMgr = new RolloverManager('nav');
	
	$("input").each(function(){
		if (this.type == 'text')
			var inputBox = new SmartInputTextbox(this);
	});

});

function close_set_list(number) {
	$("#set_list_" + number).css("display", "none");
}
 
function open_set_list(number) {
	$("#set_list_" + number).css("display", "block");
	$("#set_list_" + number).draggable({ handle: '.drag_handler', stack: { group: '.set_list' , min: 50 } });
}
 
