// Drop down navigation menu

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) 
	window.attachEvent("onload", sfHover);



$(document).ready(function() {
	// ###   Supersized setting for page background images   ###
	if ( $("#supersize.single-image").length ) {
		$(function() {
			$.fn.supersized.options = {  
				startwidth: 1800,  
				startheight: 800,
				vertical_center: 0,
				slideshow: 0,
				navigation: 1,
				transition: 1, // 0-None, 1-Fade
				pause_hover: 0,
				slide_counter: 1,
				slide_captions: 1,
				slide_interval: 0  
			};
	        	$('#supersize').supersized(); 
    		});

	} else {
		$(function() {
			$.fn.supersized.options = {  
				startwidth: 1800,  
				startheight: 800,
				vertical_center: 1,
				slideshow: 1,
				navigation: 1,
				transition: 1, // 0-None, 1-Fade
				pause_hover: 0,
				slide_counter: 1,
				slide_captions: 1,
				slide_interval: 5000  
			};
	        	$('#supersize').supersized(); 
    		});
	}

	if ( $('form.required-form').length ) {
		$('form.required-form').simpleValidate({
			errorElement: 'em'
		});
	}

	if ( $(".jMyCarousel").length ) {
		//###   Get current ID   ###
		var CurrentID = $(".jMyCarousel").attr("title");
		var $CurrentThumb = $(".jMyCarousel").find("a[rel='"+CurrentID+"']");
		var Offset = 171 * $(".jMyCarousel").find("a").index($CurrentThumb);
		

		$(".jMyCarousel").jMyCarousel({
			visible: '5',
			speed:350,
			circular:true,
			start: Offset,
			btnPrev: $('#prevBtn'),
			btnNext: $('#nextBtn')
		});
	}

	if ( $("#gallery").length ) {

				// We only want these styles applied when javascript is enabled
				$('div.navigation').css({'width' : '120px', 'float' : 'left'});
				$('div.gallery-content').css('display', 'block');

				// Initially set opacity on thumbs and add
				// additional styling for hover effect on thumbs
				var onMouseOutOpacity = 0.67;
				$('#thumbs ul.thumbs li').opacityrollover({
					mouseOutOpacity:   onMouseOutOpacity,
					mouseOverOpacity:  1.0,
					fadeSpeed:         'fast',
					exemptionSelector: '.selected'
				});
				
				// Initialize Advanced Galleriffic Gallery
				var gallery = $('#thumbs').galleriffic({
					delay:                     2500,
					numThumbs:                 4,
					preloadAhead:              4,
					enableTopPager:            false,
					enableBottomPager:         false,
					maxPagesToShow:            1,
					imageContainerSel:         '#slideshow',
					controlsContainerSel:      '#controls',
					captionContainerSel:       '#caption',
					loadingContainerSel:       '#loading',
					renderSSControls:          false,
					renderNavControls:         false,
					playLinkText:              'Play Slideshow',
					pauseLinkText:             'Pause Slideshow',
					prevLinkText:              '&lsaquo; Previous Photo',
					nextLinkText:              'Next Photo &rsaquo;',
					nextPageLinkText:          'Next &rsaquo;',
					prevPageLinkText:          '&lsaquo; Prev',
					enableHistory:             false,
					autoStart:                 false,
					syncTransitions:           true,
					defaultTransitionDuration: 900,
					onSlideChange:             function(prevIndex, nextIndex) {
						// 'this' refers to the gallery, which is an extension of $('#thumbs')
						this.find('ul.thumbs').children()
							.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
							.eq(nextIndex).fadeTo('fast', 1.0);
					},
					onPageTransitionOut:       function(callback) {
						this.fadeTo('fast', 0.0, callback);
					},
					onPageTransitionIn:        function() {
						this.fadeTo('fast', 1.0);
					}
				});
	}
});


$(document).ready(function() {
	if ($("body.home").length) {
		// Simple jQuery slideshow Script Released by Jon Raasch (jonraasch.com)
		setInterval( "slideSwitchHome()", 5000 );
	} else if ( $("#sola-slideshow").length ) {
		setInterval( "slideSwitch()", 2500 );
	}
});

function slideSwitchHome() {
	var $active = $('#sola-home-slideshow IMG.active');
	
	if ( $active.length == 0 )
		$active = $('#sola-home-slideshow IMG:last');
	
	// use this to pull the images in the order they appear in the markup
	var $next = $active.next().length ? $active.next() : $('#sola-home-slideshow IMG:first');
	
	// uncomment the 3 lines below to pull the images in random order
	    
	// var $sibs  = $active.siblings();
	// var rndNum = Math.floor(Math.random() * $sibs.length );
	// var $next  = $( $sibs[ rndNum ] );
	
	$active.addClass('last-active');
	
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}//###   End of slideSwitchHome Function   ###


// Simple jQuery slideshow Script Released by Jon Raasch (jonraasch.com)
function slideSwitch() {
	    var $active = $('#sola-slideshow IMG.active');
	
	    if ( $active.length == 0 ) $active = $('#sola-slideshow IMG:last');
	
	    // use this to pull the images in the order they appear in the markup
	    var $next =  $active.next().length ? $active.next()
	        : $('#sola-slideshow IMG:first');
	
	    // uncomment the 3 lines below to pull the images in random order
	    
	    // var $sibs  = $active.siblings();
	    // var rndNum = Math.floor(Math.random() * $sibs.length );
	    // var $next  = $( $sibs[ rndNum ] );
	
	
	    $active.addClass('last-active');
	
	    $next.css({opacity: 0.0})
	        .addClass('active')
	        .animate({opacity: 1.0}, 1000, function() {
	            $active.removeClass('active last-active');
	        });
}//###   End of slideSwitch Function   ###
	


$(document).ready(function(){
	if ($("#accordion").length) {
	
		//Set default open/close settings
		$('.acc_container').hide(); //Hide/close all containers
		//$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container
 
		//On Click
		$('.acc_trigger').click(function(){
			if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
				$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
					$(this).toggleClass('active').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
				}
			return false; //Prevent the browser jump to the link anchor
		});
	}
});
