var br_dir = 1, br_count, br_left;

$(document).ready(function(){
    var flashvars = {};
    var params = {wmode:"transparent"};
    var attributes = {};

    //swfobject.embedSWF("skin/frontend/default/images/swf/home.swf", "flash_main", "722", "377", "9.0.0","/images/swf/expressInstall.swf", flashvars, params, attributes);
    //swfobject.embedSWF("skin/frontend/default/images/swf/scroll.swf", "rotation", "1000", "233", "9.0.0","/images/swf/expressInstall.swf", flashvars, params, attributes);

    $("a.product .white").css({display: 'block', opacity: 0});
    $("a.product").mouseover(function(){
        stop_br();
        $(this).find(".white").stop();
        $(this).find(".white").animate({opacity: 0.5},100, 'linear');
    });
    $("a.product").mouseout(function(){
        start_br(1);
        $(this).find(".white").stop();
        $(this).find(".white").animate({opacity: 0},100, 'linear');
    });
    $(".home-bottom-rot .left").mouseover(function(){
        br_dir = -1;
        start_br(0.2);
    });
    $(".home-bottom-rot .left").mouseout(function(){
        start_br(1);
    });
    $(".home-bottom-rot .right").mouseover(function(){
        br_dir = 1;
        start_br(0.2);
    });
    $(".home-bottom-rot .right").mouseout(function(){
        start_br(1);
    });
    br_count = $("a.product").size();
    br_left = -(br_count-5)*180;
    start_br(1);

    // Middle rot
    $(".card").each(function(){
        var crd = new card();
        crd.init(this);
    });

});

function start_br(mult)
{
    time = ($(".home-bottom-rot .inner .frame .tape").position().left+(br_count-5)*180*(br_dir==1))/180.0*3000*mult*br_dir;
    $(".home-bottom-rot .inner .frame .tape").stop();
    $(".home-bottom-rot .inner .frame .tape").animate({left: br_left*(br_dir==1)}, time, 'linear', function(){
        br_dir*=(-1);
        setTimeout(function(){start_br(1);}, 10);
    });
}

function stop_br()
{
    $(".home-bottom-rot .inner .frame .tape").stop();
}

/* Middle Rot */

function card()
{
    
}

var middlespeed = 500;

card.prototype.init = function(el)
{
    this.el = $(el);
    this.img = $(el).find("img");
    this.frame = $(el).find(".frame");

    this.width = this.el.width();
    this.height = this.el.height();

    this.el.mouseover(function(crd){ return function(){
        crd.frame.stop();
        crd.frame.animate({top: -5, left: -5, width: crd.width+10, height: crd.height+10}, middlespeed);

        crd.img.stop();
        crd.img.animate({top: -10, left: -10}, middlespeed);
    }}(this));

    this.el.mouseout(function(crd){ return function(){
        crd.frame.stop();
        crd.frame.animate({top: 0, left: 0, width: crd.width, height: crd.height}, middlespeed);

        crd.img.stop();
        crd.img.animate({top: 0, left: 0}, middlespeed);
    }}(this));
}
