﻿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;
	});
    
     $('.CS_mediaContainer, .CS_image, .CS_topImage').CS_corners();
     	
    
     $('#wrapper').CS_scrollTo();
     $('.CS_email').CS_emailLinks();

});

jQuery.fn.CS_corners = function(grey) {
	
	if(ie6)
		return;
			
	var g = "";
	
	if(grey)
		g = 'g';
		
	this.css({position: "relative"})
	.append('<div class="CS_corner CS_tl' + g + '" />')
     	.append('<div class="CS_corner CS_tr' + g + '" />')
     	.append('<div class="CS_corner CS_bl' + g + '" />')
     	.append('<div class="CS_corner CS_br' + g + '" />');
};

jQuery.fn.CS_emailLinks =  function(){

	this.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)
		{
		
		}
    	});
};

jQuery.fn.CS_scrollTo = function(){
	this.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;
		      }
		    }
	
	     });
};