﻿// JavaScript Document

//Cufon

Cufon.replace('.latin #divisionNavigation a',{hover:true});
Cufon.replace('.latin #megaNavigation h3,#overlayFrames .element .expanderBox');


var url = $(location).attr('href');
var substr = url.split('/');
var urlData = "/?id=16129";

if(substr[2] == 'www.deif.de') {
  var urlData = "/?id=16527";
}
if(substr[2] == 'www.deif.dk') {
  var urlData = "/?id=16203";
}
if(substr[2] == 'www.deif.no') {
  var urlData = "/?id=16204";
}
if(substr[2] == 'www.deif.es') {
  var urlData = "/?id=16205";
}
if(substr[2] == 'www.deif.fr') {
  var urlData = "/?id=16239";
}
if(substr[2] == 'www.deif.cn') {
  var urlData = "/?id=16305";
}
if(substr[2] == 'www.deif.com.br') {
  var urlData = "/?id=16662";
}

  
//compile catalogue, ajax request data
function compileCatalogue(url) {
  //if no documents are selected for compiling exit
  if($('.documentSelector:checked').length===0){
    $('.errorNoneSelected').dialog({modal: true});
    return;
  }
  //else stringify data
  var postVars = [];
  for(var i=0, il=$('.documentSelector:checked').length; i<il;i++){
    postVars[i] = $('.documentSelector:checked:eq('+i+')').attr('name')+'=1';
  }
  //display proccessing message
  $('.compilingCatalogue').dialog({
    modal: true,
    closeOnEscape:false,
    open: function(event, ui) { 
      //hide close button.
      $(this).parent().children().children('.ui-dialog-titlebar-close').hide();
    }
  });
  //request ajax data
  $.ajax({
    type: 'POST',
    url: url,
    data: postVars.toString().replace(/,/g,'&'),
    success: updateCatalogueResult
  });
}
//compile catalogue display results - NOTE: data is hardcoded
function updateCatalogueResult(result){
  $('.compilingCatalogue').html('<h3>Your catalogue is ready</h3><p>Please follow the link below to download your catalogue</p><br /><br /><span class="pdfDownloadLink"></span><a href="'+result+'" target="_blank">Download catalogue</a>');
  $('.ui-dialog-titlebar-close').show();
}
//ajax eCom Search
function nzSearchKeyMove(action){
  var elmCount = $('#nzResult a').size();
  if(typeof nzSearchKeyMove.counter === 'undefined'){
    nzSearchKeyMove.counter = -1;
  }
  switch(action){
    case 'down':
      if(nzSearchKeyMove.counter<elmCount-1){
        nzSearchKeyMove.counter++;
      }
      $('#nzResult a').removeClass('highlighted');
      $('#nzResult a:eq('+nzSearchKeyMove.counter+')').addClass('highlighted');
      break;
    case 'up':
      if(nzSearchKeyMove.counter>0){
        nzSearchKeyMove.counter--;
      }
      $('#nzResult a').removeClass('highlighted');
      $('#nzResult a:eq('+nzSearchKeyMove.counter+')').addClass('highlighted');
      break;
    case 'execute':
      if($('#nzResult .highlighted').size()===1){
        window.location = $('#nzResult .highlighted').attr('href');
      }
      break;
  }
}
// TO DO - Optimize set timeout on requests to avoid posting pr. entry
function nzSearch(key){
  var query = $('#nzSearchQuery').val(),
  maxRecords = '5',
  areaid = '1',
  detailed = 'False',
  nzProductLanguageID = 'lang1',
  detailedTruncLength = '200',
  ExcludeProductGroups = 'GROUP418,GROUP408',
  inputQuery ='&ExcludeProductGroups='
        + ExcludeProductGroups
        + '&nzProductLanguageID='
        + nzProductLanguageID
        + '&query='
        + query
        + '&maxRecords='
        + maxRecords
        + '&detailed='
        + detailed
        + '&detailedTruncLength='
        + detailedTruncLength;
  if(query===''){
    return;
  }
  alert(de);
  switch(key){
    case 9: case 17: case 18: case 37: case 39:
      break;
    case 40:
      nzSearchKeyMove('down');
      break;
    case 38:
      nzSearchKeyMove('up');
      break;
    case 13:
      nzSearchKeyMove('execute');
      break;
    default:
      if (query.length > 1){
        $('#nzResult').html("");
        $('#nzResult').show();
        //Get data from Dynamic Web
        $.get(urlData + inputQuery, function(data) {
            $('#nzResult').html(data);
        });
        nzSearchKeyMove.counter = -1;
      }else{
        $('#nzResult').html("");
        $('#nzResult').hide();
      }
  };
}
function fetchDocs(id){
  var getter = urlData+'&nzProductID='+id;
  $.get(getter, function(data) {
    if(data===''){
      data = 'No documents associated with this product';
    }
    $('#productDocs').html(data);
  });
}

