/* Author: 
*/

$(document).ready(function() {
	
	$('#subMenu ul').initMenu();

	//if ($.browser.msie) { $(".shadow").boxShadow( 3,3,5, "#888" ); }
	var url = $.url().attr('file'); // for determining the current page we're viewing
	var baseUrl = $.url().attr('file').split("-");
	$("#nav ul li").click(function() { // Make the menu div clickable to the link inside it.
			window.location=$(this).find("a").attr("href");
			return false;
	});
	
	if ($.browser.msie && $.browser.version=="6.0") { // only allow a hover class for ie6
		$("#nav ul li").hover( function() {
			$(this).toggleClass('hover');
		},function(){
			$(this).toggleClass('hover');
		});	
	}
	if ((baseUrl[0].toLowerCase() == 'news') || (url.toLowerCase() == 'news.html')) { // Only show scrollable news article list on News Page
		$('#newsMenu').jcarousel({  // jcarousel home page: http://sorgalla.com/projects/jcarousel/
			vertical: true,			// jcarousel forum: https://github.com/jsor/jcarousel/issues?sort=created&direction=desc&state=open
			scroll: 2
		});
	}
	
	if (url.toLowerCase() != 'home.html') { // Show custom scroll bar on ANY secondary page, if needed
		if ($("#longArticle").length != 0) { //check if there exists an id of 'longNews' for custom scrollbar
			$("#longArticle").mCustomScrollbar("vertical",400,"easeOutCirc",1.02,"auto","yes","no",0); // for custom scrollbars
		}
	}
	
	// The following is only for the home page rotating image banner
	if ((url.toLowerCase() == 'home.html') || (url == '')) {
		var onMouseOutOpacity = 0.67;
		$('#js-thumbs ul.thumbs li').opacityrollover({
					mouseOutOpacity:   onMouseOutOpacity,
					mouseOverOpacity:  1.0,
					fadeSpeed:         'fast',
					exemptionSelector: '.selected'
				});
	    var gallery = $('#js-thumbs').galleriffic({ // Home Page at: http://www.twospy.com/galleriffic/index.html
													// Updates/comments at: http://code.google.com/p/galleriffic/updates/list
        delay:                     5000, // in milliseconds
        numThumbs:                 3, // The number of thumbnails to show page
        preloadAhead:              3, // Set to -1 to preload all images
        enableTopPager:            false,
        enableBottomPager:         false,
        imageContainerSel:         '#js-bigbox', // The CSS selector for the element within which the main slideshow image should be rendered
        controlsContainerSel:      '.controls', // The CSS selector for the element within which the slideshow controls should be rendered
        captionContainerSel:       '.caption-container', // The CSS selector for the element within which the captions should be rendered
        //loadingContainerSel:       '', // The CSS selector for the element within which should be shown when an image is loading
        renderSSControls:          true, // Specifies whether the slideshow's Play and Pause links should be rendered
        renderNavControls:         false, // Specifies whether the slideshow's Next and Previous links should be rendered
        playLinkText:              '',
        pauseLinkText:             '',
        //prevLinkText:              'Previous',
        //nextLinkText:              'Next',
        //nextPageLinkText:          'Next &rsaquo;',
        //prevPageLinkText:          '&lsaquo; Prev',
        //enableHistory:             false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes
        //enableKeyboardNavigation:  true, // Specifies whether keyboard navigation is enabled
        autoStart:                 true, // Specifies whether the slideshow should be playing or paused when the page first loads
        syncTransitions:           true, // Specifies whether the out and in transitions occur simultaneously or distinctly
        defaultTransitionDuration: 2000, // If using the default transitions, specifies the duration of the transitions
        //onSlideChange:             undefined, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
        onSlideChange: function(prevIndex, nextIndex) {
			this.find('ul.thumbs').children()
				.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 1.0);
		},
		//onTransitionOut:           undefined, // accepts a delegate like such: function(slide, caption, isSync, callback) { ... }
        //onTransitionIn:            undefined, // accepts a delegate like such: function(slide, caption, isSync) { ... }
        //onPageTransitionOut:       undefined, // accepts a delegate like such: function(callback) { ... }
		onPageTransitionOut: function(callback) {
			this.fadeTo('fast', 0.0, callback);
		},
		onPageTransitionIn: function() {
			this.fadeTo('fast',1.0);
		}
        //onPageTransitionIn:        undefined, // accepts a delegate like such: function() { ... }
        //onImageAdded:              undefined, // accepts a delegate like such: function(imageData, $li) { ... }
        //onImageRemoved:            undefined  // accepts a delegate like such: function(imageData, $li) { ... }
    });
	}
	
	// The following is NOT for the home page rotating image banner
	if ((url.toLowerCase() != 'home.html') && (url != '') && ($('#rightBox:hidden').length === 0)) {
		var onMouseOutOpacity = 0.67;
		$('#galleryThumbs ul.thumbs li').opacityrollover({
					mouseOutOpacity:   onMouseOutOpacity,
					mouseOverOpacity:  1.0,
					fadeSpeed:         'fast',
					exemptionSelector: '.selected'
				});
	    var gallery = $('#galleryThumbs').galleriffic({ // Home Page at: http://www.twospy.com/galleriffic/index.html
													// Updates/comments at: http://code.google.com/p/galleriffic/updates/list
        delay:                     5000, // in milliseconds
        numThumbs:                 5, // The number of thumbnails to show page
        preloadAhead:              8, // Set to -1 to preload all images
        enableTopPager:            false,
        enableBottomPager:         false,
		controlsContainerSel:   '#controls',
        imageContainerSel:         '#galleryBigbox', // The CSS selector for the element within which the main slideshow image should be rendered
        captionContainerSel:       '.caption-container', // The CSS selector for the element within which the captions should be rendered
        renderSSControls:          false, // Specifies whether the slideshow's Play and Pause links should be rendered
        renderNavControls:         true, // Specifies whether the slideshow's Next and Previous links should be rendered
        prevLinkText:              '',
        nextLinkText:              '',
        //nextPageLinkText:          'Next &rsaquo;',
        //prevPageLinkText:          '&lsaquo; Prev',
        autoStart:                 false, // Specifies whether the slideshow should be playing or paused when the page first loads
        syncTransitions:           true, // Specifies whether the out and in transitions occur simultaneously or distinctly
        defaultTransitionDuration: 1000, // If using the default transitions, specifies the duration of the transitions
        onSlideChange: function(prevIndex, nextIndex) {
			this.find('ul.thumbs').children()
				.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 1.0);
		}

    });
	}
	
});

