$(document).ready(function(){

	// Put logo on top of menu
	$("#swMenuFlyOutDiv").prepend("<div class=\"swLogo\"><a href=\"/\"><img src=\"/cgi-files/external/grafik/logo_brdr_friis.gif\" border=\"0\" / alt=\"Forside\" title=\"Forside\"></a></div>");
	
	// Attach PageCol to bottom
	$("#swPageCol").appendTo("body");
	$("#swPageCol").css("display", "block");
	$("#swPageCol").show();
	
	var iParent = $("#swParent").text() == "" ? "165285" : $("#swParent").text();
	var Parent = $("#swParent").text();

	$(".swColumns").eq(1).addClass("focusBox");
	
	if($(".swMainContent table[@id]").eq(0).hasClass("postcard") && (Parent == "")) {
		$(".swMainContent table[@id]").eq(0).addClass("rotator");
	} 
	else if ($(".swMainContent table[@id]").eq(0).hasClass("postcard")) {
		$(".swMainContent table[@id]").eq(0).addClass("rotator2");
	}

	
	
	$(".postcard.rotator").each(function(){
		$(this).before("<div class=\"swfRotator\"><div id=\"swfRotator\">Flash Rotator</div></div>");
		$(this).hide();
		
		var flashvars = {};
		flashvars.iParent = iParent;
		
		var params = {};
		params.menu = "false";
		params.wmode = "opaque";
		
		var attributes = {};
		attributes.id = "swfRotatorObj";
		attributes.name = "swfRotatorObj";
		
		swfobject.embedSWF("/cgi-files/external/flash/imageRotator.swf", "swfRotator", "960", "540", "9.0.0","expressInstall.swf", flashvars, params, attributes);
		
	});

	$(".postcard.rotator2").each(function(){
		$(this).before("<div class=\"swfRotator2\"><div id=\"swfRotator\">Flash Rotator</div></div>");
		$(this).hide();
		
		var flashvars = {};
		flashvars.iParent = iParent;
		
		var params = {};
		params.menu = "false";
		params.wmode = "opaque";
		
		var attributes = {};
		attributes.id = "swfRotatorObj";
		attributes.name = "swfRotatorObj";
		
		swfobject.embedSWF("/cgi-files/external/flash/imageRotator.swf", "swfRotator", "725", "175", "9.0.0","expressInstall.swf", flashvars, params, attributes);
		
	});
	
	$("#swFrontCol11 .swColumns:first").addClass("guideSelector");


	var subNavTimer;  
	var open;  

	$(".guideSelector .paragraph-imagebox img").mouseover(function(){
  		clearTimeout(subNavTimer);  
		if (open != null) {
			closeSub();
		}
		
		if (($(this).parents(".swAfsnit")) != open) {

			$(this).parents(".paragraph-imagebox").next().css("filter", "alpha(opacity=70)")
													 .css("opacity", "0.7");
															   
			$(this).parents(".paragraph-imagebox").next().slideDown("fast");
		}
		
	});
	
	$(".guideSelector .paragraph-bodytext").mouseover(function(){
  		clearTimeout(subNavTimer);  
	});

	$(".guideSelector .paragraph-imagebox img").mouseout(function(){
   		open = $(this).parents(".swAfsnit");  
   		subNavTimer = setTimeout(closeSub, 500);  
	});
	
	$(".guideSelector .paragraph-bodytext").mouseout(function(){
		open = $(this).parents(".swAfsnit");
   		subNavTimer = setTimeout(closeSub, 500);
	});

	function closeSub() {
		open.find(".paragraph-bodytext").fadeOut("slow");
		open = null;
	}

});


      function bfShowItem0(product_id)
      {
        $.ajax({
          type: 'GET',
          url: '/brdrfriis/frontend/vare.asp',
          dataType: 'html',
          beforesend: function(){
            $('#bfProductBox_0').hide();
          },
          success: function(html) {
            if(html.length > 0)
            {
              $('#bfProductBox_0').appendTo("body"); // make box go on top in IE7
			  $('#bfProductBox_0').html(html);
              $('#bfProductBox_0').show();
            }
          },
          data: {
            'productid': product_id,
            'multibaseid': '0'    
          },
          complete: function(){
          	bfInitImageSelector($(".bfProductBox"));
          },
          cache: false,
          async: true,
          timeout: 10000
        });

        
      }

      
      $(document).ready(function() {$('#bfProductBox_0').hide();});
      
		var imageArray2 = new Array();
	  	var activeImage2;
	  
	  function bfInitImageSelector(scope) {
	  		$(".bfImageSelectorPaging").remove();
			imageArray2.length = 0;
			activeImage2 = 0;
			$("div.bfProductBoxImage", scope).each(function(i){
				imageArray2.push($(this));
				if (i!=0) {
					$(this).hide();
				}
				else {
					$(this).show();
				}
			});
			if (imageArray2.length > 1) {
				scope.append("<div class=\"bfImageSelectorPaging\"><div class=\"bfImageSelectorPrev\"><a onclick=\"bfImageSelectorPrev();\" href=\"javascript:void(0);\"><</a></div><div class=\"bfImageSelectorNext\"><a onclick=\"bfImageSelectorNext();\" href=\"javascript:void(0);\">></a></div>");
			}
	  }

	  	  
	  function bfImageSelectorPrev() {
	  	if(activeImage2 > 0) 
	  	{
				imageArray2[activeImage2].hide();
				imageArray2[activeImage2-1].show();
				activeImage2--;
			}
	  }
	  
	  function bfImageSelectorNext() {
	  	if (activeImage2 < imageArray2.length-1) 
	  	{
				imageArray2[activeImage2].hide();
				imageArray2[activeImage2+1].show();
				activeImage2++;
			}
	  }

		function fnDoSearch()
		{
	
			if ( $("#searchBox").length == 0 ) {
				$("#swPageDiv").append("<p id='searchBox'></p>");		
				$("#searchBox").append("<div class='bfProductBoxCloseButton'><a class='bfProductBoxCloseButton' href='javascript:void(0);' onclick='$(this).parent().parent().hide();'></a></div>");
				$("#searchBox").append("<table border='0' class='searchBoxTable'><tr><th class='headlineproducts'>Produkter</th><th></th><th class='headlinepages'>Sider</th></tr><tr><td class='resultproducts'><div class='resultbox'><div class='resultelementproducts'></div></div></td><td class='resultsplit'></td><td class='resultpages'><div class='resultbox'><div class='resultelementpages'></div></div></td></tr></table>");
		
			  $("#searchBox").append('<div class="bfProductBox" id="bfProductBox_0"></div>');
			  $("#searchBox").append('<div class="bfProductList" id="bfProductList_0">');
		
				
			}
			$("#searchBox").show("fast");
			
    	$.ajax({
        type: 'GET',
        url: '/brdrfriis/frontend/search.asp',
        dataType: 'html',
        contentType: 'text/html; charset=iso-8859-1',
        beforesend: function(){
        	$('.resultelementproducts').hide("fast");
          $('.resultelementproducts').html("");
          
        },
        success: function(html) {
          if(html.length > 0)
          {
            $('.resultelementproducts').html(html);
          }
        },
        data: {
         	'search':  document.search.search.value
        },
        complete: function(){
        	//bfInitImageSelector($(".bfProductBox"));
        	$('.resultelementproducts').show("fast");
        },
        cache: false,
        async: true,
        timeout: 10000
      });


    	$.ajax({
        type: 'GET',
        url: '/sw/frontend/search.asp',
        dataType: 'html',
        beforesend: function(){
        	$('.resultelementpages').hide("fast");
          $('.resultelementpages').html("");
          
        },
        success: function(html) {
          if(html.length > 0)
          {
            $('.resultelementpages').html(html);
          }
        },
        data: {
          'group_id': '66',
          'search':  $("#swSearchFld").val(),
          'lightsearch': '1',
          'utf8': '1'
        },
        complete: function(){
        	//bfInitImageSelector($(".bfProductBox"));
        	$('.resultelementpages').show("fast");
        },
        cache: false,
        async: true,
        timeout: 10000
      });

			return false;
	
	
}


function escapeHTML (str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
}; 