
var flyout;

function erase() {
	flyout.style.display = "none";
}

function initSiteNav() {
	var nav = document.getElementById('siteNavBottom');
	var toggles = nav.getElementsByTagName('li');
	for ( var i = 0; i < toggles.length; i++ ) {
		toggles[i].onmouseover = function(){
			var defD = this.getElementsByTagName('dd')[0];
			if (defD != null) {
				var x = findPos(this)[0];
				defD.style.left = x + "px";
				this.className = "on";
			}
		}
		toggles[i].onmouseout = function() {
			this.className = "off";
		}
	}
}

function initThumbs() {
	var images = document.getElementById('productImages');
	var main = document.getElementById('mainImage');
	var thumbs = images.getElementsByTagName('img');
	for ( var i = 0; i < thumbs.length; i++ ) {
		thumbs[i].onclick = function() {
			main.src = this.src;
		}
	}
}

//Function to find left and top position of any DOM object...

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

	

var CUSTOMER = {
	
	init : function(){
    		
		// Customer service faqs page
		$('div.list_quest dd').hide();
		
		$('div.list_quest dt.list_quest').click(function(){
			if ($(this).hasClass('expanded')) {
				$(this).removeClass('expanded').next().slideUp('fast');
				//If we're closing the last one in a set, we need to make sure we change text to say 'show all'
				
				if($(this).parent().find('dt.expanded').length == 0){
					$(this).parent().find('a.close')
						.text(showAll)
						.removeClass('expanded-all');
						
				}
			}
			else{
				$(this).addClass('expanded').next().slideDown('fast');	
				
				if($(this).parent().find('dt.expanded').length == $(this).parent().find('dt.list_quest').length){
					$(this).parent().find('a.close')
						.text(hideAll)
						.addClass('expanded-all');
						
				}
			}
		});	
			
	$('div.list_quest dt.list_quest').hover( function(){  $(this).addClass('hovered'); }, function(){ $(this).removeClass('hovered');  });    
	
	$('#browse-categories a.close').click( function(){	
	
		if ( ! $(this).hasClass('expanded-all')    ){	 // show all
			$(this) 
				.addClass('expanded-all')
				.text(hideAll)
				.parents('dl.faqGroup:first')
					.find('dt.list_quest')
						.addClass('expanded')
						.next()
							.slideDown('fast');
		}
		else { // hide all
			$(this)   
			.removeClass('expanded-all')
			.text(showAll)
			.parents('dl.faqGroup:first')
				.find('dt.list_quest')
					.removeClass('expanded')
					.next()
						.slideUp('fast');
		}
		
		return false;
	});
				
	
	// Customer service order page
		$('div.item_list dd').hide();
	  
		$('div.item_list dt').click(function(){
			if ($(this).hasClass('expanded')) {
				$(this).removeClass('expanded').next().slideUp('fast');
			}
			else{
				$(this).addClass('expanded').next().slideDown('fast');	
			}
		});	
			
	$('div.item_list dt').hover( function(){  $(this).addClass('hovered'); }, function(){ $(this).removeClass('hovered');  });    
	} // end of init()	
		
};




// setting up singleton for RBK namespacing.
var RBK = RBK || {};

// pops up a window for the link
// example usage: <a href="http//metrics.reebok.com/privacy/getStatus.php" onclick="return popupLink();">View your current opt-out status</a>
RBK.popupLink = function(link){
 if (typeof link == 'object') { link = link.href; } // if passed an element, get the href. otherwise roll with the link.
 window.open(link,'popupLink','resizable=yes,width=400,height=255'); // cannot be smaller than 400px
 return false; 
}

RBK.largePopupLink = function(link){
 if (typeof link == 'object') { link = link.href; } // if passed an element, get the href. otherwise roll with the link.
 window.open(link,'popupLink','resizable=yes,width=400,height=400'); // cannot be smaller than 400px
 return false; 
}

if(typeof jQuery != 'undefined'){ // safe in case other pages dont have jQuery.
  
  
  jQuery(function($){  // execute on load
  
    // opt out form. change opt-out status   
    $('#opt-out-form form').submit(function(){
      var ac = $('#opt-out-form input[name="optout"]:checked').val();
	  if ($('#opt-out-form input[name="optout"]:checked').length == 0) {
		 $('#fieldRequired').show();	
		  return false;
	  }
	  $('#fieldRequired').hide();
      RBK.popupLink('http://metrics.reebok.com/privacy/privacy_handler.php'+'?dest=' + RBK.optOutDestinations[ac] + '&act=' + ac);
      return false;
    });
  }); 

}


/* This function sets up the "Empty Cart" dialog on HTML-only pages when the user has no items in their cart.  */

function bindEmptyCart(){
	/* Bind the close link */
	$('#cartEmpty a.close').bind('click', function(){
		$('#cartEmpty').css({display:'none'});
		
	})
	/* bind the cart link */
	$('li.cart a').bind('click', function(){
			var leftPos = ($('#header').width() + $('#container').offset().left) - ($('#cartEmpty').width() + 40);			
			$('#cartEmpty').css({top:'0px',left:leftPos}).show();
		})
	
}

/* Function to disable the Submit button on HTML product detail page until user selects a quantity */
function checkQty(slc, button){
	if(slc.selectedIndex === 0){
	if(slc.value=="1"){
	button.style.cursor='pointer';
	document.getElementById("buttonspan").style.cursor="pointer";
	button.disabled = false;
	$('#buttonspan').removeClass("disabled");
	}else{
		button.style.cursor='default';
		document.getElementById("buttonspan").style.cursor="default";
	 	button.disabled = true;
	 	$('#buttonspan').addClass("disabled");
		 }		
	}
	else {button.style.cursor='pointer';document.getElementById("buttonspan").style.cursor="pointer";button.disabled = false;$('#buttonspan').removeClass("disabled");}	
}

/* Function to disable the Update button on HTML Cart page until user selects another quantity other than cart quantity */
function checkCartQty(slc,item, button){
	if(slc.selectedIndex === (item-1)){
		
	 	button.disabled = true;		
	}
	else {
	
		button.disabled = false;
		
	}	
}


/* Customer Service pre-opener functions */
function openPreSet(){
	
	var docLoc = document.location.toString();  
		if(docLoc.indexOf('#') > docLoc.lastIndexOf('/') )	
		{
			var tar = parseInt(docLoc.substr(docLoc.indexOf('#')+1, docLoc.length ));
			$('.faqGroup .item_list:eq(' + tar + ')').trigger('click');
		}
}


