// JavaScript Document

var homeImages = {
	"Brands" : 
	[
		{
			"Brand" : "Vera Wang Lavender",
			"Image" : "VeraWang_1132_CS_040711_06_064_03.jpg",
			"Logo"  : "Content/core/logo/veraLogo.png",
			"Thumb" : "Content/core/home/thumbs/veraWang.gif",
			"Description" : "<p>Vera Wang celebrated her 20th anniversary in business in 2010. She began with the breathtaking bridal gowns she is so rightfully known for and grew her company into an empire. The World of Vera Wang now includes three critically acclaimed womenswear collections, a CFDA-nominated line of jewelry, shoes, fragrance, china, fine papers, soft home, flowers, mattresses, home fragrance and a suite at the Halekulani Resort in Hawaii.</p><p>Vera&rsquo;s vision for her footwear is youthful and eclectic, pairing unique materials with unexpected detailing.  The result is an extraordinary collection of contemporary fashion footwear.</p>", 
			"Link" : "http://www.verawang.com/lifestyle/footwear/"
		},
		{
			"Brand" : "Naturalizer",
			"Image" : "Naturalizer_ILLY.jpg",
			"Logo"  : "Content/core/logo/naturalizerLogo.png",
			"Thumb" : "Content/core/home/thumbs/naturalizer.gif",
			"Description" : "<p>Since 1927, Naturalizer has been known as &quot;the shoe with the beautiful fit&quot;. For more than 80 years, Naturalizer has understood how truly comfortable shoes can help women move energetically through their day and live life to the fullest. Naturalizer remains committed to designing beautiful shoes that feel as good at the end of the day as they do at the beginning. And because of this commitment, Naturalizer shoes feature our exclusive N5 comfort system-five essential features that are proven to provide all day comfort: extra cushioning, breathable linings, balance with every step, flexible soles and lightweight material. </p><p>Today, Naturalizer is inspiring women to live their lives and love their shoes in more than 60 countries around the world.</p>", 
			"Link" : "http://www.naturalizer.com"
		},
		{
			"Brand" : "Dr. Scholl's",
			"Image" : "WanderJamie.jpg",
			"Logo"  : "Content/core/logo/schollsLogo.png",
			"Thumb" : "Content/core/home/thumbs/drScholls.gif",
			"Description" : "<p>Dr. Scholl&rsquo;s Shoes is an authentic comfort brand defined by its original fashion perspective and heritage of innovation and technical foot care expertise.  With a focus on delivering proprietary comfort technology, championing unique, individual fashion, and versatile styling, Dr. Scholl&rsquo;s Shoes inspires consumers across ages, incomes and lifestyles to live active lives of discovery and play with ease.  Dr. Scholl&rsquo;s Shoes.  Go. Play.</p>", 
			"Link" : "http://www.drschollsshoes.com/"
		},
		{
			"Brand" : "AVIA",
			"Image" : "AVIA_triathletes_single-newCMYK.jpg",
			"Logo"  : "Content/core/logo/aviaLogo.png",
			"Thumb" : "Content/core/home/thumbs/avia.gif",
			"Description" : "<p>In 1979, Avia was founded on the passion to provide footwear for serious athletes. As technology advanced so did we, developing innovative shoe designs that revolutionized athletic footwear. With such designs as the Cantilever Heel, the Anatomical Cradle and FOM technology, Avia proved to be passionate, progressive, and at the top of the game. Today, we continue to lead the performance training movement and further our dedication to improving sports performance.</p>", 
			"Link" : "http://www.avia.com"
		},
		{
			"Brand" : "Fergie",
			"Image" : "Fergie_MilkStudio11.jpg",
			"Logo"  : "Content/core/logo/fergieLogo.png",
			"Thumb" : "Content/core/home/thumbs/fergie.gif",
			"Description" : "<p>Fergie, the Grammy-winning artist and member of The Black Eyed Peas, has always been influenced by fashion and creativity, both on and off the stage. Over the years, her musical talents have made her a pop star, and her trendy, sexy style has made her an icon. She&rsquo;s graced the cover of multiple fashion magazines, topped best-dressed lists at some of the most exclusive events and has now taken her passion for fashion one step further by designing a glamorous new footwear collection.</p>", 
			"Link" : "http://www.fergieshoes.com"
		},
		{
			"Brand" : "Franco Sarto",
			"Image" : "FrancoSarto_Odell.jpg",
			"Logo"  : "Content/core/logo/francoLogo.png",
			"Thumb" : "Content/core/home/thumbs/francoSarto.gif",
			"Description" : "<p>More than just a label on a footbed, Franco Sarto is the man behind the footwear designs. Franco began his career at the age of 14, carefully hand-crafting shoes in the outskirts of Venice. Now a revered and respected industry leader, Franco personally touches, fits and approves every shoe in his namesake line, always attentive to the details that make a pair of shoes a work of art. Franco Sarto provides women with beautiful style that complements all facets of their lives.</p>", 
			"Link" : "http://www.francosarto.com"
		},
		{
			"Brand" : "Naya",
			"Image" : "Naya_Jada.jpg",
			"Logo"  : "Content/core/logo/nayaLogo.png",
			"Thumb" : "Content/core/home/thumbs/naya.gif",
			"Description" : "<p>Naya was born from the belief that shoes should be beautiful on your feet, soft on your step and gentler on the environment. Naya means renewal and this inspires and guides us in everything we do to create shoes that:</p><p><ul><li>Renew your spirit with expressive, feminine style</li><li>Renew your body with premium comfort</li><li>Renew the earth with designs that have a softer footprint on the planet.</li></ul></p><p>You will wear Naya because they are beautiful, and you will love them because they are good for your body, spirit and the earth.</p>", 
			"Link" : "http://www.nayashoes.com/"
		},
		{
			"Brand" : "Sam Edelman",
			"Image" : "SamEdelman_SPR11-SPREADS_14x11_4.jpg",
			"Logo"  : "Content/core/logo/samLogo.png",
			"Thumb" : "Content/core/home/thumbs/samEdelman.gif",
			"Description" : "<p>A creative visionary and legend in the footwear industry, Sam Edelman, has been a dominant force in fashion and marketing, making an indelible impact on some of the most renowned contemporary footwear brands over the past 30 years. The Sam Edelman brand, which began in 2004, was built straight from the hottest trends and runways around the world, but at a price-point every woman could afford. Season after season, Sam Edelman continues to create imaginative, trend-on, must have shoes that are seen everywhere from the hottest fashion magazines to the soles of A- List celebrities.</p>", 
			"Link" : "http://www.samedelman.com/"
		},
		{
			"Brand" : "Via Spiga",
			"Image" : "Via%20Spiga%20final%20Selects-4.jpg",
			"Logo"  : "Content/core/logo/viaLogo.png",
			"Thumb" : "Content/core/home/thumbs/viaSpiga.gif",
			"Description" : "<p>Established in 1985, Via Spiga is named after the main street in one of the most famed shopping districts in Milan. Italian design, luxurious materials and beautiful detailing maintain Via Spiga&rsquo;s rich heritage, reflecting the cosmopolitan woman&rsquo;s sophisticated, polished and feminine style. Today&rsquo;s Via Spiga delivers sleek and modern footwear for women who like to command attention when they walk down the street.</p>", 
			"Link" : "http://www.viaspiga.com"
		},
		{
			"Brand" : "Carlos",
			"Image" : "Carlos.jpg",
			"Logo"  : "Content/core/logo/carlosLogo.png",
			"Thumb" : "Content/core/home/thumbs/carlos.gif",
			"Description" : "<p>Inspired by the artistry and passion of Carlos Santana&rsquo;s soulful rhythms and vibe, the Carlos brand delivers stunning interpretations of seasonal footwear trends for the woman who dresses to be noticed. Since its launch in 2001, Carlos by Carlos Santana has separated itself from all other brands with unmatched embellishments, colors, textures and details, creating truly distinctive, vibrant footwear. Carlos by Carlos Santana is the Sound of Style.</p>", 
			"Link" : "http://www.carlosshoes.com"
		},
		{
			"Brand" : "Etienne Aigner",
			"Image" : "EtienneAigner.jpg",
			"Logo"  : "Content/core/logo/etienneLogo.png",
			"Thumb" : "Content/core/home/thumbs/etienneAigner.gif",
			"Description" : "<p>Etienne Aigner&rsquo;s signature line of women&rsquo;s fashion footwear is heralded for its classically feminine styles, sublime quality and uncompromising value. The Aigner logo is recognized worldwide as a symbol representing tradition, innovation and trends. Etienne Aigner&rsquo;s proud and distinct heritage has evolved to combine modern design with a singular style known for the finest materials.</p>", 
			"Link" : "#"
		},
		{
			"Brand" : "Famous Footwear",
			"Image" : "famousWinter2011.jpg",
			"Logo"  : "Content/core/logo/famousLogo.png",
			"Thumb" : "Content/core/home/thumbs/famousFootwear.gif",
			"Description" : "<p>At Famous Footwear, we know that shoes are more than just something you put on your feet. Wearing the right shoe helps you make the most of every day. That&rsquo;s why our mission is to inspire our consumers&rsquo; walk through life. With over 1,100 stores in all 50 states, we&rsquo;re committed to providing women, men and kids with the brands they demand at prices they deserve.<br />Together with our partners, we meet our customers&rsquo; footwear needs by providing authority brands at attainable prices that help them define their style, and give them confidence in the choices they make for themselves and for their families.</p>", 
			"Link" : "http://www.famousfootwear.com"
		},
		{
			"Brand" : "Libby Edelman",
			"Image" : "LibbyEdelman-HomePortrait8x10bw.jpg",
			"Logo"  : "Content/core/logo/libbyLogo.png",
			"Thumb" : "Content/core/home/thumbs/libbyEdelman.gif",
			"Description" : "<p>Launched in 2008, Libby Edelman is a lifestyle brand that was created in response to a consumer need and void in the marketplace. Drawing upon her valuable years of experience as a renowned fashion editor, she gives women the ability to rediscover their style by creating a collection inspired by high fashion, reflective of the latest trends, but designed for real women with real lives.  Libby&rsquo;s personal love of fashion and expert editorial eye are what made her a natural success at translating the runway to reality. She understands that different life stages introduce different fashion needs as well as the need to evolve personal style to accommodate lifestyle.</p>", 
			"Link" : "http://www.libbyedelman.com"
		},
		{
			"Brand" : "Lifestride",
			"Image" : "LifeStride.jpg",
			"Logo"  : "Content/core/logo/lifeStrideLogo.png",
			"Thumb" : "Content/core/home/thumbs/lifeStride.gif",
			"Description" : "<p>LifeStride brought affordable fashion to the marketplace in 1941, making current, stylish footwear available to more women. Each season, LifeStride offers the most current looks and must-have styles. LifeStride always delivers on the latest trends with dynamic attitude and distinctive flair, offering a work-to-weekend shoe.</p>", 
			"Link" : "http://www.lifestride.com"
		},
		{
			"Brand" : "Ryka",
			"Image" : "Ryka.jpg",
			"Logo"  : "Content/core/logo/rykaLogo.png",
			"Thumb" : "Content/core/home/thumbs/ryka.gif",
			"Description" : "<p>Twenty-four years ago Sheri Poe stepped into the world of athletic footwear and challenged convention. She moved an entire industry to build products better suited to the needs of women. As fitness fads have come and gone, one thing remains true to this day: ryk&auml; is the only footwear company managed, designed, and solely dedicated to creating women&rsquo;s performance footwear. Women supporting women is the force motivating ryk&auml;&rsquo;s loyal and like-minded core.</p>", 
			"Link" : "http://www.ryka.com"
		},
		{
			"Brand" : "Buster Brown",
			"Image" : "Buster_Brown.jpg",
			"Logo"  : "Content/core/logo/busterLogo.png",
			"Thumb" : "Content/core/home/thumbs/busterBrown.gif",
			"Description" : "<p>Let&rsquo;s grow up together!  Good starts are essential for every child- whether it is a first step or bounding leaps, Buster Brown provides quality, style and fit for growing feet.  For over 100 years, Buster Brown has delivered fun footwear styles for kids, from a brand mom&rsquo;s know and trust.</p>", 
			"Link" : "http://www.busterbrownshoes.com"
		},
		{
			"Brand" : "Shoes.com",
			"Image" : "ShoesCom.jpg",
			"Logo"  : "Content/core/logo/shoesLogo.png",
			"Thumb" : "Content/core/home/thumbs/shoesCom.gif",
			"Description" : "<p>As one of the largest internet-only footwear sites shoes.com is the ultimate shoe lover&rsquo;s site, offering hundreds of sought after brands with the most-wanted styles and trends. In the constantly evolving digital marketing space, shoes.com utilizes the most current technologies including mobile applications, social media and international commerce.</p>", 
			"Link" : "http://www.shoes.com"
		}
	]
};


