/* DocumentReady + Navigation + Online catalog*/
/**** All languages ****/
$(document).ready(function() {
    CheckIfPrintPopup();
/******************************* List with links in HELLA colors *****************************************/
$(".toolbox .textContent ul li a, .toolbox .textToolbox ul li a").parent("li").css("color" , "#E49A00");
/********************************** 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: "#E49A00"},{ 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: "#E49A00"},{ duration: "normal"});
      }
   )
/********** IE6 Hack for breadcrumb ***********/
$("#breadcrumb").css("position","absolute");
/******************************* 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");
  }
})
/****************************** Table ****************************************/
$(".singleModuleSlide .text:has(table)").addClass("table"); 
/****************************** Sliding ********************************************/
$(".slidingModule .textDetails ul:last-child").css("margin-bottom","1.2em");

/******************************* Sitemap *****************************************/
$(".sitemapColl li.firstPage:first-child").css("padding-top","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"); } 
                            
                        }); 
    }

/*********************** Map module with Content navigtion **************************/
  
if($("#mapModule").length) {
  $(".naviModule li").hover(function(){
                      $(".naviModule li a.active").addClass("hoverActive");
                      $(".naviModule li a").removeClass("active");
                    },function(){$(".naviModule li a.hoverActive").addClass("active"); 
                      })
  $("ul#companies li").hover(function(){
                      $("ul#companies li a.active").addClass("hoverActive");
                      $("ul#companies li a").removeClass("active");
                    },function(){$("ul#companies li a.hoverActive").addClass("active"); 
                      })
                             origHeadline = $("div.imageModuleContentMap h2").html();
                             text = $("div#firstModule").html();             
                             $("div#mapModule").html(text);
                             picture = "white url('" + $("div.textSource p.pct").html() + "') top left no-repeat";
							 $("div.imageModuleContentMap").css("background",picture); 
                             $("div.imageModuleContentMap").css("height","20em");
                             
                        $("div.singleModule").click(function()
                            {
                            pict = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                            $("div.imageModuleContentMap").css("background",pict);
                            $("ul#companies").hide();
                            headline = $("div.textSource h2", this).html();
                            $("div.imageModuleContentMap h2").html(headline);                            
                        });
                               
                        $(".naviModule li").click(function()
                            {
                             $(".naviModule li a, ul#companies li a").removeClass("hoverActive");
                             $("div.imageModuleContentMap").css("background",picture);
                             $("ul#companies").show();
                             $("ul#companies li a").removeClass("active");
                             $("div.imageModuleContentMap h2").html(origHeadline);
                        });

                        $("ul#companies li").click(function()
                            {
                             $(".naviModule li a").removeClass("hoverActive");
                             $("ul#companies li a").removeClass("active, hoverActive");
                             $("a", this).addClass("active");
                        });

                        $(".naviModule li.firstModule").click(function()
                            {
                             rewriteMapModule("div#firstModule");
                             $("a", this).addClass("active");
                             $("ul#companies li#Lippstadt a").addClass("active");
                             $("div.toolbox.Hamm, div.toolbox.Erwitte, div.toolbox.Recklinghausen, div.toolbox.Bremen, div.toolbox.Wembach").hide();
                             $("div.toolbox.Lippstadt").show();
                             $("div.singleModule").click(function()
                                {
                                 pict = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                                  $("div.imageModuleContentMap").css("background",pict);
                                  $("ul#companies").hide();
                                 headline = $("div.textSource h2", this).html();
                                  $("div.imageModuleContentMap h2").html(headline);                           
                                });            
                        });
                        
                        $(".naviModule li.secondModule").click(function()
                            {
                             rewriteMapModule("div#secondModule");
                             $("a", this).addClass("active");
                             $("ul#companies li#Hamm a").addClass("active");
                             $("div.toolbox.Lippstadt, div.toolbox.Erwitte, div.toolbox.Recklinghausen, div.toolbox.Bremen, div.toolbox.Wembach").hide();
                             $("div.toolbox.Hamm").show();
                             $("div.singleModule").click(function()
                                {
                                 pict = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                                  $("div.imageModuleContentMap").css("background",pict);
                                  $("ul#companies").hide();
                                 headline = $("div.textSource h2", this).html();
                                 $("div.imageModuleContentMap h2").html(headline);                            
                                });                          
                        });
                        
                        $(".naviModule li.thirdModule").click(function()
                            {
                             rewriteMapModule("div#thirdModule");
                             $("a", this).addClass("active");
                             $("ul#companies li#Erwitte a").addClass("active");
                             $("div.toolbox.Lippstadt, div.toolbox.Hamm, div.toolbox.Recklinghausen, div.toolbox.Bremen, div.toolbox.Wembach").hide();
                             $("div.toolbox.Erwitte").show();
                             $("div.imageModuleContentMap").css("background",picture);
                             $("div.singleModule").click(function()
                                {
                                  pict = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                                  $("div.imageModuleContentMap").css("background",pict);
                                  $("ul#companies").hide();
                                  headline = $("div.textSource h2", this).html();
                                  $("div.imageModuleContentMap h2").html(headline);                            
                        });
                        });
                        
                        $(".naviModule li.fourthModule").click(function()
                            {
                             rewriteMapModule("div#fourthModule");
                             $("a", this).addClass("active");
                             $("ul#companies li#Recklinghausen a").addClass("active"); 
                             $("div.toolbox.Lippstadt, div.toolbox.Hamm, div.toolbox.Erwitte, div.toolbox.Bremen, div.toolbox.Wembach").hide();
                             $("div.toolbox.Recklinghausen").show();
                             $("div.singleModule").click(function()
                                {
                                 pict = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                                  $("div.imageModuleContentMap").css("background",pict);
                                  $("ul#companies").hide();
                                  headline = $("div.textSource h2", this).html();
                                  $("div.imageModuleContentMap h2").html(headline);                            
                                }); 
                        });
                        
                        $(".naviModule li.fifthModule").click(function()
                            {
                             rewriteMapModule("div#fifthModule");
                             $("a", this).addClass("active");
                             $("ul#companies li#Bremen a").addClass("active");
                             $("div.toolbox.Lippstadt, div.toolbox.Hamm, div.toolbox.Erwitte, div.toolbox.Recklinghausen, div.toolbox.Wembach").hide();
                             $("div.toolbox.Bremen").show();
                             $("div.singleModule").click(function()
                                {
                                 pict = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                                  $("div.imageModuleContentMap").css("background",pict);
                                  $("ul#companies").hide();
                                  headline = $("div.textSource h2", this).html();
                                  $("div.imageModuleContentMap h2").html(headline);                            
                                });   
                        });
                        
                        $(".naviModule li.sixthModule").click(function()
                            {
                             rewriteMapModule("div#sixthModule");
                             $("a", this).addClass("active");
                             $("ul#companies li#Wembach a").addClass("active");
                             $("div.toolbox.Lippstadt, div.toolbox.Hamm, div.toolbox.Erwitte, div.toolbox.Recklinghausen, div.toolbox.Bremen").hide();
                             $("div.toolbox.Wembach").show();
                             $("div.singleModule").click(function()
                                {
                                 pict = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                                  $("div.imageModuleContentMap").css("background",pict);
                                  $("ul#companies").hide();
                                  headline = $("div.textSource h2", this).html();
                                  $("div.imageModuleContentMap h2").html(headline);                            
                                });                                
                        });
    
                                               
                        $("ul#companies li#Lippstadt").click(function()
                            {
                             rewriteMapModule("div#firstModule");
                             $(".firstModule a").addClass("active");
                             $("div.toolbox.Hamm, div.toolbox.Erwitte, div.toolbox.Recklinghausen, div.toolbox.Bremen, div.toolbox.Wembach").hide();
                             $("div.toolbox.Lippstadt").show();
                             $("div.singleModule").click(function()
                                {
                                  pict = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                                  $("div.imageModuleContentMap").css("background",pict);
                                  $("ul#companies").hide();
                                  headline = $("div.textSource h2", this).html();
                                  $("div.imageModuleContentMap h2").html(headline);                            
                                });
                        });
                        
                        $("ul#companies li#Hamm").click(function()
                            {
                             rewriteMapModule("div#secondModule");
                             $(".secondModule a").addClass("active");
                             $("div.toolbox.Lippstadt, div.toolbox.Erwitte, div.toolbox.Recklinghausen, div.toolbox.Bremen, div.toolbox.Wembach").hide();
                             $("div.toolbox.Hamm").show();
                             $("div.singleModule").click(function()
                                {
                                  pict = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                                  $("div.imageModuleContentMap").css("background",pict);
                                  $("ul#companies").hide();
                                  headline = $("div.textSource h2", this).html();
                                  $("div.imageModuleContentMap h2").html(headline);                            
                                });
                        });
                        
                        $("ul#companies li#Erwitte").click(function()
                            {
                             rewriteMapModule("div#thirdModule");
                             $(".thirdModule a").addClass("active");
                             $("div.toolbox.Lippstadt, div.toolbox.Hamm, div.toolbox.Recklinghausen, div.toolbox.Bremen, div.toolbox.Wembach").hide();
                             $("div.toolbox.Erwitte").show();
                             $("div.singleModule").click(function()
                                {
                                 pict = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                                  $("div.imageModuleContentMap").css("background",pict);
                                  $("ul#companies").hide();
                                  headline = $("div.textSource h2", this).html();
                                  $("div.imageModuleContentMap h2").html(headline);                            
                                });
                        });
                        
                        $("ul#companies li#Recklinghausen").click(function()
                            {
                             rewriteMapModule("div#fourthModule");
                             $(".fourthModule a").addClass("active");
                             $("div.toolbox.Lippstadt, div.toolbox.Hamm, div.toolbox.Erwitte, div.toolbox.Bremen, div.toolbox.Wembach").hide();
                             $("div.toolbox.Recklinghausen").show();
                             $("div.singleModule").click(function()
                                {
                                  pict = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                                  $("div.imageModuleContentMap").css("background",pict);
                                  $("ul#companies").hide();
                                  headline = $("div.textSource h2", this).html();
                                  $("div.imageModuleContentMap h2").html(headline);                            
                                });                             
                        });
                        
                        $("ul#companies li#Bremen").click(function()
                            {
                             rewriteMapModule("div#fifthModule");
                             $(".fifthModule a").addClass("active");
                             $("div.toolbox.Lippstadt, div.toolbox.Hamm, div.toolbox.Erwitte, div.toolbox.Recklinghausen, div.toolbox.Wembach").hide();
                             $("div.toolbox.Bremen").show();
                             $("div.singleModule").click(function()
                                {
                                 pict = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                                  $("div.imageModuleContentMap").css("background",pict);
                                  $("ul#companies").hide();
                                  headline = $("div.textSource h2", this).html();
                                  $("div.imageModuleContentMap h2").html(headline);                            
                                }); 
                        });
                        
                        $("ul#companies li#Wembach").click(function()
                            {
                             rewriteMapModule("div#sixthModule");
                             $(".sixthModule a").addClass("active");
                             $("div.toolbox.Lippstadt, div.toolbox.Hamm, div.toolbox.Erwitte, div.toolbox.Recklinghausen, div.toolbox.Bremen").hide();
                             $("div.toolbox.Wembach").show();
                             $("div.singleModule").click(function()
                                {
                                  pict = "white url('" + $("div.pictureSource", this).html() + "') top left no-repeat";
                                  $("div.imageModuleContentMap").css("background",pict);
                                  $("ul#companies").hide();
                                  headline = $("div.textSource h2", this).html();
                                  $("div.imageModuleContentMap h2").html(headline);                            
                                }); 
                        });
                        
                        $("ul#companies li, .naviModule li").click(function()
                            {
                             $("#mapModule .listModule").accordion({  header: "h3",
                                                                 collapsible: true,
                                                                 autoHeight: false,
                                                                 active: false});
                        });
                        
                        if($("#mapModule .listModule").length) {
                        
                             $("#mapModule .listModule").accordion({  header: "h3",
                                                                 collapsible: true,
                                                                 autoHeight: false,
                                                                 active: false});                            
                          }
 } 


	/*********************** 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");
                                  }
    }
/********************************Klaptool*********************************************************/
if($(".contentSlidingList").not(".SmartEdit").length) {
            $(".slidingContent").each(function() {
                $(this).children("h2").appendTo($(this).find("li")); 
                $(this).children("p").appendTo($(this).find("li"));  
              });
            var defaultImage = $(".contentSliding").html();
            $(".slidingModule").accordion({  
                header: "h3" ,
                collapsible: true,
                autoHeight: false,
                active: false  
                });
   if (window.name != "Print") {  
   			   if($(".contentSliding .sliding").find("li").length){
	            var sudoSlider =  $(".contentSliding .sliding").sudoSlider({ 
					 fade: true,
	                 prevNext:false,
	                 pause: '2000',
	                 auto: true,
	                 insertAfter: false,
	                 autoheight: false
	                });
				}	
			$(".singleModuleSlide").click(function(){
			    sudoSlider.destroy(); 
				if($(this).find(".dataStorage .slidingContent .slider").find("li").length){
				$(".contentSliding").html($(this).find(".dataStorage .slidingContent").html()); 
				sudoSlider =  $(".contentSliding .sliding").sudoSlider({ 
					  fade: true,
			          prevNext:false,
			          pause: '2000',
			          auto: true,
			          insertAfter: false,
			          autoheight: false
	                  });				
				sudoSlider.init();	
			   }else{$(".contentSliding").html(defaultImage);
				 sudoSlider.init();
			   };
			   });			  
     }	
	if($(".infoEmployee").children().length < 1){ $(".infoEmployee").css("display","none");};
}  
/********************  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/hella-master/images/lightbox_btn_prev.gif',
         imageBtnNext: '/cps/Projects/hella-master/images/lightbox_btn_next.gif',
         imageBtnClose: '/cps/Projects/hella-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/hella-master/images/Herbstkampagne2011_Baby_mobile.png) no-repeat scroll left top #FFFFFF");
$(".mobile .imageModuleContent").css("height","18em");

/********************  TecDoc  ************************/
$('a.btn_form').click(function() {
  myAjaxForm('#add');
});

