
(function($) {
	// our global variables
	var _current 	= 0; // current active child-object in the big list
	var _timeout 	= null; // timeout variable for the auto slider
	
	$.fn.crusaderSlider = function(options) {
		var _object		= $(this);
		var _content 	= $(this).find('ul'); // main slider content selection
		var _li			= $(this).find('li');
		var _each_length = 70;
		// alert(_length);
		if(!_li.length){
			return;
		} 
		var _length		= _li.length * _each_length;
		$(_content).width(_length);

		// handle previous/next navigation
		$(_object).find('.buttons').children('.prev').children('a').click(function(){

			if(_current == 0) {
				_current = $(_content).children('li').length - 7;
			} else {
				_current -= 1;
			}
			
			mainAction(_current);
			
			return false;
		});

		$(_object).find('.buttons').children('.next').children('a').click(function(){


			if(_current >= $(_content).children('li').length - 7) {
				_current = 0; 
			} else {
				_current += 1;
			}
			
			mainAction(_current);
			
			return false;
		});

		function mainAction(_current) {
			$(_content).animate({'margin-left': -(_current * _each_length)}, 800); 
		}
		

	}
})(jQuery);



(function($) {
	// our global variables
	var _current 	= 0; // current active child-object in the big list
	var _timeout 	= null; // timeout variable for the auto slider
	
	$.fn.thumbnailSlider = function(options) {
		var _object		= $(this);
		var _content 	= $(this).find('ul'); // main slider content selection
		var _li			= $(this).find('li');
		var _each_length = 120;
		// alert(_length);
		if(!_li.length){
			return;
		} 
		var _length		= _li.length * _each_length;
		$(_content).width(_length);

		// handle previous/next navigation
		$(_object).find('.buttons').children('.prev').children('a').click(function(){

			if(_current == 0) {
				_current = $(_content).children('li').length - 4;
			} else {
				_current -= 1;
			}
			
			mainAction(_current);
			
			return false;
		});

		$(_object).find('.buttons').children('.next').children('a').click(function(){


			if(_current >= $(_content).children('li').length - 4) {
				_current = 0; 
			} else {
				_current += 1;
			}
			
			mainAction(_current);
			
			return false;
		});

		function mainAction(_current) {
			$(_content).animate({'margin-left': -(_current * _each_length)}, 800); 
		}
		

	}
})(jQuery);

(function($){
    //Resize image on ready or resize
    $.fn.supersize = function() {  
        //Invoke the resizenow() function on document ready
        $(document).ready(function() {
            $('#supersize').resizenow();
        });
        //Invoke the resizenow() function on browser resize
        $(window).bind("resize", function() {
            $('#supersize').resizenow();
        });
    };
    //Adjust image size
    $.fn.resizenow = function() {
        //Define starting width and height values for the original image
        var startwidth = 900;  
        var startheight = 600;
        //Define image ratio
        var ratio = startheight/startwidth;
        //Gather browser dimensions
        var browserwidth = $(window).width();
        // var browserheight = $(window).height();
		
        //Resize image to proper ratio
		// if ((browserheight/browserwidth) > ratio) {
            // $(this).height(browserheight);
            // $(this).width(browserheight / ratio);
            // $(this).children().height(browserheight);
            // $(this).children().width(browserheight / ratio);
        // } else {
            $(this).width(browserwidth);

            $(this).height(browserwidth * ratio);
            $(this).children().width(browserwidth);
            $(this).children().height(browserwidth * ratio);

        // }
	// if(browserwidth > 980 && browserheight > 800) {

	        //Make sure the image stays center in the window
	    $(this).children().css('left', (browserwidth - $(this).width())/2);
	    $(this).children().css('top', 0);
		// } else {
			
		// }
       
    };
})(jQuery);

$(window).bind("resize", function(){
    $('#supersize').resizenow();
});

