jQuery.noConflict();
jQuery(function($) {
	
	$(document).ready(function() {
	    $('#slideshow').cycle({
			'fx': 'fade',
			'timeout': 5000,
			cleartype: true,
			cleartypeNoBg: true
		});
	});
	
	var slideTimeout;
	$('#product-review-table').bind('bambiMagentoStaralized-Ratings', function () {
		$('.stararea label').append($('<span/>').addClass('required').html(' *'));
	});

	$('.block-crosssell li:first-child').addClass('first');
	$('.block-crosssell li:last-child').addClass('last');

	$('.breadcrumbs').append($('.category-products-header'));

	$('.col-main .home-boxes li:nth-child(3n)').addClass('last');
	/*$('.col-main div.home-box').each(function(index, item){
		$(this).addClass(index % 3 == 2 ? 'last' : '');
	});*/

	$('.one-step-checkout .order-information ol li.os-payment .payment-methods #checkout-payment-method-load > li').click(function () {
		var els = $(this).find('> input.radio');
		if (els) {
			els[0].checked = true;
			if (els[0].value == 'ccsave') {
				$('.pnummer').show();
				$('.billingData, .shippingData, p.different_shipping, #showhide_shipping').hide();
			} else {
				$('.pnummer').hide();
				$('.billingData input.disabled, .shippingData input.disabled').removeClass('disabled');
		        $('.billingData input, .shippingAddress select').unbind('focus');
				$('.billingData, .shippingData, p.different_shipping').show();
			}

			//$(els[0]).fire('click');
			$('.divs-payment > div').css('display', 'none');
			$('.divs-payment > div.payment-div-' + $(els[0]).val()).css('display', 'block');
			$('.one-step-checkout .order-information ol li.os-payment .payment-methods li').removeClass('selected');
			$(this).addClass('selected');
			$('.one-step-checkout .os-address').show(500);
			payment.switchMethod($(els[0]).val());
			payment.reloadReviewTotal();
		}
	});

	$('.block-toplists .block-content ol.products-images li').css({'opacity': 0});
	$('.block-toplists .block-content ol.products-images li').css({'visibility': 'visible', 'display': 'none'});
	$('.block-toplists .block-content ol.products-list li a').click(function () {
		clearTimeout(slideTimeout);
		$('.block-toplists .block-content ol.products-images').removeClass('next');
		slideSlideSlide(true, $('.block-toplists .block-content ol.products-images li:eq(' + ($(this).parents('li').attr('title')-1) + ')'));
		return false;
	});
	slideSlideSlide();

	function slideSlideSlide (stop, next) {
		$('.block-toplists .block-content ol.products-images').each(function () {
			var $next = $(this).find('.container.next');
			if (next == undefined) {
				var $nextnext = $($next).next('.container').length > 0 ? $($next).next('.container') : $(this).find('.container:first-child');
			} else {
				var $nextnext = next;
			}

			if ($($next).length > 0) {
				$($next).animate({'opacity': 0}, 500).css('display', 'none');
				$($next).removeClass('next');
				$('.block-toplists .block-content ol.products-list li:eq(' + ($($next).attr('title')-1) + ') a').stop().animate({'color': '#000'}, 500);
			}
			if ($($nextnext).length > 0) {
				$($nextnext).css('display', 'block').animate({'opacity': 1}, 500);
				$($nextnext).addClass('next');
				$('.block-toplists .block-content ol.products-list li:eq(' + ($($nextnext).attr('title')-1) + ') a').stop().animate({'color': '#cc092f'}, 500);
			}
		});
		if (stop == undefined) {
			slideTimeout = setTimeout(function(){slideSlideSlide();}, 5000);
		}
	}


    $('.product-img-box a.product-gallery').click(function () {
        $('.product-img-box a.product-gallery-item').each(function () {
            var hrefCurrent = ($(this).parents().find('.product-image a').attr('href'));
            if($(this).attr('href') == hrefCurrent) {
                $(this).click();
            }
        });
        return false;
    });

    $('.product-img-box a.thumbnail').click(function(){
        var hrefCurrent = $(this).parents().find('.product-image a').attr('href');
        var href = $(this).attr('href');

        if (href == hrefCurrent) {
            return false;
        }

		$(this).parents('ul').find('.selected').removeClass('selected');
        $(this).addClass('selected');
        $(this).parents().find('a.product-gallery img').attr('src', href);
        $(this).parents().find('a.product-gallery').attr('href', href);
        $('#product-title').html($(this).find('img').attr('title'));

    	var flash_src = $(this).parent().find("input[name='3d_swf_src']").attr('value');

    	if (flash_src) {
	    	swfobject.embedSWF(flash_src, "wirefusion", $('#wirefusion').width(), $('#wirefusion').height(), "9.0.0", "/media/expressInstall.swf");
    	}

    	var product_id = $(this).parent().find("input[name='product_id']").attr('value');

    	if (product_id) {
	    	$('#alternative-images li').each(function (i, el) { $(el).hide(); });
	    	$('#alternative-images li.product-' + product_id).each(function (i, el) { $(el).show(); });
			$('#alternative-images li.product-' + product_id + ' a.thumbnail').removeClass('selected');
			$('#alternative-images li.product-' + product_id + ':first a.thumbnail').addClass('selected');
    	}

        return false;
    });

	$(document).ready(function(){
		$('.product-img-box .thumbnails a.product-gallery-item').colorbox();
		$('.product-img-box .thumbnails li:first a.thumbnail').addClass('selected');
		$('.product-img-box .more-views li:first a.thumbnail').click();
	});

	$('#brand-selector').change(function() {
		window.location = $(this).val();
	});
});