/******************** 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: '#E49A00'
                },
                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 bruest1
 * Version 1.2
 * 2010-11-03
 */
    level2height = '5.47em';
    level3height = '12.85em';
    // important for ie6
    $('.transparent #level2').css({'opacity': '0.85'});
    // for browser greater ie7
    if(navigator.userAgent.indexOf('MSIE 8') != -1 || navigator.appVersion.indexOf('MSIE 9') != -1 || navigator.appVersion.indexOf('Opera') != -1) {
        $('#navLine').css({'top': function(index, value) {
            return parseInt(value) - 5;
        } });
    }
    // open navigation for the current page
    if(!$('#mainNavigation').hasClass('home')) {
        createCurrentState();
    }
    // 1. level navigationentries
    $('#mainNavigation ul.level1 li a').not('#mainNavigation .level2 li a, #mainNavigation .level3 li a').mouseenter(function() {
        $('#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: "#E49A00"}, {duration : "normal"});
        $('#navLine').stop(true, true).show();
        // positioning of the arrow
        arrowPositioning(currentItem);
        $("#level2").stop(true, true).slideDown('fast');    
        // open level2 first then show the 2. level (callback function)
        $("#level2").queue(function() {
            // highlight navigationentries
            $('#mainNavigation li a').not('ul.level1 > li a.choosen').removeClass('active');
            // close open subnavis
            $('.level2:visible, .level3:visible').stop(true, true).hide();
            //currentItem.addClass('active');
            currentItem.next().show();
            $('#level2').dequeue();
        });
        if($('#level2').css('height') != level2height) {
            $('#level2').animate({"height": level2height}, "normal");
        }
    });
    
    // 2. level navigationentries
    $('#mainNavigation .level2 li a').not('#mainNavigation .level3 li a').mouseenter(function() {
        $('#mainNavigation .level2 li a').each(function() {
            removeHighlight($(this));
        });
        // close open subnavis first; inactivate acive items
        $('.level3:visible').stop(true, true).hide();
        $('#mainNavigation .level2 li a').not('#mainNavigation .level3 li a').removeClass('active');
        $(this).animate({color: "#E49A00"}, {duration : "normal"});
        // are there any 3. level items
        if($(this).parent().has('ul').length) {
            thirdLevelPositioning(this);
            // open 3. level
            $("#level2").animate({"height": level3height}, "normal");
            $(this).next().show();
        } else {
            $('#level2').animate({"height": level2height}, "normal");
        }
    });
    
    // 3. level
    $('#mainNavigation .level3 li a').mouseenter(function() {
        $("#mainNavigation .level3 li a").each(function() {
            removeHighlight($(this));
        });
        $(this).animate({color: "#E49A00"}, {duration : "normal"});
    });
    
    // defines, what should happen after leaving the navigation area
    $('#mainNavigation').mouseleave(function() {
        // for the homepage
        if($('#mainNavigation').hasClass('home')) {
            // closing 2. and 3. level on the home site
			$('#arrow').stop(true,true).animate({'left': '0'}, 'normal');
            //$('#arrow').stop(true,true).animate({'background-position': '6.667em 0'}, 'normal'); // 100px 0px
            $('#navLine').fadeOut('normal');
            $('#level2').stop(true,true).slideUp('normal').queue(function() {
                $('#level2').css('height', level2height);
                $('#level2').dequeue();
            });
            $('#mainNavigation li a').removeClass('active');
            $('#mainNavigation li a').not(".choosen").each(function() {
                removeHighlight($(this));
            });
            $('.level2:visible, .level3:visible').stop(true, true).hide();
        } else {
            // 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(), "true", "");    
    });
 /*********** Sliding list video module *********/
    $(".reports .modVideo .videoPlay").click(function(){
          playerId = $(this).attr("class").split(' ').slice(-1);
          openVideo($("."+playerId + " .videoFile").html(), playerId, $("."+playerId + " .videoWidth").html(), $("."+playerId + " .videoHeight").html(), "true", "");    
    });
	 $(".reports .text .videoPlay").click(function(){
          playerId = $(this).attr("class").split(' ').slice(-1);
          openVideo($("."+playerId + " .videoFile").html(), playerId, $("."+playerId + " .videoWidth").html(), $("."+playerId + " .videoHeight").html(), "true", "");    
    });
	$(".reports .modVideo .playVideoArrow").click(function(){
          playerId = $(this).next(".videoPlay").attr("class").split(' ').slice(-1);
          openVideo($("."+playerId + " .videoFile").html(), playerId, $("."+playerId + " .videoWidth").html(), $("."+playerId + " .videoHeight").html(), "true", "");    
    });
 /**************** Video - type teaser  *****************/
   $(".videoTeaserModule .modVideo .videoPlay").click(function(){
          playerId = $(this).attr("class").split(' ').slice(-1);
          openVideo($("."+playerId + " .videoFile").html(), playerId, $("."+playerId + " .videoWidth").html(), $("."+playerId + " .videoHeight").html(), "true", "");    
    });
	 $(".videoTeaserModule .videoText .videoPlay").click(function(){
          playerId = $(this).attr("class").split(' ').slice(-1);
          openVideo($("."+playerId + " .videoFile").html(), playerId, $("."+playerId + " .videoWidth").html(), $("."+playerId + " .videoHeight").html(), "true", "");    
    });
	$(".videoTeaserModule .modVideo .playVideoArrow").click(function(){
          playerId = $(this).next(".videoPlay").attr("class").split(' ').slice(-1);
          openVideo($("."+playerId + " .videoFile").html(), playerId, $("."+playerId + " .videoWidth").html(), $("."+playerId + " .videoHeight").html(), "true" , "");    
    });
 /******************** Video **********************/
  if($(".pageVideo").length){
   $('.pageVideo').each(function() {
		playerId = $(this).attr("class").split(' ').slice(-1);
		openVideo($("."+playerId + " .videoFile").html(), playerId, $("."+playerId + " .videoWidth").html(), $("."+playerId + " .videoHeight").html(), "false", $("."+playerId + " .previewFile").html());       
		})
	};

 /******************** Introduction - Layout-3 Video **********************/
  if($(".pageVideoContent").length){
   $('.pageVideoContent').each(function() {
		playerId = $(this).attr("class").split(' ').slice(-1);
		openVideo($("."+playerId + " .videoFile").html(), playerId, $("."+playerId + " .videoWidth").html(), $("."+playerId + " .videoHeight").html(),  $("."+playerId + " .autoplayMode").html(), $("."+playerId + " .previewFile").html());       
		})
	};
});

