/*! This file has *//* NOT *//*! been minimized. */

/*In minimized files, *//*! credits of reused code can be found by removing ‘-min’ from the url. */

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

PWCC.loader = function() {
	var $ = jQuery,
		$body;
	
	$(function() {
		//dom load functions
		$body = $('body');
		DD_roundies.addRule('.cat-links a', '15px', true);
		compactForms();
		//$('.cat-links a').corner("15px");
		if (
			($body.hasClass('pageslug-clients') == false) &&
			($body.hasClass('pageslug-lookbooks') == false)
			) {
			$("#content a[rel^='prettyPhoto']").prettyPhoto({
				animationSpeed: 'normal', /* fast/slow/normal */
				padding: 10, /* padding for each side of the picture */
				/* opacity: 0.35, /* Value betwee 0 and 1 */
				showTitle: false, /* true/false */
				allowresize: true, /* true/false */
				counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
				theme: 'light_square' /* light_rounded / dark_rounded / light_square / dark_square */
			});
		}
		else if ($body.hasClass('pageslug-lookbooks') == true) {
			$("#content-b > div:first a[rel^='prettyPhoto']").each(function(){
					var $this = $(this),
						url = $this.attr('href');
					url = url + '?iframe=true&width=100%&height=100%';
					$this.attr('href', url);
				});
				
			$("#content a[rel^='prettyPhoto']").prettyPhoto({
				animationSpeed: 'normal', /* fast/slow/normal */
				padding: 5, /* padding for each side of the picture */
				/* opacity: 0.35, /* Value betwee 0 and 1 */
				showTitle: false, /* true/false */
				allowresize: true, /* true/false */
				counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
				theme: 'light_square' /* light_rounded / dark_rounded / light_square / dark_square */
			});
		}
	});
	
	$(window).ready(function() {
			gallerySlides();


		//sifr eg:
		//$("h3").sifr({ font: 'gunmetal' });
	});
	
	
	function compactForms() {
		// based on an idea from A List Apart's Making Compact Forms More Accessible
		// http://www.alistapart.com/articles/makingcompactformsmoreaccessible/
		var $mailingForm = $('div.sidebar form.list-form'),
			$mailingLabel = $('label',$mailingForm),
			$mailingInput = $('#tyhkz-tyhkz'),
			
			$searchForm = $('div.sidebar form.search-form'),
			$searchLabel = $('label', $searchForm),
			$searchInput = $('input.search-input', $searchForm);
			
			function fieldFocus($label) {
				$label.addClass('active');
			}
			
			function fieldBlur($label, $field) {
				if ($field.val() == '') {
					$label.removeClass('active');
				}
			}
			//hide while page is loading
			fieldFocus($searchLabel);
			fieldFocus($mailingLabel)
			
			//add events to forms
			$searchInput.focus(function(){fieldFocus($searchLabel);});
			$searchInput.blur(function(){fieldBlur($searchLabel, $searchInput);});
			
			$mailingInput.focus(function(){fieldFocus($mailingLabel);});
			$mailingInput.blur(function(){fieldBlur($mailingLabel, $mailingInput);});
			
			//once the page has loaded, wait 50ms and run blur event
			$(window).ready(function() {
				setTimeout(function() {
					fieldBlur($searchLabel, $searchInput);
					fieldBlur($mailingLabel, $mailingInput);
				},50);
			});
	}
	
	

	function gallerySlides() {
		var $gallerySlides = $('#gallerySlideShow'),
			$slides = $('img',$gallerySlides),
			jsSlides = PWCC.gallerySlides,
			
			nextShowing,
			nowShowing = 0,
			frequency = 5,
			animationSpeed = 200;
		
		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="z-index:' + (jsSlidesEl - i) + ';" src="' + jsSlides[i] + '" />');
			}
			
			
			$slides = $('#gallerySlideShow > 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');