if (document.getElementById) {

    $(document).ready(function(){
        checkLinks();
        initTabSwitching();
        initPaymentSelectLinks();
        
        //$('.img-info').focus( function() { alert("Hello"); } );
        
        if ($.fn.Tooltip) { // check if Tooltip script available
            $('.img-info').Tooltip({
              track:false,
              delay:0,
              showURL:false
            });
        }
        if ($.fn.autocomplete) { // check if Autocomplete script available
            $(".ac-me").autocomplete("search.txt", { 
                minChars:3, 
                matchSubset:1, 
                matchContains:1, 
                cacheLength:10, 
                onItemSelect:selectItem, 
                formatItem:formatItem, 
                selectOnly:1 
            });
        }
    });
    
    
    /*
     * Certain tabs can be switched through clicking. The contents of all tabs are preloaded
     * when the html page is loaded, but only those with "on" class are initially displayed.
     */
    function initTabSwitching() {
        // hide all tab sections where tab does not have "on" class
        $('div.tab li.on a').each(function(){
            $('div.tab div.' + $(this).attr("class")).show().siblings('.tab-d').hide();
        });
        // event-handler for tabs (displays corresponding tab section)
        $('div.tab div.tab-h a').click( function() {
            $(this).parent().addClass('on').siblings('.on').removeClass('on');
            $('div.tab div.' + $(this).attr("class")).show().siblings('.tab-d').hide();
            return false;
        });
    }
    
    /*
     * Certain links within payment boxes (with class "pay-select") cause hidden
     * sections to expand when clicked.
     */
    function initPaymentSelectLinks() {
        $('.payment a.pay-select').each(function(){
            $(this).parent().parent().find('form').hide();
        });
        $('.payment a.pay-select').click( function() {
            var $form = $(this).parent().next();
            if ($form.css("display") == "none") {
                $(this).parent().parent().find('form').hide();
                $('.payment a.pay-select').removeClass('selected');
                $(this).addClass('selected');
                $form.show();
            } else {
                $(this).parent().parent().find('form').hide();
                $('.payment a.pay-select').removeClass('selected');
            }
            return false;
        });
    }

	// Links
	function checkLinks() {
		if (document.getElementsByTagName) {
			var objAnchors = document.getElementsByTagName('a');
			var linkTitlePrefix, linkTitleHint;
			for (var i=0; i<objAnchors.length; i++) {
				if (objAnchors[i].getAttribute('href') && (objAnchors[i].getAttribute('rel') == 'external')) {
					objAnchors[i].onclick = function(evt) {
						return launchWindow(this, evt);
					}
					objAnchors[i].onkeypress = function(evt) {
						return launchWindow(this, evt);
					}
				}
			}
		}
	}
    
    // Windows
	function launchWindow(objAnchor, objEvent, width, height) {
		var iKeyCode;
		if (objEvent && objEvent.type == 'keypress') {
			if (objEvent.keyCode) {
				iKeyCode = objEvent.keyCode;
			} else if (objEvent.which) {
				iKeyCode = objEvent.which;
			}
			if (iKeyCode != 13 && iKeyCode != 32) {
				return true;
			}
		}
		var win = window.open(objAnchor,'win','scrollbars=yes,resizable=yes,location=yes,menubar=yes,status=yes,toolbar=yes');
		win.focus();
		return false;
	}
	
	function showfirstnewstab()
	{
		var firstnewstab = document.getElementById('newstab1');
		if (firstnewstab!=null)
		{
			firstnewstab.style.display = 'block';
		}
		for (var i=2; i<=newstabcount; i++)
		{
			var currentnewstab = document.getElementById('newstab' + i.toString());
			if (currentnewstab!=null)
			{
				currentnewstab.style.display = 'none';
			}
		}
	}

	function shownextnewstab()
	{
		if ((currentnewstabpos+1)<=newstabcount)
		{
			var newnewstabposition = currentnewstabpos+1;
			var nextnewstab = document.getElementById('newstab' + newnewstabposition.toString());
			if (nextnewstab!=null)
			{
				hideallnewstabs();
				nextnewstab.style.display = 'block';
			}
		}
	}

	function hideallnewstabs()
	{
		for (var i=1; i<=newstabcount; i++)
		{
			var currentnewstab = document.getElementById('newstab' + i.toString())
			if (currentnewstab!=null)
			{
				currentnewstab.style.display = 'none';
			}
		}
	}

	function showfirstnewstab()
	{
	}

	function showfirstnewstab()
	{
	}

	function showfirstnewstab()
	{
	}
}
