(function($) {
	//Changing article informations on variants
	if(typeof(isVariant) != 'undefined' && isVariant === true) {
		$.changeDetail(0);
	}
	$('#sAdd.variant').unbind('change').live('change', function() {
		$.changeDetail($(this).val());
	});

	//Changes the displayed informations on the
    //article detail site and changes the active
    //images which is used by variant articles
    $.changeDetail = function (ordernumber) {
    	if (typeof($.checkNotification) == 'function') {
        	if (!ordernumber){
            	$.checkNotification($.ordernumber);
        	}else {
        		$.checkNotification(ordernumber);
        	}
        }
    	try { 
			if(!ordernumber || $('#instock_'+ordernumber).val() > 0) {
				$('#article_notification').hide();
				$('#detailCartButton').show();
				$('#detailBuyInfoNotAvailable').hide();
			} else {
				$('#article_notification').show();
				if($('#detailBuyInfoNotAvailable').length) {
					$('#detailCartButton').hide();
					$('#detailBuyInfoNotAvailable').show();
				}
			}
        } catch(e) {}
        
        if (!ordernumber) {
        	// Hide Pseudoprice
        	$('.PseudoPrice').hide();
        
        	// Hide all other thumbnails
            if (isVariant) {
                var thumbs = $('.thumb_box').children('a:[id]');
                thumbs.each(function (i, el) {
                    if ($(el).attr('id') != 'thumb' + $.ordernumber) { $(el).hide(); }
                });
            }
            // Hide basket
            $('#basketButton').css('opacity', '0.4');
        } else {	
        
        	try {
				var avangate = $('#VAR'+ordernumber).attr('avangate');
			} catch (e) { 
				var avangate = "";
			}
			if(avangate) {
				$('#basketButton').bind('click', function(event) {
					var sQuantity, link;
					event.preventDefault();
					
					sQuantity = $('#sQuantity').val();

 					link = "https://secure.avangate.com/order/checkout.php?PRODS="+avangate+"&QTY="+sQuantity+"&CART=2&ORDERSTYLE=nLW0npaplH4=";
					   _gaq.push(['_link', link ]); return false;
					
				})
			}
        
        	// Show Pseudo price
        	$('#'+ordernumber).find('.PseudoPrice').show();
        	
        	// Change informations
            $('#article_details').html($('#' + ordernumber).html());
            
            //Set basket button to active
            $('#basketButton').css('opacity', '1.0');
            
            // Change main image
            $('a#zoom1 img').attr('src', $('#img' + ordernumber).find('img').attr('src'));
            
            //Wenn eine andere Variante ausgewaehlt ist
            if(ordernumber != $.ordernumber) {
            	
            	//Wenn ZoomViewer ist aktiv
            	useZoom = parseInt(useZoom);
            	if(useZoom) {
            		$('a#zoom1 img').attr('src', $('#img' + ordernumber).find('img').attr('src')).attr('title', $('#img' + ordernumber).children('a').attr('title'));
            		$('#img' + ordernumber).find('a').trigger('click');
            	} else {
            		 //Lightboxlink wechseln
                	$('a#zoom1').attr('href', $('#img' + ordernumber).children('a').attr('href'));
            	}
            	
            	//Thumbnails wechseln
            	$('#thumb' + $.ordernumber).hide();
                $('#thumb' + ordernumber).show();
                
                
                //neue Ordernumber in die globale Variable schreiben
                $.ordernumber = ordernumber;
            	try {
            		$('#variantOrdernumber').val(ordernumber);
            	}catch (err){
            		
            	}
            	// try to active liveshopping
            	try {
            		$('#article_details').liveshopping();
            	} catch(err) {}
            }
        }
    };
 
})(jQuery);

(function($) { 
$.basket.init = function () {
    	var width = 660;
    	var position = 'fixed';
    	
    	if($.browser.msie && parseInt($.browser.version) == 6) {
    		var width = width - 10;
    		var position = 'absolute';
    	}
    	
    
        var modalConfig = {
            'position': position,
            'animationSpeed': 200,
            'width': width+'px',
            'textContainer': '<div>',
            'textClass': 'ajax_add_article_container'
        };
        var sliderConfig = {
       		'headline': false,
			'navigation': false,
			'scrollSpeed': 800,
			'rotate': false,
			'width':630,
			'height': 210,
			'scrollWidth': 578,
			'containerCSS': {
				'margin': '0 0 15px 15px'
			}
        };
        
        $('a.buynow').live('click', function (event) {
            event.preventDefault();
            $.ajax({
                'dataType': 'jsonp',
                'beforeSend': function() {
                	$.loadingIndicator.open();
                },
                'url': $(this).attr('href'),
                'success': function (result) {
                	$.loadingIndicator.close();
                    $.modal(result, '', modalConfig);
                    $('#lbOverlay').css('opacity', '0').show().fadeTo('fast', '0.3');
                    
                    $('.slider_modal').ajaxSlider('locale', sliderConfig);
                    
                    $('.modal .close').hide();
                    $.basket.refreshDisplay();
                }
            })
        });
        $('.basketform').bind('submit', function (event) {
        	
            event.preventDefault();
            try {
				var avangate = $('#VAR'+ordernumber).attr('avangate');
			} catch (e) { 
				var avangate = "";
			}
			if(avangate && !isVariant) {
					var sQuantity, link;
					sQuantity = $('#sQuantity').val();
 					link = "https://secure.avangate.com/order/checkout.php?PRODS="+avangate+"&QTY="+sQuantity+"&CART=2&ORDERSTYLE=nLW0npaplH4=";
                        _gaq.push(['_link', link ]); return false;
					
			}
			
			else 
			{
				alert("Der Bestellvorgang konnte leider nicht gestartet werden.\n \n     Dies kann zwei Gründe haben.\n \n        1. Sie haben keine Variante gewählt.\n        2. Die Variante ist aktuell nicht lieferbar.\n \nSollte es Ihnen nicht möglich sein das gewünschte Produkt\nzu bestellen, wenden Sie sich bitte an unseren Vertrieb.\n \nE-Mail: sales@globell.com");
				
			}
			
        	//else {
	         //   $.ajax({
	           //      'data': $(this).serialize(),
	           //      'dataType': 'jsonp',
	           //      'url': $(this).attr('action'),
	           //      'beforeSend': function() {
	            //     	$.loadingIndicator.close();
	            //     },
	             //    'success': function(result) {
	                	
	             //    	$.loadingIndicator.close();
	                //     $.modal(result, '', modalConfig);
	                   //  $('#lbOverlay').css('opacity', '0').show().fadeTo('fast', '0.3');
	                	
	                 //	$('.slider_modal').ajaxSlider('locale', sliderConfig);
						
	                  //   $('.modal .close').hide();
	                //     $.basket.refreshDisplay();
	              //   }
	           //  });
       //  }
        });
    };
})(jQuery); 
