/* DocumentReady + Navigation + Online catalog */
$(document).ready(function() {

    CheckIfPrintPopup();
/******************************* List with links in HELLA colors *****************************************/
$(".toolbox .textContent ul li a, .toolbox .textToolbox ul li a").parent("li").css("color" , "#CD8D00");

/********************************** Toolbox p remove *******************************************/
if($(".textContent").length) {
   $("#right-side .toolbox .reports-simple .report-simple .textContent").each( function(index) {
    if ($("a", this).length <= 1) {
       //$(".toolbox .reports-simple .report-simple .textContent p").replaceWith("<span>" + $(".toolbox .reports-simple .report-simple .textContent p").html() + "</span>");
       var content = $(this).find("p");
       content.replaceWith("<span>" + content.html() + "</span>");
    }
})}

/******************************* Rollover - breadcrumb and footer *****************************************/
$("#footer-in a, #breadcrumb-channel a, #breadcrumb a").hover(function(){
            $(this).stop(true,true).animate({color: "#CD8D00"},{ duration: "normal"});
        },
      function(){
            $(this).stop(true,true).animate({color: "#000000"},{ duration: "normal"});
        }
    )
$("#breadcrumb-channel a.last, #breadcrumb a.last").hover(function(){
            $(this).stop(true,true).animate({color: "#000000"},{ duration: "normal"});
       },
     function(){
            $(this).stop(true,true).animate({color: "#CD8D00"},{ duration: "normal"});
      }
   )

/******************************* Imprint/Impressum *****************************************/
if($(".emptypage").length) {
     $(".emptypage table tr td:first-child").addClass("firstColumn");
}

/******************************* News *****************************************/
$(".textToolboxCnt .event:last-child").addClass("lastEvent");

/**************************** Press article line-height **************************/
if($(".pressContent").length) {
	$(".pressContent").children("p").each( function(index) {
                if ($("sup",this).length) { $(this).css("line-height","1.5em"); }
                if ($("sub",this).length) { $(this).css("line-height","1.5em"); }
                });
		}

$(".pressCover").each(function(){
  if($(this).has(".pressImage img").length) {
   $(".pressContent",this).css("width","28.077em");
  }
})

/****************************** Contact person ********************************************/

$(".contactPerson").each(function(){
  if($(this).has("img").length) {
   $(".personDescription p",this).css("width","33.154em");
  }
})

/****************************** Sliding ********************************************/
$(".slidingModule .textDetails ul:last-child").css("margin-bottom","1.2em");

/******************************* Sitemap *****************************************/
$(".sitemapColl li.firstPage:first-child").css("padding-top","0");
$("#sitemap .sitemapColl:last-child").css("padding","0");

/********************************  Tools *************************************/
$('#tools img').hover(
    function() {
      if ($(this).parent().attr('rel').length > 0) {
        src = $(this).attr('src');
        $(this).attr('src',$(this).parent().attr('rel'));
        $(this).parent().attr('rel',src);
      }
    },
    function() {
      if ($(this).parent().attr('rel').length > 0) {
        rel = $(this).parent().attr('rel');
        $(this).parent().attr('rel',$(this).attr('src'));
        $(this).attr('src',rel);
      }
    }
  )
$('#print a').click(function() {
    OpenPrintPopup();
    return false;
})
$('#mail a').click(function() {
    window.open($(this).attr('href'),'popup','height=500,width=450,top=10,left=10,location=no,menubar=no,resizable=no,toolbar=no,status=no,scrollbars=no');
    return false;
})
$('.action-close').click(function() {
    window.close();
})
/*********************** Scroll link list with gallery **************************/
  if($(".scrollListModule").length) {
  
       $(".scrollListModule").accordion({  header: "h3",
                                           collapsible: true,
                                           autoHeight: false,
                                           active: false});
                            
                          }

/*********************** Scroll link list with image **************************/
  if($("#left-side .listModule").length) {
  
      $("#left-side .listModule").accordion({  header: "h3" ,collapsible: true, autoHeight: false, active: false});
                            
                            $("div.singleModule").click(function()
                            {
                            picture = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                            $("div.imageModule").css("background",picture);
                               
                             headline = $("div.textSource h2", this).html();
                             $("div.imageModule h2").html(headline);
                             textfield = $("div.textSource .textField", this).html();
                             $("div.imageModule .textField").html(textfield);

                             if($(".textDetails .infoEmployee",this).children().length == 1){
                                $(".textDetails .infoEmployee",this).css("display", "none");
                               }
                             
                             if($("div.textSource .videoSource", this).length) {
                                $(".singleModule .ui-state-active img.playScroll").css("display", "inline");
                             }else{ $(".singleModule .ui-state-active img.playScroll").css("display", "none"); } 
                            
                        }); 
    }

 /*********************** Image with Content navigtion **************************/
  
if($("#contentModule").length) {
  $(".naviModule li").hover(function(){
                      $(".naviModule li a.active").addClass("hoverActive");
                      $(".naviModule li a").removeClass("active");
                    },function(){$(".naviModule li a.hoverActive").addClass("active"); 
                      })
              text = $("div#firstModule").html();                    
                             $("div#contentModule").html(text);
                             picture = "white url('" + $("div.textSource p", this).html() + "') top left no-repeat";
                             $("div.imageModuleContent").css("background",picture); 
                             $("div.imageModuleContent").css("height","20em");
                             $("div#contentModule p").replaceWith("<span>" + $("div#contentModule p").text() + "</span>");
                               
                        $(".naviModule li.firstModule").click(function()
                            {
                             $(".naviModule li a").removeClass("hoverActive");
                             rewriteModule("div#firstModule");
                             $("a", this).addClass("active");
                             $("div#contentModule p").replaceWith("<span>" + $("div#contentModule p").text() + "</span>");
                        });
                        
                        $(".naviModule li.secondModule").click(function()
                            {
                             $(".naviModule li a").removeClass("hoverActive");
                             rewriteModule("div#secondModule");
                             $("a", this).addClass("active");
                             $("div#contentModule p").replaceWith("<span>" + $("div#contentModule p").text() + "</span>");
                        });
                        
                        $(".naviModule li.thirdModule").click(function()
                            {
                             $(".naviModule li a").removeClass("hoverActive");
                             rewriteModule("div#thirdModule");
                             $("a", this).addClass("active");
                             $("div#contentModule p").replaceWith("<span>" + $("div#contentModule p").text() + "</span>");
                        });
                        
                        $(".naviModule li.fourthModule").click(function()
                            {
                             $(".naviModule li a").removeClass("hoverActive");
                             rewriteModule("div#fourthModule");
                             $("a", this).addClass("active"); 
                             $("div#contentModule p").replaceWith("<span>" + $("div#contentModule p").text() + "</span>");
                        });
                        
                        $(".naviModule li.fifthModule").click(function()
                            {
                             $(".naviModule li a").removeClass("hoverActive");
                             rewriteModule("div#fifthModule");
                             $("a", this).addClass("active"); 
                             $("div#contentModule p").replaceWith("<span>" + $("div#contentModule p").text() + "</span>");
                        });
                                                     
                             var i = 0;
                             
                             $('.naviModule li a').each(function() {
                             
                                  i += $(this).html().length;
                                  var value = $(this).html();
                                  value = value.replace(" ", "&nbsp;");
                                  $(this).html(value);                                  
                              });
                              
                              if (i > 48)
                              {
                                  $(".naviModule").css("height","3.3em");
                                  $(".naviModule ul li").css("margin-bottom","0.4em");
                                  }						
    }
/********************************Sliding list*********************************************************/
if($(".contentSlidingList").not(".smartEdit").length) {
            $(".slidingModule").accordion({  
                header: "h3" ,
                collapsible: true,
                autoHeight: false,
                active: false  
                });
   if (window.name != "Print") {
			$(".singleModuleSlide").click(function(){
				num = $(".slidingContent ul.slider",this).children().length; 
			    $("#controls").remove();
				$(".contentSliding").html($(this).find(".dataStorage .slidingContent").html()); 
				$(".contentSliding .sliding").sudoSlider({ 
                  continuous: true,
                  prevNext:true,
                  fadespeed: '1200',
                  nextHtml: '<a href="#" class="nextBtn"><img src="/cps/Projects/microsite-master/images/pfeil_weiss_gross.png" width="40" height="39"></a>',
                  insertAfter: false,
                  autoheight: false
                  });   
				if(num == 1) $("#controls").hide();
			   });
			   
               $(".contentSliding .sliding").sudoSlider({ 
                  continuous: true,
                  prevNext:false,
                  fadespeed: '1200',
                  autoheight: true 
                  });    
         }		 
	}      
/********************  Toolbox Downloadbox ****************************************/             
if($(".reflection img").length) {
    $('.reflection img').reflect({height: 0.25, opacity: 0.3});  
}

/********************  Toolbox Scroll list text and links  ************************/
$('.toolbox .listModule .singleModuleSlide:first h3').css('border-top', 0);
$('.toolbox .listModule').accordion({ header: 'h3' ,collapsible: true, autoHeight: false, active: false });

/********************  Login and Language Drop down box ************************/           
          
if($(".otherLoginsFrame").length) {
        $("#login li.mainLogin a.drop-login").mouseenter(function(){
                        $(".ui-widget-overlay").stop(true, true);
                        $('.otherLoginsFrame').stop(true, true).slideDown('normal');
                        $('.otherLanguageFrame').stop(true, true).slideUp('normal');
                        $(this).addClass("active");
                        $("#login a.drop-language").removeClass("active");
                        $("#tools img").css("visibility","hidden"); 
                        if($(".ui-widget-overlay").length == 0) {
                          $("#container").append("<div class=\"ui-widget-overlay\" style=\" " + $(document).width() + " ; opacity: 0; height:" + $(document).height() + ";  top: 0; left: 0; position: fixed; display: block; z-index: 1001;\"></div>");
                          }                        
                        $(".ui-widget-overlay").animate( {opacity: 0.3}, 400);   
                });


           $('.mainLogin').mouseleave(function() {
                  $('.otherLanguageFrame, .otherLoginsFrame').stop(true, true).slideUp('normal');
                  $("#login a").removeClass("active");
                  $("#tools img").css("visibility","visible");
                  $(".ui-widget-overlay").animate( {opacity: 0}, 400, function() { $(".ui-widget-overlay").remove() });
               });   
}
/********************  Gallery ************************/ 
    if($(".lightbox-gallery").length) {
      $(".lightbox-gallery").each(function() {
        galId = $(this).attr('id');
        $('#' + galId + ' a').attr('rel', 'lightbox-' + galId);
      })
    }

     $(".lightbox-gallery a").lightBox({
         txtImage: '',
         txtOf: '/',
         imageBtnPrev: '/cps/Projects/microsite-master/images/lightbox_btn_prev.gif',
         imageBtnNext: '/cps/Projects/microsite-master/images/lightbox_btn_next.gif',
         imageBtnClose: '/cps/Projects/microsite-master/images/lightbox_btn_close.gif',
         overlayBgColor: '#aaa',
         overlayOpacity: 0.3
     });

/******************** Teaser with hover effect **********************/
if($(".teasers-hover").length) { 
         textOriginal = $(".teaser-hover-text").html();
                  
         if(window.name == "Print") {
             var dockOptions =  { 
                  align: 'middle' 
                , size: 70
                , labels: 'bc'
                   };
                }else{
             var dockOptions =  { 
                  align: 'middle' 
                , size: 85
                , labels: 'bc'
                   };
                          }  
        $('.teaser-hover-images').jqDock(dockOptions);
                            
        $(".teaser-hover-images img").mouseenter( function() { 
                          $(".teaser-hover-label").hide(); 
                          text = $("#label-content-" + $(this).attr('id') + ' div').html();                 
                          $(".teaser-hover-text").html(text);
                          //alert($(this).attr('id'));
                    });
        $('.teaser-hover-images img').mouseleave(function() { 
                          $(".teaser-hover-label").show(); 
                          $(".teaser-hover-text").html(textOriginal);
                    });                    
    }

/********************  Annual Report Sliding ************************/
if($(".report-slider").not(".smartEdit").length) {    
  $(".report-slider").sudoSlider({
	    continuous:  true,
      auto: true,
      prevNext:false,
      controlsAttr: 'class="toolbox-controls"',
      pause: '10000',
      numeric: true,
      numericAttr:'class="controls"',
      fadespeed:  '1200',
      insertAfter:  false,
      autoheight: false
  });

  $('.report-slider .reports .text p:last-child').css({'margin-bottom': 0});    

  $('.toolbox-controls .nextBtn img, .toolbox-controls .prevBtn img').hover(
    function() {
      if ($(this).parent().attr('rel').length > 0) {
        src = $(this).attr('src');
        $(this).attr('src',$(this).parent().attr('rel'));
        $(this).parent().attr('rel',src);
      }
    },
    function() {
      if ($(this).parent().attr('rel').length > 0) {
        rel = $(this).parent().attr('rel');
        $(this).parent().attr('rel',$(this).attr('src'));
        $(this).attr('src',rel);
      }
    }
  )
                               
}

/********************  Mobile ************************/

$(".mobile .imageModuleContent").css("background","url(/cps/Projects/microsite-master/images/Herbstkampagne2011_Baby_mobile.png) no-repeat scroll left top #FFFFFF");
$(".mobile .imageModuleContent").css("height","18em");

/******************** Glossary / Bubble Tip ***********************/
    i = 0;
    j = 0;
    $('.glossary-mark').each(function() {
        $(this).attr('id', 'bbt-' + i++);
    });
    $('.glossary-content').each(function() {
        $(this).attr('id', 'bbt-' + j++ + '-c');
    });
    for (k = 0; k <= i; k++) {
        if ($('#bbt-' + k + '-c').length) {
            $('#bbt-' + k).qtip({
              content: $('#bbt-' + k + '-c').html(),
              position: {
                corner: {
                  target: 'topLeft',
                  tooltip: 'bottomRight'
                },
                adjust: {
                  screen: true
                }
              },
              style: {
                name: 'light',
                tip: 'bottomRight',
                border: {
                  radius: 5,
                  color: '#cd8d00'
                },
                width: {
                  min: 250,
                  max: 500
                }
              }
            });
        }
    }

/********************* Open all external urls and files in new window ***************************/
//variable projectName set in the top
 $('a').not(".searchLink").not(".showAll").each(function() {
      // look for link to file
      var ext = $(this).attr('href').match(/([^\.]*)\.(pdf|xls|doc|zip|exe|jpg|gif)/);
      //look for link references out from project or to "#"
         var ms =  $(this).attr('href').indexOf(projectName);
      if ((ext !== null || ms < 0) && $(this).attr('href') != '#') {
        $(this).attr('target', '_blank');
      }else { linkTarget = $(this).attr('href');
              if(linkTarget.indexOf('rdeLocaleAttr')<0 && linkTarget.indexOf('#')!=0){$(this).attr('href', linkTarget+"?rdeLocaleAttr="+currentlanguage);}}
       
    })
     
     linkTarget = $(".showAll").attr('href');
     $(".showAll").attr('href',linkTarget+"&rdeLocaleAttr="+currentlanguage );
     
     $("#search form").attr("action", $("#search form").attr("action")+"?rdeLocaleAttr="+currentlanguage );

/******************** Search ***********************/
    $('#search-submit').click(function() {
       s = $('#search input');
       if (s.val() == s.attr('title')) s.val('').focus().select();
       else document.search.submit();
    })
    $('#search input').focusin(function() {
       $(this).css({background: '#fff'});
       if ($(this).val() == $(this).attr('title')) $(this).val('');
    })
    $('#search input').focusout(function() {
       $(this).css({background: 'transparent'});
       if ($(this).val() == '') $(this).val($(this).attr('title'));
    })
    $('#search input').mouseenter(function() {
       $(this).css({background: '#fff'});
    })
    $('#search input').mouseleave(function() {
       if (!$(this).is(':focus')) $(this).css({background: 'transparent'});
    })

/****************** CONTACT *********************/

$(".contactModule").accordion({
     header: "h3" ,
     collapsible: true, 
     active: true,
     autoHeight: false
   });
  
/*********** Navigatin script  ************
 * @author spacja1
 */
    // important for ie6
  /*  $('.transparent .level2').css({'opacity': '0.90'}); 
    $('.transparent .level2').css({'filter': 'alpha(opacity=90)'}); */
    //  background  when level 3 exist
    $('#mainNavigation .level2 li').each(function(){
		if($(this).has('.level3').length){
			$(this).css("background","url(\'/cps/Projects/microsite-master/images/navigation-level.gif\') no-repeat scroll 95% 50% transparent");             
		}
	});
	// homepage fix
	if(!$('#mainNavigation').hasClass('home')) {
	    // open navigation for the current page	
		createCurrentState();
	}else{ $('#arrow').stop(true,true).hide(); };
    // 1. level navigation entries    
    $('#mainNavigation ul.level1 li a').not('#mainNavigation .level2 li a, #mainNavigation .level3 li a').mouseenter(function() {  
          $('.level2').stop(true,true).hide();
		  $('#arrow').stop(true,true).show();
          $('#mainNavigation ul.level1 li a').each(function() {
              removeHighlight($(this));
          });
          currentItem = $(this);
          $('#mainNavigation ul.level1 li a').not('#mainNavigation .level2 li a, #mainNavigation .level3 li a').stop(true,true).css({color: "#000000"});
          currentItem.animate({color: "#CD8D00"}, {duration : "normal"});
          // positioning of the arrow
                  
          if(currentItem.parent().has('.level2').length){
            maxWidth = columnWidth(currentItem.parent().find('.level2'));
			if(currentItem.next().has("li").length){currentItem.next().stop(true, true).slideDown('slow');}
          }else{maxWidth = 0;}
		  
			arrowPositioning(currentItem,maxWidth);	
		
		
		 $('.level3').stop(true,true).hide();		
      });
    
    // 2. level navigation entries
    $('#mainNavigation .level2 li a').not('#mainNavigation .level3 li a').mouseenter(function() {
        $('.level3').stop(true,true).hide();
        $('#mainNavigation .level2 li a').each(function() {
            removeHighlight($(this));
        });
        // close open subnavis first; inactivate acive items
        $('#mainNavigation .level2 li a').not('#mainNavigation .level3 li a').removeClass('active');
        $(this).animate({color: "#CD8D00"}, {duration : "normal"});
        // are there any 3. level items
        
        if($(this).parent().has('.level3').length){
            thirdLevelPositioning($(this));
            $(this).next().stop(true, true).slideDown('slow');   
            //$(this).show();			
        }
    });
    
    // 3. level
    $('#mainNavigation .level3 li a').mouseenter(function() {
        $("#mainNavigation .level3 li a").each(function() { removeHighlight($(this)); });
        $(this).animate({color: "#CD8D00"}, {duration : "normal"});
    });
    
    // defines, what should happen after leaving the navigation area
    $('#mainNavigation').mouseleave(function() {
	  if($('#mainNavigation').hasClass('home')) {
		// closing 2. and 3. level on the home site
            //$('#arrow').stop(true,true).animate({'background-position': '6.667em 0'}, 'normal'); // 100px 0px
			$('#arrow').stop(true,true).animate({'left': '1em'}, 'fast', function() {
							// Animation complete.
							$('#arrow').hide();
					});
			
            $('#level2').stop(true,true).slideUp('normal').queue(function() {
                $('.level3').hide();
				$('#content-navi ul:empty').parent().hide();	
            });
            $('#mainNavigation li a').removeClass('active');
            $('#mainNavigation li a').not(".choosen").each(function() {
                removeHighlight($(this));
            });
            $('.level2:visible, .level3:visible').stop(true, true).hide();

		} else {
		    $('.level2').stop(true,true).slideUp('fast',function(){
				$('.level3').hide();
				$('#content-navi ul:empty').parent().hide();			
			});
            // restore navigation for the current page
            createCurrentState();
        }
		
    });

    $('#content-navi ul:empty').parent().hide();
 /*********** Video module *********/
    $(".infoEmployee .modVideo .videoPlay").click(function(){
          playerId = $(this).attr("class").split(' ').slice(-1);
          openVideo($("."+playerId + " .videoFile").html(), playerId, $("."+playerId + " .videoWidth").html(), $("."+playerId + " .videoHeight").html());    
    });
});
/****************** END OF document.ready *******************************/
function openVideo(videoName, playerID, videoWidth, videoHeight){ 
     downloadTrack(videoName);          
     var flashvars = {};     
         /* flv player parameters */        
        flashvars.playerpath = "http://www.hella.com/player";                 
        flashvars.contentpath = "";    
             
        flashvars.video = videoName; 
        flashvars.preview = "";                        
              
        flashvars.skin = "skin-applestyle.swf";
        flashvars.skincolor = "0x7C7B6D";
        flashvars.skinscalemaximum = "4.5";
        flashvars.buttonoverlay = "buttonoverlay2.swf";
        flashvars.autoplay = "true";
        flashvars.smoothing = "true";
        flashvars.autoscale = "false";
        flashvars.videowidth = videoWidth;
        flashvars.videoheight = videoHeight;        
        /* end */        
                          
      var params = {};
          params.scale = "noscale";
          params.allowfullscreen = "true";
          params.salign = "tl";   
          params.base = "";  
      
      var attributes = {};
          attributes.align = "center";   
                  
  /* embed flv player */            
  // adapt the path to flvplayer.swf and expressInstall.swf
  // adapt the display size of the flash file
    
  swfobject.embedSWF("../player/flvplayer.swf", "videoPlayer"+playerID, videoWidth, videoHeight, "9.0.28", "../player/expressInstall.swf", flashvars, params, attributes);
        
      $("#dialog").dialog("destroy");
  
      $("#videoStorage"+playerID).dialog({
          height: parseInt(videoHeight)+30,
          width: parseInt(videoWidth),
          modal: true,
          dialogClass: "videoDialogUi",
          close: function(event, ui) { swfobject.removeSWF("videoPlayer391"+playerID);
                                       $(this).append("<div id=\"videoPlayer\"+playerID style=\"display: none; \"></div>");}
      });
}