jQuery.fn.initMenu = function() {
	$('.ul-0 .ul-1').hide(); //ul-0 is base "menu" class
	if ($('.SubCurrent').length>0) {
		$('.ul-0 .SubCurrent .ul-1').show();
	} else {
		$('.ul-0 .ul-1:first').show(); 
	}
	$('.ul-0 li div').click(
		function() {
			var checkElement = $(this).next();
			if ((checkElement.is('.ul-1')) && (checkElement.is(':visible'))) {
				window.location.href=$(this).find("a").attr("href");
				return false;
			}
			if((checkElement.is('.ul-1')) && (!checkElement.is(':visible'))) {
				$('.ul-0 .ul-1:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}

/* jQuery functions for form: */

$(document).ready(function(){
	$('#password-password').hide();
	$('#password-clear').show();

	$('#password-clear').focus(function() {
    	$('#password-clear').hide();
    	$('#password-password').show();
    	$('#password-password').focus();
	});
	$('#password-password').blur(function() {
    	if($('#password-password').val() == '') {
        	$('#password-clear').show();
        	$('#password-password').hide();
    	}
	});
	
	$('.default-value').each(function() {
		var default_value = this.value;
    	$(this).focus(function() {
        	if(this.value == default_value) {
            	this.value = '';
        	}
    	});
    	$(this).blur(function() {
        	if(this.value == '') {
            	this.value = default_value;
        	}
    	});
	});

});

/* End jQuery */


