/*
	@Authors  : 
	Cvetozar Ninov, Boris Delev 
*/
$(document).ready(function () {
    $(".gallery_content").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".back",
        visible: 4,
        circular: false
    });

	 $('.gallery_content a').lightBox({
	 	fixedNavigation : true,
	 	popup_width		: 600,
	 	imageLoading:	images_url+'lightbox-ico-loading.gif',
		imageBtnPrev:	images_url+'lightbox-btn-prev.gif',
		imageBtnNext:	images_url+'lightbox-btn-next.gif',
		imageBtnClose:	images_url+'lightbox-btn-close.gif',
		imageBlank:		images_url+'lightbox-blank.gif'
	 });

	 $('.gallery_looks a').lightBox({
	 	fixedNavigation : true,
	 	popup_width		: 600,
	 	imageLoading:	images_url+'lightbox-ico-loading.gif',
		imageBtnPrev:	images_url+'lightbox-btn-prev.gif',
		imageBtnNext:	images_url+'lightbox-btn-next.gif',
		imageBtnClose:	images_url+'lightbox-btn-close.gif',
		imageBlank:		images_url+'lightbox-blank.gif'
	 });

	 $('.gallery_previews a').lightBox({
	 	fixedNavigation : true,
	 	popup_width		: 600,
	 	imageLoading:	images_url+'lightbox-ico-loading.gif',
		imageBtnPrev:	images_url+'lightbox-btn-prev.gif',
		imageBtnNext:	images_url+'lightbox-btn-next.gif',
		imageBtnClose:	images_url+'lightbox-btn-close.gif',
		imageBlank:		images_url+'lightbox-blank.gif'
	 });


		$('.input_btn input').click(function()
		{
            if($('#rating').val() > 0){
                $.post(xhr+'?method=save_review',$('#jquery-mask #review').serialize(),function(response){
                    add_flash_message(response);
                    $('#jquery-mask #review')[0].reset();
                    $('.popup').hide();
                    hide_mask();
				});
            }else{
                alert('Please rate this product.');
            }
		});

	$('div.sliderGallery').each(function () {
		var ul = $('ul', this);
		//var productWidth = ul.innerWidth() - $(this).outerWidth();
		var productWidth = $('ul li:first', this).outerWidth()*$('ul li', this).length-$(this).outerWidth() - 10;

		var slider = $('.slider', this).slider({
		  handle: '.handle',
		  minValue: 0,
		  maxValue: productWidth,
		  slide: function (ev, ui) {
			ul.css('left', '-' + ui.value + 'px');
		  },
		  stop: function (ev, ui) {
			ul.animate({ 'left' : '-' + ui.value + 'px' }, 500, 'linear');
		  }
		});
	});
	
	$('div.popup a.y_close').click(function(){
		hide_mask();
	});
});