/****************** END OF document.ready *******************************/
function openVideo(videoName, playerID, videoWidth, videoHeight, autoPlay, previewImage){ 
     downloadTrack(videoName);          
     var flashvars = {};     
         /* flv player parameters */        
        flashvars.playerpath = "http://www.hella.com/player";                 
        flashvars.contentpath = "";    
             
        flashvars.video = videoName; 
        flashvars.preview = previewImage;                        
              
        flashvars.skin = "skin-applestyle.swf";
        flashvars.skincolor = "0x6A7A86";
        flashvars.skinscalemaximum = "4.5";
        flashvars.buttonoverlay = "buttonoverlay2.swf";
        flashvars.autoplay = autoPlay;
        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
  
  
  if(!previewImage){   
	swfobject.embedSWF("../player/flvplayer.swf", "videoPlayer"+playerID, videoWidth, parseInt(videoHeight)+26, "9.0.28", "../player/expressInstall.swf", flashvars, params, attributes);
       
      $("#dialog").dialog("destroy");
  
      $("#videoStorage"+playerID).dialog({
          height: parseInt(videoHeight)+56,
          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>");}
      });
	}else{swfobject.embedSWF("../player/flvplayer.swf", "videoStorage"+playerID, videoWidth, parseInt(videoHeight)+26, "9.0.28", "../player/expressInstall.swf", flashvars, params, attributes);
			}
}

