function in_array(item,arr) {
for(p=0;p<arr.length;p++) if (item == arr[p]) return true;
return false;
}
function wrand(n) {
  return (Math.floor(Math.random()*n+1));
}
function countdown() {
	
	var start_date = new Date();
	var mytime = new Date();
	if(start_date.getHours()<12){ hour = 12; day = start_date.getDate(); } else {
		if(start_date.getHours()>12 && start_date.getHours()<17){ hour = 17; day = start_date.getDate(); } else {
			hour = 12; 
			day = start_date.getDate()+1;
		}
	}
	var nowork = ['01-01','22-04','25-04','01-05','02-06','13-06','03-10','25-12','26-12'];
	var end_date = new Date(start_date.getFullYear(),start_date.getMonth(),day,hour,0,0);
	if(start_date<end_date) {
		var years = 0, month = 0, days = 0, hours = 0, minutes = 0, seconds = 0;
		hours = Math.floor((end_date-start_date)/(60*60*1000));
		start_date.setTime(start_date.getTime()+hours*60*60*1000);
		minutes = Math.floor((end_date-start_date)/(60*1000));
		start_date.setTime(start_date.getTime()+minutes*60*1000);
		seconds = Math.floor((end_date-start_date)/1000);
		if(in_array(mytime.getDate()+'-'+mytime.getMonth(),nowork)){
			hours = hours + 24;
		}
		if(start_date.getDay() == 0){
			hours = hours + 24;
		}
		if(start_date.getDay() == 6){
			hours = hours + 48;
		}
		
	}
	$('#cdn_hour').html(hours);
	$('#cdn_min').html(minutes);
	$('#cdn_sec').html(seconds);
	setTimeout('countdown()',200);
}
$.fn.NewWin = function(w,h, src){
	$('.xwin_wrapper').remove();
	var rand = wrand(12);
	$('body').append('<div class="xwin_wrapper" id="'+rand+'"><div class="xwin"></div></div>');
	if(w) { $('#'+rand+' .xwin').css('width',w+'px') }
	if(h) { $('#'+rand+' .xwin').css('height',h+'px') }
	$('#'+rand+' .xwin').append('<a href="#" onclick="$(this).parent().parent().remove();" class="xwin_close">Schließen</a>');
	if(src){ $('#'+rand+' .xwin').append($(src).html()); }
	$('#'+rand).css('margin-left','-'+(parseInt($('#'+rand).width())/2)+'px');
}

$.fn.go4Producer = function() {
	if($(this).val() != 'none') {
		window.location = 'http://www.nvood.de/index.php?c1=&c2=&c3=&c4=&c5=&ActionCall=WebActionArticleSearch&Params[SearchInDescription]=0&Params[Producer]='+$('#sel_prod option:selected').text();
	}
	
}

$.fn.open_basket = function() {
	$.ajax({ url: '/index.php', type: 'post', data: $('.article_order_form').serialize(), success: function() {
			$('.mbasket_bg').show();
			$('.mbasket_top').fadeIn(200);
			$('.mbasket_con').show().animate({ height: '+=225' }, 400, function() {
			    $('.mbasket_content').fadeIn(500);
			});
		}
	});
	return false;
}





$(document).ready(function(){

	
	$('.article_order_form').submit(function(){
		if($('.t2384').length){
			$.ajax({ url: '/index.php', type: 'post', data: $('.article_order_form').serialize(), success: function() {
				var add_price = $('#fnl34j2fb').html().replace(' €','').replace( /,/,"." );
				var old_price = $('#mbas_amount').html().replace( /,/,"." );
				var new_price = parseFloat(add_price) + parseFloat(old_price);
				new_price = new_price * 100;
				new_price = Math.round(new_price);
				new_price = new_price / 100;
				$('#mbas_amount').html(new_price);
				var qty = parseInt($('#mbas_qty').html())+1;
				$('#mbas_qty').html(qty);
				$('.mbasket_bg').show();
				$('.mbasket_top').fadeIn(200);
				$('.mbasket_con').show().animate({ height: '+=225' }, 400, function() {
				    $('.mbasket_content').fadeIn(500);
				});
			}
			});
			return false;
		}
	});
	
	$('a').live("click", function(){
		if($(this).attr('href').substr(1)!='#'){
			$('.loader_31').show();
		}
		
	});
	
	if($('.t2384').length) {
		$('.basket_glow').fadeIn(700).fadeOut(700);
	} 

	if($('.image_nav').length) {
		
		$('.images_nav_items').click(function(){
			$('.main_image a').fadeOut(200);
			var title = '';
			$('.main_image a').attr('href',title);
			$('.main_image_img').attr('src',title);
			var title = $(this).attr('title');
			$('.main_image a').attr('href',title);
			$('.main_image_img').attr('src',title);
			$('.main_image a').fadeIn(200);
			return false;
		});
		
		$('.image_nav_layer').scrollable({vertical: true, size: 3});
		
		
        setTimeout('countdown()',200);
	
	}
	
	$('a')
	
	
	
	
	
	
});
