﻿var ie6 = false;
 var opera = false;
 
 $(document).ready(function() {

    	jQuery.each(jQuery.browser, function(i, val) {
  		if(i=="msie" && jQuery.browser.version.substr(0,3)=="6.0")
     		ie6 = true;
     		if(i=="opera" && val == true)
     		opera = true;
	});
	
	var minHeight = ($(document).height() - $("#footer").height() - $("#header").height() - 75);
	
	if($(".CS_pageContent").height() < minHeight)
    	{	$(".CS_pageContent").animate({
			minHeight: minHeight + "px"
		},500);
	}
	else{
		minHeight = ($(window).height() -$("#footer").height() - $("#header").height() - 75);
		
		$(".CS_pageContent").css({
			minHeight: minHeight + "px"
		});
		
		
	}
	
	setCookie("minHeight", minHeight);
	
	$("a.CS_bigImageLink").css({cursor : "default"}).click(function (){
        	return false;
        $("body").append('<div class="CS_bigImageBoxBG"/><div class="CS_bigImageBox"><div class="CS_inner"><img src="' + $(this).attr("href") + '" /></div></div>');
        
        $(".CS_bigImageBoxBG").css({
            height: $(document).height() + "px",
            width: $(document).width() + "px",
            opacity: 0.6
        });
               
        
        $(".CS_bigImageBox img").attr("title","Klicka för att stänga.").click(function(){
            $(".CS_bigImageBox").remove();
            $(".CS_bigImageBoxBG").remove();
        });
                       
        return false;
    });
    
     
    
      scrollTo($("#wrapper"));
      emailLinks($(".CS_email"));

});
function emailLinks(obj)
{
	$(obj).each(function(){
    	try{

		var sEmail = $(this).text();
		sEmail = sEmail.replace("[at]","@").toLowerCase();
		$(this).hide();
		$(this).after('<a href="mailto:' + sEmail + '" title="Skicka e-post till ' + sEmail + '">' + sEmail + '</a>');
		$(this).remove();
	}
	catch(e)
	{
	
	}

    });
}

function scrollTo(obj)
{
 	$(obj).find("a[href^=#]").click(function() {
	  
	 
		  if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		    && location.hostname == this.hostname) {
		      var $target = $(this.hash);
		      $target = $target.length && $target 
		      || $('[name=' + this.hash.slice(1) +']');
		      if ($target.length) {
		        var targetOffset = $target.offset().top - 94;
		        $('html,body')
		        .animate({scrollTop: targetOffset},{duration: 600, easing:'easeInSine'});
		       return false;
		      }
		    }
	
	     });
}

$(document).ready(function () {
    $(".CS_question").after("<span class=\"CS_showHideQuestion\">Visa svar</span>");    
    
    $(".CS_faqList").each(function (i){
          
          if($(this).find("li").length > 1)
          {
            $(this).find("h2").after("<span class=\"CS_showHideQuestions\">Visa alla svar</span>");
          
                $(this).find(".CS_showHideQuestions").click(function(){       
        
                    if($(this).hasClass("CS_active"))
                    {
                            $(this).parent().find("li div").slideUp({ duration: 500, easing: "easeOutSine" });
                            $(this).parent().find("li .CS_showHideQuestion").removeClass("CS_active").text("Visa svar");
                    }
                    else
                    {
                            $(this).parent().find("li div").slideDown({ duration: 500, easing: "easeOutSine" });
                            $(this).parent().find("li .CS_showHideQuestion").addClass("CS_active").text("Dölj svar");
                    }
                
                    $(this).toggleText("Visa alla svar","Dölj alla svar").toggleClass("CS_active");       
                
                });
          }  
    });
        
    
    $(".CS_showHideQuestion").click(function(){
        $(this).toggleText("Visa svar","Dölj svar").toggleClass("CS_active").parent().find("div").slideToggle({ duration: 500, easing: "easeOutSine" });
    });
       
    
     $(".CS_documentList .CS_info").click(function(){
		$(this).toggleClass("CS_active");
		$(this).parent().parent().next().find("p").slideToggle({ duration: 200, easing:'easeOutQuad'});
     });      

    
});

jQuery.fn.toggleText = function(a, b) {
      return this.each(function() {
        jQuery(this).text(jQuery(this).text() == a ? b : a);
      });
};