

//auto-generated 'shop' JS



var SHOP_redirect_search = false;


$(document).ready(function() {

	
	
	$('a.jArticleNotification').click(function() {
		//alert('demo');
	});
	
	
	
	$('div.articlepic').bind('mouseenter mouseleave', function() {
		$(this).find('div.number').toggle();
	});
	
	
	
	$('form#form_c2c').live('submit', function() {
		$('div.generalbox').hide();
		$.post('/en/shop/c2c/', $(this).serialize(), function(data) {
			$('div.jC2cMsg_'+data['stat']+'_'+data['msg']).show();
			if (data['stat']=='ok') {
				$('form#form_c2c').find('input[name=recipient_email]').val('');
				$('form#form_c2c').find('input[name=recipient_name]').val('');
			}
		},'json');
		return false;
	});
	
	
	
	$('form#form_notification').submit(function() {
		$('div.generalbox').hide();
		$.post('/en/shop/notification/', $(this).serialize(), function(data) {
			$('div.jMsgNotify_'+data['stat']+'_'+data['msg']).show();
			if (data['stat']=='ok') {
				document.forms['form_notification'].reset();
			}
		},'json');
	});
	
	
	
	$('form#form_salenotification').submit(function() {
		$('div.generalbox').hide();
		$.post('/en/shop/salenotification/', $(this).serialize(), function(data) {
			$('div.jMsgNotify_'+data['stat']+'_'+data['msg']).show();
			if (data['stat']=='ok') {
				document.forms['form_salenotification'].reset();
			}
		},'json');
	});
	
	
	
	$('form#form_article_selector').submit(function() {
		
		var page = $(this).find('input[name=page]').val();
		var perpage = $(this).find('input[name=perpage]').val();
		var brand = $(this).find('select[name=brand]').val();
		var range = $(this).find('select[name=range]').val();
		var gender = $(this).find('select[name=gender]').val();
		
		var instock = ($(this).find('input[name=instock]').is(':checked')) ? 1 : 0;
		var preorder = ($(this).find('input[name=preorder]').is(':checked')) ? 1 : 0;
		var reduced = ($(this).find('input[name=reduced]').is(':checked')) ? 1 : 0;
		var query = $(this).find('input[name=query]').val();
		
		var urlextra = (instock==1 || preorder==1 || reduced==1 || query!='') ? ','+instock+','+preorder+','+reduced+','+encodeURI(query) : '';
		var url = '/en/shop/browse/'+page+','+perpage+','+brand+','+range+','+gender+urlextra+'/';
		
		window.location.href = url;
		
	});

	
	
	$('img.articlevotelayer').click(function() {
		
		$.ajax({
			url: '/en/shop/vote/',
			data: 'id='+$(this).attr('rel'),
			type: 'POST',
			dataType: 'html',
			success: function(data) {
				noticebox(data, true);
			}
		});
		
	});
	
		
	
	$('li.jShowShopSelect').bind('mouseenter', function() {
		$(this).find('ul').show();
	});
	
	$('li.jShowShopSelectPosition').bind('mouseenter', function() {
		var position = $(this).position();
		$(this).find('ul').css({'left':position.left-14}).show();
	});
	
	$('li.jShowShopSelect').bind('mouseleave', function() {
		$(this).find('ul').hide();
	});
	
	$('li.jShowShopSelectPosition').bind('mouseleave', function() {
		$(this).find('ul').hide();
	});


	
	$('.jC2c').click(function() {
	
		$.ajax({
			url: '/en/shop/c2c/',
			data: 'article='+$(this).attr('rel'),
			type: 'POST',
			dataType: 'HTML',
			success: function(data) {
				noticebox(data, true);
				setTimeout("FB.XFBML.parse();", 400);
			}
		});
		
	});
	
	
	
	$('.jDetailsearch').click(function() {
		$('div.jDetailSearchForm').slideToggle(function() {
			$('select.sb, select.sbsmall, select.sbmini, select.sbwide').selectBox();
		});
	});
		
	
	
	$('form#form_article_vote').live('submit', function() {
		
		$.ajax({
			url: $(this).attr('action'),
			data: $(this).serialize(),
			type: 'POST',
			dataType: 'html',
			success: function(data) {
				noticebox_content(data);
			}
		});
		
		return false;
		
	});
	
	
	
	$('form#form_sizedropdown').find('select[name=size]').change(function() {
	
		var data = $(this).find('option:selected').attr('data').split('|'); 
		
		if (data[1]!='0.00') {
			$('span.jArticleOldpriceHolder').show();
		} else {
			$('span.jArticleOldpriceHolder').hide();
		}
		
		$('div.jArticleStatus').hide();
		$('div.jArticleStatus_'+data[2]).show();
		
		if (data[2]=='instock') {
			$('a.jAddToCart').show();
			$('a.jAddToNotification').hide();
		} else {
			$('a.jAddToCart').hide();
			$('a.jAddToNotification').show();
		}
		
		$('span.jSelectedArticlePrice').text(data[0]);
		$('span.jSelectedArticleOldprice').text(data[1]);
		
	});
	
		
	
	$('form#form_sizedropdown').find('select[name=size]').trigger('change');
	
	
	
	$('a.jAddToCart').click(function() {
		var form = $('form#form_sizedropdown');
		SHOP_add2cart(form.find('input[name=article]').val(), form.find('option:selected').val());
	});
	
	$('a.jAddToNotification').click(function() {
		var form = $('form#form_sizedropdown');
		var data = form.find('option:selected').attr('data').split('|');
		SHOP_notification(form.find('input[name=article]').val(), form.find('option:selected').val(), data[3]);
	});
	
	
	
});



