jQuery(function($) {
  

  var amount = 7;
  // Anzahl geladener Bilder
  var loaded = 0;
  $('#img0, #img1').load(function(){
      loaded++;
      if(loaded >= amount){
          // fertig geladen
          $('#preload-container').remove();
          setTimeout(function(){
            $('#loading img#loading-gif').fadeToggle("normal");
          }, 1500);
          setTimeout(function(){
            $('#loading p img').fadeToggle("normal");
          }, 2000);
          setTimeout(function(){
            $('#loading').remove();
            $('#loading-background').fadeToggle("normal");
          }, 2500);
          setTimeout(function(){
            $('#loading-background').remove();
          }, 2800);
          
          setTimeout(function(){
            // Text Container wird eingeblendet
            $('.text').fadeToggle("fast", function(){
              $('.text').removeClass('hidden');
            });
          }, 2900);
          setTimeout(function(){
            // Text Container wird eingeblendet
            $('.text #home-container img').fadeToggle("fast");
          }, 3100);
          setTimeout(function(){
            // Text Container wird eingeblendet
            $('.text #home-container p').fadeToggle("fast");
          }, 3300);

          // Icons einblenden
          setTimeout(function(){
            $('#twitter').fadeToggle("fast"); 
          }, 3500);
          setTimeout(function(){
            $('#googleplus').fadeToggle("fast"); 
          }, 3600);
          setTimeout(function(){
            $('#androidweekly').fadeToggle("fast"); 
          }, 3700);
          setTimeout(function(){
            $('#mail').fadeToggle("fast"); 
          }, 3800);
          setTimeout(function(){
            $('#youtube').fadeToggle("fast"); 
          }, 3900);
          setTimeout(function(){
            $('#blogger').fadeToggle("fast"); 
          }, 4000);
          setTimeout(function(){
            $('#elements').fadeToggle("fast"); 
          }, 4100);
          setTimeout(function(){
            $('#maps').fadeToggle("fast"); 
          }, 4200);

          // erster Preil wird eingeblendet
          setTimeout(function(){
            $('img#help_one').fadeToggle("normal"); 
          }, 4300);
      }
  });

  


// Parallax positions
  var winheight = $(window).height();
  var winwidth = $(window).width();

  var background_left = 500;
  var background_bottom = -270;
  var handy_left = -400;
  var handy_bottom = 150;
  var text_left = -150;
  
  if (winheight < 720) {
    background_bottom = -470;
    $('#handy .background').css('bottom','-400px');
    handy_bottom = -90;
    $('#handy .device').css('bottom','0px');
		$('#handy .lpcinfo').css('bottom','-200px');
	$('#handy .galerie').css('top','80px');
	$('#handy .text').css('bottom', '280px');
  }
  
  if (winwidth > 1450) {
    background_left = 350;
    $('#handy .background').css('left','-350px');
    handy_left = -950;
    $('#handy .device').css('left','750px');
		$('#handy .lpcinfo').css('left','550px');
	  $('#handy .galerie').css('left','650px');
    text_left = -190;
    $('#handy .text').css('left','150px');
  }


  
  $('div#header-parallax.parallax').parallax({
    'elements': [
      // Handy
      {
        // initialposition Handy Background
        'selector': 'div#header-parallax  div#handy.p-effect .background',
        'properties': {
          'x': {
            'left': {
              'initial': background_left,
              'multiplier': 0.1,
              'invert': true
            }
          },
          'y': {
            'bottom': {
              'initial': background_bottom,
              'multiplier': 0.1,
              'invert': false
            }
          }
        }
      },
      {
        // initialposition Handy Device
        'selector': 'div#header-parallax  div#handy.p-effect .device',
        'properties': {
          'x': {
            'left': {
              'initial': handy_left,
              'multiplier': 0.15,
              'invert': true
            }
          },
          'y': {
            'bottom' : {
              'initial': handy_bottom,
              'multiplier': 0.15,
              'invert': false
            }
          }
        }
      },
        {
          // initialposition Handy Text
          'selector': 'div#header-parallax  div#handy.p-effect .text',
          'properties': {
            'x': {
              'left': {
                'initial': text_left,
                'multiplier': 0.2,
                'invert': true
              }
            }
          }
        },
		 {
        // initialposition  Galerie
        'selector': 'div#header-parallax  div#handy.p-effect .galerie',
        'properties': {
          'x': {
            'left': {
              'initial': handy_left,
              'multiplier': 0.11,
              'invert': true
            }
          },
          'y': {
            'bottom' : {
              'initial': handy_bottom,
              'multiplier': 0.11,
              'invert': false
            }
          }
        }
      },
	 {
	        // initialposition LPCinfo
	        'selector': 'div#header-parallax  div#handy.p-effect .lpcinfo',
	        'properties': {
	          'x': {
	            'left': {
	              'initial': handy_left,
	              'multiplier': 0.16,
	              'invert': true
	            }
	          },
	          'y': {
	            'bottom': {
	              'initial': handy_bottom,
	              'multiplier': 0.16,
	              'invert': false
	            }
	          }
	        }
	      }
    ]
  });

  
  
  // Parallax positions
    $('div.showcase-container.parallax').parallax({
      'elements': [
        // KAMERA
        {
          // initialposition Cam Background
          'selector': 'div.showcase-container.parallax #showcase-parallax.p-effect .background',
          'properties': {
            'x': {
              'left': {
                'initial': 90,
                'multiplier': 0.1,
                'invert': true
              }
            },
            'y': {
              'bottom': {
                'initial': -99,
                'multiplier': 0.1,
                'invert': false
              }
            }
          }
        },
        {
          // initialposition Cam Device
          'selector': 'div.showcase-container.parallax #showcase-parallax.p-effect .device',
          'properties': {
            'x': {
              'left': {
                'initial': 20,
                'multiplier': 0.2,
                'invert': true
              }
            },
            'y': {
              'bottom' : {
                'initial': -160,
                'multiplier': 0.2,
                'invert': false
              }
            }
          }
        }
      ]
    });
    
    // Kamera in Kamera
    $('#showcase-parallax.p-effect .device').parallax({
      'elements': [
        {
          'selector': 'div#cam-parallax',
          'properties': {
            'x': {
              'left': {
                'initial': -40,
                'multiplier': 0.05,
                'invert': false
              }
            },
            'y': {
              'top': {
                'initial': -30,
                'multiplier': 0.05,
                'invert': false
              }
            }
          }
        }
      ]
    });
  


  
  // Email Decoder
      var m = $.base64.decode('bWFpbHRvOm1hcnRpbi5n123lckA5ZWxlbWVudHMuY29t');
  // Email Parser
    $('a.email').each(function() {
       this.href = m;
    });
});