/**
* Opens the navigation depending on the currently choosen page
* @looks for the css class "choosen"
*/
function createCurrentState() {
    $('#mainNavigation li a').stop(true, true);
    // inactivate navigation items
    $('#mainNavigation li a').removeClass('active');
    $('#mainNavigation li a').not(".choosen").css({color: "#000000"});
    $('#mainNavigation .choosen').next().show();
    $('#mainNavigation .choosen').addClass('active');
    $('#mainNavigation .choosen').css({color: "#CD8D00"});
	$('.level3 , .level2').hide();
    // positioning the arrow
	arrowPositioning($('ul.level1 > li a.choosen'),0);

}
/**
* positions the arrow beneth the choosen top level navigation item
* @param: the top level element 
*/
function arrowPositioning(element,maxWidth) {
    position = $(element).position();
    width = $(element).width();
	levelWidth = position.left + (width - 185)/2 + 30;  //parseInt(maxWidth)*9)
    $('#arrow').animate({'left': position.left + (width - 320)/2 + 'px'}, 'normal');
    $('.level2').css("left",levelWidth + 'px');    
	
}
/**
* positioning of 3. level below 2. level item
* @param: the 2. level active anchor item 
*/
function thirdLevelPositioning(element) {
    $(element).next().css('left', $(element).parent().position().left + $(element).parent().width() + 6 + 'px'); /*10*/
    $(element).next().css('top', $(element).parent().position().top - 2);  
}
/**
 * animates the color of the given element to black
 * if it has the color #CD8D00
 * @param the a element
 */
