var time = 15000;
var queue;

//(function($) {
$.extend($.fn, {
    getCss: function(key) {
        var v = parseInt(this.css(key));
        if (isNaN(v))
            return false;
        return v;
    }
});
$.fn.Drags = function(opts) {
    var ps = $.extend({
        zIndex: 20,
        opacity: .7,
        handler: null,
        onMove: function() { },
        onDrop: function() { }
    }, opts);
    var dragndrop = {
        drag: function(e) {
            var dragData = e.data.dragData;
            dragData.target.css({
                left: dragData.left + e.pageX - dragData.offLeft,
                top: dragData.top + e.pageY - dragData.offTop
            });
            dragData.handler.css({ cursor: 'move' });
            dragData.onMove(e);
        },
        drop: function(e) {
            var dragData = e.data.dragData;
            dragData.target.css(dragData.oldCss); //.css({ 'opacity': '' });
            dragData.handler.css('cursor', dragData.oldCss.cursor);
            dragData.onDrop(e);
            $().unbind('mousemove', dragndrop.drag)
                    .unbind('mouseup', dragndrop.drop);
        }
    }
    return this.each(function() {
        var me = this;
        var handler = null;
        if (typeof ps.handler == 'undefined' || ps.handler == null)
            handler = $(me);
        else
            handler = (typeof ps.handler == 'string' ? $(ps.handler, this) : ps.handle);
        handler.bind('mousedown', { e: me }, function(s) {
            var target = $(s.data.e);
            var oldCss = {};
            if (target.css('position') != 'absolute') {
                try {
                    target.position(oldCss);
                } catch (ex) { }
                target.css('position', 'absolute');
            }
            oldCss.cursor = target.css('cursor') || 'default';
            oldCss.opacity = target.getCss('opacity') || 1;
            var dragData = {
                left: oldCss.left || target.getCss('left') || 0,
                top: oldCss.top || target.getCss('top') || 0,
                width: target.width() || target.getCss('width'),
                height: target.height() || target.getCss('height'),
                offLeft: s.pageX,
                offTop: s.pageY,
                oldCss: oldCss,
                onMove: ps.onMove,
                onDrop: ps.onDrop,
                handler: handler,
                target: target
            }
            target.css('opacity', ps.opacity);
            $().bind('mousemove', { dragData: dragData }, dragndrop.drag)
                    .bind('mouseup', { dragData: dragData }, dragndrop.drop);
        });
    });
}
//})(jQuery); 
function frontPageEqualHeight() {
    $(".rightInfoBox").height($(".rightInfoBox .topImageWrapper img").height());
    var rightHeight = $(".rightInfoBox").height();
    $(".latestNews li").each(function() {
        var h2Height = $(this).children("h3").height();
        var pNewHeight = Math.floor((rightHeight - h2Height - 56 - 58) / 20) * 20;
        if (pNewHeight > 0) {
            $(this).children("p").height(pNewHeight).show('fast');
        }
    });
}
function slideShow() {
    var index = $('.promoBox .navigation li').size() - 1;

    count = 0;
    setInterval(function() {
        if (count == index) {
            animateBox($('.promoBox .navigation li:eq(' + count + ') a'));
            count = 0;
        }
        else {
            animateBox($('.promoBox .navigation li:eq(' + count + ') a'));
            count++;
        }


    }, time);
    //	

}

function animateBox(el) {
    if (typeof ($('.promoBox .navigation a').queue("fx")) != 'undefined') {
        queue = $('.promoBox .navigation a').queue("fx").length || $('.promoBox .slide').queue("fx").length
    }


    $('.promoBox .navigation li').removeClass('active');

    if (queue < 1) {

        $(el).animate(
				{

				    fontSize: "18px",
				    marginTop: "0px",
				    height: "49px",
				    paddingRight: "21px",
				    paddingLeft: "21px",
				    lineHeight: "49px"
				}, 800, "linear", function() {
				    $(el).parent().addClass('active');
				    $(el).removeAttr('style');

				}
			);
        index = $(".promoBox .navigation li").index($(el).parent());
        $('.promoBox .slide').fadeOut(800);
        $('.promoBox .slide:eq(' + index + ')').fadeIn(800, function() {
            $(el).addClass('active');
            $(el).removeAttr('style');
        });
    }

}

