//This positions the footer at the bottom of the page
function centerBottom(selector){
	var newTop = $(window).height() - $(selector).height();
	var newLeft = ($(window).width() - $(selector).width())/2;
	$(selector).css({
		'position': 'fixed',
		'left': newLeft,
		'top': newTop
	});
}
//This sets the height of the container and positions it between the header and floating footer
function container(selector){
	$(selector).css({'height': (($(window).height()) - 161)+'px', 'width': ($(window).width())});
}
$(document).ready(function(){
	$('a#dash-click').click(function(){
		$('div#dash-contain').animate({'height': 'toggle'}).parent().toggleClass();
		$(this).toggleClass();
		if($('a#dash-click').hasClass('dash-close')){
			$(this).text('open').css({'width': '960px'}).css({'background': 'url(/media/wwwtpl/strand/tpl/dash-up.png) no-repeat right center'});
		}
		else{
			$(this).text('close').css({'width': '150px'}).css({'background': 'url(/media/wwwtpl/strand/tpl/dash-down.png) no-repeat right center'});
		}
	});
});
function enter(){
	if($('#dashboard-outer').hasClass('dash-down')){
		$(this).find('#dashnav').stop().animate({'height': '30px'}, 150);
	}
	else{
		$(this).stop();
	}
}
function leave(){
	if($('#dashboard-outer').hasClass('dash-down')){
		$(this).find('#dashnav').stop().animate({'height': '20px'}, 150);
	}
	else{
		$(this).stop();
	}
}

function homeNavImgHover(){
	$('#home-navigation li, #home-btns li').mouseover(function(){
		$(this).find('div').stop().show();
	});
	$('#home-navigation li, #home-btns li').mouseleave(function(){
		$(this).find('div').stop().hide();
	});
}

function vidsHover(){
	$('#the-scene a.vid-anchors').append('<div style="display:none;" class="play-btn"></div>')
	$('#the-scene a.vid-anchors').mouseleave(function(){
		$(this).find('div.play-btn').stop().hide();
	});
	$('#the-scene a.vid-anchors').mouseover(function(){
		$(this).find('div.play-btn').stop().show();
	});
}
//This is dash nav functionality
function navBtns(){
	$('div.dash-content').css({'display': 'none'});
	$('#dashnav a.dash-link:first').addClass('active').show();
	$('div.dash-content:first').show();
	$('#dashnav a.dash-link').click(function(){
		$('#dashnav a.dash-link').removeClass('active');
		$(this).addClass('active');
		$('div.dash-content').css('display', 'none');
		
		var activeTab = $(this).attr('href');
		$(activeTab).fadeIn();
		return false;
	});
}
function lightResize(){
	var lightHeight = $(window).height();
	if(lightHeight < 800){
		$('#header-outer, #footer-outer').css({'z-index': '100'});
	}
	else{
		$('#header-outer, #footer-outer').css({'z-index': '9999'});
	}
}
function imageResizes(){
			var width = $(this).width();
			$('.module img.fe_left').each(function(){
				if(width>230){
					$(this).css('width', '230px');
				}
			});
			$('.module img.fe_right').each(function(){
				if(width>230){
					$(this).css('width', '230px');
				}
			});
			$('.double-img img').each(function(){
				if(width>340){
					$(this).css('width', '340px');
				}
			});
			$('.sinlge-img img').each(function(){
				if(width>710){
					$(this).css('width', '710px');
				}
			});
			$('.triple-img img').each(function(){
				if(width>260){
					$(this).css('width', '260px');
				}
			});
			$('div.message .double-img').each(function(){
				$(this).find('img:last').css({'margin-right': '0px'});
			});
}
function colourThing(){
	$('.cat_color_1').each(function(){
		$(this).find('.musi-top').attr('src', '/media/wwwtpl/strand/tpl/green-mustache-top.png');
		$(this).find('.musi-bottom').attr('src', '/media/wwwtpl/strand/tpl/green-mustache-bottom.png');
		$(this).find('h3').css('color', '#6dcd57');
		$(this).find('.cat-direction-arrows').attr('src', '/media/wwwtpl/strand/tpl/green-arrow.png');
	});
	$('.cat_color_2').each(function(){
		$(this).find('.musi-top').attr('src', '/media/wwwtpl/strand/tpl/pink-mustache-top.png');
		$(this).find('.musi-bottom').attr('src', '/media/wwwtpl/strand/tpl/pink-mustache-bottom.png');
		$(this).find('h3').css('color', '#db9bd3');
		$(this).find('.cat-direction-arrows').attr('src', '/media/wwwtpl/strand/tpl/pink-arrow.png');
	});
	$('.cat_color_4').each(function(){
		$(this).find('.musi-top').attr('src', '/media/wwwtpl/strand/tpl/small-moustache-top2.jpg');
		$(this).find('.musi-bottom').attr('src', '/media/wwwtpl/strand/tpl/small-moustache-bottom2.jpg');
		$(this).find('h3').css('color', '#697FB9');
		$(this).find('.cat-direction-arrows').attr('src', '/media/wwwtpl/strand/tpl/pink-arrow.png');
	});
	$('.cat_color_5').each(function(){
		$(this).find('.musi-top').attr('src', '/media/wwwtpl/strand/tpl/yellow-mustache-top.png');
		$(this).find('.musi-bottom').attr('src', '/media/wwwtpl/strand/tpl/yellow-mustache-bottom.png');
		$(this).find('h3').css('color', '#dadc56');
		$(this).find('.cat-direction-arrows').attr('src', '/media/wwwtpl/strand/tpl/yellow-arrow.png');
	});
}

