/*$.backstretch("/-/img/bg-alt.jpg", {speed: 150});*/

$(document).ready(function() {
	
	$('#home-nav a').click(function() {
		var id = $(this).attr('id').split('-');
		$('.tab').hide();
		$('#tab-'+id[1]).show();
		$('#home-nav a').removeClass('on');
		$('#btn-media').removeClass('no-border');
		$(this).addClass('on');
		return false;
	});
	
	$('#nav-home, #logo').click(function() {
		$('.tab').hide();
		$('#home-slides').show();
		$('#home-nav a').removeClass('on');
		$('#btn-media').addClass('no-border');
	});

	

	//On Hover Over
function megaHoverOver(){
    $(this).find('.sub').stop().fadeTo(250, 1).show(); //Find sub and fade it in
    $(this).children('a:first').addClass('on');
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find('ul').each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    
}
//On Hover Out
function megaHoverOut(){
  $(this).removeClass('on').find('.sub').stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
  $(this).children('a:first').removeClass('on');
}

var config = {
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
     interval: 100, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 500, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};

$('ul#nav li .sub').css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$('ul#nav li.dd').hoverIntent(config); //Trigger Hover intent with custom configurations

$('#home-slides').slides({
		preload: true,
		preloadImage: '-/img/loading.gif',
		play: 3500,
		pause: 3500,
		container: 'slides',
		hoverPause: true
	});
	
// Placeholder text for input boxes
	$("input[type=text]").each(function() {
		$(this).attr("default", $(this).attr("value"));
	
		$(this).focus(function() {
			if ($(this).attr("value") == $(this).attr("default")) {
				$(this).attr("value", "");
			}
		}).blur(function() {
			if ($(this).attr("value") == "") {
				$(this).attr("value", $(this).attr("default"));
			}
		});
	});

// Uniform Select Dropdowns
$('select#filter-ministry, select#filter-classes').uniform();
$('#filter-ministry').change(function(){
	var v = $('#filter-ministry option:selected').attr('value');
	window.location.href = '/events/' + v;
});
$('#filter-classes').change(function(){
	var v = $('#filter-classes option:selected').attr('value');
	window.location.href = '/classes/' + v;
});

});
