/**
* Product Nav bar
*/
function showBar(barToShow, barToHide){
	document.getElementById('bar_'+barToShow).style.display = 'block';
	document.getElementById('bar_'+barToHide).style.display = 'none';
}

/**
* Opening of subpages
*/
function openSubPage(){
	// check if page call was initiated from a subpage
	if(window.location.search != '' && window.location.search.indexOf('show=') != -1){
		var pageToShow =  window.location.search.substring(6);
		var pageToShowAbsolute = window.location.protocol+ '//' + window.location.host + pageToShow; 
		
		// parse all content navi links and open the one belonging to subpage
		var contentNavigation = document.getElementById("contentNavigation");
		if(contentNavigation){
			
			var allContentLinks = contentNavigation.getElementsByTagName('a');
			
			for(var c=0; c < allContentLinks.length; c++){
				
				// ie7 returns absolute links, so make link absolute
				var currentLink = allContentLinks[c].getAttribute('href');
				if(currentLink.indexOf(window.location.host) == -1){
					currentLink = window.location.protocol + '//' + window.location.host + '/' + currentLink;
				}
				
				if(currentLink == pageToShowAbsolute){
					Shadowbox.open(allContentLinks[c]);
					break;
				}
			}
		}
	}
}


/**
* Scroller Object
*/
function Scroller(){

	var showScroller = false;
	var scrollContainer = null;
	var textContainer = null;
	var scrollControl = null;
	
	var scrollIntervalId = null;
	
	var _scrollSteps = 100;
	var _scrollInterval = 20;

	this.init = function(){
		var shadowBoxContent = document.getElementById('shadowbox_content');
		if(!shadowBoxContent){
			// things are easy, script is called from iframe inside of shadowbox
			scrollControl = document.getElementById('scrollControl');
			scrollContainer = document.getElementById('scrollContainer');
			textContainer = document.getElementById('textContainer');
			
		} else {
			// scroller called with inline content in shadowbox. DOM looks like this:
			//  shadowbox_content->inlineTextContent->scrollControl
			//                                      ->scrollContainer
			//                                      ->scrollContainer->textContainer
			scrollContainer = null;
			textContainer = null;
			scrollControl = null;
			
			var allChildDivs = shadowBoxContent.getElementsByTagName('div');
			for(var c=0; c < allChildDivs.length; c++){
			
				if(allChildDivs[c].id){
					if(allChildDivs[c].id == 'scrollControl') {
						scrollControl = allChildDivs[c];
					} else if(allChildDivs[c].id == 'textContainer'){
						textContainer = allChildDivs[c];
					} else if(allChildDivs[c].id == 'scrollContainer'){
						scrollContainer = allChildDivs[c];
					}
					if(scrollContainer && textContainer && scrollControl) break;
				}
			}                    
		}
	
		
		
		if(!scrollContainer || !textContainer || !scrollControl){ 
			return;
		}
		
		if(scrollContainer.offsetHeight < textContainer.offsetHeight){
			showScroller = true;
			this.renderScroller();
		}
	};
	
	this.renderScroller = function() { 
		textContainer.style.width = (textContainer.offsetWidth - 20) + 'px';
		scrollControl.style.display = 'block';
	};
	
	
	this.start = function(direction) {
		this.stop();
      	var step = (textContainer.offsetHeight / _scrollSteps) * direction;
      	scrollIntervalId = window.setInterval(function(){ scroll(step); }, _scrollInterval);
	};
	
	this.stop = function() {
		window.clearInterval(scrollIntervalId);
	};
	
	var scroll = function(step){  
      if ((step > 0 && textContainer.scrollTop < scrollContainer.offsetHeight ) || (step < 0 && scrollContainer.scrollTop > 0)) {
        scrollContainer.scrollTop += step; 
      } else { 
        stop();
      }
    
    };
	
};

var scroller = new Scroller();
