// remap jQuery to $
jQuery(function($){
  $.fn.superbgimage.options = {
    id: 'superbgimage', // id for the containter
    z_index: 0, // z-index for the container
    inlineMode: 0, // 0-resize to browser size, 1-do not resize to browser-s
    showimage: 1, // number of first image to display
    vertical_center: 0, // 0-align top, 1-center vertical 31     
    transition: 1, // 0-none, 1-fade, 2-slide down, 3-slide left, 4-slide to
    transitionout: 1, // 0-no transition for previous image, 1-transition fo
    randomtransition: 0, // 0-none, 1-use random transition (0-7)
    showtitle: 0, // 0-none, 1-show title 35     slideshow: 0, // 0-none, 1-autostart slideshow 36     slide_interval: 5000, // interval for the slideshow
    randomimage: 0, // 0-none, 1-random image 38     speed: 'slow', // animation speed
    preload: 1 // 0-none, 1-preload images
  };

  if ($("body").hasClass("start")) {
  	
  	$(".main-teaser-button").delay(7000).fadeOut(500);
  	$("#claim").delay(400).fadeIn(2000).delay(5000).fadeOut(500);
  	
  	
    $.fn.superbgimage.options = {
      slideshow: 1, // 0-none, 1-autostart slideshow
      slide_interval: 7000, // interval for the slideshow
      vertical_center: 0,
      speed: 'slow' // animation speed
    };
    
      $.fancybox(
		'<iframe src="http://player.vimeo.com/video/36481133?portrait=0&amp;color=ffffff&amp;autoplay=1" width="800" height="450" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
		{
        	'autoDimensions'	: false,
			'width'         	: 800,
			'height'        	: 'auto',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'padding'			: 0,
			'overlayOpacity'	: 0.8,
			'overlayColor'		: '#000'
		}
	);
  }
  
  
  if ($("body").hasClass("come")) { 	
    $.fn.superbgimage.options = {
      slideshow: 1, // 0-none, 1-autostart slideshow
      slide_interval: 7000, // interval for the slideshow
      vertical_center: 0,
      speed: 'slow' // animation speed
    };
  }
  
  
  if ($("body").hasClass("accecoires")) {
    $.fn.superbgimage.options = {
      slideshow: 1, // 0-none, 1-autostart slideshow
      slide_interval: 7000, // interval for the slideshow
      vertical_center: 1,
      speed: 'slow', // animation speed
      inlineMode: 0, // 0-resize to browser size, 1-do not resize to browser-s
      preload: 1 // 0-none, 1-preload images
    };
  }
  
  if ($("html").hasClass("wear")) {
    $.fn.superbgimage.options = {
      slideshow: 0, // 0-none, 1-autostart slideshow
      vertical_center: 1,
      preload: 1, // 0-none, 1-preload images
      speed: 2000 // animation speed
    };
  }
  

  
  // initialize SuperBGImage
  $('#thumbs').superbgimage().hide();
  
  
	$('#memory-link').click(function() {
    	$('.activeslide').fadeTo('slow', 0.2, function() {
    		$('#collection-memory').load($('#memory-link a').attr("href"), function() {
  				$('#collection-memory').fadeIn('slow', function() {
       				 // Animation complete
     			 });


          // Collection memory
 				 $(".memory").fancybox({
					'transitionIn'	:	'elastic',
					'transitionOut'	:	'elastic',
					'speedIn'		:	600, 
					'speedOut'		:	200, 
					'overlayShow'	:	false
				});
			});
    	      		
   		});
   		return false;
  });
  

  
  // prev slide
  $('a.prev').click(function() {
    return $('#thumbs').prevSlide();
  });

  // next slide
  $('a.next').click(function() {
    return $('#thumbs').nextSlide();
  });
  
  
  
  //Brand
  $('.accordion').accordion ({
		header: 'h3',
    autoHeight: false
	});
  



  if (!Modernizr.input.placeholder){
  }
  else
  {
    $('label').css('display','none');
  }
  
  $(".cmxform").validate({
    rules: {
      anrede: "required"
    },
    messages: {
      first_name: "This field is required"

    }
  });

  $("#form").validate({
    messages: {
      lastname: "Bitte geben Sie Ihren Nachnamen ein.",
      email: {
        required: "Bitte geben Sie Ihre Emailadresse ein.",
        email: "Ihre Email muss im Format name@domain.com eingegeben werden"
      }
    }
  });

  $('#coda-slider-1').codaSlider({
    dynamicArrows: false,
    dynamicTabs: false
  });
});

if ($("body").hasClass("come")) {

  //Store locator
  populateStores();
  
  }

  $('#country').change(function() {
    $('#store-data').empty();
    $('#store-data').fadeOut(200, function() {
      populateStores();
      $('#store-data').fadeIn("slow");
    });
  });

  $('#city').change(function() {
    $('#store-data').empty();
    $('#store-data').fadeOut(200, function() {
      // Animation complete.
      populateStoreData();
      $('#store-data').fadeIn(400);
    });
  });
  

    


 //Store locator
function populateStores() {
  $.getJSON('/_/php/store_locator.inc.php', {country:$('#country').val()}, function(data) {
    var select = $('#city');
    var options = select.attr('options');
    $('option', select).remove();

    $.each(data, function(index, array) {
      options[options.length] = new Option(array['city']);

    });
    populateStoreData();
  });

}
function populateStoreData() {
  $.getJSON('/_/php/store_locator_data.inc.php', {city:$('#city').val()}, function(data) {
    var container = $('#store-data');
    $('#store-data').empty();
    $.each(data, function(index, array) {
      $('#store-data').append('<div class="store-row"><h2>' + array['shop_location'] + '</h2>' + array['street'] + '<br/>' + array['plz'] + ' ' + array['city'] + '<br/>Phone: ' + array['phone'] + '</div>');
    });
  });
}

// Adresses
if ($("body").hasClass("addresses")) {
	$('#store-data').fadeIn("slow");
	populateAddressData();
}
$('#department').change(function() {
		$('#store-data').fadeOut(200, function() {
		    populateAddressData();
		 $('#store-data').fadeIn("slow");
		 });
	});

function populateAddressData() {
  $.getJSON('/_/php/addresses_data.inc.php', {country:$('#department').val()}, function(data) {
    var container = $('#store-data');
    $('#store-data').empty();
    $.each(data, function(index, array) {
      $('#store-data').append('<div class="store-row"><h2>' + array['name_1'] + '</h2>' + array['name_2'] + '<br/>'+ array['titel'] + '<br/>'+ array['address'] + '<br/>'+ array['street'] + '<br/>' + array['plz'] + ' ' + array['city'] + '<br/>Phone: ' + array['phone'] + '<br/>Fax: ' + array['fax'] + '<br/><a href=mailto:' + array['email'] + '>' + array['email'] + '</a></div>');
    });
  });
}