function buildGallery(){
  $('#gallery').append('<div id="galleryThumbs"></div>');
  $('.galleryThumb').each(function(){
    $(this).appendTo($('#galleryThumbs'));
  });
  $('#gallery > img:eq(0)').addClass('active').show();
  $('#galleryThumbs > img:eq(0)').addClass('current').show();
}

function pushToHeader(){
  $('#pageHeading').text($('.pushToHeader').text());
}

function pushRSS(){
  $('<span class="spacer"></span>').prependTo($('#printShare'));
  $('.rssFeed').prependTo($('#printShare'));
  $('.rssFeed').css('display','block');
}

//slideshow plugin
(function($){$.fn.contentSlider=function(a){var b={slideSpeed:10000,showNumbers:false,showMarkers:false,showNavigation:false,transition:"fade",inView:1,loop:true,contentOutCall:function(){},contentInCall:function(){}};return this.each(function(){if(a){$.extend(b,a)}var e=$("li",this).length;if(e<b.inView+1){return}var n=$(this);n.append('<span class="nextArrow"></span><span class="previousArrow"></span>');var j=$(".nextArrow",this),k=$(".previousArrow",this),h=$("li:first",this).outerHeight(true),l,c=0,d=0,q=$("li:first",this).outerWidth(true)*b.inView,p=$("li:first",this).outerWidth(true),e=Math.ceil(e/b.inView);$(this).css({position:"relative",height:h,width:q,overflow:"hidden"});switch(b.transition){case"fade":l=[0,0];thisIn={opacity:1};thisOut={opacity:0};break;case"up":l=[0,h];thisIn={top:0};thisOut={top:-h};break;case"down":l=[0,-h];thisIn={top:0};thisOut={top:h};break;case"left":l=[p,0];thisIn={left:0};thisOut={left:-p};break;case"right":l=[-p,0];thisIn={left:0};thisOut={left:p};break}$("li",this).each(function(){$(this).css({position:"absolute",left:(b.inView>1)?l[0]+p*($(this).index()%b.inView):l[0],top:l[1]})});$("li",this).slice(0,b.inView).css("z-index","999").addClass("current");if(b.transition==="fade"){$("li",this).slice(b.inView).css({opacity:0,"z-index":998})}else{$("li:first",this).css({left:0,top:0})}if(b.slideSpeed!=0){var f=setTimeout(function(){j.click();if(b.loop!=false||(b.loop===false&&c!=e-1)){setTimeout(arguments.callee,b.slideSpeed)}},b.slideSpeed)}if(b.showMarkers===true){var m="";for(var g=1,o=e;g<=o;g++){if(b.showNumbers===true){m=m+"<li>"+g+"</li>"}else{m=m+"<li></li>"}}$(".nextArrow",n).after('<ul class="markers"></ul>');$(".markers",this).append(m);$(".markers li:first",this).addClass("current");$(".markers li",this).click(function(){c=$(".markers li",n).index(this)-1;j.click()})}j.click(function(i){i.stopPropagation();if(c+1===e){c=0}else{c++}$("ul:first li.current",n).animate(thisOut,600,"swing",function(){if(b.transition!="fade"){$(this).css({left:l[0],top:l[1]})}b.contentOutCall.call(this)}).css("z-index","998").removeClass("current");$(".markers li",n).removeClass("current");$(".markers li:eq("+c+")",n).addClass("current");$("ul:first li",n).slice(c,c+b.inView).animate(thisIn,600,"swing",function(){b.contentInCall.call(this)}).css("z-index","999").addClass("current")});k.click(function(i){i.stopPropagation();if(c===0){c=e-1}else{c--}$("ul:first li.current",n).animate(thisOut,600,"swing",function(){if(b.transition!="fade"){$(this).css({left:l[0],top:l[1]})}b.contentOutCall.call(this)}).css("z-index","998").removeClass("current");$(".markers li",n).removeClass("current");$(".markers li:eq("+c+")",n).addClass("current");$("ul:first li",n).slice(c,c+b.inView).animate(thisIn,600,"swing",function(){b.contentInCall.call(this)}).css("z-index","999").addClass("current")})})};})( jQuery );