function SHOP_add2cart(article, step) {
	
	$('div#cart_content').html('<div class="center"><img src="/img/bb/loader_cart.gif" alt="loader" /></div>');
	
	$.post('/en/cart/add/', {article:article, step:step}, function(data) {
		if (data['stat']=='ok') {
			$.scrollTo('img#logo', '500', {onAfter:function() {

				$('div.teaserholder_cartadded').css({'opacity':'0'}).show()
					.animate({'top':'+=20px', 'opacity':'100'}, 750, 'swing')
					.animate({'top':'-=20px'}, 750, 'swing')
					.animate({'top':'+=20px'}, 750, 'swing')
					.animate({'top':'-=20px'}, 750, 'swing')
					.animate({'top':'+=20px'}, 750, 'swing')
					.animate({'top':'-=20px', 'opacity':'0'}, 750, 'swing');
				
			}});
		}
		CART_load();	
	},'json');
}

function SHOP_loadtwitter() {
	$.ajax({
		url: '/en/shop/twitter/',
		type: 'GET',
		dataType: 'HTML',
		success: function(data) {
			$('span#footer_twitter').html(data);
		}
	});
}

function SHOP_notification(article, step, size) {
	$('div.generalbox').hide();
	$('div.jArticleSaleNotification').hide();
	$('span.jArticleNotificationSize').html(size);
	$('form#form_notification').find('input[name=article]').val(article);
	$('form#form_notification').find('input[name=step]').val(step);
	$('div.jArticleNotification').show();
	$.scrollTo('div.jArticleNotification', 500);
}

function SHOP_sale(article, step, size) {
	$('div.generalbox').hide();
	$('div.jArticleNotification').hide();
	$('span.jArticleSaleNotificationSize').html(size);
	$('form#form_salenotification').find('input[name=article]').val(article);
	$('form#form_salenotification').find('input[name=step]').val(step);
	$('div.jArticleSaleNotification').show();
	$.scrollTo('div.jArticleSaleNotification', 500);
}

function SHOP_preload_navigation(brand, range, gender) {
	if (brand!='') $('li.jDropdownselectBrand').find('a.jNavigationHeadline').text( $('li#selectBrand'+brand).text() );
	if (range!='') $('li.jDropdownselectRange').find('a.jNavigationHeadline').text( $('li#selectRange'+range).text() );
	if (gender!='') $('li.jDropdownselectGender').find('a.jNavigationHeadline').text( $('li#selectGender'+gender).text() );
	$('li#selectBrand'+brand).addClass('selected');
	$('li#selectRange'+range).addClass('selected');
	$('li#selectGender'+gender).addClass('selected');
}



