// jquery.boxshadow.js
/* Created by Martin Hintzmann 2008 martin [a] hintzmann.dk
* MIT (http://www.opensource.org/licenses/mit-license.php) licensed.
*
* Version: 0.1
*
* Requires:
*   jQuery 1.2+
*/
(function ($) {
    $.fn.boxShadow = function (xOffset, yOffset, blurRadius, shadowColor) {
        if (!$.browser.msie) return;
        return this.each(function () {
            $(this).css({
                position: "relative",
                zoom: 1,
                zIndex: 2
            });
            $(this).parent().css({
                position: "relative"
            });

            var div = document.createElement("div");
            $(this).parent().append(div);

            var _top, _left, _width, _height;
            if (blurRadius != 0) {
                $(div).css("filter", "progid:DXImageTransform.Microsoft.Blur(pixelRadius=" + (blurRadius) + ", enabled='true')");
                _top = yOffset - blurRadius - 1;
                _left = xOffset - blurRadius - 1;
                _width = $(this).outerWidth() + 1;
                _height = $(this).outerHeight() + 1;
            } else {
                _top = yOffset;
                _left = xOffset;
                _width = $(this).outerWidth();
                _height = $(this).outerHeight();
            }
            $(div).css({
                top: _top,
                left: _left,
                width: _width,
                height: _height,
                background: shadowColor,
                position: "absolute",
                zIndex: 1
            });
            $(div).addClass("shadowBoxIE");
        });
    };
})(jQuery);

/* tabs for edit-mode */
/*
 * jQuery Tools 1.2.5 - The missing UI library for the Web
 * 
 * [tabs]
 * 
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * 
 * http://flowplayer.org/tools/
 * 
 * File generated: Fri Nov 26 01:57:10 GMT 2010
 */
(function(c){function p(d,b,a){var e=this,l=d.add(this),h=d.find(a.tabs),i=b.jquery?b:d.children(b),j;h.length||(h=d.children());i.length||(i=d.parent().find(b));i.length||(i=c(b));c.extend(this,{click:function(f,g){var k=h.eq(f);if(typeof f=="string"&&f.replace("#","")){k=h.filter("[href*="+f.replace("#","")+"]");f=Math.max(h.index(k),0)}if(a.rotate){var n=h.length-1;if(f<0)return e.click(n,g);if(f>n)return e.click(0,g)}if(!k.length){if(j>=0)return e;f=a.initialIndex;k=h.eq(f)}if(f===j)return e;
g=g||c.Event();g.type="onBeforeClick";l.trigger(g,[f]);if(!g.isDefaultPrevented()){o[a.effect].call(e,f,function(){g.type="onClick";l.trigger(g,[f])});j=f;h.removeClass(a.current);k.addClass(a.current);return e}},getConf:function(){return a},getTabs:function(){return h},getPanes:function(){return i},getCurrentPane:function(){return i.eq(j)},getCurrentTab:function(){return h.eq(j)},getIndex:function(){return j},next:function(){return e.click(j+1)},prev:function(){return e.click(j-1)},destroy:function(){h.unbind(a.event).removeClass(a.current);
i.find("a[href^=#]").unbind("click.T");return e}});c.each("onBeforeClick,onClick".split(","),function(f,g){c.isFunction(a[g])&&c(e).bind(g,a[g]);e[g]=function(k){k&&c(e).bind(g,k);return e}});if(a.history&&c.fn.history){c.tools.history.init(h);a.event="history"}h.each(function(f){c(this).bind(a.event,function(g){e.click(f,g);return g.preventDefault()})});i.find("a[href^=#]").bind("click.T",function(f){e.click(c(this).attr("href"),f)});if(location.hash&&a.tabs=="a"&&d.find("[href="+location.hash+"]").length)e.click(location.hash);
else if(a.initialIndex===0||a.initialIndex>0)e.click(a.initialIndex)}c.tools=c.tools||{version:"1.2.5"};c.tools.tabs={conf:{tabs:"a",current:"current",onBeforeClick:null,onClick:null,effect:"default",initialIndex:0,event:"click",rotate:false,history:false},addEffect:function(d,b){o[d]=b}};var o={"default":function(d,b){this.getPanes().hide().eq(d).show();b.call()},fade:function(d,b){var a=this.getConf(),e=a.fadeOutSpeed,l=this.getPanes();e?l.fadeOut(e):l.hide();l.eq(d).fadeIn(a.fadeInSpeed,b)},slide:function(d,
b){this.getPanes().slideUp(200);this.getPanes().eq(d).slideDown(400,b)},ajax:function(d,b){this.getPanes().eq(0).load(this.getTabs().eq(d).attr("href"),b)}},m;c.tools.tabs.addEffect("horizontal",function(d,b){m||(m=this.getPanes().eq(0).width());this.getCurrentPane().animate({width:0},function(){c(this).hide()});this.getPanes().eq(d).animate({width:m},function(){c(this).show();b.call()})});c.fn.tabs=function(d,b){var a=this.data("tabs");if(a){a.destroy();this.removeData("tabs")}if(c.isFunction(b))b=
{onBeforeClick:b};b=c.extend({},c.tools.tabs.conf,b);this.each(function(){a=new p(c(this),d,b);c(this).data("tabs",a)});return b.api?a:this}})(jQuery);