function removeHighlight(element) {
    if(element.is(":animated") || element.css("color") == "#CD8D00" || element.css("color") == "rgb(205, 141, 0)" || element.css("color") == "rgb(205,141,0)") {
        element.stop(true, true).animate({color: "#000000"}, {duration : "normal"});
    }
}
/**
 * Width settings in navigation for second level.
 */
function columnWidth(element) {
  var maxWidth = 0;
  var elemWidth = 0;
  var stringValue = "";
  $(element).children().each(function() {
      stringValue = $(this).find('a').html();
      elemWidth = parseInt(stringValue.length);
	 
      if (parseInt(elemWidth) > maxWidth) {
          maxWidth = elemWidth;
      }
  });
  $(element).children().each(function() {
      if( (parseInt(maxWidth)*9) < 100 ){
		$(this).css('width', "110px");
		stringValue = $(this).find('a.lev2').html();
		$(this).find(".lev2").css('padding-right', (100 - parseInt(stringValue.length)*9) + 5  + "px");
		maxWidth = 10;
	  }else{
		$(this).css('width', maxWidth * 9 +"px");
		stringValue = $(this).find('a.lev2').html();
		$(this).find(".lev2").css('padding-right', (parseInt(maxWidth) - parseInt(stringValue.length)) * 9 + 5  + "px");
	  }

  });
  return maxWidth;
}
function rewriteModule(elementName){
   text = $(elementName).html();                    
   $("div#contentModule").html(text);
   $(".naviModule a").removeClass("active");                          
}
 
