var rspb = function() {
	
	function toolTips() {
		$('#moments a').tooltip({
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - ",
			fade: 250,
			top: 25, 
			left: -65
		});
	}
	
	function editorsPicks() {
		$('#picks_title').css('visibility', 'hidden');
		$('#editors_picks').cycle({
			fx: 'fade',
			speed: 1000,
			timeout: 8000,
			pager: '#nav',
			before: editorsPicksTitleOut,
			after: editorsPicksTitleIn,
			pause: 1 ,
			cleartype: 1
		});
	}
	
	function editorsPicksTitleOut() { 
		$('#picks_title').fadeOut(600);
		$('#picks_title').css('visibility', 'visible');
	}
	
	function editorsPicksTitleIn() {
		$('#picks_title').css('visibility', 'visible');
		$('#picks_title').html(this.title);
		$('#picks_title').fadeIn(400);
	}
	
	var _gallery_animating = false;
	
	function initGallery(){	
		$('a.recent_right').click(function() {
			rspb.moveGallery(this, 'forward');
			return false;
		});
		$('a.recent_left').click(function() {
			rspb.moveGallery(this, 'backward');
			return false;
		});		
	}
	
	function moveGallery(element, direction){
		var defaultSpeed = 800;
		var defaultWidth = 520;
		var width = 0;	
		
		$(element).parent().find('.recent_moments_inner ol li').each(function() {
			width += 130;
		});		
	
		if(!rspb._gallery_animating) {
			
			rspb._gallery_animating = true;
			var imageList = $(element).parent().find('.recent_moments_inner ol');		
			var currentLeft = imageList.css('left') == 'auto' ? 0 : parseInt(imageList.css('left').replace('px', ''));
				
			switch(direction) {
				
				case 'forward':
					var leftVal = currentLeft - defaultWidth;
					var leftPane = currentLeft - (defaultWidth*2);
					if(Math.abs(leftPane) > width) {
						leftVal = parseInt('-' + (width - defaultWidth));
					}			
					break;
					
				case 'backward':
					var leftVal = currentLeft + defaultWidth;
					var leftPane = Math.abs(currentLeft) - defaultWidth;
					if(leftPane < 0) {
						leftVal = 0;
					}		
					break;	
			}

			var time = Math.abs(defaultSpeed * ((currentLeft - leftVal) / defaultWidth));
						
			imageList.animate({left: leftVal + 'px'},time,'swing',
			function() {
				rspb._gallery_animating = false;
			});
		}	
	}
	
	function limitEntry(txtid,infid,linelimit,charlimit){
		var txt = $('#'+txtid).val();
		var txtlength = txt.length;
		var line = txt.replace(/\s+$/g,"");
		var split = line.split("\n");
		var splitlength = split.length;
		
		if(splitlength > linelimit || txtlength > charlimit){
			$('#'+infid).html('<span class="caution">Your entry has reached '+(charlimit)+' characters!</span>');
			$('#'+txtid).val(txt.substr(0,linelimit));
			$('#'+txtid).val(txt.substr(0,charlimit));
			return false;
		}else{
			$('#'+infid).html((charlimit - txtlength)+' characters remaining');
			return true;
		}

	}
	
	function webkitStyles(){
		if($.browser.safari) { 
			$('.form_elm_file input').css('color', 'white');
			$('#moments_item_top').css('minHeight', 80);
		}	
	}
	
	return {
		initGallery: initGallery,
		moveGallery: moveGallery,
		toolTips: toolTips,
		editorsPicks: editorsPicks,
		limitEntry: limitEntry,
		webkitStyles: webkitStyles
	};
           
}();

var diagnose = function(boxy) {
        alert("Position: " + boxy.getPosition() +
              "\nSize: " + boxy.getSize() +
              "\nContent size: " + boxy.getContentSize() +
              "\nCenter: " + boxy.getCenter());
    };
    
    
function Loadimagepreview(){
 
$('.load_image').submit(function() {
	$('.preview').attr('id','loading');  
});
}

$(document).ready(function() { 
	rspb.initGallery(); 
	rspb.toolTips();
	rspb.editorsPicks();
	rspb.webkitStyles();
	$('#ctl00_main_ShareYourMomentWizard_TextBoxDescription').keyup(function(){
		rspb.limitEntry('ctl00_main_ShareYourMomentWizard_TextBoxDescription','counter',100,250); /*changed - a.seabridge 02/10/2008 - changed name of textbox*/
	})
	//Modal Popups
    $('a[rel*=facebox]').facebox()
    //Loadimagepreview();
});

