
// jQuery scripts for Grovik site 

	
	window.onload = function(){

		// Animator for hover on images
			$(".hoverimage").each(function(i){
				// wrap image with a wrapper
					$(this).wrap("<div class=\'hover_wrap\'></div>");
					var wrapper = $(this).parent()
				
				// Set css height and width from image width and height
					wrapper.css("width",wrapper.width());
					wrapper.css("height",wrapper.height());

				// Modify the wrapper a little
					wrapper.css("position","relative");
					wrapper.css("overflow","hidden");
				
				// We pick the text from the alt text on the image -- grøvik gets treated differently 
				// by converting text to images
					var s = $(this).attr("alt");
					var a = new Array();
					a = s.split("&#x0A;") // char used to produce line break
					
					if (a.length > 1)
					{
						s = "<img class='prod_descr1' src='common/generate_text_image.asp?config=2&text="+a[0] + "' /><br style='clear:both' />"
						s = s + "<img class='prod_descr2' src='common/generate_text_image.asp?config=1&text="+a[1] + "' />"
					} else {
						s = "<img class='prod_descr1' src='common/generate_text_image.asp?config=3&text="+a[0] + "' /><br style='clear:both' />"
					}

				// Add the popupbox
					$(this).after("<br style=\'clear:both\'><div class=\'hover_popup\'>" + s + "</div>");
					var popup = $(this).parent().find(".hover_popup")
					popup.css("position","absolute");
					popup.css("width","100%");
					popup.css("padding","4px");
					popup.css("padding-left","10px");
					popup.css("opacity",0);
					popup.css("background","#fff");
					popup.css("text-decoration","none");

				// zero out alt text
					$(this).attr("alt","");

				// position the popupbox exactly undeneath the viewpoint
					popup.css("top",wrapper.height());			
					
				// if there's an a tag wrapping the wrapper, load that URL on click
					if (wrapper.parent().attr("href") != null){
						wrapper.click(function(){
							document.location = $(this).parent().attr("href")
						});
						wrapper.css("cursor","hand");
					}

				// add hover effect
					wrapper.hover(function(){
						var popup = $(this).find(".hover_popup");
						popup.animate({
							top:popup.parent().height()-popup.height()-8,
							opacity:0.98
						}, 400, "easein");
					},function(){
						var popup = $(this).find(".hover_popup");
						popup.animate({
							top:popup.parent().height(),
							opacity:0
						}, 1200, "easein");
					});
			});
		

		// Hover effect on menu items 
		// Don't apply to safari
		if($.browser.safari)
		{
		}
		else
		{

			$(".rightmenu li").addClass("rightmenu_anim")
			$(".rightmenu li").hover(function(){
				$(this).animate({
				  backgroundPosition:1
				}, 300, "easein");
				return "";
			},function(){
				$(this).animate({
				  backgroundPosition:-181
				}, 500, "easein");
				return "";
			});
		}
	};

