$( document ).ready( function (){
	
	// Logo Scroller
	$( '#scroller' ).scrollFollow({
		easing: 'easeOutQuart',
		speed: 1500,
		offset: 240
	});
	
	// Drop-Down Company search
	$( '#company' ).change(function(){
		$('#content').load('js/get.php?type=normal&id='+$('#company option:selected').attr('value'));
	});
	
	// Logo Company search
	$( '.logo_north' ).click(function() {
		$('#content').load('js/get.php?id1=22&id2=23&id3=24&type=kathari_a');
	});
	$( '.logo_south' ).click(function() {
		$('#content').load('js/get.php?id1=25&id2=23&id3=24&type=kathari_b');
	});
	
	// Impressum
	$('#impressum').click(function() {
		$('#content').text(".").load('js/get.php?type=impressum');
	});
	
	// Adds
	$('#add_north').click(function() {
		$('#content').text(".").load('js/get.php?type=add_north');
	});
	$('#add_south').click(function() {
		window.location.href = "/../img/kathari_matten.pdf";
	});
	
	// Company-Feld skalieren
	$('.company').css({height: (Number($('.content').css('height').replace('px', '')) - 50)+'px'});
	
	var cBasePath = 'http://www.kathari.com/'; // Absoluter Pfad zur Index.php
  
  // ==============================================================================
  
  $.getJSON(cBasePath+'map/get.php',{type: 'getCoords'},
   function(json){
      $.each(json, function(index,item) {
        switch(item.tAlign) {
          case 'right':
            $('.cMap').append('<div id="'+item.group_id+'" class="cMapItem" title="cNewItem"><div class="cMapItemPoint_i"><div class="cMapItemPoint_a"></div></div><div class="cMapItemCity">'+item.city+'</div></div>');
            break;
          case 'left':
            $('.cMap').append('<div id="'+item.group_id+'" class="cMapItem" title="cNewItem"><div class="cMapItemCity">'+item.city+'</div><div class="cMapItemPoint_i"><div class="cMapItemPoint_a"></div></div></div>');
            break;
          default:
            $('.cMap').append('<div id="'+item.group_id+'" class="cMapItem" title="cNewItem"><div class="cMapItemPoint_i"><div class="cMapItemPoint_a"></div></div><div class="cMapItemCity">'+item.city+'</div></div>');
            break;
        }
        // Hauptfilialen hervorheben
        if(item.main_city == 1) {
          $('div[title=cNewItem]').children('.cMapItemCity').addClass('bold');
        }
        
        // Points verstecken
        $('div[title=cNewItem]').children('.cMapItemPoint_i').children().hide();
        
        $('div[title=cNewItem]').css({left:item.mapx+'px', top:item.mapy+'px'});
        // Mouseevent click
        $('div[title=cNewItem]').click(function() {
          $('#content').load('js/get.php?type=normal&id='+item.place_id);
          $('#company').children().each(function () {
            if($(this).val() == item.place_id) {
              $(this).attr('selected', true);
            }else{
              $(this).attr('selected', false);
            }
          });
        });
        
        // Mouseevent over
        $('div[title=cNewItem]').mouseenter(function() {
            $('.cMapItem').children('.cMapItemCity').css({color:'#c6c6c6'},100);
            $('.cMapItem').children('.cMapItemPoint_i').children().hide();
            $(this).children('.cMapItemCity').css({color:'#404040'},1000);
            $(this).children('.cMapItemPoint_i').children().show();
        });
        // Mouseevent out
        $('div[title=cNewItem]').mouseleave(function() {
            $(this).children('.cMapItemCity').css({color:'#c6c6c6'},1000);
            $(this).children('.cMapItemPoint_i').children().hide();
        });
        
        $('div[title=cNewItem]').attr('title', '');
      });
  });
	
});