/* ===== Variables ===== */
var brandCount = homeImages.Brands.length - 1;
var moveImg = '';
var nextImg = '';
var moveThumb = '';
var nextThumb = '';
var moveDesc = '';
var nextDesc = '';
var moveLink = '';
var nextLink = '';
var appendImg = false;
var appendThumb = false;
var appendDesc = false;
var timeout = '';
var imgTimeout = '';
var slideTime = 3500;
var aniMult = 1800;
var aniWidth = 650;
var aniTime = 740;
var winWidth = $(window).width();
var currImg = '';
var fadeStart = false;
var currImgHeight = Math.round($('#homeWrap').height() - 47) + 'px';
var loadFlag=false;
var browseStarted = false;

/* ===== Functions ===== */
function placeInfoBox(el) {
	$('#brandWrapper').css({'visibility' : 'hidden', 'display' : 'block'});
	var elHeight = el.height();
	var elWidth = el.outerWidth();
	var offset = el.offset();
	var infoWidth = $('#brandWrapper').outerWidth();
	var infoHeight = $('#brandWrapper').outerHeight();
	var leftPos = Math.round(offset.left + elWidth * .5) - Math.round(.5 * infoWidth);
	$('#brandWrapper').css({'visibility' : 'visible', 'left' : leftPos}).fadeTo(0,0).fadeTo(0, 1);
}

