/* Uppercase */
function uppercase(str) {
	return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
        return $1.toUpperCase();
    });
}

function isiPad(){
    return (navigator.platform.indexOf("iPad") != -1);
}

/* Newsletter-Dropdown */
$('.sdropdown').on(
	'change',
	'select',
	function() {
		$(this).prev().text(uppercase($(this).val()));
	}
);
/* Returns selected option text instead of val - t.oppelt AT superreal.de*/
$('.sroptiontext').on(
	'change',
	'select',
	function() {
		$(this).prev().text($(':selected',this).text());
	}
);

/* Header-Navi */
$('.header > ul > li').on(
	{
		mouseenter: function(){
			$('li > a', '.header').not($(this).children('a')).addClass('dark');
		},
		mouseleave: function(){
			$('li > a', '.header').removeClass('dark');
		}
	}
);

if ( !isiPad() ) {
	$("#mycarousel").hover(
	  function () {
	    $('#overlay').not($(this).children('a')).fadeIn(150);
	    $(this).addClass('visible');
	  },
	  function () {
	    $('.fix, #special').css('z-index', 201);
	    $('#overlay').not($(this).children('a')).fadeOut(
	    	150,
	    	function() {
	    		$("#mycarousel").removeClass('visible');
	    		$('.fix, #special').css('z-index', 0);
	    	}
	    );

	  }
	);
}

/* Fancybox */
$(document).ready(function() {
	$(".fancybox-button").fancybox({
		prevEffect		: 'fade',
		nextEffect		: 'fade',
		closeBtn		: true,
		helpers		: {
			title	: { type : 'inside' },
			buttons	: {}
		},
		afterShow: function () {
			var count = this.href.match(/(\d+).jpg/g);
			count = parseInt(count[0].replace('.jpg', ''));
			
			$('<iframe class="facebook" src="http://www.facebook.com/plugins/like.php?locale=en_US&amp;app_id=123198731128524&amp;href&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21&amp;href=' + encodeURIComponent(location.href.split("?")[0] + '?img=' + this.href + '&imgid=' + count) + '" scrolling="no" frameborder="0" allowTransparency="true"></iframe>').appendTo($('.fancybox-outer'));
		}
	});

	/* Like */
	if ( $('#mycarousel') ) {
		/* Aufruf von Facebook */
		if ( location.search ) {
			var count = location.search.match(/imgid=(\d*)$/g);
			
			if ( !count || !count[0] ) {
				return;
			}
			
			count = count[0].replace('imgid=', '');
			
			var	obj = $($('#mycarousel').children('li').get(count - 1));

			if ( obj.length ) {
				obj.children('a').click();
			}
		}

		/*
		$('li', '#mycarousel').each(
			function(index) {
		    	$('<iframe src="http://www.facebook.com/plugins/like.php?locale=en_US&amp;app_id=201377993239347&amp;href&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21&amp;href=' + encodeURIComponent(location.href.replace('#', '?')) + '" scrolling="no" frameborder="0" allowTransparency="true"></iframe>').appendTo($(this)).delay(500).fadeIn();
			}
		);
		*/
	}


});

/* Fancybox Startseite */
$(document).ready(function() {
	$(".various").fancybox({
		maxWidth	: 640,
		maxHeight	: 360,
		fitToView	: false,
		width		: '70%',
		height		: '70%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none'
	});
});


/* Lookbook */
$('#mycarousel').jcarousel({
	wrap: 'circular'
});

/* Startseite */
 $(document).ready(function() {
 	var currrent_index = 2;

 	/* Resize Slider */
 	function resize_bxslider(index) {
 		currrent_index = parseInt(index) || currrent_index;

 		$('#mslider').css(
 			'left',
 			'-' + parseInt( ( $('li:first', '#mslider').width() * currrent_index ) - ( $(window).width() - $('li:first', '#mslider').width() ) / 2 ) + 'px'
 		);
 	}


     $('#mslider').bxSlider(
     	{
     		auto: true,
     		prevText: '',
     		nextText: '',
     		displaySlideQty: 3,
     		onAfterSlide: function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) {
     			$('#mslider').children('li').removeClass('act');
     			currentSlideHtmlObject.next().addClass('act');
     			resize_bxslider(currentSlideNumber + 2);
     		}
     	}
     );




 	$(window).resize(resize_bxslider);
 });

/* fancy box fpr blog images */

$(document).ready(function() {
    $(".blog-image").fancybox({
          helpers: {
              title : {
                  type : 'float'
              }
          }
      });
});
