

var fauxFinish = {
	config : { running : false ,
		   webtrends : { 
			diy: {
				oldworld : { url : '/do_it_yourself/faux_finishing/old_world_impressions/', name : 'Old World Impressions' },
				metallic : { url : '/do_it_yourself/faux_finishing/metallic_impressions/', name : 'Metallic Impressions' },
				quartz : { url : '/do_it_yourself/faux_finishing/quartz_stone_impressions/', name : 'Quartz Stone Impressions' },
				artisan : { url : '/do_it_yourself/faux_finishing/artisan_impressions/', name : 'Artisan Impressions' },
				TexturedFresco : { url : '/do_it_yourself/faux/old_world_impressions/textured_fresco_brochure', name : 'Textured Fresco Brochure' },
				SmoothFresco : { url : '/do_it_yourself/faux/old_world_impressions/smooth_fresco_brochure', name : 'Smooth Fresco Brochure' },
				HighPolishFresco : { url : '/do_it_yourself/faux/old_world_impressions/high_polish_fresco', name : 'High Polish Fresco' },
				SmoothMetallic : { url : '/do_it_yourself/faux/metallic_impressions/smooth_metallic_brochure', name : 'Smooth Metallic Brochure' },
				BrushedMetallic : { url : '/do_it_yourself/faux/metallic_impressions/brushed_metallic_brochure', name : 'Brushed Metallic Brochure' },
				TexturedMetallic : { url : '/do_it_yourself/faux/metallic_impressions/textured_metallic_brochure', name : 'Textured Metallic Brochure' },
				SmoothQuartzStone : { url : '/do_it_yourself/faux/quartz_stone_impressions/', name : 'Quartz Stone Impressions' },
				BrushedQuartzStone : { url : '/do_it_yourself/faux/quartz_stone_impressions/brushed_quartz_stone_brochure', name : 'Brushed Quartz Stone Brochure' },
				StriaeQuartzStone : { url : '/do_it_yourself/faux/quartz_stone_impressions/striae_quartz_stone_brochure', name : 'Striae Quartz Stone Brochure' },
				Crackle : { url : '/do_it_yourself/faux/artisan_impressions/crackle_brochure', name : 'Crackle Brochure' },
				Leaf : { url : '/do_it_yourself/faux/artisan_impressions/leaf_brochure', name : 'Leaf Brochure' },
				TissuePaper : { url : '/do_it_yourself/faux/artisan_impressions/tissue_paper_brochure', name : 'Tissue Paper Brochure' }
			},
			pro : { 
				oldworld : { url : '/pro/faux_finishing/old_world_impressions/', name : 'Old World Impressions' },
				metallic : { url : '/pro/faux_finishing/metallic_impressions/', name : 'Metallic Impressions' },
				quartz : { url : '/pro/faux_finishing/quartz_stone_impressions/', name : 'Quartz Stone Impressions' },
				artisan : { url : '/pro/faux_finishing/artisan_impressions/', name : 'Artisan Impressions' },
				TexturedFresco : { url : '/pro/faux/old_world_impressions/textured_fresco_brochure', name : 'Textured Fresco Brochure' },
				SmoothFresco : { url : '/pro/faux/old_world_impressions/smooth_fresco_brochure', name : 'Smooth Fresco Brochure' },
				HighPolishFresco : { url : '/pro/faux/old_world_impressions/high_polish_fresco', name : 'High Polish Fresco' },
				SmoothMetallic : { url : '/pro/faux/metallic_impressions/smooth_metallic_brochure', name : 'Smooth Metallic Brochure' },
				BrushedMetallic : { url : '/pro/faux/metallic_impressions/brushed_metallic_brochure', name : 'Brushed Metallic Brochure' },
				TexturedMetallic : { url : '/pro/faux/metallic_impressions/textured_metallic_brochure', name : 'Textured Metallic Brochure' },
				SmoothQuartzStone : { url : '/pro/faux/quartz_stone_impressions/', name : 'Quartz Stone Impressions' },
				BrushedQuartzStone : { url : '/pro/faux/quartz_stone_impressions/brushed_quartz_stone_brochure', name : 'Brushed Quartz Stone Brochure' },
				StriaeQuartzStone : { url : '/pro/faux/quartz_stone_impressions/striae_quartz_stone_brochure', name : 'Striae Quartz Stone Brochure' },
				Crackle : { url : '/pro/faux/artisan_impressions/crackle_brochure', name : 'Crackle Brochure' },
				Leaf : { url : '/pro/faux/artisan_impressions/leaf_brochure', name : 'Leaf Brochure' },
				TissuePaper : { url : '/pro/faux/artisan_impressions/tissue_paper_brochure', name : 'Tissue Paper Brochure' }
			}
		}
	},
	helpers : {
		getIndex : function(el){
			return ( el.parent().index() + 1 );
		},
		styleNav : function(el){
			$('#nav li a, #home').removeClass('clicked');
			el.addClass('clicked');	
		},
		getHash : function(){
			return window.location.hash;
		},
		showPage : function(){
			$('#copy, #nav, #header').removeClass('hidden');
		}
	},
	animations : {
		fade : function(el){
			fauxFinish.config.running = true;
			if (el.attr('id') == 'home') { $('#header .landing').css({ 'z-index' : '1' });}
			var current = $('#header > li').filter(function() {
			     return $(this).css('z-index') == '2';
			});
			var header = (el.attr('id') != 'home') ? $('#header li').eq(fauxFinish.helpers.getIndex(el)) : $('#header li').eq(0);
			header
				.css({ 'z-index' : '1'});
			
			current
				.animate(
					{ opacity : '0'},
				       	{ duration : 1000,
					  queue : false, 
					  complete : function(){
						$(this).css({ 'z-index' : '0' });		
						header.css({ 'z-index' : '2' });		
						$('#header li').css('opacity', '1'); 
						fauxFinish.config.running = false;
					}
			});
		},
		slide : function(el, type){
			var copy = (el.attr('id') != 'home') ? $('#copy > li').eq(fauxFinish.helpers.getIndex(el)) : $('#copy .landing');
			copy
				.css({ 'z-index' : '2', 'left' : '502px'})
				.animate(
					{ left : '0'},
					{ duration : 1000,
					  queue : false, 
					  complete : function(){
						$('#copy li').not(this).css({ 'z-index' : '0' })		
						$(this).css({ 'z-index' : '1' });		
						window.location.hash = type;
						fauxFinish.config.clicked = false;
					}
				});

		}

	},
	init : {
		loadContent : function(){
			var hash = fauxFinish.helpers.getHash();
			var scene = fauxFinish.helpers.getHash().replace('#', '');
			fauxFinish.helpers.showPage();

			if(hash.length > 1){
				$('#header > li, #copy > li').not('#header .' + scene, '#copy .' + scene).css('z-index' , '0');
				$('#header .' + scene).css( 'z-index' , '2' );
				$('#copy .' + scene ).css( 'z-index' , '1' );
				$('#nav a, #home').removeClass('clicked');
				(scene != 'landing') ? $('#nav .' + scene + ' a').addClass('clicked') : $('#home').addClass('clicked');
			}else{
				$('#home').addClass('clicked');
			}
		},
		clickNav : function(){
			$('#nav li a, #home').click(function(event){
				var type = ($(this).attr('id') != 'home') ? $(this).parent().attr('class') : 'landing';
				event.preventDefault();
				$('#header > li, #copy > li, #nav > li').clearQueue();
				if(!fauxFinish.config.running && !$(this).hasClass('clicked')){
					fauxFinish.helpers.styleNav($(this));
					for(prop in fauxFinish.animations){
						fauxFinish.animations[prop]($(this), type);
					}
				}else{
					return false;
				}


				return false;
			});	
		},
		webtrends : function(){
			$('[href$=pdf], #nav li a').click(function(){
				var envr = ($('body').attr('id') == 'faux') ? 'diy' : 'pro';
				var type = ($(this).parent().parent().attr('id') == 'nav') ? $(this).parent().attr('class') : $(this).prev().text();
				var type = type.replace(' ', '');
				dcsMultiTrack('DCS.dcsuri', fauxFinish.config.webtrends[envr][type].url,'WT.ti', fauxFinish.config.webtrends[envr][type].name)
			});
		},
		hashChange : function(){
			$(window).bind( 'hashchange', function(){
					fauxFinish.init.loadContent();
			});	
		}
	}
}
$(document).ready(function(){
	for(prop in fauxFinish.init){
		fauxFinish.init[prop]();
	}
	
});