function resizeImages() {
	var wrapHeight = Math.round($('#homeWrap').height() - 47) + 'px';
	currImgHeight = wrapHeight;
	var currHeightNum = parseInt(currImgHeight.replace('px', ''));
	$('#homeWrap img').each(function() {
		var imgRatio = $(this).attr('imgRatio') / 10000;
		var imgWidth = currHeightNum * imgRatio;
		$(this).attr({ 'height' : wrapHeight, 'width' : imgWidth }).height(wrapHeight).width(imgWidth);
	});	
}
$(window).resize(function() {
	winWidth = $(window).width();
	clearTimeout(imgTimeout);
	imgTimeout = setTimeout("resizeImages()", 1);
	clearTimeout(timeout);
	if ($('#browseBrands').hasClass('active')) {	
		timeout = setTimeout("closeBrandNav()", 200);
	} else {
		timeout = setTimeout("moveImage()", slideTime);
	}
	resized=true;
});
$('#brandThumbs img').live('click', function() {
	if (currImg != $(this).attr('src')) {
		if (fadeStart == false) {
			fadeStart = true;
			fadeInDiscover($(this));
			currImg = $(this).attr('src');
		}
	} else {
		if (fadeStart == false) {
			fadeOutDiscover();
			currImg = '';
		}
	}
});

