if (typeof PWCC == "undefined" || !PWCC) {
	//create PWCC namespace if it hasn't been done already
	PWCC = new Object();
}

PWCC.loader = function() {
	var $ = jQuery,
		$body,
		winHeightStyles = false,
		homeIntTwo = false,
		homeIntTwoContentHeight = 0;
		
	$(function(){
		$body = $('body');
		
		/* sort out nav heights and pad accordingly */
		$('#nav > li > a').css('height', 'auto').each(function(){
			var $this = $(this),
				aHeight = $this.height();				
				$this.css('padding-top', (112 - 13 - aHeight) + 'px');
		});
		
		if (($body.hasClass('home') == true) || ($body.hasClass('template-int2') == true)) {
			PWCC.equalHeight('.content-body'); // ie6 bug on int#2
		}
		
		//if ($body.hasClass('home') == true) {
			bodyToWinHeight();
			$body.resize(function(){bodyToWinHeight();});
		//}
		
		if ($body.hasClass('internal')) {
			gallerySlides();
		}
	});
	
	function bodyToWinHeight() {
		var winHeight = $(window).height(),
			bodyHeight = $body.height();
			
			if (bodyHeight < winHeight){
				PWCC.createStyleRule('body', 'min-height: ' + winHeight + 'px;');
				PWCC.createStyleRule('* html body', 'height: ' + winHeight + 'px;');
				winHeightStyles = true;
			}
			else if (winHeightStyles == true) {
				PWCC.createStyleRule('body', 'min-height: auto;', 'screen, projection, handheld');
				PWCC.createStyleRule('* html body', 'height: auto;', 'screen, projection, handheld');
				winHeightStyles = false; //as good as them not being set
			}
	}

	function gallerySlides() {
		var $gallerySlides = $('#slideshow'),
			$slides = $('img',$gallerySlides),
			jsSlides = PWCC.gallerySlides,
			
			nextShowing,
			nowShowing = 0,
			frequency = 5,
			animationSpeed = 1000;
		
		if (($gallerySlides.length >= 1) && (jsSlides)) {
			var jsSlidesEl = jsSlides.length;

			$slides.css('z-index', jsSlides.length + 1); // position on top of js added slides
			$slides.attr('id', 'slide' + (jsSlides.length + 1)); //name top slide
		
			for (var i=0; i<jsSlidesEl; i++){
				$gallerySlides.append('<img class="slide" id="slide' + (jsSlidesEl - i) + '" style="position: absolute; z-index:' + ((jsSlidesEl - i)) + ';" src="' + jsSlides[i] + '" />');
			}
			
			
			$slides = $('#slideshow > img'); //recache slides
			
			//set opacity of all jsSlides to 0
			$slides.stop().fadeTo(1, 0);
			$slides.eq(0).stop().fadeTo(1, 1);
			jsSlidesEl = $slides.length;

			//begin animation
			function nextSlide(){
				nextShowing = nowShowing + 1;
				if (nextShowing == jsSlidesEl) {
					nextShowing = 0;
					//fade in next showing
					$slides.eq(nextShowing).stop().fadeTo(animationSpeed, 1,function(){
						$slides.eq(nowShowing).stop().fadeTo(1,0);
					});
					
				}
				else {
					//fade out now showing
					$slides.eq(nextShowing).stop().fadeTo(1,1);
					$slides.eq(nowShowing).stop().fadeTo(animationSpeed, 0);
				}
				
				nowShowing = nextShowing;
				setTimeout(nextSlide, frequency * 1000);

			}
			setTimeout(nextSlide, frequency * 1000);
		}
	
	}
	
	
}();

PWCC.nav('#nav', 'sfhover');

PWCC.gallerySlides = new Array();
PWCC.gallerySlides[0] = "http://www.ruralfunds.com.au/images/slideshow/1.jpg";
PWCC.gallerySlides[1] = "http://www.ruralfunds.com.au/images/slideshow/2.jpg";
PWCC.gallerySlides[2] = "http://www.ruralfunds.com.au/images/slideshow/3.jpg";
PWCC.gallerySlides[3] = "http://www.ruralfunds.com.au/images/slideshow/4.jpg";
PWCC.gallerySlides[4] = "http://www.ruralfunds.com.au/images/slideshow/5.jpg";
PWCC.gallerySlides[5] = "http://www.ruralfunds.com.au/images/slideshow/6.jpg";