/**
* Opens the navigation depending on the currently choosen page
* @looks for the css class "choosen"
*/
function createCurrentState() {
    $('#mainNavigation li a').stop(true, true);
    $('#navLine').show();
    // close open subnavis first
    $('.level2:visible, .level3:visible').stop(true, true).hide();
    // 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: "#E49A00"});
    // handling the background
    if($('#mainNavigation .choosen').length) {
        $('#level2').show();
    }
    // positioning the arrow
    arrowPositioning($('ul.level1 > li a.choosen'));
    // has to be at the end -> before no position is given -> display:block
    if($('ul.level2 > li a.choosen').length) {
        thirdLevelPositioning($('ul.level2 > li a.choosen'));
    }
    if($('#level2').css('height') != level2height) {
        $('#level2').animate({"height": level2height}, "normal");
    }
}
/**
* positions the arrow beneth the choosen top level navigation item
* @param: the top level element 
*/
function arrowPositioning(element) {
    position = $(element).position();
    width = $(element).width();
    //$('#arrow').animate({'background-position': position.left + (width - 120)/2 + 'px' + ' 0px'}, 'normal');
	$('#arrow').animate({'left': position.left + (width - 320)/2 + 'px'}, "normal");
}
/**
* 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);
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ 
             var ieversion=new Number(RegExp.$1) 
             if (ieversion>=8)  $(element).next().css("margin-top", "1em");
             else if (ieversion<=7)   $(element).next().css("margin-top", "2.5em");
    } else {  
        $(element).next().css("margin-top", "1em");
    }
}
/**
 * animates the color of the given element to black
 * if it has the color #E49A00
 * @param the a element
 */