function fadeInDiscover(imgEl) {
	var offset = imgEl.offset();
	var imgTop = Math.round(offset.top);
	var imgLeft = Math.round(offset.left);
	var imgWidth = imgEl.width();
	var infoWidth = $('#brandWrapper').outerWidth();
	//var leftPos = imgLeft + Math.round(imgWidth / 2) - Math.round(infoWidth / 2);
	var leftPos = imgLeft;
	var winHeight = $(window).height();
	//var botPos = winHeight - imgTop + 25;
	var botPos = winHeight - imgTop + 7;
	var navOffset = $('#brandNav').offset();	
	var navLeft = navOffset.left;
	var navWidth = $('#brandNav').width();
	var infoHeight = $('#brandWrapper').height();
	var imgIndex = imgEl.index();
	var infoOffset = $('#brandInfo .info').eq(imgIndex).offset();
	var brandOffset = $('#brandInfo').offset();
	var infoLeft = infoOffset.left;
	var brandLeft = brandOffset.left;
	var scrolled = $('#brandInfo').scrollLeft();
	var scrollDist = Math.round(infoLeft - brandLeft + scrolled);
	$('#brandWrapper').slideUp(400, function() {
		/* switch active brand story */
		var index = imgEl.index();
		$('#brandInfo .active').removeClass('active');
		$('#brandInfo .info').eq(index).addClass('active');
		var linkHref = $('#brandInfo .info').eq(index).children('a:last').attr('href');
		$('#brandLink a').attr('href', linkHref);
		
		/* switch left - right class */
		if (leftPos < navLeft) {
			leftPos = navLeft;
		} else if ((leftPos + infoWidth) > (navLeft + navWidth)) {
			//leftPos = navLeft + navWidth - infoWidth;
			leftPos = imgLeft + imgWidth - infoWidth;
			$('#brandWrapper').addClass('right');
		} else {
			$('#brandWrapper').removeClass('right');
		}
				
		var destImgWidth = $('#homeSlides img').eq(imgIndex).outerWidth();
		var destOffset = $('#homeSlides img').eq(imgIndex).offset();
		destOffset = destOffset.left;
		var destScrolled = $('#homeWrap').scrollLeft();
		var scrollSlides = Math.round(destOffset + destScrolled);
		
		var scrollLeftPos = Math.round((infoWidth - destImgWidth) / 2 + leftPos);
		scrollSlides = scrollSlides - scrollLeftPos;
		if (scrollSlides < 0) { scrollSlides = 0; }
		
		var scrollDist = Math.round(Math.abs(scrollSlides - destScrolled));
		var homeTime = Math.round(scrollDist / aniWidth * aniMult);		
		
		$('#homeSlides img:lt('+imgIndex+'), #homeSlides img:gt('+imgIndex+'), #brandThumbs img:lt('+imgIndex+'), #brandThumbs img:gt('+imgIndex+'), #brandNav .arrow').fadeTo(400, .4);
		$('#brandThumbs img').eq(imgIndex).stop().fadeTo(400,1);
		$('#homeSlides img').eq(imgIndex).stop().fadeTo(400,1, function() {
			$('#homeWrap').stop(true, false).animate({ 'scrollLeft' : scrollSlides }, homeTime, 'easeInOutSine', function() {
				$('#brandWrapper').animate({'bottom' : botPos, 'left' : leftPos}, 0, function() {
					$('#brandWrapper').slideDown(600, function() { 
						fadeStart = false; 
					});
				});
			});
		});
	});
}
function fadeOutDiscover() {
	$('#homeSlides img, #brandNav img, #brandNav .arrow').fadeTo(1, 600);
	$('#brandWrapper').slideUp(600);
}
function closeBrandNav() {
	fadeStart = false;
	/* fadeOut Discover */ $('#brandWrapper').slideUp(600);
	var imgWidth = $('#brandThumbs img:first').outerWidth();
	var navWidth = $('#brandThumbs').width();
	var visiCount = Math.floor(navWidth / imgWidth);
	$('#leftArrow, #rightArrow').fadeOut(400, function() {
		$('#leftArrow, #rightArrow').removeClass('active').removeAttr('style');
	});
	$('#brandNav img').each(function() {
		var fadeCount = $(this).index();
		if (fadeCount >= visiCount) { var fadeDelay = 0; var fadeTime = 0; } 
		else { var fadeDelay = fadeCount * 80; var fadeTime = 450; }
		$(this).stop().delay(fadeDelay).fadeTo(fadeTime, .01, function() {
			$(this).css({'visibility' : 'hidden'}).fadeTo(0,0);
		});
	});
	var delayAni = visiCount * 80 + 150;
	$('#brandNav').delay(delayAni).animate({'height' : '0', 'paddingTop' : '0'}, 400, function() {
		$(this).animate({'width' : '16%', 'marginLeft' : '-8%'}, 200, function() {
			var scrollDist = $('#homeWrap').scrollLeft();
			var homeTime = Math.round(scrollDist / aniWidth * aniMult);
			$('#homeSlides img, #brandThumbs img').fadeTo(400,1, function() {
				$('#homeWrap').animate({'scrollLeft' : 0}, homeTime, 'easeInOutSine');
				$('#brandWrap').scrollLeft(0).removeAttr('style');
				$('#brandThumbs').removeAttr('style');
				$('#leftArrow, #rightArrow').removeClass('active').removeAttr('style');
			});
			browseStarted=false;
			clearTimeout(timeout);
			timeout = setTimeout("moveImage()", slideTime);
		});
	});
}