$(document).ready(function () {

    $(".searchHeadline").each(function () {
        if ($(this).children("h2:contains('(0)')").length == 1) {
            $(this).next().css("display", "none");
        }
    });

    var valH = $('#leftNavigation div').length;
    if (valH == 0) {
        $('#leftNavigation').hide();
    }

    //  $('.dontShowInAllTrue').hide();
    $('.dontShowInAllTrue').css('display', 'none');

    //$('#contentContainer .ParagraphContainer .TextTop div:first > ul li').prepend('&gt;&nbsp;');

    $('.ccMainCategory').each(function (i) {
        $(this).find('.h2:first').show();
    });

    $(".various2").fancybox();
    $(".various3").fancybox();

    // List Content - Home 2 column.
    $('.boxHalf:nth-child(odd)').css({ 'padding': '13px 20px 13px 0', 'background': 'url(/files/system/deif/gfx/border.png) top right no-repeat' });
    //$('.boxHalf:nth-child(1n+1)').css({'borderBottom':'1px solid #D3D5D7'});
    //function to check all checkboxes in compile catalogue module in 3 scopes
    $('.selectAll').click(function () {
        if ($(this).parent().parent().attr('id') === 'catalogueCompiler') {
            var $this = $(this).parent().nextAll('div:eq(0)');
            $('.documentSelector', $this).attr('checked', true);
        } else if ($(this).parent().next().attr('id') === 'catalogueCompiler') {
            $('.documentSelector').attr('checked', true);
        } else {
            var $this = $(this).parent().nextAll('table:eq(0)');
            $('.documentSelector', $this).attr('checked', true);
        }
    });
    //function to uncheck all checkboxes in compile catalogue module in 3 scopes
    $('.deselectAll').click(function () {
        if ($(this).parent().parent().attr('id') === 'catalogueCompiler') {
            var $this = $(this).parent().nextAll('div:eq(0)');
            $('.documentSelector', $this).attr('checked', false);
        } else if ($(this).parent().next().attr('id') === 'catalogueCompiler') {
            $('.documentSelector').attr('checked', false);
        } else {
            var $this = $(this).parent().nextAll('table:eq(0)');
            $('.documentSelector', $this).attr('checked', false);
        }
    });



    //contentSlider
    $('.contentSlider.right').contentSlider({
        'showMarkers': true,
        'showNumbers': true,
        'transition': 'left'
    });
    $('.contentSlider.left').contentSlider({
        'showMarkers': true,
        'showNumbers': true,
        'transition': 'left',
        'slideSpeed': 0
    });

    //relatedProducts
    $('.relatedSlider').contentSlider({
        'showMarkers': true,
        'showNumbers': true,
        'inView': 2,
        'slideSpeed': 0,
        'showNavigation': true
    });

    //Drop down
    $('.dropDown span').click(function (event) {
        var $this = $(this).siblings('ul');
        $this.slideToggle();
        $this.click(function (event) {
            event.stopPropagation();
        });
        event.stopPropagation();
        $('body').one('click', function () {
            $this.hide();
        });
    });


    //Home content zoomer
    $('#overlayFrames .element .expanderBox').bind('mouseenter', function () {
        var $this = $(this),
      offset = $this.offsetParent().offsetParent().offset(),
      $thisParent = $this.offsetParent();
        if ($('.frameContent', $thisParent).is(':hidden')) {
            $('body').trigger('click');
        }
        $this.parent().css({
            zIndex: '999' // Hello my name is IE7, i complain when i dont understand z-index behavior
        });
        $this.next().css({
            display: 'block',
            zIndex: '999'
        });
        $this.next().stop('true', 'true').animate({
            left: offset.left + 30 - $this.offset().left + 'px',
            top: '0',
            width: '900px',
            height: '365px'
        }, 300, function (event) {
            $('.frameContent', $thisParent).each(function (index) { // sets style for box with menu items
                $(this).css({
                    top: '0',
                    left: offset.left + (30 + index * 450) - $this.offset().left + 'px',
                    height: '346px', //Don't know what this does
                    zIndex: '999' //Sets z-index of menu items
                });
            });
            $('.frameContent', $thisParent).show(); //shows box with menu items
            $('.frameContent', $thisParent).click(function (event) {
                event.stopPropagation();
            });

            $('body').one('click', function () {
                $('.frameContent', $thisParent).hide();
                $this.next().removeAttr('style');
                $this.parent().css({ zIndex: '998' }); // Hello my name is IE7, i complain when i dont understand z-index behavior
            });

            //$this.mouseout(function(){
            //  $('body').trigger('click');
            //});
        });
    });

    /*
    // JAKOB W KODE
    $("#productAreaOne .expanderBox").hover(function () {
    $(this).next().appendTo($(this));
    //$(this).next().appendTo($(this));
    $(this).find('.frame').css({'width':'900px','height':'365px','margin-top':'-341px','margin-left':'20px','z-index':'99'});
    $(this).find('.frame').show();
    $(this).parent().find('.frameContent').show();

    }, 
    function () {
    $(this).find('.frame').hide();
    });
    */


    $('.whiteBG').bind('mousemove', function () {
        //      alert('whitebg mousemove');
        //      $('body').trigger('click');
    });
    $('div.glassy').bind('mousemove', function () {
        //      alert('whitebg mousemove');
        //     $('body').trigger('click');
    });
    $('div.glassy').bind('mouseover', function () {
        //      alert('glassy mouseover');
        //      $('body').trigger('click');
    });





    $('#overlayFrames').hover(
    function () {

    },
    function () {
        $('.frameContent').delay(100).fadeOut(400);
        $('.frame').delay(100).fadeOut(400);
    }
  );


    $('#overlayFrames .frame .closeBtn').click(function () {
        $('body').trigger('click');
    });

//  Used to trigger mouseout from the menu box
  $('.borderTop, .whiteBG, #rightInnerWrap, #leftInnerWrap, footer').mousemove(function () {
    $('.frameContent').hide();
    });

    //add mod2 class
    $('.mod2Left:nth-child(2n)').addClass('mod2');

    //add mod3 class
    //  $('.mod3Left:nth-child(3n)').addClass('mod3');
    $('.mod3Left:visible').filter(function (index) { //Does the same as above, but does not include display:none-elements
        return index % 3 == 2;
    }).addClass('mod3');

    //add class on last 2 matched elements in contained selected
    $('.mod2Left').last().addClass('lastRow');
    $('.lastRow').prev().addClass('lastRow');

    //caseGallery
    $('#galleryThumbs img').click(function () {
        var $this = $(this);
        if ($this.hasClass('current') != true) {
            $('#gallery img.active').fadeOut();
            $('#gallery img:eq(' + $this.index() + ')').fadeIn().addClass('active');
            $('#galleryThumbs img').removeClass('current');
            $this.addClass('current');
        }
    });

    //tab navigation
    $('#tabs li').click(function () {
        var $this = $(this);
        $('#tabSection section').hide();
        $('#tabSection section:eq(' + $this.index() + ')').show();
        $('#tabs li').removeClass('active');
        $this.addClass('active');
    });



    //Button sorter
    $('#sorting li').click(function () {
        var $this = $(this);
        $('#sorting li').removeClass('selected');
        $this.addClass('selected');
        $('.contactDivision').text($this.text());
        if ($this.attr('id') === 'all') {
            $('#contacts li').show(); //Shows all contact persons
            $('#contacts li').each(function () {
                if ($(this).hasClass('dontShowInAllTrue')) { //Hides contact persons with checked checkbox
                    $(this).hide();
                };
            });
        }
        else {
            $('#contacts li').hide();
            $('#contacts li').each(function () {
                if ($(this).hasClass($this.attr('id')) === true) {
                    $(this).show();
                };
            });
        }
        $('.mod3Left').removeClass('mod3');
        $('.mod3Left:visible').filter(function (index) {
            return index % 3 == 2;
        }).addClass('mod3');
        $('.mod2Left').removeClass('mod2');
        $('.mod2Left:visible').filter(function (index) {
            return index % 2 == 1;
        }).addClass('mod2');
    });

    //Mega Navigation
    $('#divisionNavigation a').bind('click', function (event) {
        var $this = $(this),
    $thisOpened = $('#megaNavigation section:eq(' + $this.index() + ')');
        var pointerPosition = ($(this).width() / 2) + $this.position().left;
        event.preventDefault();
        $('#megaNavigation section').hide();
        $('#megaNavigationPointer').css({ 'left': pointerPosition, 'top': $this.position().top + 20 }).show();
        $thisOpened.css({ 'left': $('#divisionNavigation a:eq(0)').position().left - 35, 'top': $this.position().top + 32 }).slideDown();
        $thisOpened.click(function (event) {
            event.stopPropagation();
        });
        event.stopPropagation();
        $('body').one('click', function () {
            $thisOpened.hide();
            $('#megaNavigationPointer').hide();
        });
    });

    $('#megaNavigation section').bind('mouseleave', function () {
        $('body').trigger('click');
    });

    //Expand content
    //### DO NOT COPY - THIS CODE IS HORRIBLE ###//
    /*
    $('.slideContent ul').hide();
    $('.navigationSlider').bind('mouseenter mouseleave', function(event){
    var $this = $(this);
    $('.slideContentBG',$this).clearQueue();
    $('.slideContent ul',$this).clearQueue();
    if(event.type=='mouseenter'){
    $('.slideContentBG',$this).animate({
    height:20+$('.slideContent ul',$this).outerHeight(),
    opacity:1
    },'fast');
    $('.slideContent ul',$this).slideDown('fast');
    }
    if(event.type=='mouseleave'){
    $('.slideContentBG',$this).removeAttr('style');
    $('.slideContent ul',$this).removeAttr('style');
    }
    });
    */
    $(".slideContentContainer").hover(function () {
        $(this).children().children().find('#sitemap').stop(true, true).slideDown(400);
    }, function () {
        $(this).children().children().find('#sitemap').stop(true, true).delay(250).slideUp(400);
    });


    // Hide bottom row if empty
    if ($('#bottomContent').text() === '') {
        $('.glassyFade').hide();
    }

    // Hide/Show product documentation, used on eCom product details page
    $('.productDocsType').live('click', function () {
        $('div', this).toggle('fast');
    });
});
