$(document).ready(function() {
    $('div#container').append('<div id="flashbg"></div>');
    $('div#flashbg').flash({
        swf: 'files/products.swf',
        height: 800,
        width: 1200,
        wmode: 'transparent',
        flashvars: {
            Syear: 2010,
            Smonth: 01,
            Sdate: 10,
            Shour: 19
        }
    });

    $('div#container').append('<div id="imgbg"></div>');

    $('div#imgbg').css({
        'background-image': 'url(img/products_bg.jpg)',
        'position': 'absolute',
        'top': '0px',
        'left': '0px',
        'height': '800px',
        'width': '1200px',
        'z-index': '-2'
    });

    $('div.scroll-pane').jScrollPane({showArrows:true, scrollbarWidth:19, dragMaxHeight:69});
    $('div.scroll-box').corner('round bottom');

    $('.product:not(.orange)').addClass('hidden').hide();

    $('a#next-product').bind('click', nextProduct);
    $('a#prev-product').bind('click', disableLink);

    $('a.product-link').click(function() {
        $('a#prev-link').unbind('click', disableLink).bind('click', prevProduct);
        $('a#next-link').unbind('click', disableLink).bind('click', nextProduct);

        var index = $('a.product-link').index(this);
        if(index == 0) {$('a#prev-product').unbind('click', prevProduct).bind('click', disableLink)};
        if(index == 4) {$('a#next-product').unbind('click', nextProduct).bind('click', disableLink)};

        var pid = $(this).attr('rel');
        $('.product').addClass('hidden').hide();
        $('.'+pid).removeClass('hidden').show();
        return false;
    });


    function disableLink(e) {
        return false;
    }

    function nextProduct(e) {
        var color = $('.product-info:not(.hidden)').next('.hidden').attr('id');
        $('.product').addClass('hidden').hide();
        $('.'+color).removeClass('hidden').show();

        if($('.product:not(.hidden)').next('.hidden').html() == null) $(this).unbind('click', nextProduct).bind('click', disableLink);
        $('a#prev-product').unbind('click', disableLink).bind('click', prevProduct);
        return false;
    }

    function prevProduct(e) {
        var color = $('.product-info:not(.hidden)').prev('.hidden').attr('id');
        $('.product').addClass('hidden').hide();
        $('.'+color).removeClass('hidden').show();


        if($('.product:not(.hidden)').prev('.hidden').html() == null) $(this).unbind('click', prevProduct).bind('click', disableLink);
        $('a#next-product').unbind('click', disableLink).bind('click', nextProduct);
        return false;
    }
});

