
$(document).ready(function(){
  $(".content:first").css("padding", "0px 0px 20px 0px");
  $('#countrySelector').hover(
	function() {
		$(this).find('#selectList').css({ display: 'block', opacity: 0 }).stop().animate({ opacity: 1 }, 100, 'easeInOutQuad');
	},
	function() {
		$(this).find('#selectList').stop().animate({ opacity: 0 }, 300, 'easeInOutQuad', function() {
			$(this).css({ display: 'none' })
		});
	});
	if($('#varukorg').length >= 1) {
	  var top = $('#varukorg').offset().top - parseFloat($('#varukorg').css('marginTop').replace(/auto/, 0));
	  $(window).scroll(function (event) {
		// what the y position of the scroll is
		var y = $(this).scrollTop();
	  
		// whether that's below the form
		if (y >= top) {
		  // if so, ad the fixed class
		  $('#varukorg').addClass('fixed');
		} else {
		  // otherwise remove it
		  $('#varukorg').removeClass('fixed');
		}
	  });
	}
	storemenu2 = $(".storemenu2");
    if (storemenu2.length) {
  		$("a.anchorLink").anchorAnimate()
	}
});    
storemenu2 = $(".storemenu2");
    if (storemenu2.length) {
	jQuery.fn.anchorAnimate = function (settings) {
		if ($(this).attr('class').indexOf('storesubmenuanchor') == -1) {
			settings = jQuery.extend({
				speed: 1100
			}, settings);
	
			return this.each(function () {
				var caller = this
				$(caller).click(function (event) {
					event.preventDefault()
					var locationHref = window.location.href
					var elementClick = $(caller).attr("href")
					var elementClick2 = $(caller).attr("href").substring(10);
					if(window.console){
						console.log(elementClick2);
					}
					var destination = $(elementClick2).offset().top;
					$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination }, settings.speed, function () {
						window.location.hash = elementClick
					});
					return false;
				})
			})
		}
	}
}
$("a.gallerylink[rel]").each(function(i) {	
	var overlay = $(this).overlay({
		mask: { color: '#fff',
				loadSpeed: 200,
				opacity: 0.7
		},
		onBeforeLoad: function() {	
			// grab wrapper element inside content
			var wrap = this.getOverlay().find(".contentWrap");	
			// load the page specified in the trigger
			//wrap.load(this.getTrigger().attr("href"));
			$('#overlay_iframe').attr('src', this.getTrigger().attr("href"));
		
			if ($.browser.msie && $.browser.version == 9) {
				$('body').css('overflow-x', 'hidden');
			}
		},
		onClose : function () {
			if ($.browser.msie && $.browser.version == 9) {
				$('body').css('overflow-x', 'visible');
			}	
		}

	});		
});
$("a.vetamer[rel]").each(function(i) {	
	var overlay = $(this).overlay({
		mask: { color: '#fff',
				loadSpeed: 200,
				opacity: 0.5
		},
		top: "center",
		left: "center",
		onBeforeLoad: function() {	
			// grab wrapper element inside content
			var wrap = this.getOverlay().find(".contentWrap");	
			// load the page specified in the trigger
			//wrap.load(this.getTrigger().attr("href"));
			$('#overlayvetamer_iframe').attr('src', this.getTrigger().attr("href"));
		
			if ($.browser.msie && $.browser.version == 9) {
				$('body').css('overflow-x', 'hidden');
			}
		},
		onClose : function () {
			if ($.browser.msie && $.browser.version == 9) {
				$('body').css('overflow-x', 'visible');
			}	
		}

	});
});
$("a.offertforfragan[rel]").each(function(i) {	
	var overlay = $(this).overlay({
		mask: { color: '#fff',
				loadSpeed: 200,
				opacity: 0.5
		},
		top: "center",
		left: "center",
		onBeforeLoad: function() {	
			// grab wrapper element inside content
			var wrap = this.getOverlay().find(".contentWrap");	
			// load the page specified in the trigger
			//wrap.load(this.getTrigger().attr("href"));
			$('#overlayvetamer_iframe').attr('src', this.getTrigger().attr("href"));
				
			if ($.browser.msie && $.browser.version == 9) {
				$('body').css('overflow-x', 'hidden');
			}
		},
		onClose : function () {
			if ($.browser.msie && $.browser.version == 9) {
				$('body').css('overflow-x', 'visible');
			}	
		}
	});
});
$("a.flashmovie[rel]").each(function (i) {
    var overlay = $(this).overlay({
        mask: { color: '#fff',
            loadSpeed: 200,
            opacity: 0.5
        },
        top: "center",
        left: "center",
        onBeforeLoad: function () {
            
            var width = 0;
            var height = 0;
            
            var size = this.getTrigger().attr("size").split(";");
            width = size[0];
            height = size[1];

            // grab wrapper element inside content
            var wrap = this.getOverlay().find(".contentWrap");
            // load the page specified in the trigger
            swfobject.embedSWF(this.getTrigger().attr("href"), 'flashContainer', width, height, "9.0.0");
            //wrap.load(this.getTrigger().attr("href"));

				
			if ($.browser.msie && $.browser.version == 9) {
				$('body').css('overflow-x', 'hidden');
			}
		},
		onClose : function () {
			if ($.browser.msie && $.browser.version == 9) {
				$('body').css('overflow-x', 'visible');
			}	
		}

    });
});
$(window).load(function() {
	$(".lavaLamp").lavaLamp({ fx: "easeOutQuad", speed: 700 })
	$("a.prod2[rel]").each(function(i) {	
		
		var tabIndex  = $(this).attr("id").replace("tab", "");
		var tabIndexInt =  parseInt(tabIndex);
		var tabIndexInt2 =  tabIndexInt-1;

		var target = $('#refwrapper2').offset();
		var overlay = $(this).overlay({
			// common configuration for each overlay
			oneInstance: false, 
			closeOnClick: false, 

			// setup custom finish position
			top: 'top',
			left:'left',
			fixed: false,
			effect:'drop',
			onBeforeLoad: function(e) {	
			    $('html, body').stop().animate({
					scrollTop: target.top
				}, 500,'easeInOutExpo');
			},
			onLoad: function(e) {	
				$("ul.tabs li a").removeClass("current");
				$("ul.tabs li:nth-child("+tabIndexInt+") a").addClass("current");
				//$("ul.tabs li:nth-child("+tabIndexInt+") a").trigger("click");
				//$("ul.tabs").data("tabs").click(tabIndexInt2);
				$('.panes > div').hide(0);
				$('.panes > div').eq(tabIndexInt2).fadeIn(500);
			}
		});
    });

    $(".storeProductListContainer a[rel]").each(function (i) {

        var tabIndex = $(this).attr("id").replace("tab", "");
        var tabIndexInt = parseInt(tabIndex);
        var tabIndexInt2 = tabIndexInt - 1;

        if ($(this).attr("rel").indexOf('div.overlayviktigtkeycontrol') == -1 && $(this).attr("rel").indexOf('div.overlayviktigtexpansion') == -1) {
            var target = $('#overlaywebbshopstore').offset();
            var overlay = $(this).overlay({
                oneInstance: false,
                closeOnClick: false,
                top: 'top',
                left: 'left',
                fixed: false,
                effect: 'drop',
                onBeforeLoad: function (e) {
                    $('html, body').stop().animate({
                        scrollTop: target.top
                    }, 500, 'easeInOutExpo');
                },
                onLoad: function (e) {
                    $("ul.tabs li a").removeClass("current");
                    $("ul.tabs li:nth-child(" + tabIndexInt + ") a").addClass("current");
                    $('.panes > div').hide(0);
                    $('.panes > div').eq(tabIndexInt2).fadeIn(500);
                }
            });
        }

        else {
            $(this).overlay({
                oneInstance: false,
                closeOnClick: false,
                top: 200,
                left: 'center',
                fixed: false
            });
        }
    });


	$('ul.tabs').tabs('.panes > div', {		
		initialIndex: null,
		effect: 'fade',
		fadeInSpeed: 500,
		fadeOutSpeed: 500
	}).slideshow({clickable: false,autoplay: false});
	
	$('ul#hotNews').tabs('.hotnews > div', {		
		initialIndex: 0,
		effect: 'fade',
		fadeInSpeed: 500,
		fadeOutSpeed: 500
	}).slideshow({autoplay: true, interval: 5000});	
	
	var origHeight	= $('div#modulgallery').outerHeight();
	$('.overlaygallery .close').live("click", function(){
		$('div#modulgallery').animate({
			height: origHeight }, 400, function() {
			// Animation complete.
		});
		$('.modulgallery a').each(function(i) {	
			$(this).removeClass('active');
		});	
	});
	$('.overlaygalleryvid .close').live("click", function(){
		$('div#modulgallery').animate({
			height: origHeight }, 400, function() {
			// Animation complete.
		});
		$('.modulgallery a').each(function(i) {	
			$(this).removeClass('active');
		});	
	});
	$('.modulgallery a').live("click", function(){
		$('.modulgallery a').each(function(i) {	
			$(this).removeClass('active');
		});	
		$(this).addClass('active');
	});
	$(".modulgallery a[rel]").each(function(i) {	
		var target = $('#menu').offset();
		var overlay = $(this).overlay({
			// common configuration for each overlay
			oneInstance: true, 
			closeOnClick: true, 
			// setup custom finish position
			top: 'top',
			left:'left',
			fixed: false,
			effect:'drop2',
			onBeforeLoad: function(e) {	
			    //$('html, body').stop().animate({
				//	scrollTop: target.top
				//}, 500,'easeInOutExpo');	
				var modulHeight	= this.getOverlay().outerHeight();
				$('div#modulgallery').animate({
					height: modulHeight }, 400, function() {
					// Animation complete.
				});	
			},
			onLoad: function(e) {	
  				//$('div#modulgallery').height();
			}
		});		
	});	
	
	relimgslides = $(".relimgslides");
    if (relimgslides.length) {
		if($('.relimgslides img').length > 1) {
			$('.relimgslides').cycle({
				fx:      'fade',
				timeout:  0,
				pager:   '.relimgslidesnav ul',
				pagerAnchorBuilder: pagerFactory
			});
		}
	}
	function pagerFactory(idx, slide) {
		return '<li><a href="#"></a></li>';
	};
});	