$(document).ready(function() {
    if (isEditMode != 1) {
        slideShow();
        frontPageEqualHeight();
    }
    /*
    var outerWidth = $('body').outerWidth() - $('#MSOTlPn_Tbl').width();
    $('#MSOTlPn_Tbl').css({ 'left': outerWidth,
    'right': 'auto', 'display': 'block', 'width': 'auto', 'height': 'auto'
    });
    $('#MSOTlPn_Tbl').css({
    handler: '.handler'
    });

    $('#MSOTlPn_Tbl').Drags({
    handler: '#MSOTlPn_ToolPaneCaption'
    });
    */

    $('.promoBox .navigation li a').click(function() {
        if (!$(this).parent().hasClass('active')) {
            animateBox(this)
        }
        return false;
    })


})








isOP = (navigator.userAgent.indexOf('Opera') > 0) ? true : false;
isIE = (navigator.appName == 'Microsoft Internet Explorer' && !isOP) ? true : false;
isIE5n6 = (navigator.appVersion.indexOf('MSIE 7') == -1 && isIE) ? true : false;
isMOZ = (navigator.appName.indexOf == 'Netscape') ? true : false;
function addListener(elm, evtName, callback) {
    if (elm.addEventListener) {
        elm.addEventListener(evtName, callback, false);
    }
    else if (elm.attachEvent) {
        elm.attachEvent("on" + evtName, callback);
    }
    else {
        elm["on" + evtName] = callback;
    }
    return callback;
}


function emulateHoverPseudoClass() {
    navigationListItems = $('nav').getElementsByTagName('UL')[0].getElementsByTagName('LI');
    for (i = 0; i < navigationListItems.length; i++) {
        navigationListItems[i].onmouseover = function() { this.className += ' over' };
        navigationListItems[i].onmouseout = function() { this.className = this.className.replace(' over', '') };
    }
}
function setHrefTarget() {
    hrefs = document.getElementsByClassName('external');
    for (var i = 0; i < hrefs.length; i++) {
        hrefs[i].target = '_blank';
    }
}
function objectEmbed(url, vars, w, h) {
    if (canPlayFlash()) {
        document.write(getFlashString(url, vars, w, h));
    }
}
function getFlashString(url, vars, w, h) {
    return '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + w + '" height="' + h + '" id="kampagnefelt" align="" VIEWASTEXT><param name="FlashVars" value="' + vars + '"><param name="movie" value="' + url + '"><param name="menu" value="false"><param name="quality" value="high"><param name="wmode" value="transparent"><embed src="' + url + '" menu="false" quality="high" wmode="transparent" width="' + w + '" height="' + h + '" FlashVars="' + vars + '" name="" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
}


minPlayer = 6;

function Flash_checkForPlugIn() {
    var plugin = (navigator.mimeTypes &&
  navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
    if (plugin) {
        var pluginversion = parseInt(plugin.description.substring(plugin.description.indexOf(".") - 1))
        if (pluginversion >= minPlayer) { return true; }
    }
    return false;
}


if (isIE) {
    document.write(
    '<script language=VBScript>' + '\n' +
    'Function Flash_checkForActiveX()' + '\n' +
    'Dim hasPlayer, playerversion' + '\n' +
    'hasPlayer = false' + '\n' +
    'playerversion = 10' + '\n' +
    'Do While playerversion >= minPlayer' + '\n' +
    'On Error Resume Next' + '\n' +
    'hasPlayer = (IsObject(CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" & playerversion & \"\")))' + '\n' +
    'If hasPlayer = true Then Exit Do' + '\n' +
    'playerversion = playerversion - 1' + '\n' +
    'Loop' + '\n' +
    'Flash_checkForActiveX = hasPlayer' + '\n' +
    'End Function' + '\n' +
    '<\/script>'
  );
}
function canPlayFlash() {
    if (isIE) {
        return Flash_checkForActiveX();
    } else {
        return Flash_checkForPlugIn();
    }
}