function categoryTitle(){
	$("div.category_title h3:contains(Evening Wear)").css({'color': '#697fb9'}).prev().attr('src', '/media/wwwtpl/strand/tpl/small-moustache-top2.jpg').next().next().attr('src', '/media/wwwtpl/strand/tpl/small-moustache-bottom2.jpg');
}
function homeResizer(){
	var homeSize = $(window).height();
	if(homeSize<756){
		$('#home-container .items div.scroll-content div').css({'margin':'16% auto 0 24%'});
		$('div.scroll-content h1').css({'font-size':'36px','margin-bottom':'35px','line-height':'36px'});
		$('#home-container .items div.scroll-content p').css({'margin-bottom':'32px'});
	}
	else if(homeSize>756){
		$('#home-container .items div.scroll-content div').css({'margin':'21% auto 0 15%'});
		$('div.scroll-content h1').css({'font-size':'46px','margin-bottom':'45px','line-height':'44px'});
		$('#home-container .items div.scroll-content p').css({'margin-bottom':'40px'});
	}
}
$(document).ready(function(){
	$('#nav li a:last').css('margin-right', '0');
	$('#nav li a:first').css('margin-left', '0');
	centerBottom('#footer-outer');
	container('#container-outer');
	container('#home-container');
	container('div.scroll-item');
	$(window).resize(function(){
		centerBottom('#footer-outer');
		container('#container-outer');
		container('#home-container');
		container('div.scroll-item');
	});
	$('h1#page-title').wrap('<div id="page-title-div"></div>')
	$('#home-navigation li:first').css({'margin-left': '0'});
	$('#home-navigation li:last').css({'margin-right': '0'});
	$('.dash-down').hover(enter, leave);
	navBtns();
	//Functions to execute once the window has loaded
	$(window).load(function(){
		$('#home-container').delay(500).fadeIn(1000);
		$('#dashnav').delay(750).slideToggle(1500);
	});
	homeNavImgHover();	
	homeResizer();	
	lightResize();
	$(window).resize(function(){
		lightResize();
		homeResizer();
	});
	$('#dash-contain #signup input#firstname').attr('value','First Name');
	vidsHover();
	$('#dash-contain #signup input#subscribe').attr('value','Email');
	$('#store-inner #store-retailer li:eq(2)').css('clear', 'left');
	$('div.inline-gal').parent().addClass('#fancybox-content-child');
	$('form#signup').parent().addClass('signup-div-dash');
	imageResizes();
	$('#directory li span.name').each(function(){
		$(this).parent().addClass('name-anchor');
	});
	categoryTitle();
	$('ul#store-retailer .website-link').prev().prev().addClass('store-location-spot');
	$('#home-container').scrollable({ circular: true, speed: 150, items: '.items'}).navigator({navi: 'ul#home-navigation'}).autoscroll({interval: 5000});
	$('#getdirections li:last').css('margin-right', '0');
	$('ul#directory-btns li a:last').css('padding-left', '0');
	$('ul#directory-btns li a.directory-img[title]').tooltip({
		effect: "fade",
		fadeOutSpeed: 200,
		predelay: 25,
		position: "bottom left",
		offset: [-26, -2]
	});
	$('ul#directory-btns li a.listing-img[title]').tooltip({
		effect: "fade",
		fadeOutSpeed: 200,
		predelay: 25,
		position: "bottom left",
		offset: [-26, -28]
	});
});