function removeHighlight(element) {
    if(element.is(":animated") || element.css("color") == "#E49A00" || element.css("color") == "rgb(228, 154, 0)" || element.css("color") == "rgb(228,154,0)") {
        element.stop(true, true).animate({color: "#000000"}, {duration : "normal"});
    }
}

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
}
/**New oline catolog**/
//	function to open the Hella Online Catalogue (TecDoc)
//		user	= username for Hella Online-Catalogue as string; optional
//		pass	= password for Hella Online-Catalogue as string; optional
//		articleDirectId	= number of article to search as string; optional
function onlineCatalogueTecDoc(user, pass, articleDirectId) {
 	catalogueurl = 'http://webshop-cs.tecdoc.net/hella';
	
  user		  = user ? user : '';
  pass	    = pass ? pass : '';
  articleDirectId = articleDirectId ? articleDirectId : '';
  
	url = catalogueurl+'?';
  if( user!='' && pass!='' ) {
		url = url+'user='+user+'&pass='+pass;
		if( articleDirectId!='' ) {
		  url = url+'&articleDirectId='+articleDirectId;
	  } 
	} else if( articleDirectId!='' ) {
		url = url+'articleDirectId='+articleDirectId;
	} 
	
	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 rewriteMapModule(elementName){
   text = $(elementName).html();                    
   $("div#mapModule").html(text);
   $(".naviModule a").removeClass("active");                          
}

