
$(document).ready( function() {  
    if(typeof Cufon != 'undefined' && Cufon) {
        //Simian Text Chimpanzee oder Simian Text Orangutan
        //Cufon.replace('#stage h1.cufon, h1 span, h2 span a, .cufon_tag a', { fontFamily: 'Vegur',hover: true });
        Cufon.replace('#stage h1.cufon, h2 span a, #wide h1 span, .stage_content p.font_gen', {
            fontFamily: 'Franklin Gothic Heavy',
            hover: true
        });
        Cufon.replace('.landingpage h1, .landingpage h2', {
            fontFamily: 'Helvetica Neue',
            hover: true
        });
        Cufon.replace('#small h1 span, .cufon_tag a', {
            fontFamily: 'Franklin Gothic Heavy',
            hover: true
        });
        Cufon.replace('.description .copy h1.cufonDescription', {
            fontFamily: 'SimianText-Chimpanzee',
            hover: true
        });
    }

    $('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });   
	
    if($('#content-pages') && $('#content-pages').length > 0) {
        $('#content-pages').pager('div');
    }
	
    $('.teaser-image .background').hover(
        function () {
            $(this).addClass("active");
        },
        function () {
            $(this).removeClass("active");
        }
        );
	
    $('.teaser-text .background').hover(
        function () {
            $(this).addClass("active");
        },
        function () {
            $(this).removeClass("active");
        }
        );


    //bugfix hover event, text color
	  $('div.teaser-image > div.background').hover(
      function () {
        $(this).find('.col_content').children().children().css('color','#0C2635');
      },
      function () {
        $(this).find('.col_content').children().children().css('color','#fff');
      }
    );
    
    
    $('.Cteaser-image .background').hover(
        function () {
            $(this).addClass("active");
        },
        function () {
            $(this).removeClass("active");
        }
        );
	
    $('.Cteaser-text .background').hover(
        function () {
            $(this).addClass("active");
        },
        function () {
            $(this).removeClass("active");
        }
        );


    //bugfix hover event, text color
	  $('div.Cteaser-image > div.background').hover(
      function () {
        $(this).find('.col_content').children().children().css('color','#0C2635');
      },
      function () {
        $(this).find('.col_content').children().children().css('color','#fff');
      }
    );


    $('.item-product .background-item').hover(
        function () {
            $(this).addClass("active");
        },
        function () {
            $(this).removeClass("active");
        }
        );
	
	
    var defaul_teaser_small_bg = "";
    $('#teaser-small .background').hover(
        function () {
            var element = $(this);
            $(this).css({
                "background-image":"url(../static/image/background_teaser_small_mouseover.jpg)",
                "background-color":"#D7DBDA",
                "color":"#0C2635"
            });
            defaul_teaser_small_bg = over_teaser_small_bg = $(".visual img", element)[0].src;
            $(".visual img", element)[0].src = over_teaser_small_bg.replace(/.png/,"_mouseover.png");
        },
        function () {
            var element = $(this);
            $(this).css({
                "background-image":"url(../static/image/background_teaser_small.jpg)",
                "background-color":"#0C2635",
                "color":"#fff"
            });
            $(".visual img", element)[0].src = defaul_teaser_small_bg;
        }
        );
    
/*
    $('#submit_button').hover(
        function () {
            $(this).css({
                backgroundImage: "url(../static/image/_common/send_button_mouseover.png)",
                color: "#000"
            });
        },
        function () {
            $(this).css({
                backgroundImage: "url(../static/image/_common/send_button.png)",
                color: "#fff"
            });
        }
        );        
*/
    var circlespeed = 3000;
	
    if($('.slideshow') && $('.slideshow').length > 0 ) {
        $('.slideshow').cycle({
            fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
            speed:    circlespeed,
            timeout: 7000
        });
    }

    /* teaser info left */
    $('.teaser .teaser-products .scroll_content .item:even').hover(
        function () {
            $('.item_text',this).animate({
                left:75
            });
            $(this).css("z-index",10);
        },
        function () {
            $('.item_text',this).stop();
            $('.item_text',this).css({
                left:4
            });
            $(this).css("z-index",1);
        }
        );

    /* teaser info right */
    $('.teaser .teaser-products .scroll_content .item:odd').hover(
        function () {
            $(this).css("z-index",10);
            $('.item_text',this).animate({
                left:-66
            });
        },
        function () {
            $('.item_text',this).stop();
            $('.item_text',this).css({
                left:4
            });
            $(this).css("z-index",1);
        }
        );



    // initialize scrollable recommended products
    var emptyItemRecommendedProduct = '<div class="item" style="visibility: hidden;"></div>';
    if($('.teaser-products .scrollable') && $('.teaser-products .scrollable').length > 0 ) {

        if( (Math.round($('.teaser-products .scrollable .items .item').length % 2 == 1)) == 1 ) {
          $('.teaser-products .scrollable .items').append(emptyItemRecommendedProduct);
        }

        $(".teaser-products .scrollable").scrollable({
            vertical:true,
            size: 6
        }).mousewheel();
        if($('.teaser-products .scrollable .items .item') && $('.teaser-products .scrollable .items .item').length <=6)
            $('.teaser-products .nextPage').css({
                display:'none'
            });
    }


    // initialize scrollable category products
    var emptyItemProduct = '<div class="item-product" style="visibility: hidden;"></div>';
    if($('#big #stage .intro_small .scrollable') && $('#big #stage .intro_small .scrollable').length > 0 ) {

        if( (Math.round($('#big #stage .intro_small .scrollable .items .item-product').length % 2 == 1)) == 1 ) {
          $('#big #stage .intro_small .scrollable .items').append(emptyItemProduct);
        }

        $("#big #stage .intro_small .scrollable").scrollable({
            vertical:true,
            size: 6
        }).mousewheel();
        
        if($('#big #stage .intro_small .scrollable .items .item-product') && $('#big #stage .intro_small .scrollable .items .item-product').length <=6) {
          $('#big #stage .nextPage').css({
              display:'none'
          });
        }
    }
	
    // initialize scrollable form stage
    /*
    if($('#big #stage .intro_big .scrollable') && $('#big #stage .intro_big .scrollable').length > 0 ) {
        $("#big #stage .intro_big .scrollable").scrollable({
            vertical:true,
            size: 1
        }).mousewheel();
        if($('#big #stage .intro_big .scrollable .items .form') && $('#big #stage .intro_big .scrollable .items .form').length <=1)
            $('#big #stage .nextPage').css({
                display:'none'
            });
    }*/
	
    if($('.scroll-pane') && $('.scroll-pane').length > 0) {
        $(function()
        {
            $('.scroll-pane').jScrollPane({
                showArrows: true,
                arrowSize:12,
                scrollbarWidth:17
            });
        });
    }

	
    Cufon.now();
    $('.equal_height').equalHeights(true);
    $(document).pngFix();
	
	
  //function GeI(i) {return (x=document.getElementById(i))?x:null;}
  
  
  
  
  		 if($(window).scrollTop() + $(window).height() > 730){
		   $("#bottom_background").animate( { top:($(window).scrollTop() + $(window).height()- 350) + "px"}, 1, function(){
         $("#bottom_background").css("width", ($(window).scrollLeft() + $(window).width()) + "px");
       });
	   }else{
	      $("#bottom_background").animate( { top:"380px"}, 1, function(){
          $("#bottom_background").css("width", ($(window).scrollLeft() + $(window).width()) + "px");
          $("#bottom_background").css("width", ($(window).scrollLeft() + $(window).width()) + "px");
        });
	   }
		
		$(window).bind("resize scroll", function() {
		  
	   if($(window).scrollTop() + $(window).height() > 730){
		   $("#bottom_background").animate( { top:($(window).scrollTop() + $(window).height()- 350) + "px"}, 1, function(){
         $("#bottom_background").css("width", ($(window).scrollLeft() + $(window).width()) + "px");
       });
	   }else{
	      $("#bottom_background").animate( { top:"380px"}, 1, function(){
          $("#bottom_background").css("width", ($(window).scrollLeft() + $(window).width()) + "px");
        });
	   }
	   
	 });

  // Social Bookmarks
  $('#dialog-overlay, #socBookLyr').hide();
	$('#dialog-overlay, #socBookLyrLinks, #socBookLyrClose').click(function () {		
		$('#dialog-overlay, #socBookLyr').hide();		
		return false;
	});
	//$(window).resize(function () {
		//if (!$('socBookLyr').is(':hidden')) popup();		
	//});	
  urlLink = location.href;
  urlLink = unescape(urlLink);
  $("#locationStr").html();
  $("#locationStr").html(urlLink);

    //$('#socBookLyr').hide();
    //$('#socBookLink').hover( function(event) { $('#socBookLyr').show(); GeI('socBookLink').className='socBookOn'; }, function(event) { $('#socBookLyr').hide();GeI('socBookLink').className='';});
    //$('#socBookLyr').hover( function(event) { $('#socBookLyr').show(); GeI('socBookLink').className='socBookOn'; }, function(event) { $('#socBookLyr').hide(); GeI('socBookLink').className='';});
  
  
});

//Popup dialog
function popup() {
	$('#dialog-overlay').show();
	$('#socBookLyr').show();	
}
function openPage(url) {
    window.location.href=url;
}

function PopUp(URL,popupname,b,h,scrollbars) {
		var PopUpName = popupname || 'PopUp';
		var breite = b || 698;
		var hoehe = h || 512;
		var ScrollBars = scrollbars || 'auto';
		var xPos = (screen.availWidth - breite) / 2
		var yPos = (screen.availHeight - hoehe ) / 2
		var fenster = window.open(URL,PopUpName,'width='+breite+',height='+hoehe+',scrollbars='+ScrollBars+',toolbar=no,menubar=no,screenX='+xPos+',screenY='+yPos+',left='+xPos+',top='+yPos)
		fenster.focus();
}
  
/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element 
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units 
 		by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article: 
		http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
 * Usage Example: $(element).equalHeights();
  		Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
 * Version: 2.0, 08.01.2008
--------------------------------------------------------------------*/

$.fn.equalHeights = function(px) {
    $(this).each(function(){
        var currentTallest = 0;
        $(this).children().each(function(i){
            if ($(this).height() > currentTallest) {
                currentTallest = $(this).height();
            }
        });
        // for ie6, set height since min-height isn't supported
        if ($.browser.msie && $.browser.version == 6.0) {
            $(this).children().css({
                'height': currentTallest
            });
        }
        $(this).children().css({
            'min-height': currentTallest
        });
    });
    return this;
};



$(document).ready( function() {
  
  var lengthOfProductrange = $("div.wrap_products div.wrap_product").length;
  $("div.left_arrow a").hide();	
  $("div.right_arrow a").hide();
  
  $("div.wrap_products div.wrap_product").hide();
  
  var counter   = 0;
  
  if(lengthOfProductrange <= groupSize) {
  	groupSize = lengthOfProductrange;
  }
  
  var myWidth = 92; // twice the arrow width + paddings
  
  for(var i = counter; i < (counter + groupSize); i++) {
		if(categoryOverviewScaleImages == "true") {
  	  if((i == counter) || (i == counter + 2)) {
  	    $("div.wrap_product:eq(" + i + ") a img").removeClass("normalImage");
  	    $("div.wrap_product:eq(" + i + ") a img").addClass("scaledImage");
  	  }  
  	}
  }
	
  myWidth += groupSize * 140;
		  
  $("div.wrap_slider_center").width(myWidth);
	
  for(var i = counter; i < (counter + groupSize); i++) {
  	$("div.wrap_products div.wrap_product:eq(" + i + ")").show();  	
  }
  
  if(lengthOfProductrange <= groupSize) {
    $("div.left_arrow a").hide();	
    $("div.right_arrow a").hide();	
  } else {
    $("div.right_arrow a").show();
  }  
  
  
  
  
  
  $("div.left_arrow a").click(
    function(e) {
      e.preventDefault();
      counter--;
      if((counter + groupSize) >= 0) {
        $("div.wrap_products div.wrap_product").hide();
        $("div.wrap_product:eq(" + i + ") a img").removeClass("scaledImage");
        $("div.wrap_product:eq(" + i + ") a img").addClass("normalImage");
        for(var i = counter; i < (counter + groupSize); i++) {
  	      $("div.wrap_products div.wrap_product:eq(" + i + ")").show();
  	      
  	      if((i == counter && categoryOverviewScaleImages == "true") || (i == counter + 2 && categoryOverviewScaleImages == "true")) {
  	      	$("div.wrap_product:eq(" + i + ") a img").removeClass("normalImage");
  	      	$("div.wrap_product:eq(" + i + ") a img").addClass("scaledImage");
  	      } else {
  	      	$("div.wrap_product:eq(" + i + ") a img").removeClass("scaledImage");
  	      	$("div.wrap_product:eq(" + i + ") a img").addClass("normalImage");
  	      }
        }
        if(counter == 0) {
          $("div.left_arrow a").hide();
        } else {
      	  $("div.left_arrow a").show();
        }
        $("div.right_arrow a").show();
        
      }	
    }
  
  );
  
  
  
  
  $("div.right_arrow a").click(
    function(e) {
      e.preventDefault();
      counter++;
      if((counter + groupSize) <= lengthOfProductrange) {
        $("div.wrap_products div.wrap_product").hide();
        $("div.wrap_product:eq(" + i + ") a img").removeClass("scaledImage");
        $("div.wrap_product:eq(" + i + ") a img").addClass("normalImage");
        
        for(var i = counter; i < (counter + groupSize); i++) {
  	      $("div.wrap_products div.wrap_product:eq(" + i + ")").show();
  	      
  	      if((i == counter && categoryOverviewScaleImages == "true") || (i == counter + 2 && categoryOverviewScaleImages == "true")) {
  	      	$("div.wrap_product:eq(" + i + ") a img").removeClass("normalImage");
  	      	$("div.wrap_product:eq(" + i + ") a img").addClass("scaledImage");
  	      } else {
  	        $("div.wrap_product:eq(" + i + ") a img").removeClass("scaledImage");
  	      	$("div.wrap_product:eq(" + i + ") a img").addClass("normalImage");	
  	      }
  	      
        }
        $("div.left_arrow a").show();
        if((counter + groupSize) >= lengthOfProductrange) {
          $("div.right_arrow a").hide();
        } else {
      	  $("div.right_arrow a").show();
        }
      }	
    }
  );
});


// Tooltip
$(function() {
	$('.wrap_product img').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		//showBody: " - ",
		fade: 250,
		top: 10,
		left: 10
	});
});

// Tooltip IE6
$(function() {
	$('.wrap_product span').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		//showBody: " - ",
		fade: 250,
		top: 10,
		left: 10
	});
});