$('.close').live("click", function() {
	$('.pane').css('display', 'none');
});


// create custom animation algorithm for jQuery called "drop" 
$.easing.drop = function (x, t, b, c, d) {
	return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
};


// loading animation
$.tools.overlay.addEffect("drop", function(css, done) { 
   
   // use Overlay API to gain access to crucial elements
   var conf = this.getConf(),
       overlay = this.getOverlay();           
   
   // determine initial position for the overlay
   if (conf.fixed)  {
      css.position = 'fixed';
   } else {
      css.top += $(window).scrollTop();
      css.left += $(window).scrollLeft();
      css.position = 'absolute';
   } 
   
   // position the overlay and show it
   overlay.css(css).show();
   // begin animating with our custom easing
   overlay.animate({ top: '+=505'}, 400, 'easeOutQuad', done);
   
   /* closing animation */
   }, function(done) {
      this.getOverlay().animate({top:'-=505'}, 400, 'easeOutQuad', function() {
         $(this).hide();
         done.call();      
      });
   }
);

// create custom animation algorithm for jQuery called "drop" 
$.easing.drop2 = function (x, t, b, c, d) {
	return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
};


// loading animation
$.tools.overlay.addEffect("drop2", function(css, done) { 
   
   // use Overlay API to gain access to crucial elements
   var conf = this.getConf(),
   overlay = this.getOverlay();           
   ovHeight = overlay.outerHeight();
   overlay.css('marginTop', -ovHeight);
   
   // determine initial position for the overlay
   if (conf.fixed)  {
      css.position = 'fixed';
   } else {
      css.top += $(window).scrollTop();
      css.left += $(window).scrollLeft();
      css.position = 'absolute';
   } 
   
   // position the overlay and show it
   overlay.css(css).stop(false, true).fadeIn(10);
   // begin animating with our custom easing
   overlay.stop(false, true).animate({"top": ovHeight}, 400, 'easeOutQuad', done);
   
   /* closing animation */
   }, function(done) {
      this.getOverlay().stop(false, true).animate({"top": 0}, 400, 'easeOutQuad', function() {
         $(this).stop(false, true).hide(10);
         done.call();      
      });
   }
);

function myFocus(form, defaultTxt) {
	var parentClass = form.parentNode.className;
	
	if(form.value == defaultTxt) {
		form.value = '';
		
	}
}

function myBlur(form, defaultTxt) {
	if(form.value == '') {
		form.value = defaultTxt;
	}
}

function hideOtherElements(idToShow) { 
   // $('#' + idToShow).
}
