/*jQuery(document).ready(function($) {
	$('div#basket_area, .ajax_basket_result').live("mouseover mouseout", function(event) {
		if ( event.type == "mouseover" ) {
			basketin();
		} else {
			basketout();
		}
	})
});


function basketout(){
	basketTimeout = setTimeout(function(){
		$('.ajax_basket_result').removeClass('active').slideToggle('fast');
	},500);
}

function basketin() {
	try{
		clearTimeout(basketTimeout);
	} catch(e){}
	
	if(!$('.ajax_basket_result').hasClass('active')) {
		$.basket.getBasket();
	}
}
*/


/**
 * AJAX Basket Plugin
 * for Shopware
 *
 * Shopware AG (c) 2010
 */
(function ($) {

    //Initialize the basket module
    //and binds the needed events
    $.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').live('submit', function (event) {
            event.preventDefault();
            $.ajax({
                'data': $(this).serialize(),
                'dataType': 'jsonp',
                'url': $(this).attr('action'),
                'beforeSend': function() {
                	$.loadingIndicator.open();
                },
                '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();
                }
            });
        });
    };

    $.basket.getBasket = function () {
        if(!$($.basket.options.basketResult).length) {
        	$('<div>', {
        		'class': 'ajax_basket_result'
        	}).appendTo(document.body);
        }
        $($.basket.options.basketLoader).show();
        $.ajax({
            'data': {
                'sAction': 'ajaxCart'
            },
            'dataType': 'jsonp',
            'url': $.basket.options.viewport,
            'success': function (result) {
            	var offset = $($.basket.options.basketParent).offset();
            	$($.basket.options.basketResult).css({
            		'top': offset.top + 22,
            		'left': offset.left -($($.basket.options.basketResult).width() - $($.basket.options.basketParent).width() -37)
            	});
                $($.basket.options.basketLoader).hide();
                if (result.length) {
                    $($.basket.options.basketResult).empty().html(result);
                } else {
                    $($.basket.options.basketResult).empty().html($.basket.options.emptyText);
                }
                $($.basket.options.basketResult).addClass('active').slideDown('fast');
                $(document.body).bind('click', function() {
    				$($.basket.options.basketResult).removeClass('active').slideUp('fast');
    				$(document.body).unbind('click');
    			});
            }
        })
    }
})(jQuery);


