/* ---------------------------------------------------------------------------------------------------- */
/* JQUERY --------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------- */
$(document).ready(function(){
	
	if ( $( '#catalog_form' )[0] ) {
		$( '#tradeprofessional' ).click( function( event ) {
			$( '#catalog_form' ).find( '.toggle' ).removeClass( 'hidden' );
			$( '#catalog_form' ).find( '.toggle' ).find( 'input' ).addClass( 'validate[required]' );
			if ( $( '.companyformError' )) {
				$( '.companyformError' ).removeClass( 'hidden' );
			};
		});
		$( '#homeowner' ).click( function( event ) {
			$( '#catalog_form' ).find( '.toggle' ).addClass( 'hidden' );
			$( '#catalog_form' ).find( '.toggle' ).find( 'input' ).removeClass( 'validate[required]' );
			if ( $( '.companyformError' )) {
				$( '.companyformError' ).addClass( 'hidden' );
			};
		});
	}
	
	// Look Book Rotator
	if($('#slideshow')[0]){	
		$( '.flexslider' ).flexslider( {
			animation:		'slide',
			slideshow:		true,
			slideshowSpeed: 	5000,
			animationDuration: 	1500,
			directionNav:		true,
			pauseOnAction: 	true,
			pauseOnHover: 		true,
			controlsContainer:	'.slider_controls'
		});
	}
	
	// form validation
	$("form.validate").validationEngine();
	
	// in-field labels
	$("form.infield label").inFieldLabels({
		fadeOpacity: 0.5,
		fadeDuration: 300
	});
	
	// fancybox
	$("a.zoom").fancybox({
		'padding'        : 10,
		'width'          : 480,
		'height'         : 495,
		'autoScale'      : false,
		'overlayShow'	 : true,
		'overlayOpacity' : .5,
		'overlayColor'   : '#000',
		'speedIn'		 : 600,
		'speedOut'		 : 200,
		'transitionIn'   : 'elastic',
		'transitionOut'  : 'elastic',
		'autoDimensions' : false
	});
	
	// fancybox
	$("a.lightbox").fancybox({
		'padding'        : 10,
		'autoScale'      : false,
		'overlayShow'	 : true,
		'overlayOpacity' : .5,
		'overlayColor'   : '#000',
		'speedIn'		 : 600,
		'speedOut'		 : 200,
		'transitionIn'   : 'elastic',
		'transitionOut'  : 'elastic',
		'autoDimensions' : true
	});
	
	/* type tabs -------------------------------------------------------------------------------- */
	/* ------------------------------------------------------------------------------------------ */
	var type = 't1';
	
	// get variables
	$('#type a').click(function(){type = $(this).attr('rel');});
	
	// actions
	$('#type a').click(function(){

		// change tabs
		$(this).parent('li').siblings().removeClass('active');
		$(this).parent('li').addClass('active');
		
		// show/hide divs
		$(this).parents('#type').siblings('div').hide();
		$(this).parents('#type').siblings('div#'+type).show();
		
		// remove validation errors
		$('.formError').remove();
	
	});
	/* ------------------------------------------------------------------------------------------ */
	
	// trade validation
    $.validator.addMethod("username", function(value, element) {
        return this.optional(element) || /^[a-z0-9\_]+$/i.test(value);
    }, "Username must contain only letters, numbers, or underscore.");

    $("#regForm").validate();
	
	// photo gallery
	$('#gallery').galleria({
		width: 440,
		height: 350
	});
	
	// tooltips
	$('.styles a').each(function(){
		$(this).qtip({
			content: {
				url: $(this).attr('rel') // use the rel attribute of each element for the url to load
			},
			position: {
				corner: {
					target: 'bottomMiddle', // position the tooltip above the link
					tooltip: 'topMiddle'
				},
				adjust: {
					screen: true // keep the tooltip on-screen at all times
				}
			},
			style: {
				tip: true, // apply a speech bubble tip to the tooltip at the designated tooltip corner
				border: {
					width: 0,
					radius: 4
				},
				name: 'light',
				width: 320
			}
		})
	});
	
	/* nav -------------------------------------------------------------------------------------- */
	/* ------------------------------------------------------------------------------------------ */
	// dropdown animation
	$("#nav ul li").hover(function(){
		$(this).find("ul:first").css({visibility:"visible",display:"none"}).show(400);
	},function(){
		$(this).find("ul:first").css({visibility:"hidden"});
	});

	// maintain hover
	$("#nav ul ul").hover(function(){
		$(this).parent().find("a:first").addClass("hover");
	},function(){
		$(this).parent().find("a:first").removeClass("hover");
	});

	// add more arrow
	$("#nav li li:has(ul)").addClass("more");
	
	/* subnav accordion ------------------------------------------------------------------------- */
	/* ------------------------------------------------------------------------------------------ */
	$("#subnav a.expand").click(function(){
		$(this).siblings("ul").slideUp("slow");
		$(this).siblings("ul:hidden").slideDown("slow");
	});
	
	/* catalog show/hide ------------------------------------------------------------------------- */
	/* ------------------------------------------------------------------------------------------ */
	$("#landing .benefits a.button").click(function(){
		$("#landing div.benefits").hide();
		$("#landing div.form").show();
	});
	
	/* font effects ----------------------------------------------------------------------------- */
	/* ------------------------------------------------------------------------------------------ */
	$("span.h").FontEffect({
		outline: true,
		outlineColor1: "#2d2619",
		outlineColor2: "#2d2619",
		outlineWeight: 1, // 1=light, 2=normal, 3=bold
		mirror: false,
		mirrorColor: "",
		mirrorOffset: -10, // distance from text
		mirrorHeight: 50, // reflection height (%)
		mirrorDetail: 1, // 1=high, 2=medium, 3=low
		mirrorTLength: 50, // gradient height (%)
		mirrorTStart: 0.2, // starting reflection opacity (0-1)
		shadow: true,
		shadowColor: "#000",
		shadowOffsetTop: -1, // top offset position (px)
		shadowOffsetLeft: -1, // left offset position (px)
		shadowBlur: 2, // 1=none, 2=low, 3=high
		shadowOpacity: 0.05, // 0=none,1=all (%)
		gradient: false,
		gradientColor: "",
		gradientPosition: 20, // starting gradient position (%)
		gradientLength: 50, // gradient length (%)
		gradientSteps: 20,
		hideText: false // hide source text
	}).css({width:"auto"}); // fix: fixed width
	
	$("span.h2").FontEffect({
		outline: true,
		outlineColor1: "#2d2619",
		outlineColor2: "#2d2619",
		outlineWeight: 1, // 1=light, 2=normal, 3=bold
		mirror: false,
		mirrorColor: "",
		mirrorOffset: -10, // distance from text
		mirrorHeight: 50, // reflection height (%)
		mirrorDetail: 1, // 1=high, 2=medium, 3=low
		mirrorTLength: 50, // gradient height (%)
		mirrorTStart: 0.2, // starting reflection opacity (0-1)
		shadow: true,
		shadowColor: "#000",
		shadowOffsetTop: -1, // top offset position (px)
		shadowOffsetLeft: -1, // left offset position (px)
		shadowBlur: 2, // 1=none, 2=low, 3=high
		shadowOpacity: 0.05, // 0=none,1=all (%)
		gradient: false,
		gradientColor: "",
		gradientPosition: 20, // starting gradient position (%)
		gradientLength: 50, // gradient length (%)
		gradientSteps: 20,
		hideText: false // hide source text
	}).css({width:"auto"}); // fix: fixed width
	
	$("span.h3").FontEffect({
		outline: true,
		outlineColor1: "#2d2619",
		outlineColor2: "#2d2619",
		outlineWeight: 1, // 1=light, 2=normal, 3=bold
		mirror: false,
		mirrorColor: "",
		mirrorOffset: -10, // distance from text
		mirrorHeight: 50, // reflection height (%)
		mirrorDetail: 1, // 1=high, 2=medium, 3=low
		mirrorTLength: 50, // gradient height (%)
		mirrorTStart: 0.2, // starting reflection opacity (0-1)
		shadow: true,
		shadowColor: "#000",
		shadowOffsetTop: -1, // top offset position (px)
		shadowOffsetLeft: -1, // left offset position (px)
		shadowBlur: 2, // 1=none, 2=low, 3=high
		shadowOpacity: 0.05, // 0=none,1=all (%)
		gradient: false,
		gradientColor: "",
		gradientPosition: 20, // starting gradient position (%)
		gradientLength: 50, // gradient length (%)
		gradientSteps: 20,
		hideText: false // hide source text
	}).css({width:"auto"}); // fix: fixed width

	//Image Swap on the Before and After Page
	$('.controller a.unactive').live('click', function( event ){
		$('.images li').toggle();
		$('.controller a').toggleClass('unactive');
		event.preventDefault();
	});
	
	$('.controller a.before').click(function( event ){
		event.preventDefault();
		$('#tips').hide();
	});
	
	$('.controller a.after').click(function( event ){
		event.preventDefault();							
		$('#tips').show();
	});
	
	$('#tips .tip').click(function( event ){
		event.preventDefault();
		$(this).children('div').show();
	});

});

