var _G = GEL,
    _GC = _G.config,
    _I = _G.thepage.initializer,
    _UA = _G.env.ua;
_G.Element.Script.prototype.attachToElement = document.body;

var _windowURL = window.location.href;
function getURLParameterByName(name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(_windowURL);
	if (results == null)
		return "";
	else
		return decodeURIComponent(results[1].replace(/\+/g, " "));
}
if (_windowURL.indexOf("alias=") != -1 && _windowURL.indexOf("usat-vocdevweb") != -1)
	_GC.AdPage = getURLParameterByName("alias");

_I.add({
    name: "search",
    priority: 1,
    //namespace: "org.jQuery",
    callback: function () {
        (function (jQuery) { jQuery.fn.autofill = function (options) { var defaults = { value: 'First Name', defaultTextColor: "#b2adad", activeTextColor: "#333" }; var options = jQuery.extend(defaults, options); return this.each(function () { var obj = jQuery(this); obj.css({ color: options.defaultTextColor }).val(options.value).focus(function () { if (obj.val() == options.value) { obj.val("").css({ color: options.activeTextColor }); } }).blur(function () { if (obj.val() == "") { obj.css({ color: options.defaultTextColor }).val(options.value); } }); }); }; })(jQuery);
        jQuery('#googleSearch').autofill({
            value: 'Google',
            defaultTextColor: '#999',
            activeTextColor: '#000'
        });
        jQuery('#djSymb').autofill({
            value: 'Enter symbol(s)',
            defaultTextColor: '#999',
            activeTextColor: '#000'
        });
    }
});
_I.add({
    name: "toggleCaption",
    priority: 50,
    //namespace: ["org.jQuery"],
    callback: toggleCaption
});


_I.add({
    name: "tabs",
    priority: 5,
    namespace: ["widget.GELTabs", "anim.YUIAnimator"],
    callback: initTabs
});

function toggleCaption() {
	if (jQuery(".photo-caption-text").length > 0) {
		var captionLength = jQuery(".photo-caption-text").html().length;
		if (captionLength < 1)
		{ jQuery(".photo-caption-toggle .caption").css({ 'visibility': 'hidden' }) }
		else {
			jQuery(".photo-caption-toggle .caption").css({ 'visibility': 'visible' });
			jQuery("#caption-toggle").toggle(
					function () {
						jQuery(".photo-caption").css({ "visibility": "hidden" });
						jQuery("#caption-toggle.caption-toggle").css({ "background-position": "0px -11px" });
					},
					function () {
						jQuery(".photo-caption").css({ "visibility": "visible" });
						jQuery("#caption-toggle.caption-toggle").css({ "background-position": "0px -25px" });
					}
				);
			jQuery("#caption-toggle").click();
		}
	}
}

function initTabs() {
	if (jQuery("#conveyor").length > 0) {
		var _TP = _G.thepage;
		_TP.scrollTabs = new _G.widget.GELTabs("conveyor", {
			metaAnimationClass: GEL.anim.YUIAnimator.Scroller,
			autoRotate: true,
			rotationInterval: 20
		});

		_TP.scrollTabs.init();

		var _hiderList = _TP.foreach("a.hider", function () {
			var _g = _G.ement(this), _tabEl = (function (e) {
				var _e = e.nextSibling;
				while (_e && _e.nodeType != 1)
					_e = _e.nextSibling
				return _G.ement(_e);
			})(this);
			_g.on("click", function (t, e) {
				e.preventDefault();
				_tabEl.toggle();
				if (_tabEl.isVisible()) {
					_g.setHTML("Hide");
				} else {
					_g.setHTML("Show");
				}
			});
		});
	}
}


setTimeout(function () { _I.init(); }, 20);