/*
 * OpenPrintPopup()
 * 
 * Function:
 * Open the print popup
 *     
 */
 
function OpenPrintPopup () {  
  myPrintwindow = window.open(window.location.pathname+"?rdeLocaleAttr="+currentlanguage, "Print", "width=900,height=700,left=10,top=10,scrollbars=yes,dependent=yes,toolbar=yes,resizable=yes,status=yes");
}
/*
 * setActiveStyleSheet ( name of the stylesheet to show )
 * 
 * Function:
 * Load a aditional stylesheet for displaying  
 */
function setActiveStyleSheet(title) {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      if(a.getAttribute("title") == title) a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}
/*
 * CheckIfPrintPopup (void)
 * 
 * Usage:
 * body onload="CheckIfPrintPopup()"
 * 
 * Function:
 * Activate the print CSS for Screen if this page is loaded in the print popup
 */
function CheckIfPrintPopup() {
  if (window.name == "Print") {
    setActiveStyleSheet('print');    
  }
}
 
 
String.prototype.ReplaceAll = function(stringToFind,stringToReplace){
    var temp = this;
    var index = temp.indexOf(stringToFind);
        while(index != -1){
            temp = temp.replace(stringToFind,stringToReplace);
            index = temp.indexOf(stringToFind);
        }
        return temp;
    }