$().ready(function(){
	
	
	// SOME LHS MENU FUNCTIONS

	$(".page ul.children").not('li ul .children').not('li ul li a').hide(function() {
	  $(".page ul.children li ul.children").show();
	  $(".page .current_page_item").parent().show();
	  $(".page .current_page_item").parent().parent().show();
	  $(".page .current_page_item").parent().parent().parent().show();
	  $(".page .current_page_item .children").show();
	  $(".page .current_page_ancestor ul").show();
	});
	
/*	$(".page .children").not("li ul li a").not('.current_page_item ul').not('ul.children li ul.children').parent().hover(
	function(){
	$(this).children("ul").slideDown('fast');
	},
	  function () {
	    $(this).children("ul").slideUp('fast');
	  }
	);
	
*/	
	
	// SHOPIFY Expander Cue
	$('#shopify_container .expander p').expander({
	    slicePoint:       100,  // default is 100
	    expandText:         '[more]', // default is 'read more...'
	    // collapseTimer:    5000, // re-collapses after 5 seconds; default is 0, so no re-collapsing
	     userCollapseText: '[less]'  // default is '[collapse expanded text]'
	  });
	
	// prayer page
	
	$(".twitter-hash-tag-widget li:first").addClass("prayer-first-item");
	$('.sidebar-more .more-by li:last').addClass("last");
	$('.sidebar-more .in-category li:last').addClass("last");
	$('#supersize').resizenow(); 
	
	

	
	$('#top-nav li:last').addClass('last').addClass('flag');
	$('#footer-nav li:last, .sidebar .involve-links li:last, .sidebar .god-links li:last, .box-info dd .topics li:last, #main .sidebar.links .menu > li:last').addClass('last');
	
	
	$(".box-info dd .join .input")
	.css('color','#999999')
	.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
			$(this).css('color','#3a3a3a');
		}
	})
	.blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
			$(this).css('color','#999999');
		}
	});
	
	// hero nav
	$('#menu.home a').hover(function(){
		var _class = $(this).parent('li').attr('class');
		$('#content .section-1 .image dd:not(.' + _class + ')').hide();
		$('#content .section-1 .image dd.' + _class).fadeIn('slow');
	});
	
//	$('.thumbnailgrid').each(function(){
//		var _each_width = '65';
//		var _items = $(this).find('.wrap ul:first li').length;
//		var _width = _items * _each_width;
//		
//		$(this).width(_width + 20);
//	});
	
	$("a.fancybox").fancybox();
	

	$("a.youtube").click(function() {
         $.fancybox({
          'padding'             : 0,
          'autoScale'   : false,
          'transitionIn'        : 'none',
          'transitionOut'       : 'none',
          'title'               : this.title,
          'width'               : 680,
          'height'              : 495,
          'href'                : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
          'type'                : 'swf',    // <--add a comma here
          'swf'                 : {'allowfullscreen':'true','wmode':'transparent'} // <-- flashvars here
          });
         return false;

    }); 

	$('.casourel').crusaderSlider();
	$('.thumbnailslider').thumbnailSlider();
	
	//$(".page ul.children").parent().find("a").not("li ul li a").append(" +");  // this one works.. weirdly...
	//$(".page ul.children").parent().find("a").not("li ul li a").addClass("down_arrow");  // or.. sometimes this one works...
	
	$(".page ul.children").not('li ul .children').not('li ul li a').hide(function() {
	  $(".page ul.children li ul.children").show();
	  $(".page .current_page_item").parent().show();
	  $(".page .current_page_item").parent().parent().show();
	  $(".page .current_page_item").parent().parent().parent().show();
	  $(".page .current_page_item .children").show();
	  $(".page .current_page_ancestor ul").show();
	});
	
	
	$('.casourel a').hover(function(){
		var _url = $(this).attr('href');
		var _rel = $(this).attr('rel');
		var _path = $(this).parent('li').parent('ul').parent('.wrap').parent('.casourel').siblings('.thumbnail');
		
		_path.children('a').attr('href', _url);
		_path.find('img').attr('src', 'http://crusaders.edu.au/wp-content/themes/crusader/timthumb.php?src=' + _url + '&w=530&h=250&a=' + _rel).fadeIn();
		
		$(this).parent('li').parent('ul').find('li').removeClass('active');
		$(this).parent('li').addClass('active');
		
		return false;
	})
	$('.casourel ul li a').not('.next, .pref').fancybox();
	
	// Home Page Subscription Form UI Effects
	$('#input_1_1').focus(function() { this.select();});
	$('#input_1_2_3').focus(function() { this.select();});
	$('#input_1_2_6').focus(function() { this.select();});
	//$('#input_1_2_3').val('First Name');
	//$('#input_1_2_6').val('Last Name');
	
	$(".join").hover(
	  function () {
	     $('.join').animate({height: '100', top: '20'}, 200).animate({opacity: '+=0'}, 5000);
	  },
	  function () {
	     $('.join').animate({height: '70', top: '70'}, 180);
	  }
	);
	
});

