﻿// Sub Class
window.$BTJ.CustomerService = new function() {
	var $this = this;
	

	// Variables
	
	// Methods
	$this.init =  function() {
		$this.Faq(".Question", ".Answer");
		$this.smoothInternalScroll('.Kundtjanst .TabContainer.Guide a[href^=#], .Kundtjanst .TabContainer.Searchtip a[href^=#], .Kundtjanst .TabContainer.Legal a[href^=#], .jsInternalScrollLink', 120, 1000, "swing");		
		$this.initInternalTabLinks();
	
	}
	
	
	// Faq
	$this.Faq = function(q, a) {
		
		$(a).hide();
		
		$(q).each(function(){
			
			var question = $(this);
			question.click(function(){
			
			question.next().slideToggle("fast");
				
				if (question.hasClass("Active")){
					question.removeClass("Active");
				} else {
					question.addClass("Active");
				}
			});
		});
	};
	
	 $this.initInternalTabLinks = function() {
		$('.jsInternalTabLink').click(function() {
			var href = $(this).attr('href');
			$('.TabLink[href=' + href + ']').click(); //find the tab with corresponding href and click it
		});
	 }
	
	 $this.smoothInternalScroll = function(selector, offset, time, ease) {
		// in ie6, header scrolls with page, so no need to use offset 
		var ie6 = $.browser.msie && ($.browser.version == "6.0"); 
		if(ie6) {
			offset = 0;
		};
	
		// Internal links affected secified by selector
		$(selector).each(function() { 
		
		$(this).click(function(event) { // When clicking the link
			event.preventDefault(); // Kill the default event
			// Extract the href
			var href = $(this).attr('href');
			href = href .replace(/^[^#]+#/, ""); //remove hash
			href = href .replace(/^#/, ""); //remove hash

			var targetElm = $("a[name="+href+"]");
		
			// Scroll
			$('html,body').animate({
			// Scroll to element with name
			scrollTop: targetElm.offset().top - offset
			},{
			duration: time,
			easing: ease
			});
			
			
		});
	});
}

}