function menuGo(n){
	switch(n)
		{
		case 1:
		  	window.location=document.getElementById("subnavigationSel").value;
			break;
		case 2:
		  	window.location=document.getElementById("subnavigationSel2").value;
			break;
		case 3:
		  	window.location=document.getElementById("subnavigationSel3").value;
			break;
		}
}
function wwidth(){
	if($(window).width()<990){
		$('.productTableSm table.productTable').show();
		if($(window).width()<727){
			$('body').removeClass('wsmall'); $('body').addClass('wiphone');
			$('#FlashID, #content>div>embed').parent('div').hide();
			} else {
				$('body').addClass('wsmall'); $('body').removeClass('wiphone');
				$('#FlashID, #content>div>embed').parent('div').hide();
			}
		} else { $('body').removeClass('wsmall'); $('body').removeClass('wiphone'); $('#FlashID, #content>div>embed').parents('div').show(); $('.productTableSm table.productTable').hide(); }
	$('#productListHeader').each(function(){
		if($(this).width()-$(this).find('#productListNumberOfProducts').width()-$(this).find('#productListProductsPerPage').width()<$(this).find('.productListPages').width()){ $(this).find('.productListPages').css('margin-top',20); } else { $(this).find('.productListPages').css('margin-top',0); }
	});
}

$(function(){
	$('.logo').parents('a').addClass('alogo');
	$('#watchListText').each(function(){
		var text = $(this).text();
		text = text.substring(0,text.indexOf(' '));
		$('h1 a#blockTitleWatchList').append('<span id="watchListText2">('+text+')</span>');
	});
	$('#watchListText2').hide();
	$('.watchList,.order').each(function(){$(this).html('<span class="i">'+$(this).html()+'</span>')});
	
	$('#subnavigation').each(function(){
		$(this).before('<select id="subnavigationSel" onchange="menuGo(1)"></select>');
	});
	var subNavDeep = 1;
	$('#subnavigation>li').each(function(){
		var basehr = '';
		if($(this).children('a').attr('href').match(/^[\/|i]/)){ basehr=$('base').attr('href')+'/'; } else { basehr = ''; };
		$('#subnavigationSel').append('<option value="'+basehr+$(this).children('a').attr('href')+'">'+$(this).children('a').text()+'</option>');
		$(this).children('ul').each(function(){ subNavDeep = 2; $('#subnavigationSel option:last-child').attr('selected','selected'); $('#subnavigationSel').after('<select id="subnavigationSel2" onchange="menuGo(2)"></select>'); }).children('li').each(function(){
			if($(this).children('a').attr('href').match(/^[\/|i]/)){ basehr=$('base').attr('href')+'/'; } else { basehr = ''; };
			$('#subnavigationSel2').append('<option value="'+basehr+$(this).children('a').attr('href')+'">'+$(this).children('a').text()+'</option>');
			$(this).children('ul').each(function(){ subNavDeep = 3; $('#subnavigationSel2 option:last-child').attr('selected','selected'); $('#subnavigationSel2').after('<select id="subnavigationSel3" onchange="menuGo(3)"></select>'); }).children('li').each(function(){
				if($(this).children('a').attr('href').match(/^[\/|i]/)){ basehr=$('base').attr('href')+'/'; } else { basehr = ''; };
				$('#subnavigationSel3').append('<option value="'+basehr+$(this).children('a').attr('href')+'">'+$(this).children('a').text()+'</option>');
			});
		});
	});
	switch(subNavDeep)
		{
		case 1:
		  selAct = '#subnavigationSel'; break;
		case 2:
		  selAct = '#subnavigationSel2'; break;
		case 3:
		  selAct = '#subnavigationSel3'; break;
		}
	$(selAct).each(function(){
			var slctd = false;
			var hrefVar = window.location.href.match(/[?](.)*$/)[0];
			$(this).find('option').each(function(){
				var optVal = $(this).val().match(/[?](.)*$/)[0];
				if(optVal==hrefVar){ $(this).attr('selected','selected'); slctd = true; };
			});
			if(slctd == false) { $(this).prepend('<option selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- NAVIGATION --</option>');  }
		});
		if(subNavDeep==2){
			if($('#subnavigation>li>ul>li>.subnavigationActive').size()) { } else {
				if($('#subnavigationSel2 option').contents('NAVIGATION')) {} else {$('#subnavigationSel2').prepend('<option selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- NAVIGATION --</option>');}
				}
		}
		if(subNavDeep==3){
			if($('#subnavigation>li>ul>li>ul>li>.subnavigationActive').html()) {} else {
				
				if($('#subnavigationSel3 option').contents('NAVIGATION')) {} else {$('#subnavigationSel3').prepend('<option selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- NAVIGATION --</option>');}
				}
		}
	$('#subnavigationSel,#subnavigationSel2,#subnavigationSel3').hide();
	
	$('table.productTable').each(function(){
		$(this).after('<div class="productTableSm">');
		$(this).clone().appendTo($(this).next('.productTableSm'));
		$(this).find('input:text').bind('change keyup',function(){
			var inpName = $(this).attr('name');
			var inpVal = $(this).val();
			$('table.productTable').find('input[name='+inpName+']').val(inpVal);
		});
	});
	
	$('.productTableSm table.productTable').each(function(){
		$(this).find('thead tr').each(function(){
			$(this).children('th:gt(1)').hide();
			$(this).children('th:gt(7)').show();
		});
		$(this).find('tbody tr').each(function(){
			$(this).children('td:gt(1)').hide();
			$(this).children('td:gt(7)').show();
		});
	});
	$('.productTableSm table.productTable').hide();
	
	$('.nrOfProducts').each(function(){
		$(this).after('<span class="nrOfProducts2">('+$(this).text().match(/([0-9]+)[\s]/)[1]+')</span>');
	});
	$('.nrOfProducts2').hide();
	
	
	$('div#productDetailHeader').each(function(){
		$('a.pagingLeft').each(function(){
			if($('a.backLink').attr('href').match(/clang=0/)){ $(this).append('<em>Voriges</em>'); }
			if($('a.backLink').attr('href').match(/clang=1/)){ $(this).append('<em>Precedente</em>'); }
			if($('a.backLink').attr('href').match(/clang=2/)){ $(this).append('<em>Précédente</em>'); }
		});
		$('a.pagingRight').each(function(){
			if($('a.backLink').attr('href').match(/clang=0/)){ $(this).append('<em>Nächstes</em>'); }
			if($('a.backLink').attr('href').match(/clang=1/)){ $(this).append('<em>Prossimo</em>'); }
			if($('a.backLink').attr('href').match(/clang=2/)){ $(this).append('<em>Suivant</em>'); }
		});
	});
	$('div#productDetailHeader a.pagingLeft em, div#productDetailHeader a.pagingRight em').hide();
	
	$(window).bind('load resize', function(){
		wwidth();
	})
});
