//Juniors Features : Jquery Rotation Script
var autoRotate,
	curStory = -1,
	rate = 850;

$.fn.buildNavigation = function() {
	
	$('#coverNav span')
		.before('<img src="'+PageParameters.imageUrl+'default/shop/image/common/transpixel.gif" class="divider" />')
		.after('<img src="'+getImageURL()+'store/common/transpixel.gif" class="divider" />');
	
	return this.each(function(i) {
		
		$('#coverNav span')
			.append('<a href="javascript:void(0)"><img src="'+PageParameters.imageUrl+'default/shop/image/common/transpixel.gif" alt="Slide '+(i+1)+' Nav" /></a>')
			.children('a:last')
				.bind('readChapter', function() {
					
					var n = $('#coverNav span a').index(this);
					
					curStory = n;
					
					$(this)
						.addClass('sel')
							.siblings()
								.removeClass('sel');
					
					$('#coverImages > div').eq(n).trigger('readable');
				});
		
		if( $('#coverImages > div').index(this)!=0 ) {
			
			$(this).css({opacity:0});
		}
		
		$('#coverCopy > div')
			.not($('#coverNav')[0])
				.css({visibility:'visible',opacity:0});
		
		$(this)
			.css({visibility:'visible'})
			.bind('readable', function(e) {
				
				var n = $('#coverImages > div').index(this);
				
				if( $('#coverCopy > div').length > 2 ) {
					
					$('#coverCopy > div').eq(n).animate({opacity:1}, rate).addClass('active');
					
					$('#coverImages > div').not(e.target).each(function(){
						
						var n = $('#coverImages > div').index(this);
						
						$('#coverCopy > div').eq(n).css({opacity:0}).removeClass('active');
					});
					
				} else {
					
					$('#coverCopy > div').css({opacity:1});
				}
				
				$(this).addClass('trans').animate({opacity:1}, rate, function(){
					
					$(this).addClass('active').removeClass('trans');
					
					$('#coverImages > div').not(e.target).trigger('unreadable');
				});
			})
			.bind('unreadable',function(e){
				
				$(this).animate({opacity:0}, rate).removeClass('active trans');
			});
	});
}
$(document).ready(function(){
	
	$('#coverNav')
		.prepend('<a href="javascript:void(0)"><img src="'+PageParameters.imageUrl+'default/shop/image/common/back.gif" alt="BACK" /></a><span></span><a href="javascript:void(0)"><img src="'+PageParameters.imageUrl+'default/shop/image/common/next.gif" alt="NEXT" /></a>')
		.css({top: $('#coverCopy > div:first').height() + 15});
	
	$('#coverImages > div').buildNavigation();
	
	$('#coverNav > a,#coverNav > span > a')
		.filter(':first')
			.bind('prevChpt',function(){
				
				if(curStory==0){
					$('#coverNav > span > a').eq($('#coverImages > div').length-1).trigger('readChapter');
				}else{
					$('#coverNav > span > a').eq(curStory-1).trigger('readChapter');
				}
			})
		.end()
		.filter(':last')
			.bind('nextChpt',function(){
				
				if(curStory==$('#coverImages > div').length-1){
					$('#coverNav > span > a').eq(0).trigger('readChapter');
				}else{
					$('#coverNav > span > a').eq(curStory+1).trigger('readChapter');
				}
				autoRotate=setTimeout(function(){$('#coverNav > a:last').trigger('nextChpt');},5000);
			})
		.end()
		.click(function(e) {
	
			e.preventDefault();
			
			$('#cover *:animated').stop(true);
			
			clearTimeout(autoRotate);
			
			$(this).trigger('readChapter').trigger('prevChpt').trigger('nextChpt');
			
			clearTimeout(autoRotate);
		})
		.trigger('nextChpt');
			
	$('#cover a').each(function(){
		
		if($(this).attr('name')=='undefined'||!$(this).attr('name').length>0){
			if($('> img',this).length>0){
				$(this).attr('name',$('> img',this)[0].alt);
			}else{
				$(this).attr('name',$(this).text());
			}
		}
	});
});

//Juniors Features : BP. Fashion Board Blog RSS Reader
google.load("feeds", "1");
function initialize(){
	var feed = new google.feeds.Feed("http://fromthefloor.nordstrom.com/bpfashionboard/rss.xml");
	var container = document.getElementById("feed");
	var itemTpl = '<div><span class="socialTitleMed">{TITLE}</span><br /><br /><p class="byline">by {AUTHOR} on {DATE}</p><br /><p>{BODY}</p><br /><div id="blogDots"><a href="{HREF}" target="_blank"><img src="' + PageParameters.imageUrl + 'default/shop/image/dlp/juniors/2010/0821/features/read_more.gif" alt="ReadMore" /></a></div><br /><br /></div>';
	var items = [];
	var month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
	feed.setNumEntries(2);
	feed.includeHistoricalEntries(true);
	feed.load(function(result) {
		if (!result.error) {
			for (var i = 0; i < result.feed.entries.length; i++) {
				var entry = result.feed.entries[i];
				var published = new Date(entry.publishedDate);
				items.push(
					itemTpl.replace('{TITLE}', entry.title)
						.replace('{HREF}', entry.link)
						.replace('{AUTHOR}', entry.author)
						.replace('{DATE}', month[published.getMonth()] + ' ' + published.getDate() + ', ' + published.getFullYear())
						.replace('{BODY}', entry.contentSnippet)
						.replace('{HREF}', entry.link)
				);
			}
			container.innerHTML = items.join("\n");
		}
	});
}
google.setOnLoadCallback(initialize);

//All Juniors : Facebook Like Button
$(window).load(function() {
	addLikeBox($('#facebookLike'), {
		'id': '152863595007',
		'height': '62px',
		'width': '245px'
	});
});
