$(document).ready(function() {
	
	$('#searchterm').focus(function() {
		$('#search').css('background-image', 'url(images/search_hl.jpg)');
	});

	$('#searchterm').blur(function() {
		$('#search').css('background-image', 'url(images/search.jpg)');
	});
	
	var addHeight = 22;
	
	if(jQuery.browser.msie && jQuery.browser.version == '7.0') {
		addHeight = 25;
	}
  
  
  $('#sidebar, #sidebar .container, #sidebar .opener, #sidebar .content').height(350 + addHeight + $('#productText').height());

	
	$('#sidebar .content').animate({width: '1'}, 2100);

  $('#sidebar .opener .arrow').toggle(
      function() {
          $('#sidebar .content').animate({width: '200'}, 750);
          if($(this).attr('src').indexOf('_r') == -1) {
          	$(this).attr('src', $(this).attr('src').replace(/.jpg/, '_r.jpg'));
          }
      },
      function() {
          $('#sidebar .content').animate({width: '1'}, 750);
          $(this).attr('src', $(this).attr('src').replace(/_r.jpg/, '.jpg'));
      }
  );

    $('#sidebar .content .item ul li:last').css('border', 'none');
    
   //$('#bandsaege ul li ul > li:last').css('border', 'none');
    //$('#besaeum ul li ul > li:last').css('border', 'none');
    //$('#kreissaege-profilier ul li ul > li:last').css('border', 'none');
    //$('#gatter ul li ul > li:last').css('border', 'none');
    
    $('#nav').droppy({speed: 400});

	$('#nav > li:not(".active")').mouseenter(function() {
		
		var img = $('img', this);
				
		if($(img).attr('src').indexOf('_hl.gif') == -1) {
			$(img).attr('src', $(img).attr('src').replace(/.gif/g, '_hl.gif'));
		}
	});
	
	$('#nav > li:not(".active")').mouseleave(function() {
		var img = $('img', this);
		
		if($(img).attr('src').indexOf('_hl.gif') > 0) {
			$(img).attr('src', $(img).attr('src').replace(/_hl.gif/g, '.gif'));
		}
	});
        
//    $('#nav li:not(".active") a img, #subnav li:not(".active") a img').hover(
//        function() {
//            if($(this).attr('src').indexOf('_hl.gif') == -1) {
//                $(this).attr('src', $(this).attr('src').replace(/.gif/g, '_hl.gif'));
//            } 
//        },
//
//        function() {
//            if($(this).attr('src').indexOf('_hl.gif') > 0) {
//                $(this).attr('src', $(this).attr('src').replace(/_hl.gif/g, '.gif'));
//            }
//        }
//    );

 $('#news .item:even').addClass('grey');
  $('#productlist .row:even').addClass('grey');  
 
	$('#productlist .row .product .pic').mouseover(function(){
    if($(this).parent('.product').children('.teaser').html().length > 0) {
    	$(this).parent('.product').children('.teaser').fadeIn("slow");
    }
  }).mouseout(function(){
		if($('#productlist .row .product .teaser').html().length > 0) {
			$('#productlist .row .product .teaser').fadeOut("slow");
		}
  });

  	//Weltkarte
	
	$('#contactMap area').hover(
		function() {
			var id = $(this).attr('class');
			$('#welt .hover').css('background', 'url(images/worldmap/ww_' + id + '.gif) no-repeat left top');
		},
		function() {
			$('#welt .hover').css('background', 'url(images/worldmap/map.gif) no-repeat left top');
		}
	);
 
	$('#contactMap.europe area').hover(
		function() {
			var id = $(this).attr('class');
			$('#welt .hover').css('background', 'url(images/euromap/eu_' + id + '.gif) no-repeat left top');
		},
		function() {
			$('#welt .hover').css('background', 'url(images/euromap/map.gif) no-repeat left top');
		}
	);
  
	$('#contactMap area').click(function() {
		var id = $(this).attr('class');
		if(id == 'europa') {
			return true;
		} else {
			$('#welt .click').css('background', 'url(images/worldmap/ww_' + id + '.gif) no-repeat left top');
			$('#welt .data .country').hide();
			$('#' + id).show();
			
			return false;
		}
	});

	$('#contactMap.europe area').click(function() {
		var id = $(this).attr('class');
		
		$('#welt .click').css('background', 'url(images/euromap/eu_' + id + '.gif) no-repeat left top');
		$('#welt .data .country').hide();
		$('#' + id).show();
	});
	
	
	
	
	//Eurpopakarte


	$('#contactMap area').hover(
		function() {
			var id = $(this).attr('class');
			$('#europe .hover').css('background', 'url(images/worldmap/ww_' + id + '.gif) no-repeat left top');
		},
		function() {
			$('#europe .hover').css('background', 'url(images/worldmap/map.gif) no-repeat left top');
		}
	);
 
	$('#contactMap.europe area').hover(
		function() {
			var id = $(this).attr('class');
			$('#europe .hover').css('background', 'url(images/euromap/eu_' + id + '.gif) no-repeat left top');
		},
		function() {
			$('#europe .hover').css('background', 'url(images/euromap/map.gif) no-repeat left top');
		}
	);
  
	$('#contactMap area').click(function() {
		var id = $(this).attr('class');
		if(id == 'europa') {
			return true;
		} else {
			$('#europe .click').css('background', 'url(images/worldmap/ww_' + id + '.gif) no-repeat left top');
			$('#europe .data .country').hide();
			$('#' + id).show();
			
			return false;
		}
	});

	$('#contactMap.europe area').click(function() {
		var id = $(this).attr('class');
		
		$('#europe .click').css('background', 'url(images/euromap/eu_' + id + '.gif) no-repeat left top');
		$('#europe .data .country').hide();
		$('#' + id).show();
	});	
	
	
	
	
	
  	
});

function setSubNavWidth() {
  $('#nav ul.subMenu').each(function() {
        $(this).width($(this).parents('#nav li').width() + 1);
  });
  
  $('#nav ul.subMenu ul.subSubMenu').each(function() {
      $(this).css('left', ($(this).parents('ul.subMenu').width() - 0) + 'px');
      $(this).children('li:last').addClass('last');
  });	
}

function showVideo(file) {
    var playerMarginLeft = (($(document).width() - 500) / 2) + 'px';
    var playerMarginTop = (($(window).height() - 312) / 2) + 'px';

    $('#dark').width($('html').width()).height($('html').height()).css('opacity', 0.5).fadeIn('slow');
    $('#player').css({ left: playerMarginLeft, top: playerMarginTop}).attr('src', 'swf/player.php?file=' + file);
    $('#video').show();
}

function hideVideo() {    
    $('#video').hide();
    $('#player').css({ left: 0, top: 0}).attr('src', '');
    $('#dark').width(0).height(0).fadeOut('slow');
}