//NEW ROLEX CREATIONS GLOBAL OBJECT
var nrc = new Object();
//ALIGN NAVIGATION
nrc.alignNav = function () {
    var OFFSET_BOTTOM = 115;
    var OFFSET_BOTTOM_GALLERY = 26;
    var OFFSET_LEFT = 20;
    var OFFSET_LEFT_NAV = 13;
    var OFFSET_TOP = 100;
    var OFFSET_GALL = 0;
    var OFFSET_MAX_MID = 1;
    var NRC_NAV_GALLERY = null;
    var NRC_NAV_GALLERY_CON = $('#spotlight-gallery-nav-bg')
    var NRC_NAV_GALLERY_LINK = $('#spotlight-content')

    
    if($('#sol-gallery-nav')){
        NRC_NAV_GALLERY = $('#spotlight-gallery-nav');
    }                                                            
    
    var topPosition = 0;
     
    if (height >= (MAXHEIGHT)){
        topPosition = MAXHEIGHT - TOPPADDING - marginTop + OFFSET_MAX_MID;
    }
    else if (height <= (MINHEIGHT)){
        topPosition = MINHEIGHT -  TOPPADDING - marginTop + FOOTERHEIGHT;
    }
    else{
        topPosition = height - TOPPADDING - marginTop + OFFSET_MAX_MID;           
    }
    leftPosition = LEFTPADDING - marginLeft - OFFSET_LEFT;
    if(NRC_NAV_GALLERY){
	NRC_NAV_GALLERY.css({top:topPosition  - OFFSET_TOP - OFFSET_BOTTOM_GALLERY + "px"});
	NRC_NAV_GALLERY_CON.css({top:topPosition  - OFFSET_BOTTOM - OFFSET_BOTTOM_GALLERY + "px"});
	NRC_NAV_GALLERY_CON.css({left:leftPosition + "px"});
	NRC_NAV_GALLERY_CON.css({width:width + "px"});
	NRC_NAV_GALLERY_LINK.css({top:topPosition  - OFFSET_TOP + "px"});
    }
}

// If they want some sort of barrel nav use this code
var FedererNav = function(id) {
	var scrollTimeout = 250;
	var scrollActiveMaximumDuration = 150;
	var scrollActiveDurationMultiplier = 0.8;
	var scrollOutDuration = 500;
	var scrollOffset = 50; //Negative numbers for scrollOffset will create negative values, with overflow, it doesn't matter though.
	
	$('#'+id).click(function(event) {
		var eventTarget = $(event.target);
		
		if(eventTarget.is('dt'))
			switchToCollection(eventTarget.parent(), id); //clicked definition term (aka collection header)
		
		if(eventTarget.is('a')) {
			if(eventTarget.parent().is('dd')) //filter link
				switchToFilter(eventTarget, id);
		}
		//event.preventDefault();
	}).addClass('left-nav-active');
	
	$('#'+id+' ul').each(function(){
		var scrollDefault = 0; //Default value to scroll to when navigation is at rest
		
		$(this).hover(
			function(event) { //over
				if(!$(this).data('totalHeight')) {
					var listHeight = $(this).height();
					$(this).height('auto');
					$(this).data('totalHeight', $(this).height());
					$(this).height(listHeight);
				}
			},
			function(event) { //out
				var el = this;
				setTimeout(function() {
					$(el).animate({
						scrollTop:scrollDefault
					}, scrollOutDuration);
				}, scrollTimeout);
			}
		);
		
		$(this).mousemove(function(event) {
			var mouseLoc =  event.pageY - $(this).offset().top;
			var mouseLocNormal = (mouseLoc / $(this).height()).toFixed(2); //normalized relative mouse location
			var tempScrollTo = parseInt(mouseLocNormal * $(this).data('totalHeight')) - scrollOffset;
			
			var scrollDuration = parseInt(Math.abs(tempScrollTo - $(this).scrollTop()) * scrollActiveDurationMultiplier); //Dynamic duration
			scrollDuration = (scrollDuration > scrollActiveMaximumDuration) ? scrollActiveMaximumDuration : scrollDuration;
			
			$(this).stop();
			$(this).animate({
				scrollTop:tempScrollTo
			}, scrollDuration);
		});
		
		//Begin ugly way to calculate position, due to method used to hide/show content area that prevents the snapping effect. assuming each item is 10px tall.
		listElements = $(this).children('li');
		
		listElements.each(function(index, obj) {
			if($(obj).children('.active')[0] != null)
				scrollDefault = 12 * index;
		});
		//End of the ugly!
		
		//Scroll to the selected item
		$(this).animate({
			scrollTop:scrollDefault
		}, scrollOutDuration);
		
		$(this).addClass('scroll-height');
	});
	
	$('#'+id).css('overflow', 'hidden');
}

function setupExploreNavClicks(){
	$('#defining-swimming-link').click(function(e){try{document.jsAPI.trackLink("defining-moments-swimming", "browse_link>gallery_datejust_special_edition", "m81208-0033>catalogue")}catch(e){}});
	$('#defining-sound-barrier-link').click(function(e){try{document.jsAPI.trackLink("defining-moments-sound-barrier", "browse_link>gallery_datejust", "m116200-0011>catalogue")}catch(e){}});
	$('#defining-antarctic-link').click(function(e){try{document.jsAPI.trackLink("defining-moments-antarctic", "browse_link>gallery_lady_datejust_pearlmaster", "m80298-0067>catalogue")}catch(e){}});
	$('#defining-everest-link').click(function(e){try{document.jsAPI.trackLink("defining-moments-everest", "browse_link>gallery_datejust_special_edition", "m81208-0033>catalogue")}catch(e){}});
}


//ONLOAD HANDLERS
onloadHTMLHandlers[onloadHTMLHandlers.length] = 'nrc.alignNav();setupExploreNavClicks();';
onresizeHTMLHandlers[onresizeHTMLHandlers.length] = 'nrc.alignNav()';