﻿
$(document).ready(function() {

    $('.catalog-popup-link a').mouseover(function() {
        var y = $(this).offset().top - 260;
        if (y > 300) y -= 180;
        var id = this.href.substring(this.href.lastIndexOf('/'));
        //setTimeout(function() {
        $('#preview').css({ visibility: 'visible', display: 'block', top: y + 'px', zIndex: '20000' });
        $('#preview-content').load('http://www.shoptwigs.com/Preview' + id);
        //}, 1000);
    });

    $('.catalog-popup-link a').mouseout(function() {
        $('#preview').css({ visibility: 'hidden' });
        $('#preview-content').html('');
    });



    // Create scrollbars
    $('.scroller').draggable({ containment: 'parent', axis: 'y', drag: function(event, ui) {
        var loc = parseInt($(this).css('top')) / ($(this).parent().height() - $(this).height());
        var target = $('#' + this.id.substring(0, this.id.lastIndexOf('-')) + '-content');
        target.css('top', '-' + Math.round(loc * (target.outerHeight() - target.parent().innerHeight())) + 'px');
    }
    });

    $('.scroll-area').click(function(event) {
        var y = event.pageY - $(this).offset().top;
        var slider = $(this).children();
        var space = $(this).height() - slider.height();
        var pos = Math.min(space, Math.max(0, y - (slider.height() / 2)));
        slider.css('top', pos + 'px');

        var loc = pos / space;
        var target = $('#' + this.id.substring(0, this.id.lastIndexOf('-')) + '-content');
        target.css('top', '-' + Math.round(loc * (target.outerHeight() - target.parent().innerHeight())) + 'px');
    });

    $('.scroll-up').mousedown(function(event) {
        var id = $(this).parent().attr('id');
        id = id.substring(0, id.lastIndexOf('-'));
        var scroller = $('#' + id + '-scroller');
        var content = $('#' + id + '-content');
        scroller.animate({ top: '0' }, 1000);
    });

    $('.scroll-dn').mousedown(function(event) {

    });
});

function resizeMenu()
{
    var high = $('#layout-stretch').height();
    if (high != null && high > 570)
    {
        $('#layout-left').height(high);
    }
}

function addCartHide()
{
    document.getElementById('addtocart').style.display = 'none';
}