$(document).bind("ready", main);

jQuery.easing.easeOutQuart = function(x, t, b, c, d){
    return -c * ((t = t / d - 1) * t * t * t - 1) + b;
};

function main(){

    $('.sliderGallery').serialScroll({
        items: 'li',
        offset: -150, //when scrolling to photo, stop 230 before reaching it (from the left)
        start: 1, //as we are centering it, start at the 2nd
        duration: 0,
        force: true,
        stop: true,
        lock: false,
        cycle: true, //don't pull back once you reach the end
        easing: 'easeOutQuart', //use this easing equation for a funny effect
        jump: true //click on the images to scroll to them
    });
    
    $('#goodSlider').serialScroll({
		items:'li',
		prev:'a.g_prev',
		next:'a.g_next',
		offset:0, //when scrolling to photo, stop 230 before reaching it (from the left)
		start:1, //as we are centering it, start at the 2nd
		duration:0,
		force:true,
		stop:true,
		lock:false,
		cycle:false, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect
		jump: false //click on the images to scroll to them
	}); 
}

function showthemes(){
    if ($('#themes').css('display') == 'none') {
        $.getJSON('http://printshop.maryjane.ru/stock/getthemes', function(data){
            if (data.length > 0) {
                $('#themesUL').empty();
                for (i = 0; i < (data.length - 1); i++) {
                    var li = '<li><a href="/stock/sortby/themes/' + data[i].theme_id + '"> ' + data[i].theme_name + '</a></li>';
                    $(li).appendTo('#themesUL');
                }
            }
            $('#themes').show();
        });
    }
    else {
        $('#themes').hide();
    }
}

function showAddToBasket(good_id, style_id, color){
	
    if (style_id == undefined) 
        style_id = 0;
    if (color == undefined) 
        color = 0;
		
    tb_show('Добавить в корзину', '/addtobasket/' + good_id + '/' + style_id + '/?height=295&width=660');
    return false;
}

function showAddToBasketForm(good_id, style_id, color){

    if (style_id == undefined) 
        style_id = 0;
    if (color == undefined) 
        color = 0;
		
    tb_show('Добавить в корзину', '/addtobasketform/' + good_id + '/' + style_id + '/' + color + '/?width=900&height=520');
    return false;
}

function setColor(obj, good_id, style_id) {
    var color = $(obj).val();
    $('.coloredPreviews').hide();
    $('#color_' + color).show();
	$('#colorSelect').val(color);

    $('.price').hide();
    $('#price_' + color).show();

    $('#sizeSelect')
        .ajaxStart(function() { $(this).attr('disabled','disabled'); })
        .ajaxStop (function() { $(this).removeAttr('disabled'); });
    
    $.getJSON('/ajax/retreviewsizes/' + good_id + '/' + style_id + '/' + color, function (data) {
        if (data.length > 0) {
            $('#sizeSelect').empty();
            $('#sizeSelect').append('<option value="">-</option>');
            for (i = 0; i < data.length; i++) {
                var option = "<option value='" + data[i].size_id + "'>" + data[i].size_name + "</option>";
                $('#sizeSelect').append(option);
            }
        }
    });
}

function showCatPic(pic_id, obj){
    $(".cat_pic").removeClass("cat_pic_active");
    $(obj).addClass("cat_pic_active");
    $(obj).blur();
    $.get("/ajax/getcatalogpicture/", { 'pid': pic_id }, function(data){
        if (data != "no") {        
            $("#pictureContainer").empty();
            $(data).appendTo($("#pictureContainer"));
        }
    });
}

function zoomPic(pic) {
	tb_show('', "/ajax/zoom/" + pic + "/?width=660&height=500");
	return false;
}