jQuery.extend(jQuery.expr[':'], {
    focus: function(element) { 
        return element == document.activeElement; 
    }
});

// *** Online Catalog ****
function openOnlineCatalogue( def, country, language, groupid) {
     catalogueurl = 'http://www.hella.com/toc/enter';
    
      country     = country ? country : 'DE';
      language    = language ? language : 'DE';
    
      if( def!='' ) {
        url = catalogueurl+'?DEFAULT='+def+'&COUNTRY='+country+'&LANGUAGE='+language;
    } else {
        url = catalogueurl+'?COUNTRY='+country+'&LANGUAGE='+language;
    }
    if( groupid!='' ) {
        url = url+'&GROUP_ID='+groupid;
    }
    var winWidth = screen.availWidth-10;
    var winHeight = screen.availHeight-50;
    var left = 0;
    var top = 0;
    var toolbar_str = 'no';
    var menubar_str = 'no';
    var statusbar_str = 'no';
    var scrollbar_str = 'yes';
    var resizable_str = 'yes';
    var ocwin = window.open(url, 'oc', 'left='+left+',top='+top+',width='+winWidth+',height='+winHeight+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
    ocwin.focus();
}
//
//    function to open the Hella Online Catalogue
//
//     onlineCatalogue( country, language[, basket[, prices[, articleNO[, formfieldID]]]] )
//
//        country        = country as string for old catalogue, i. e. 'DE'; default 'DE'
//        language    = language as string for old catalogue, i. e. 'DE'; default 'DE'
//        basket        = 'showing a shoppping basket' as int (1=yes, 0=no); optional
//        prices        = 'showing prices' as int (1=yes, 0=no); optional
//        articleNO    = number of article to search as string; optional
//        formfieldID    = id of form field to search as string; optional
//
function onlineCatalogue( country, language, basket, prices, articleNO, formfieldID ) {
     // new catalogue? ( 0=old - 1=new )
    var newCat                = 1;
    
    // old catalogue
    var oldCatalogueURL     = 'http://www.hella.com/toc/enter';
    var tmpCountry            = 'DE'; // default
    var tmpLanguage            = 'DE'; // default
    var basketPart            = '&DEFAULT=2';
    
    // new catalogue
    var newCatalogueURL     = 'http://www.hella.com/toc/enter';
    
    var profileIDArr        = new Array();
    profileIDArr[0]            = 21; // no shopping basket
    profileIDArr[1]            = 23; // shopping basket
    
    // general
    var searchPart            = '&SEARCH_PATH=4&SearchNumber=';
    var pricesPart            = 'GROUP_ID=test_1';
    
    // init
    var tmpCatalogueURL;
    var tmpProfile;
    var tmpURL;
    var tmpArt;
    
    // build catalogue url
    // general
    if ( country && country != '' ) {
        tmpCountry    = country;
    } // country set
    if ( language && language != '' ) {
        tmpLanguage    = language;
    } // language set
    tmpProfile        = 'COUNTRY=' + tmpCountry + '&LANGUAGE=' + tmpLanguage;
    
    if ( !basket || basket != 1 ) {
        basket = 0;
    } // no basket
    
    if ( newCat == 1 ) {
        tmpProfile        += '&profile=' + profileIDArr[basket];
        tmpURL = newCatalogueURL + '?' + tmpProfile;
    } else { // new catalogue
        tmpURL = oldCatalogueURL + '?' + tmpProfile
        if ( basket && basket == 1 ) {
            tmpURL = tmpURL + basketPart;
        } // shopping basket in old oc
    } // old catalogue
    
    // additional setting    
    if ( prices && prices == 1 ) {
        tmpURL = tmpURL + '&' + pricesPart;
    } // prices shown
    
    // article search by number
    if ( formfieldID && formfieldID != '' && document.getElementById( formfieldID ) ) {
        if ( ( tmpArt = document.getElementById( formfieldID ).value ) != '' ) {
            tmpURL = tmpURL + searchPart + tmpArt;
        } else if ( ( tmpArt = document.getElementById( formfieldID ).value ) == '' ) { // article no set in form field
            tmpURL = '';
        } // empthy form field
    } else if ( articleNO && articleNO != '' ) { // search by form field
        tmpURL = tmpURL + searchPart + articleNO;
    } // search by optional set article no
    if ( tmpURL != '' ) {
        // window setting
        var winWidth        = screen.availWidth-10;
        var winHeight         = screen.availHeight-50;
        var left             = 0;
        var top             = 0;
        var toolbar_str     = 'no';
        var menubar_str     = 'no';
        var statusbar_str     = 'no';
        var scrollbar_str     = 'yes';
        var resizable_str     = 'yes';
        
        // WebTrends
        downloadTrack(tmpURL);
        // opening the catalogue
        var ocwin = window.open( tmpURL, 'ocwin', 'left=' + left + ',top=' + top + ',width=' + winWidth + ',height=' + winHeight + ',toolbar=' + toolbar_str + ',menubar=' + menubar_str + ',status=' + statusbar_str + ',scrollbars=' + scrollbar_str + ',resizable=' + resizable_str);
        ocwin.focus();
    } // no URL top open
}