$(window).load(function(){
	// nivo slider
	//// home
	$(".slider.home").nivoSlider({
		effect: "fade", // random, fold, fade, sliceDown(Left), sliceUp(Left,Down,DownLeft)
		slices: 15,
		animSpeed: 750, // slide transition speed
		pauseTime: 4000,
		startSlide: 0, // set starting slide (0 index)
		directionNav: true, // next & prev
		directionNavHide: false, // only show on hover
		controlNav: true, // 1,2,3...
		controlNavThumbs: false, // use thumbnails for control nav
		controlNavThumbsFromRel: false, // use image rel for thumbs
		controlNavThumbsSearch: ".jpg", // replace this with...
		controlNavThumbsReplace: "_thumb.jpg", // ...this in thumb img src
		keyboardNav: true, // use left & right arrows
		pauseOnHover: true, // stop animation while hovering
		manualAdvance: false, // force manual transitions
		captionOpacity: 0.8, // universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} // triggers after all slides have been shown
	});
	//// shutters
	$(".slider.shutters").nivoSlider({
		effect: "fade", // random, fold, fade, sliceDown(Left), sliceUp(Left,Down,DownLeft)
		slices: 15,
		animSpeed: 750, // slide transition speed
		pauseTime: 7000,
		startSlide: 0, // set starting slide (0 index)
		directionNav: true, // next & prev
		directionNavHide: false, // only show on hover
		controlNav: false, // 1,2,3...
		controlNavThumbs: false, // use thumbnails for control nav
		controlNavThumbsFromRel: false, // use image rel for thumbs
		controlNavThumbsSearch: ".jpg", // replace this with...
		controlNavThumbsReplace: "_thumb.jpg", // ...this in thumb img src
		keyboardNav: true, // use left & right arrows
		pauseOnHover: true, // stop animation while hovering
		manualAdvance: false, // force manual transitions
		captionOpacity: 0.8, // universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} // triggers after all slides have been shown
	});
	//// hardware
	$(".slider.hardware").nivoSlider({
		effect: "fade", // random, fold, fade, sliceDown(Left), sliceUp(Left,Down,DownLeft)
		slices: 15,
		animSpeed: 750, // slide transition speed
		pauseTime: 7000,
		startSlide: 0, // set starting slide (0 index)
		directionNav: true, // next & prev
		directionNavHide: false, // only show on hover
		controlNav: false, // 1,2,3...
		controlNavThumbs: false, // use thumbnails for control nav
		controlNavThumbsFromRel: false, // use image rel for thumbs
		controlNavThumbsSearch: ".jpg", // replace this with...
		controlNavThumbsReplace: "_thumb.jpg", // ...this in thumb img src
		keyboardNav: true, // use left & right arrows
		pauseOnHover: true, // stop animation while hovering
		manualAdvance: false, // force manual transitions
		captionOpacity: 0.8, // universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} // triggers after all slides have been shown
	});
	
});

/* ---------------------------------------------------------------------------------------------------- */
/* SWFOBJECT ------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------- */
var vars = {};
var params = {
	menu: "false",
	wmode: "transparent"
};
var attr = {};

swfobject.embedSWF(
	"/_video/installation.swf",
	"mov-installation","440","345",
	"9.0.0","/_video/expressInstall.swf",vars,params,attr
);
swfobject.embedSWF(
	"/_video/measuring.swf",
	"mov-measuring","440","345",
	"9.0.0","/_video/expressInstall.swf",vars,params,attr
);
swfobject.embedSWF(
	"/_video/p-allen.swf",
	"mov-p-allen","440","307",
	"9.0.0","/_video/expressInstall.swf",vars,params,attr
);
swfobject.embedSWF(
	"/_video/curb-appeal.swf",
	"mov-curb-appeal","440","308",
	"9.0.0","/_video/expressInstall.swf",vars,params,attr
);
swfobject.embedSWF(
	"/_video/katie-brown.swf",
	"mov-katie-brown","440","308",
	"9.0.0","/_video/expressInstall.swf",vars,params,attr
);
