﻿var url=location.href,shareNmore,externalLinks;
jQuery(document).ready(function(){
	/*DW NewsV2 START*/
	if(url.indexOf("&M=NewsV2")>-1) location.replace(url.replace("&M=NewsV2",""));
	/*DW NewsV2 SLUT*/
	Cufon.replace('h1,h2,h5,h6');
	if(navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1){
		//F?lgende b?r optimeres
		jQuery(document).pngFix();
	}
	externalLinks=jQuery("a[href^=http]").click(function(){
		window.open(this.href,'','');
		return false;
	});
	if(screen.height<769){
		jQuery("#wrapper").css("top","89px");
	}
	else if(screen.height<801){
		jQuery("#wrapper").css("top","62px");
	}
	initCollectionSlide();
	initCollectionGallery();
});
jQuery(window).load(function(){
	setTimeout(function(){intiShareNmore();}, 750);
});
/*SlideBoxes START*/
var listBoxes,slidingBoxesNudge = 15,slidingBoxesAdjustment = 10,slidingBoxesIsScrolling = false;
function initCollectionSlide(){
  listBoxes = jQuery(".collection ul");
  var boxItems = listBoxes.children("li");
  if(boxItems.length>3){
    listBoxes.css("width",boxItems.length*boxItems.outerWidth(true)+"px");
    jQuery("#arrowLeft").click(function(){
      if(jQuery(this).css("opacity")!="1") return;
      var nudge=slidingBoxesNudge*-1;
      var left=listBoxes.position().left+listBoxes.parent().width()+slidingBoxesAdjustment;
      slideTheBoxes(nudge,left);
    }).css("display","block");
    jQuery("#arrowRight").click(function(){
      if(jQuery(this).css("opacity")!="1") return;
      var nudge=slidingBoxesNudge;
      var left=listBoxes.position().left+(listBoxes.parent().width()*-1)-slidingBoxesAdjustment;
      slideTheBoxes(nudge,left);
    }).css("display","block");
    handleArrows();
  }
}
function slideTheBoxes(nudge,left){
  if(slidingBoxesIsScrolling) return;
  toggleIsScrolling();
  listBoxes.animate({
    left: listBoxes.position().left+nudge+"px"
    }, 200,
    function(){listBoxes.animate({
      left: left+"px"
      }, 1000,
      function(){toggleIsScrolling();handleArrows();}
      );
    }
  );
}
function handleArrows(){
  var left=listBoxes.position().left;
  if(left>=0){ jQuery("#arrowLeft").animate({opacity:0.1},100); }
  else{ jQuery("#arrowLeft").animate({opacity:1},200); }
  if(left*-1>=listBoxes.width()-listBoxes.parent().width()){ jQuery("#arrowRight").animate({opacity:0.1},100); }
  else{ jQuery("#arrowRight").animate({opacity:1},200); }
}
function toggleIsScrolling(){
  slidingBoxesIsScrolling = !slidingBoxesIsScrolling;
}
/*SlideBoxes SLUT*/
/*BilledGallery START*/
function initCollectionGallery(){
	var co3GalleryImages = jQuery(".collection li img"),settings = {
		Corner_TR: 'http://jscripts.s3.co3.dk/Co3Gallery/x.gif',
		Corner_BL: 'http://jscripts.s3.co3.dk/Co3Gallery/x.gif',
		Corner_BR: 'http://jscripts.s3.co3.dk/Co3Gallery/x.gif',
		Corner_TL: 'http://jscripts.s3.co3.dk/Co3Gallery/x.gif',
		ArrowPrev: '/files/billeder/dranella/gfx/arrow-left.png',
		ArrowNext: '/files/billeder/dranella/gfx/arrow-right.png',
		Close: '/files/billeder/dranella/gfx/btn-close.png',
		Play: '',
		SideMargin: 0,
		PaddingTop: 0,
		PaddingRight: 0,
		PaddingBottom: 0,
		PaddingLeft: 0,
		ImageMarginTop: 0,
		ImageMarginBottom: 0,
        imageInformationHeight: 18,
        imageInformationTemplate: '<a href="[downloadhref]">[downloadtext]</a>'
	};
	co3GalleryImages.CreateGallery(settings);
	co3GalleryImages.css("cursor","pointer").next().not(":contains('download'),:contains('Download')").click(function(){
		jQuery(this).prev().click();
		return false;
	});
}
/*BilledGallery SLUT*/
/*Share & more START*/
function intiShareNmore(){
	shareNmore=jQuery("#shareNmore");
	var shareNmoreStartPos=parseInt(shareNmore.css("top")),shareNmoreHeight=shareNmore.height()-22;
	if(document.referrer.indexOf(location.host)==-1){ 
		shareNmore.animate({top:shareNmoreStartPos+5+"px"}, 100).animate({top:shareNmoreStartPos-shareNmoreHeight+"px"}, 150).animate({top:shareNmoreStartPos+10+"px"}, 300).animate({top:shareNmoreStartPos+"px"}, 100);
	}
	else{ 
		shareNmore.animate({top:shareNmoreStartPos-10+"px"}, 100).animate({top:shareNmoreStartPos+5+"px"}, 200).animate({top:shareNmoreStartPos+"px"}, 100);
	}
	shareNmore.find("h5").click(function(){
		if(shareNmore.css("top")==shareNmoreStartPos+"px"){ 
			shareNmore.animate({top:shareNmoreStartPos+5+"px"}, 100).animate({top:shareNmoreStartPos-shareNmoreHeight-5+"px"}, 300).animate({top:shareNmoreStartPos-shareNmoreHeight+"px"}, 100);
		}
		else{ 
			shareNmore.animate({top:shareNmoreStartPos-shareNmoreHeight-5+"px"}, 100).animate({top:shareNmoreStartPos+10+"px"}, 300).animate({top:shareNmoreStartPos+"px"}, 100); 
		}
	}).css("cursor","pointer");
}
/*Share & more SLUT*/
function onPaperLoad(){return;}
function getURLParam(strParamName){
	return getParameterFromLink(strParamName, window.location.href);
}
function getParameterFromLink(strParamName, link){
	var strReturn = "";
	var strHref = link;
	if(strHref.indexOf("?") > -1){
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for(var iParam = 0; iParam < aQueryString.length; iParam++){
			if(aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1){
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return unescape(strReturn);
}

jQuery(window).load(function(){
          jQuery('div#imgGal ul#billed-content').bxSlider({
            mode: 'fade',
            prevText:'',
            prevImage:'/Files/Billeder/Ecomotion/gfx/galBtnPrev.png',
            nextText:'',
            nextImage:'/Files/Billeder/Ecomotion/gfx/galBtnNext.png',
            captions: true,
            auto: false,
            controls: true
        });
          jQuery('div#fontImgGal ul#billed-content').bxSlider({
            mode: 'fade',
            captions: true,
            auto: true,
        });
});
