if (typeof PWCC == "undefined" || !PWCC) {
	//create PWCC namespace if it hasn't been done already
	PWCC = new Object();
}

PWCC.loader = function() {
	var $ = jQuery,
		$body,
		bodyHeightSet = false,
		WIN = window;
		
	$(function(){
		$body = $('body');
		
		if (typeof $body.pngFix != "undefined") {
			$body.pngFix();
		}
		//min window height
		bodyHeight();
		$(WIN).resize(function(){bodyHeight();});
		
		gallerySlides();
		
		videoSlides();
		
		$("#videos > a").each(function(){
			var $this = $(this),
				padding = 15;
				a = $this.attr('href');
				
			$this.attr('href', a + '?iframe=true&width=' + (635 + (padding * 2)) + '&height=' + (371 + (padding * 2)));
			$this.attr('rel', 'prettyPhoto[videos]');
		});
		
		$("#mlistlink").each(function(){
			var $this = $(this),
				padding = 15;
				a = $this.attr('href');
				
			$this.attr('href', a + '?iframe=true&width=' + (635 + (padding * 2)) + '&height=' + (371 + (padding * 2)));
			$this.attr('rel', 'prettyPhoto[mlist]');
		});
		
		$("a[rel^='prettyPhoto']").prettyPhoto({
			theme: 'dark_square', /* light_rounded / dark_rounded / light_square / dark_square */
			showTitle: true, /* true/false */
			animationSpeed: 'fast', /* fast/slow/normal */
			allowresize: false /* true/false */



		});

	});
	
	function bodyHeight() {
		var winHeight = $(WIN).height(),
			bodyHeight = $body.height();
			
			if (bodyHeight < winHeight){
				PWCC.createStyleRule('body', 'min-height: ' + winHeight + 'px;', 'screen, projection, handheld');
				PWCC.createStyleRule('* html body', 'height: ' + winHeight + 'px;', 'screen, projection, handheld');
				bodyHeightSet = true;
			}
			else if (bodyHeightSet == true) {
				PWCC.createStyleRule('body', 'min-height: auto;', 'screen, projection, handheld');
				PWCC.createStyleRule('* html body', 'height: auto;', 'screen, projection, handheld');
				bodyHeightSet = false; //as good as them not being set
			}
		
	}

	function gallerySlides() {
		var $gallerySlides = $('#photos'),
			$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=1; i<jsSlidesEl; i++){
				$gallerySlides.append('<img class="slide" id="slide' + (jsSlidesEl - i) + '" style="position: absolute; z-index:' + ((jsSlidesEl - i)) + ';" src="' + jsSlides[i] + '" />');
			}
			
			
			$slides = $('#photos > 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);
		}
	
	}
	
	function videoSlides() {
		var $gallerySlides = $('#videos'),
			$slides = $('a',$gallerySlides),
			jsSlides = PWCC.videoClips,
			jsGrabs = PWCC.videoGrab,
			
			nextShowing,
			nowShowing = 0,
			frequency = 5,
			animationSpeed = 1000,
			topSlide = 0;
		
		if (($gallerySlides.length >= 1) && (jsSlides)) {
			var jsSlidesEl = jsSlides.length;
			
			topSlide = jsSlides.length + 1;
			$slides.css('z-index', topSlide); // position on top of js added slides
			$slides.attr('id', 'vslide' + (jsSlides.length + 1)); //name top slide
		
			for (var i=1; i<jsSlidesEl; i++){
				$gallerySlides.append('<a href="' + jsSlides[i] + '" class="slide" id="vslide' + (jsSlidesEl - i) + '" style="position: absolute; z-index:' + ((jsSlidesEl - i)) + ';"><img width="260" height="119" src="' + jsGrabs[i] + '" /></a>');
			}
			
			
			$slides = $('#videos > a'); //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
				topSlide = topSlide + 1;
				$slides.eq(nextShowing).css('z-index', topSlide);
				$slides.eq(nextShowing).stop().fadeTo(animationSpeed, 1,function(){
					$slides.eq(nowShowing).stop().fadeTo(1,0);
				});
				
				nowShowing = nextShowing;
				setTimeout(nextSlide, frequency * 1000);

			}
			setTimeout(nextSlide, frequency * 1000);
		}
	
	}
	
}();


PWCC.gallerySlides = new Array();
PWCC.gallerySlides[0] = "assets/i/photos/01.jpg";
PWCC.gallerySlides[1] = "assets/i/photos/02.jpg";
PWCC.gallerySlides[2] = "assets/i/photos/03.jpg";
PWCC.gallerySlides[3] = "assets/i/photos/04.jpg";
PWCC.gallerySlides[4] = "assets/i/photos/05.jpg";
PWCC.gallerySlides[5] = "assets/i/photos/06.jpg";
PWCC.gallerySlides[6] = "assets/i/photos/07.jpg";
PWCC.gallerySlides[7] = "assets/i/photos/08.jpg";
PWCC.gallerySlides[8] = "assets/i/photos/09.jpg";
PWCC.gallerySlides[9] = "assets/i/photos/10.jpg";


PWCC.videoClips = new Array();
PWCC.videoClips[0] = "assets/f/buff-adonis-2.html";
PWCC.videoClips[1] = "assets/f/chad-still-got-it.html";
PWCC.videoClips[2] = "assets/f/crazy-lady.html";
PWCC.videoClips[3] = "assets/f/delete-the-deer.html";
PWCC.videoClips[4] = "assets/f/gold-mine-shaft.html";
PWCC.videoClips[5] = "assets/f/gotta-be-brave.html";
PWCC.videoClips[6] = "assets/f/long-divide-my-love.html";
PWCC.videoClips[7] = "assets/f/mills-and-boon-love-song.html";
PWCC.videoClips[8] = "assets/f/out-of-facebook-into-myspace.html";
PWCC.videoClips[9] = "assets/f/thought-we-were-already-there.html";
PWCC.videoClips[10] = "assets/f/with-different-face.html";

PWCC.videoGrab = new Array();
PWCC.videoGrab[0] = "assets/f/flv/buff-adonis-2.jpg";
PWCC.videoGrab[1] = "assets/f/flv/chad-still-got-it.jpg";
PWCC.videoGrab[2] = "assets/f/flv/crazy-lady.jpg";
PWCC.videoGrab[3] = "assets/f/flv/delete-the-deer.jpg";
PWCC.videoGrab[4] = "assets/f/flv/gold-mine-shaft.jpg";
PWCC.videoGrab[5] = "assets/f/flv/gotta-be-brave.jpg";
PWCC.videoGrab[6] = "assets/f/flv/long-divide-my-love.jpg";
PWCC.videoGrab[7] = "assets/f/flv/mills-and-boon-love-song.jpg";
PWCC.videoGrab[8] = "assets/f/flv/out-of-facebook-into-myspace.jpg";
PWCC.videoGrab[9] = "assets/f/flv/thought-we-were-already-there.jpg";
PWCC.videoGrab[10] = "assets/f/flv/with-different-face.jpg";