function moveImage() {

	if (appendImg) {
		var currHeight = $('#homeSlides img:first').attr('height');
		var imgRatio = appendImg.attr('imgRatio');
		imgRatio = imgRatio / 10000;
		var imgWidth = Math.round(currHeight * imgRatio);
		appendImg = appendImg.attr('height', currHeight).height(currHeight).width(imgWidth);
		appendThumb = appendThumb.removeAttr('style');
		$('#homeSlides').append(appendImg);
		$('#brandThumbs').append(appendThumb);
		$('#infoWrapper').append(appendDesc);
	}
	
	
	moveImg = nextImg;
	moveThumb = nextThumb;
	moveDesc = nextDesc;
	
	nextImg = moveImg.next();
	nextThumb = moveThumb.next();
	nextDesc = moveDesc.next();
	
	var outerWidth = moveImg.outerWidth();
	var marginAni = '-' + outerWidth + 'px';
	var scrollDist = '+=' + outerWidth + 'px';
	aniTime = Math.round(outerWidth / aniWidth * aniMult);
	if (aniTime > 1200) { aniTime = 1200; }
	clearTimeout(timeout);
	$("#homeWrap").stop().animate({'scrollLeft' : scrollDist }, aniTime, 'easeInOutSine', function() {
		nextImg = moveImg.next();
		nextThumb = moveThumb.next();
		
		appendThumb = moveThumb.clone();
		appendImg = moveImg.clone();
		appendDesc = moveDesc.clone();
		
		moveImg.delay(100).remove();
		moveThumb.delay(100).remove();
		moveDesc.delay(100).remove();
		
		$('#homeWrap').scrollLeft(0);
		timeout = setTimeout("moveImage()", slideTime);
	});
}