/*
* Slides, A Slideshow Plugin for jQuery
* Intructions: http://slidesjs.com
* By: Nathan Searles, http://nathansearles.com
* Version: 1.0.2
* Updated: November 30th, 2010
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

(function($){$.fn.slides=function(option){option=$.extend({},$.fn.slides.option,option);return this.each(function(){$('.'+option.container,$(this)).children().wrapAll('<div class="slides_control"/>').children().css({display:'block'});var elem=$(this),control=$('.slides_control',elem),total=control.children().size(),width=control.children().outerWidth(),height=control.children().outerHeight(),start=option.start-1,effect=option.effect.indexOf(',')<0?option.effect:option.effect.replace(' ','').split(',')[0],paginationEffect=option.effect.indexOf(',')<0?effect:option.effect.replace(' ','').split(',')[1],next=0,prev=0,number=0,current=0,loaded,active,clicked,position,direction;if(total<2){return;}
if(option.start){current=start;};if(option.randomize){control.randomize();}
$('.'+option.container,elem).css({overflow:'hidden',position:'relative'});control.css({position:'relative',width:(width*3),height:height,left:-width});control.children().css({position:'absolute',top:0,left:width,zIndex:0,display:'none'});if(option.autoHeight){control.animate({height:control.children(':eq('+start+')').outerHeight()},o.autoHeightSpeed);}
if(option.preload&&control.children()[0].tagName=='IMG'){elem.css({background:'url('+option.preloadImage+') no-repeat 50% 50%'});var img=$('img:eq('+start+')',elem).attr('src')+'?'+(new Date()).getTime();$('img:eq('+start+')',elem).attr('src',img).load(function(){$(this).fadeIn(option.fadeSpeed,function(){$(this).css({zIndex:5});elem.css({background:''});loaded=true;});});}else{control.find(':eq('+start+')').fadeIn(option.fadeSpeed,function(){loaded=true;});}
if(option.bigTarget){control.children().css({cursor:'pointer'});control.children().click(function(){animate('next',effect);return false;});}
if(option.hoverPause&&option.play){control.children().bind('mouseover',function(){stop();});control.children().bind('mouseleave',function(){pause();});}
if(option.generateNextPrev){$('.'+option.container,elem).after('<a href="#" class="'+option.prev+'">Prev</a>');$('.'+option.prev,elem).after('<a href="#" class="'+option.next+'">Next</a>');}
$('.'+option.next,elem).click(function(e){e.preventDefault();if(option.play){pause();};animate('next',effect);});$('.'+option.prev,elem).click(function(e){e.preventDefault();if(option.play){pause();};animate('prev',effect);});if(option.generatePagination){elem.append('<ul class='+option.paginationClass+'></ul>');control.children().each(function(){$('.'+option.paginationClass,elem).append('<li><a rel='+number+' href="#">'+(number+1)+'</a></li>');number++;});}else{$('.'+option.paginationClass+' li a',elem).each(function(){$(this).attr('rel',number);number++;});}
$('.'+option.paginationClass+' li a:eq('+start+')',elem).parent().addClass('current');$('.'+option.paginationClass+' li a',elem).click(function(){if(option.play){pause();};clicked=$(this).attr('rel');if(current!=clicked){animate('pagination',paginationEffect,clicked);}
return false;});if(option.play){playInterval=setInterval(function(){animate('next',effect);},option.play);elem.data('interval',playInterval);};function stop(){clearInterval(elem.data('interval'));};function pause(){if(option.pause){clearTimeout(elem.data('pause'));clearInterval(elem.data('interval'));pauseTimeout=setTimeout(function(){clearTimeout(elem.data('pause'));playInterval=setInterval(function(){animate("next",effect);},option.play);elem.data('interval',playInterval);},option.pause);elem.data('pause',pauseTimeout);}else{stop();}};function animate(direction,effect,clicked){if(!active&&loaded){active=true;switch(direction){case'next':prev=current;next=current+1;next=total===next?0:next;position=width*2;direction=-width*2;current=next;break;case'prev':prev=current;next=current-1;next=next===-1?total-1:next;position=0;direction=0;current=next;break;case'pagination':next=parseInt(clicked,10);prev=$('.'+option.paginationClass+' li.current a',elem).attr('rel');if(next>prev){position=width*2;direction=-width*2;}else{position=0;direction=0;}
current=next;break;}
if(effect==='fade'){if(option.crossfade){control.children(':eq('+next+')',elem).css({zIndex:10}).fadeIn(option.fadeSpeed,function(){control.children(':eq('+prev+')',elem).css({display:'none',zIndex:0});$(this).css({zIndex:0});active=false;});}else{control.children(':eq('+prev+')',elem).fadeOut(option.fadeSpeed,function(){if(option.autoHeight){control.animate({height:control.children(':eq('+next+')',elem).outerHeight()},option.autoHeightSpeed,function(){control.children(':eq('+next+')',elem).fadeIn(elem.data('slides').fadeSpeed);});}else{control.children(':eq('+next+')',elem).fadeIn(option.fadeSpeed,function(){if($.browser.msie){$(this).get(0).style.removeAttribute('filter');}});}
active=false;});}}else{control.children(':eq('+next+')').css({left:position,display:'block'});if(option.autoHeight){control.animate({left:direction,height:control.children(':eq('+next+')').outerHeight()},option.slideSpeed,function(){control.css({left:-width});control.children(':eq('+next+')').css({left:width,zIndex:5});control.children(':eq('+prev+')').css({left:width,display:'none',zIndex:0});active=false;});}else{control.animate({left:direction},option.slideSpeed,function(){control.css({left:-width});control.children(':eq('+next+')').css({left:width,zIndex:5});control.children(':eq('+prev+')').css({left:width,display:'none',zIndex:0});active=false;});}}
if(option.pagination){$('.'+option.paginationClass+' li.current',elem).removeClass('current');$('.'+option.paginationClass+' li a:eq('+next+')',elem).parent().addClass('current');}}};});};$.fn.slides.option={preload:false,preloadImage:'/img/loading.gif',container:'slides_container',generateNextPrev:false,next:'next',prev:'prev',pagination:true,generatePagination:true,paginationClass:'pagination',fadeSpeed:350,slideSpeed:350,start:1,effect:'slide',crossfade:false,randomize:false,play:0,pause:0,hoverPause:false,autoHeight:false,autoHeightSpeed:350,bigTarget:false};$.fn.randomize=function(callback){function randomizeOrder(){return(Math.round(Math.random())-0.5);}
return($(this).each(function(){var $this=$(this);var $children=$this.children();var childCount=$children.length;if(childCount>1){$children.hide();var indices=[];for(i=0;i<childCount;i++){indices[indices.length]=i;}
indices=indices.sort(randomizeOrder);$.each(indices,function(j,k){var $child=$children.eq(k);var $clone=$child.clone(true);$clone.show().appendTo($this);if(callback!==undefined){callback($child,$clone);}
$child.remove();});}}));};})(jQuery);

// Start site scripts
var $deJQ = jQuery.noConflict();
function executeSlides () {

    // Accordion - begin
    $deJQ("#accordion").tabs("#accordion div.accordion-pane", { tabs: 'div.accordion-header a.accordion-link', effect: 'slide', initialIndex: null });
    // Accordion - end

    var pauseTime = 5000;
    var pause = $deJQ("#rotationTime").val();
    if (pause !== undefined) {
        pauseTime = parseInt(pause);
    }

    // Slideshow - begin
    $deJQ('.slides').slides({
        preload: true,
        preloadImage: '/Style%20Library/DanEjendomme/gfx/slideshow-loader.gif',
        play: pauseTime,
        pause: 2500,
        slideSpeed: 1000,
        hoverPause: true
    });
}

$deJQ(document).ready(function () {

    $deJQ("#frontpage-quicklinks table:has( > tbody > tr > td > div.ms-WPBody)").addClass("shadowbox");
    //$deJQ("table:has( > tbody > tr > td > div.ms-WPBody > div.BoksWebPart)").addClass("shadowbox");
    $deJQ(".horizontal-webparts:has( > div.box > table)").addClass("margin");
    //$deJQ("div.medium:has( > table > tbody > tr > td > table > tbody > tr > td > div.ms-WPBody > div.boks-container)").addClass("multiple");
    //$deJQ("div.large:has( > table > tbody > tr > td > table > tbody > tr > td > div.ms-WPBody > div.boks-container)").addClass("multiple");

    $deJQ("div.medium div.boks-container:last-child").addClass("last");
    $deJQ("div.large div.boks-container:last-child").addClass("last");

    // IE box shadow - begin
    if ($deJQ.browser.msie) {
        $deJQ('.shadowbox').boxShadow(2, 2, 2, "#dddddd");
        //$deJQ(css-selector).boxShadow( xOffset, yOffset, blurRadius, shadowColor );
    }
    // IE box shadow - end

    // Change all links containing isDlg to open in dialog
    try {

//        var content = document.getElementById('content-right');
        var content = document.getElementById('content-container');
        
        if (content == null) {
            content = document.body;
        }
        if (content != null) {
            var links = content.getElementsByTagName('a');
            for (i = 0; i < links.length; i++) {
                if (links[i].href.toLowerCase().indexOf('?isdlg') > -1) {
                    links[i].href = "javascript:openDialog('" + links[i].href + "');";
                }
                if (links[i].innerText == '' && links[i]['contentEditable'] == 'true') {
                    links[i].innerText = '---';
                }
            }
        }
    }
    catch (e) {
        alert('Dialog replace error: ' + e.message);
    }
});



function openDialog(dialogUrl) {
    var dWidth = 600;
    var dHeight = 400;
    var dTitle = "Dialog";

    try {
        //var url = dialogUrl.toLowerCase();
        url = dialogUrl.substring(dialogUrl.indexOf('?'));
        var params = url.split('&')
        for (i = 0; i < params.length; i++) {
            param = params[i].split('=');
            if (param.length = 2) {
                switch (param[0]) {
                    case 'W':
                    case 'w':
                        dWidth = param[1];
                        break;
                    case 'h':
                    case 'H':
                        dHeight = param[1];
                        break;
                    case 'T':
                    case 't':
                        dTitle = unescape(param[1]);
                        break;
                }
            }
        }

        var options = {
            url: dialogUrl,
            width: dWidth,
            height: dHeight,
            title: dTitle
        };

        SP.UI.ModalDialog.showModalDialog(options);
    }
    catch (e) {
        alert('Dialog Error: ' + e.message);
    }

}



