var rim = rim || {};

var stringJSP =					'.jsp';
var stringIndexJSP = 			'index.jsp';
var stringFlashVideo = 			"<div id='flashMovieReplace'>&nbsp;</div>";
var documentHref = 				document.location.href;
var devicePageLink = 			documentHref.substring(0, documentHref.indexOf(stringJSP));
var scrollerContentID =			'#scrollerContent';


if (devicePageLink.indexOf('curve') > -1 || devicePageLink.indexOf('pearl') > -1) {
	devicePageLink = devicePageLink + "3G";
}

if (documentHref.indexOf(stringJSP) > -1 && documentHref.indexOf(stringIndexJSP) > -1) {
	var hScrollerLI = $($('#scrollerContent ul li')[0]);
	
	hScrollerLI.html(hScrollerLI.html() + "<a href='" + devicePageLink + "/' class='devicePageMainLink'>&nbsp;</a>");
}

rim.OnloadEvents.Register(function () {
	var shareUrl = documentHref;

	if (shareUrl.indexOf('?') > -1) {
		shareUrl = shareUrl.substring(0, shareUrl.indexOf('?'));
	}
	
	if (document.getElementById("buzz") != null) {
		$("#buzz ul").remove();
		$("#buzz").append("<div id='feeds_body'></div>");
		
		parseXML((typeof(deviceFeedsXmlUrl) != "undefined") ? deviceFeedsXmlUrl : 'torch.xml', $("#feeds_body"));
	}
});

rim.HeroScrollerFamily = function (selector) {
	this.WrapRight = 	false;
	this.WrapLeft = 	false;

	this.WrapBothClass = 	'wrapBoth';
	this.WrapLeftClass = 	'wrapLeft';
	this.WrapRightClass = 	'wrapRight';

	this.ScrollerSelector = selector;
	this.Self = 			$(this.ScrollerSelector);

	this.StopPointSelector = '.stopPoint';
	this.StopPoints = 		$(this.StopPointSelector);

	this.ScrollLeftButton = 	$('#pageLeft');
	this.ScrollRightButton = 	$('#pageRight');

	this.PrevNameAttr = 'prevname';
	this.NextNameAttr = 'nextname';
	this.PrevUrlAttr = 	'prevurl';
	this.NextUrlAttr = 	'nexturl';

	this.OffsetAttr = 'offset';

	this.PrevNameDefault = '';
	this.NextNameDefault = '';

	this.CurrentIndex = 0;

	this.safeArea = 985;
	
	this.hasInteractions = false;
	
	this.autoScrollToEndTime = 		18000;
	this.defaultScrollSpeed = 		1800;
	this.autoScrollByFrameTime =	10000;
	this.timeBeforeAutoScroll = 	10000;
	
	this.scrollerContnetSelector = 		scrollerContentID;
	this.overscrollHelperSelector = 	'#overscrollHelper';
	this.scrollerContentLISelector = 	this.scrollerContnetSelector + ' li';
	this.lastFrameCellSelector =		'#lastFrame .cell';
	this.lastFrameLargeSelector = 		this.lastFrameCellSelector + ' .large';
	this.hoverTextSelecor = 			'.hoverText em';
	
	this.promoXmlPromoSelector = 		'promo#';
	this.promoXmlGroupSelector = 		'group';
	
	this.omnitureAttrPromo = 				'promo';
	this.omnitureAttrOmnitag =				'omnitag';
	this.omnitureAttrCtaScrollToFrame = 	'ctaScrollToFrame';
	this.omnitureAttrCta = 					'cta';
	this.omnitureAttrFlashPromo =			'flashPromo';
	this.omnitureAttrFrameView = 			'frameView';
	this.omnitureAttrHomepagePromo =		'Homepage-Promo-';
	this.omnitureAttrScrollerEventText = 	'Horizontal Scroller Event';
	this.omntureAttrLoad = 					'load';
	
	this.touchScrollerDivHtml = '<div id="touchScroller" />';
	this.showButtonCSS =	 	{'display': 'block', 'visibility': 'visible'};
	this.visibleCSS =			{'visibility': 'visible'};
	this.slideFromLeftValue = 	'slideFromLeft';
	this.inactiveClass = 		'inactive';
	this.replaceClass = 		'replace';

	this.InitScroller();
};