/* ===== Event Capture ===== */
$('#browseBrands').click(function() {
	if (!browseStarted) {
		if ($(this).hasClass('active')) {
			browseStarted = true;
			$(this).removeClass('active');
			if ($('#brandWrapper').is(':visible')) {
				$('#brandWrapper').stop().slideUp(400, function() {
					closeBrandNav();
				});
			} else {
				closeBrandNav();
			}
		} else {
			browseStarted=true;
			clearTimeout(timeout);
			var navWidth = Math.floor($(window).width() *.8);
			$(this).addClass('active');
			$('#brandNav').animate({'width' : navWidth, 'marginLeft' : '-40%'}, 400, function() {
				var imgWidth = $('#brandThumbs img:first').outerWidth();
				var navWidth = navWidth - 80;
				var imgCount = Math.floor(navWidth / imgWidth);
				var imgMargin = Math.floor((navWidth - (imgCount * imgWidth)) / imgCount);
				var sideMargin = navWidth - (imgWidth*imgCount+imgMargin*imgCount);
				$(this).animate({'height' : '100px', 'paddingTop' : '26px'}, 300, function() {
					$('#brandNav img').css({'margin-right' : imgMargin, 'display' : 'none', 'visibility' : 'visible'});
					calcBrandWrap();
					$('#brandNav img').each(function() {
						var fadeCount = $(this).index();
						var fadeDelay = fadeCount * 80;
						$(this).stop().fadeOut(0).delay(fadeDelay).fadeTo(450,1);
						$('#leftArrow, #rightArrow').fadeIn(400).addClass('active').removeAttr('style');
						browseStarted=false;
					});
				});
			});
		}
	}
	return false;
});


var winHeight = $(window).height();
if (winHeight < 501) { var folder='Content/2011/home/500'; }
else if (winHeight < 751) { var folder='Content/2011/home/750'; }
else { var folder = 'Content/2011/home/1200';}


