/* Author: 

*/
;
(function($){
$(document).ready(function(){
	
	var win = $(window),
		doc = $(document),
		body = $('body'),
		base = 'http://www.amillionsighs.com/wp-content/themes/amillionsighs_v2/'
	;
	
	$('.says').remove();
	
	var frameAPI = (function(){
		var currentImg = 1,
			currentFrame = 1,
			imageList,
			frame = $('#photoframe'),
			frameInterval
		;
		
		var setList = function(a){
			imageList = a;
		};
		
		var changeFrame = function(){
			currentImg++;
			if(currentImg >= imageList.length){
				currentImg = 0;
			};
			frame
				.find('.img-trans-'+currentFrame)
				.fadeOut(1500, 'linear', function(){
					$(this).find('img').attr('src', base+'framephotos/'+imageList[currentImg]);
				})
			;
			currentFrame = currentFrame===1 ? 2 : 1;
			frame
				.find('.img-trans-'+currentFrame)
				.fadeIn(1500, 'linear')
			;
		};
		
		var init = function(){
			currentImg = 1;
			currentFrame = 1;
			frame.find('.img-trans-1').show().html('<img src="'+base+'framephotos/'+imageList[0]+'" style="z-index:7;" />');
			frame.find('.img-trans-2').hide().html('<img src="'+base+'framephotos/'+imageList[1]+'" style="z-index:7;" />');
		};
				
		frameInterval = setInterval(changeFrame, 5000);
		
		return {
			init: init,
			setList: setList
		};
	})();
	
	frameAPI.setList(frameImageList);
	frameAPI.init();
	
/*
	var fixCommentBox = (function(){
		
		var oldBox = $(),
			currentBox = $(),
			currentBoxXY={},
			fixed = false,
			posCheck,
			commentBox = $(),
			respondBox = $(),
			cloneBox,
			botY
		;

		var fixBox = function(that){
			oldBox.css({position:'static'});
			oldBox = currentBox;
			currentBox = that;
			currentBoxXY.y = currentBox.offset().top;
			currentBoxXY.x = currentBox.offset().left;
			commentBox = currentBox.next('.comments-wrap');
			respondBox = commentBox.next('.respond');
			commentBox.show();
			respondBox.show();
			botY = currentBoxXY.y + commentBox.outerHeight(true) + respondBox.outerHeight(true);
			commentBox.hide();
			respondBox.hide();
		};
		
		var clearBoxes = function(moveIt){
			currentBox.css({position:'static'});
			commentBox.css({marginTop:0});
			if(moveIt!==false){
				try{
					$('html, body').animate({ scrollTop: currentBox.offset().top - 20 });
				}catch(clearBoxErr){};
			};
			oldBox = $();
			currentBox = $();
			respondBox = null;
		};
		
		win.bind('scroll.sighs', function(){
			var t = win.scrollTop();
			posCheck = t >= currentBoxXY.y;
			if(fixed===false && posCheck===true){
				fixed = true;
				currentBox.css({
					position: 'fixed',
					top: -10,
					left: currentBoxXY.x,
					zIndex: 30
				});
				commentBox.css({marginTop:74});
			}else if(fixed===true && posCheck===false){
				fixed = false;
				currentBox.css({
					position: 'static'
				});
				commentBox.css({marginTop:0});
			}else if( t >= botY ){
				clearBoxes(false);
			}
		});
		
		win.trigger('scroll.sighs');
		
		return {
			fixBox: fixBox,
			clearBoxes: clearBoxes
		};
		
	})();
*/
	
	var toggleComment = function(that, btn){
		var commentBox = that.parent().parent().next('.comments-wrap'),
			isOpen = commentBox.is(':visible'),
			respond = commentBox.next('.respond'),
			numBtn = that.parent().parent().find('.comments-number .button'),
			cB = commentBox.prev('.comments-info')
		;
		
		numBtn.text( isOpen===true && btn==='num' ? numBtn.attr('data-num') : 'Close Comments' );
		commentBox.add(respond)[isOpen===true && btn==='num'?'slideUp':'slideDown'](function(){
			if(btn==='form'){
				$('html, body').animate({
					scrollTop: respond.offset().top - 90
				});
			};
		});
	};
	
	$('.comments-number a').bind('click', function(){
		toggleComment($(this), 'num');
		return false;
	});
	
	$('.comments-add a').bind('click', function(){
		toggleComment($(this), 'form');
		return false;
	});
	
	
});

})(jQuery);