rim.HeroScrollerFamily.prototype = {
	InitializeOmnitureHandling: function() {
		var me = this;
		
		me.omnitureFrame = 		1;
		me.omniturePageName = 	"";
		me.omnitureFrameName = 	"";
		me.hasOmnitureTagging = false;
		
		$('#threeSixtyImage').live('mousedown', function() {
			doOmnitureUIEvent('360:NAV ACTION');
		});

		if ($(me.scrollerContnetSelector).attr(me.omnitureAttrOmnitag)) {
			me.omniturePageName = $(me.scrollerContnetSelector).attr(me.omnitureAttrOmnitag);
			me.hasOmnitureTagging = true;
		} else if (typeof(_rpn) != "undefined") {
			me.omniturePageName = _rpn;
			me.hasOmnitureTagging = false;

			return;
		}
		
		me.InitializeFrameCTAs();
		
		me.DoOmnitureEvent(me.omntureAttrLoad);
		
	},
	InitializeFrameCTAs: function() {
		var me = this;
		
		$(me.scrollerContentLISelector + ' a.cta').bind('mouseup', function() {
			if ($(this).attr(hScroller.omnitureAttrPromo)) {
				hScroller.DoOmnitureEvent(hScroller.omnitureAttrPromo, $(this).attr(hScroller.omnitureAttrOmnitag));
			} else if ($(this).hasClass(hScroller.omnitureAttrCtaScrollToFrame)) {
				hScroller.DoOmnitureEvent(hScroller.omnitureAttrCtaScrollToFrame, $(this).attr(hScroller.omnitureAttrOmnitag));
			} else {
				hScroller.DoOmnitureEvent(me.omnitureAttrCta, $(this).attr(hScroller.omnitureAttrOmnitag));
			}
		});
	},
	AutoScrollNoInteractions: function() {
		var me = this;
		
		if (!me.hasInteractions) {
			var stopPoints = 	$(me.StopPointSelector),
				length = 		stopPoints.length;
				
			me.CurrentIndex = length - 1;
			me.ScrollTo(false, me.autoScrollToEndTime);
		}
	},
	AutoScrollNoInteractionsByFrame: function () {
		var me = this;
		
		if (!me.hasInteractions) {
			var stopPoints = 	$(me.StopPointSelector),
				length = 		stopPoints.length;
				
			me.CurrentIndex++
			
			if (me.CurrentIndex > (stopPoints.length - 1)) {
				me.CurrentIndex = me.CurrentIndex - 1;
				return;
			}
			
			me.ScrollTo(false);
			
			setTimeout("hScroller.AutoScrollNoInteractionsByFrame()", me.autoScrollByFrameTime);
		}
	},
	UpdateFrameForOmniture: function() {
		var me = this;
		
		if (this.CurrentIndex != (this.omnitureFrame - 1)) {
			this.omnitureFrame = this.CurrentIndex + 1;
			
			this.DoOmnitureEvent(me.omnitureAttrFrameView);
		}
	},
	DoOmnitureEvent: function(type, text) {
		var me = this, s = s_gi(s_account);
		
		s.products = 		"";
		s.eVar21 =		me.omniturePageName; 

		// default frame tag
		var frameTag = 	';' + me.omniturePageName + ':frame' + me.omnitureFrame;
		
		// get frameTitle from omnitag attribute on li
		
		// NOFLASH: if the frame has an omnitag, use that instead of 'frame#'
		if($('#flashContent').css('display') == 'none'){
			me.omnitureFrameName = me.StopPoints.eq(me.CurrentIndex).attr(me.omnitureAttrOmnitag);
			frameTag = 	';' + me.omniturePageName + ':' + me.omnitureFrameName;
			s.products = 	frameTag; 
		}else{ // HAS FLASH
			if(me.omnitureFrameName != ''){
				frameTag = 	';' + me.omniturePageName + ':' + me.omnitureFrameName;
			} else{
				me.omnitureFrameName = me.StopPoints.eq(me.CurrentIndex).attr(me.omnitureAttrOmnitag);
				frameTag = 	';' + me.omniturePageName + ':' + me.omnitureFrameName;
			}
			s.products = 	frameTag; 
		}
		
		if (type == me.omnitureAttrCta || type == me.omnitureAttrCtaScrollToFrame || type == me.omnitureAttrPromo || type == me.omnitureAttrFlashPromo) {
			s.events =			'event19'; 
			s.linkTrackVars =	'eVar21,products,events'; 
			s.linkTrackEvents =	'event19'; 
		} else {
			s.events =			'event18'; 
			s.linkTrackVars =	'eVar21,products,events'; 
			s.linkTrackEvents =	'event18'; 
		}
	
		if (type == me.omntureAttrLoad) {
			/* nothing custom for load here yet */
		} else if (type == me.omnitureAttrCta || type == me.omnitureAttrCtaScrollToFrame) {
			s.products = 	s.products + ',' + frameTag + '-' + text; 
		} else if (type == me.omnitureAttrPromo || type == me.omnitureAttrFlashPromo) {
			s.products = 	s.products + ',' + frameTag + '-' + text; 
		} else if (type == me.omnitureAttrFrameView) {
			var stopPoints = 	$(me.StopPointSelector),
				length = 		stopPoints.length;
				
			if (me.omnitureFrame == stopPoints.length) {
				var endFrameCtas = 			$($(me.StopPointSelector)[stopPoints.length - 1]).find('.cta'),
					endFrameCtasLength = 	endFrameCtas.length,
					promoText = 			"";
				
				// ignore all the promo products when you land on the sidekicks frame
				// for (var i = 0; i < endFrameCtasLength; i++) {
				// 	if ($(endFrameCtas[i]).attr(me.omnitureAttrPromo)) {
				// 		promoText += ",;" + me.omnitureAttrHomepagePromo + $(endFrameCtas[i]).attr(me.omnitureAttrOmnitag);
				// 	}
				// }
				
				s.products = 	s.products + promoText; 
			}
		}
		
		void(s.tl(this,'o', this.omnitureAttrScrollerEventText));
	},
	CreatePromoHtml: function (xmlPromo) {
		var me = this, title = xmlPromo.find('title').text(), titleLine2, titleLine2Obj = xmlPromo.find('titleLine2'),
			link = 	xmlPromo.find('link').text(), linkText = xmlPromo.find('linkText').text(),
			linkTarget = xmlPromo.find('linkTarget').text(), omnitureTag = xmlPromo.find('omnitureTag').text(),
			staticOffsetY = xmlPromo.find('staticOffsetY').text(), staticOffsetX = xmlPromo.find('staticOffsetX').text(),
			imagePath = xmlPromo.find('imagePath').text(), titleHtml = "", html = "<div class='large " + me.replaceClass +"'>";

		if (titleLine2Obj.length > 0) {
			titleLine2 = titleLine2Obj.text();
			titleHtml = "<div class='indent'>";
		}
		
		titleHtml += title;
		
		if (titleLine2Obj.length > 0) {
			titleHtml += "</div>" + titleLine2;
		}
		
		html = "<img src='" + imagePath + "' style='position:absolute;top:" + staticOffsetY + "px;left:" + staticOffsetX + "px;'/>" + html + titleHtml + "</div><a href='" + link + "' class='" + me.omnitureAttrCta + "' promo='true'";
		
		if (linkTarget != "") {
			html += " target='" + linkTarget + "'";
		}
		
		html += " " + me.omnitureAttrOmnitag + "='" + omnitureTag + "'>" + linkText + "</a>";

		return html;
	},
	InitPromos: function() {
		var me = this, promoXML = (typeof(tempEndPromos) != "undefined") ? tempEndPromos : "endpromos.xml";
		
		$.ajax({
		    type: "GET",
			url: promoXML,
			dataType: "xml",
			success: function(xml) {
				var promoGroupsCount = $(xml).find(me.promoXmlGroupSelector).length, groupToUse = 0;
				
				if (promoGroupsCount > 1) {
					groupToUse = Math.floor(Math.random() * ((promoGroupsCount - 1) - 0 + 1)) + 0;
				}

				var promos = $($(xml).find(me.promoXmlGroupSelector)[groupToUse]).text().split(",");

				$(me.lastFrameCellSelector + '1').html(me.CreatePromoHtml($(xml).find(me.promoXmlPromoSelector + promos[0])));
				$(me.lastFrameCellSelector + '2').html(me.CreatePromoHtml($(xml).find(me.promoXmlPromoSelector + promos[1])));
				$(me.lastFrameCellSelector + '3').html(me.CreatePromoHtml($(xml).find(me.promoXmlPromoSelector + promos[2])));
				
				rim.InitCufon();
				
				$(me.lastFrameLargeSelector).css(me.visibleCSS);
			}
		});
	},
	InitScroller: function () {
		var me = this;
		
		setTimeout(function() {
		    me.Self.scrollLeft(0)
		}, 0);
		
		if ($(me.lastFrameCellSelector).length > 0) {
			me.InitPromos();
		}	
	
		this.InitializeOmnitureHandling();
		
		var newLeft = 	($(window).width() - 985)/2,
			scroller = 	me.Self.find('ul:first'),
			scrollerContent = $(me.scrollerContnetSelector);
			
        
		newLeft = (newLeft < 0) ? 0 : newLeft;

		scroller.css({'left': newLeft + 'px', 'visibility': 'visible'});
		
		if (scrollerContent.attr('autoscroll') == "true") {
			setTimeout("hScroller.AutoScrollNoInteractions();", me.timeBeforeAutoScroll);
		} else if (scrollerContent.attr('autoscrollByFrame') == "true") {
			setTimeout("hScroller.AutoScrollNoInteractionsByFrame()", me.timeBeforeAutoScroll);
		}

		var scrollerLastLI = 	scroller.find('>li:not(' + me.overscrollHelperSelector + '):last');
        var scrollerWidth = 	scrollerLastLI.width() + scrollerLastLI.position().left + newLeft;
        
        scroller.width(scrollerWidth);
        
        if (rim.IsTouchDevice && typeof(hScrollerDontAddTouchWidth) == "undefined") {
			$('#heroContent').width(scrollerWidth+300).wrap(me.touchScrollerDivHtml);
		} else if (rim.IsTouchDevice && typeof(hScrollerDontAddTouchWidth) != "undefined") {
			$('#heroContent').width(scrollerWidth).wrap(me.touchScrollerDivHtml);
		}
        

		$('.scroller .'+ me.replaceClass).css(me.visibleCSS);

		me.ScrollLeftButton.css(me.visibleCSS);
		me.ScrollRightButton.css(me.visibleCSS);
		
		var parent = me.Self.parent();

		if (parent.hasClass(me.WrapBothClass)){
			me.WrapRight = true;
			me.WrapLeft = true;
		}

		if (parent.hasClass(me.WrapRightClass)){
			me.WrapRight = true;
		}

		if (parent.hasClass(me.WrapLeftClass)){
			me.WrapLeft = true;
		}
        if (!rim.IsTouchDevice) {
			var appTooltipTemplate = '<div><div role="appTooltip"></div></div>';
			
			$('.embed-application-tooltip').each(function() {
				var tip = new Rf.EmbeddedTooltip(this, '.application-tooltip-content', {
					ID : 'MyAppTooltip',
					ClassName : 'appTooltip',
					Template : appTooltipTemplate
				}).WatchHover(250)
				  .WatchFocus(250);
	
			    tip.Bind(Rf.Tooltip.Events.Show, function(element, event) {
			    	$('.appTooltip .title').addClass(hScroller.replaceClass);
			    	$('.appTooltip .price').addClass(hScroller.replaceClass);
			    	rim.InitCufon();
			    });
			});
        }
        
		$(document).bind('keydown', function (e) {
			switch(e.keyCode) {
				case 37://left
					if(me.CurrentIndex > 0){
						me.SlideLeft();
					}
					break;
				case 39://right
					if(me.CurrentIndex < (me.StopPoints.length - 1)){
						me.SlideRight();
					}
					break;
			}
		});
		
		if (!rim.IsTouchDevice) {
			var overscrollHelper = null;
			
			if (!scroller.find(me.overscrollHelperSelector).length) {
	            scroller.append('<li id="overscrollHelper">&nbsp;</li>');
	            $(me.overscrollHelperSelector).css({
	                width: '100%',
	                height: '100%',
	                position: 'absolute',
	                top: '0px',
	                left: '0px',
	                zIndex: '99999999',
	                display: 'none'
	            });
	            overscrollHelper = $(me.overscrollHelperSelector);
	        } else {
	            overscrollHelper = $(me.overscrollHelperSelector);
	        }
        
	        // me.Self.bind('mousedown', function() {
	        // 	        	if (!this.hasInteractions) {
	        // 		        	me.Self.stop();
	        // 		        	var currentItem = $('ul.scroller > li' + me.StopPointSelector +':in-viewport:first'), found = false, index = false;
	        // 		            me.StopPoints.each(function(i) {
	        // 		                if ($(this).attr('id') == currentItem.attr('id')) {
	        // 		                    me.CurrentIndex = i;
	        // 		                    me.UpdateScrollButtons();
	        // 		                } else if (found && !index) {
	        // 		                	index = i;
	        // 		                }
	        // 		            });
	        // 		            
	        // 		            me.CurrentIndex = index;
	        // 		            me.UpdateScrollButtons();
	        // 	        	}
	        // 	        });
	        
			me.Self.overscroll({direction:'horizontal', showThumbs: false, openedCursor: '/assets_refresh/images/opened.cur',closedCursor: '/assets_refresh/images/closed.cur', onDriftStart: function(){
	            overscrollHelper.show();
	            if ($.browser.msie) {
	                document.selection.empty();
	            }
	            $(this).disableTextSelect();
	            if (!me.ScrollLeftButton.is('.' + hScroller.inactiveClass)) me.ScrollLeftButton.addClass(hScroller.inactiveClass);
	            if (!me.ScrollRightButton.is('.' + hScroller.inactiveClass)) me.ScrollRightButton.addClass(hScroller.inactiveClass);
	        }, onDriftEnd: function(){
	        
	        	var header;
				if ($('#hdr').length == 0) {
					header = '#header-content';
				} else { header = '#hdr'; }
				
	            overscrollHelper.hide();
	            var currentItem = $('ul.scroller > li' + me.StopPointSelector).filter(function(){
                    return $(this).offset().left > $(header).offset().left
                }).first()
	            me.StopPoints.each(function(i) {
	                if ($(this).attr('id') == currentItem.attr('id') || i+1 == me.StopPoints.length) {
	                    me.CurrentIndex = i;
	                    me.UpdateScrollButtons();
	                    return false;
	                };
	            });
	            $(this).enableTextSelect();
	            if (!me.ScrollLeftButton.is('.' + hScroller.inactiveClass)) me.ScrollLeftButton.removeClass(hScroller.inactiveClass);
	            if (!me.ScrollRightButton.is('.' + hScroller.inactiveClass)) me.ScrollRightButton.removeClass(hScroller.inactiveClass);
	        }});
		} else {
			var iScroller = new iScroll('touchScroller', { 
															zoom: true, 
															zoomMin: 0.75, 
															zoomMax: 15, 
															bounce: false,
															vScrollbar: false,
															hScrollbar: false,
															useTransition: true
														  });
														
			setTimeout(function() {iScroller.refresh()}, 0);
			
			if ($('#flashContent').length > 0) {
				$('#touchScroller').css({'display':'none'});
			}
		}
		
		me.InitScrollerNav();
		
		var firstFrame = scrollerContent.attr('firstFrame');

		if (firstFrame && firstFrame != me.slideFromLeftValue) {
			me.CurrentIndex = firstFrame - 1;
			me.ScrollTo(true);
		} else if (firstFrame && firstFrame == me.slideFromLeftValue) {
			/* set the scroller off the page */
			var stopPoints = $(me.StopPointSelector);
			var newLeft = me.GetNewLeft(stopPoints.length - 1);

			$($(me.scrollerContentLISelector)[$(me.scrollerContentLISelector).length - 2]).css('border-right', '1200px solid #000');
				
			me.Self.scrollLeft(newLeft + $($(me.StopPointSelector)[0]).width() + 2000);
		}

		me.Self.show();

		if (firstFrame && firstFrame == me.slideFromLeftValue) {
			me.CurrentIndex = 0;
			me.ScrollTo(false, 3000);
		}

	},
	
	ScrollToFrame: function(frame) {
		var me = this;
		
		me.CurrentIndex = frame - 1;
		me.ScrollTo(false);
	},
	
	LoadVideo: function(embedCode, xmlPathUrl) {
		rim.LoadVideo(embedCode, xmlPathUrl);
	},
	
	CloseVideo: function() {
		var lightBox = $('#videoLightbox');
		
		lightBox.css('display', 'none');
		lightBox.html('&nbsp;');
	},

	InitScrollerNav: function () {
		var me = this;

		if (rim.IsTouchDevice) {
            me.ScrollLeftButton.add(me.ScrollRightButton).hide();
            
            $(me.StopPointSelector).each(function(index) {
                var current = $(this);
                
                if (current.attr(me.PrevNameAttr) && current.attr(me.PrevUrlAttr)) {
                    if (typeof(scrollerDontWrapLeft) == "undefined") {
            			me.ScrollLeftButton.css(me.showButtonCSS);
            		}
            		
                    me.ScrollLeftButton.find(me.hoverTextSelecor).html(current.attr(me.PrevNameAttr));
        			me.ScrollLeftButton.attr("href", current.attr(me.PrevUrlAttr));
        			$(me.ScrollLeftButton).find(me.hoverTextSelecor).show();
                }
                if (current.attr(me.NextNameAttr) && current.attr(me.NextUrlAttr)) {
                    if (typeof(scrollerDontWrapRight) == "undefined") {
            			me.ScrollRightButton.css(me.showButtonCSS);
            		}
            		
                    me.ScrollRightButton.find(me.hoverTextSelecor).html(current.attr(me.NextNameAttr));
        			me.ScrollRightButton.attr("href", current.attr(me.NextUrlAttr));
                    $(me.ScrollRightButton).find(me.hoverTextSelecor).show();
                }
            });
        } else {
			me.UpdateScrollButtons();
	
			me.ScrollLeftButton.add(me.ScrollRightButton).hover(
				function () {
					var button = $(this);
					if (button.is('.' + me.inactiveClass)) return;
					$(this).find(hScroller.hoverTextSelecor).show();
				},
				function () {
					var button = $(this);
					if (button.is('.' + me.inactiveClass)) return;
					$(this).find(hScroller.hoverTextSelecor).hide();
				}
			);
		}
	},
	GetNewLeft: function(index){
		var me = 			this,
			currentSlide = 	$(me.StopPointSelector + ":eq(" + index + ")"),
				offset = 		currentSlide.attr(me.OffsetAttr);

		offset = (!offset) ? 0 : parseInt(offset);

		var windowWidth = $(window).width();

		return currentSlide.position().left;
	},
	UpdateScrollButtons: function () {
		var me = 			this,
			currentSlide = 	$(me.StopPointSelector + ":eq(" + me.CurrentIndex + ")"),
			showPrev = 		true,
			showNext = 		true;
		
        if (documentHref.indexOf(stringJSP) == -1 || documentHref.indexOf(stringIndexJSP) >- 1) {
            if (!me.WrapLeft && me.CurrentIndex == 0)
    		 	showPrev = false;
        }

		if ((typeof(scrollerDontWrap) != "undefined" || typeof(scrollerDontWrapRight) != "undefined") && me.CurrentIndex == (me.StopPoints.length - 1))
			showNext = false;

		if ((typeof(scrollerDontWrap) != "undefined" || typeof(scrollerDontWrapLeft) != "undefined") && me.CurrentIndex == 0)
			showPrev = false;

		var prevName = 	currentSlide.attr(me.PrevNameAttr),
			prevUrl = 	currentSlide.attr(me.PrevUrlAttr),
			nextName = 	currentSlide.attr(me.NextNameAttr),
			nextUrl = 	currentSlide.attr(me.NextUrlAttr);
		
		if (!prevName)
			prevName = me.PrevNameDefault;

		if (!nextName)
			nextName = me.NextNameDefault;

		if (!prevUrl) {
			me.ScrollLeftButton.unbind('mouseup').bind('mouseup', function (event) {
				event.preventDefault();
				
				if ($.browser.msie || $.browser.webkit) {
				    setTimeout("hScroller.SlideLeft();", 10);
				    return false;
				} else {
				    $(this).delay(10);
				    me.SlideLeft();
				}
			});
			
			me.ScrollLeftButton.attr("href", "#");
		} else
			me.ScrollLeftButton.unbind('mouseup');

		if (!nextUrl) {
			me.ScrollRightButton.unbind('mouseup').bind('mouseup', function (event) {
				event.preventDefault();
				
			    if ($.browser.msie || $.browser.webkit) {
				    setTimeout("hScroller.SlideRight();", 10);
				    return false;
				} else {
				    $(this).delay(10);
				    me.SlideRight();
				}
			});
			me.ScrollRightButton.attr("href", "#");
		} else
			me.ScrollRightButton.unbind('mouseup');
		
		if (showPrev) {
			me.ScrollLeftButton.removeClass(me.inactiveClass);
			me.ScrollLeftButton.find(me.hoverTextSelecor).html(prevName);
			me.ScrollLeftButton.attr("href",prevUrl);
		} else
			me.ScrollLeftButton.addClass(me.inactiveClass);

		if (showNext) {
			me.ScrollRightButton.removeClass(me.inactiveClass);
			me.ScrollRightButton.find(me.hoverTextSelecor).html(nextName);
			me.ScrollRightButton.attr("href",nextUrl);
		} else{
			me.ScrollRightButton.addClass(me.inactiveClass);
		}
			
		me.UpdateFrameForOmniture()

	},
	SlideLeft: function(){
		this.hasInteractions = true;
		
		if (!omnitureArrowClicks) {
			omnitureArrowClicks = 0;
		}
		
		omnitureArrowClicks++;
		
		if (!this.hasOmnitureTagging)
			doOmnitureUIEvent('nav - left - ' + omnitureArrowClicks);

		var me = this, jump = false;

		me.CurrentIndex--;
		
		if (me.CurrentIndex < 0){
			jump = true;
			me.CurrentIndex = me.StopPoints.length - 1;
		}

		me.ScrollTo(jump);
	},
	SlideRight: function(){
		this.hasInteractions = true;
		
		if (typeof(omnitureArrowClicks) == "undefined") {
			omnitureArrowClicks = 0;
		}
		
		omnitureArrowClicks++;
		
		if (!this.hasOmnitureTagging)
		 	doOmnitureUIEvent('nav - right - ' + omnitureArrowClicks);

		var me = this, jump = false;

		me.CurrentIndex++;

		if (me.CurrentIndex >= me.StopPoints.length){
			jump = true;
			me.CurrentIndex = 0;
		}
		
		me.ScrollTo(jump);
	},
	ScrollTo: function (jump, speed){
		var me = this;
		
		if (!speed)
			speed = me.defaultScrollSpeed;

		me.ScrollLeftButton.addClass(me.inactiveClass);
		me.ScrollRightButton.addClass(me.inactiveClass);

		var newLeft = me.GetNewLeft(me.CurrentIndex), scroller = me.Self.find('ul:first');

		if (jump)
            me.Self.scrollLeft(newLeft);
		else
            me.Self.animate({scrollLeft: newLeft}, speed);

		me.UpdateScrollButtons();
	}
};

var hScroller;

rim.OnloadEvents.Register(function () {
	hScroller = new rim.HeroScrollerFamily(scrollerContentID);
});

$("body").bind("click", function() {
	hScroller.hasInteractions = true;
});