var index = 0;
var thumbSrc = homeImages.Brands[0].Thumb;
var imgSrc = folder+'/'+homeImages.Brands[0].Image;
$('document').ready(function() {
	$('#homeWrap').scrollLeft(0);
	loadImage(imgSrc, thumbSrc, 0);

});

/* ===== Stop Animation when using Menu ===== */
function loadImage(imgSrc, thumbSrc, i) {
	var img = new Image();
	var tmpSrc = imgSrc;
	var tmpThSrc = thumbSrc;
	$("<img/>").load(function() {
		var width = this.width;
		var height = this.height;
		var imgRatio = width / height;
		var wrapHeight = Math.round($('#homeWrap').height() - 47);
		var imgWidth = Math.round(wrapHeight * imgRatio) + 'px';
		wrapHeight = wrapHeight + 'px';
		var attrRatio = Math.round(imgRatio * 10000);
		$(img).attr({'imgRatio' : attrRatio, 'height' : wrapHeight }).attr('width', imgWidth).css({'height' : wrapHeight, 'width' : imgWidth }).attr('src', tmpSrc).fadeTo(0, 0);
		$('#homeSlides').append(img);
		$('#infoWrapper').append('<div class="info"><h2 class="brandLogo"><img src="'+homeImages.Brands[i].Logo+'" alt="'+homeImages.Brands[i].Brand+'" /></h2>'+ homeImages.Brands[i].Description +'<a href="' + homeImages.Brands[i].Link + '">View Website</a></div>');
		$('#brandThumbs').append('<img src="'+tmpThSrc+'" />');
		var fadeTime = 600 + (200 * i);
		$(img).fadeTo(fadeTime, 1);
		if (i == brandCount) {
			nextImg = $('#homeSlides img:first');
			nextThumb = $('#brandThumbs img:first');
			nextDesc = $('#infoWrapper .info:first');
			timeout=setTimeout("moveImage()", slideTime);
		} else if (!loadFlag) {
			loadFlag=true;
			for (i=1; i<=brandCount; i++) {
				var index = i;
				var thumbSrc = homeImages.Brands[i].Thumb;
				var imgSrc = folder+'/'+homeImages.Brands[i].Image;
				loadImage(imgSrc, thumbSrc, i);
			}
		}
	}).attr('src', imgSrc);
}
function calcBrandWrap() {
	var thumbWidth = $('#brandThumbs img:first').outerWidth(true);
	var thumbMargin = Math.floor(thumbWidth - $('#brandThumbs img:first').outerWidth());
	var totalThumbs = $('#brandThumbs img').length;
	var brandThumbsWidth = Math.ceil(totalThumbs * thumbWidth);
	var wrapWidth = Math.floor($(window).width()*.8) - 80;
	var thumbCount = Math.floor(wrapWidth / thumbWidth);
	var wrapMargin = '0 ' + Math.floor(40 + (wrapWidth - thumbWidth * thumbCount + thumbMargin) / 2) + 'px';
	$('#brandThumbs').width(brandThumbsWidth);
	$('#brandWrap').css('margin', wrapMargin);
}
function stopSlide() {
	clearTimeout(timeout);
}

var wrapConfig = { over: stopSlide, out: closeBrandNav, sensitivity:1 }
$("#menuWrapper").hoverIntent( wrapConfig );

/* ===== Scroll Through Brand Thumbs ===== */
$('#leftArrow').click(function() {
	/* fadeOut Discover */ $('#brandWrapper').slideUp(600);
	var scrollWidth = $('#brandThumbs img:first').outerWidth(true);
	$('#brandWrap').animate({'scrollLeft' : '-=' + scrollWidth}, 600);
	return false;
});
$('#rightArrow').click(function() {
	/* fadeOut Discover */ $('#brandWrapper').slideUp(600);
	var fullWidth = $('#brandThumbs').width();
	var scrolled = $('#brandWrap').scrollLeft() + $('#brandWrap').width();
	var scrollWidth = $('#brandThumbs img:first').outerWidth(true);
	if ((fullWidth - scrolled) >= scrollWidth) {
		$('#brandWrap').animate({'scrollLeft' : '+=' + scrollWidth}, 600);
	}
	return false;
});
$('#menuWrapper').mouseenter(function() {
	/* fadeOut Discover */ $('#brandWrapper').slideUp(600);
});

