

$(document).ready(function() {
    $('.menu ul li').hover(function(){
        $(this).css({'background-color':'#c9982f'});
    
    },function(){
        $(this).css({'background-color':'#e5b53b'});
    
    });
    
    
        
    window.active = null;

    window.x = 0;
    
    window.offset =0;
    $('.rightarrow').css({display:'none'});
    $('.leftarrow').css({display:'none'});
    /*$(".leftarrow").hover(function(){
        $(".leftarrow").animate({paddingTop:'0'},100);
    },function(){
        $(".leftarrow").animate({paddingTop:'5px'},100);
    });
    $(".rightarrow").hover(function(){
        $(".rightarrow").animate({paddingTop:'5px'},100);
    },function(){
        $(".rightarrow").animate({paddingTop:'0'},100);
    });
   */
    window.store = [];

    var max = 29;
    var fadespeed = 300;
    var resizespeed = 300;
    var cols = 3;
    var rows = 8;
    var x_offset = 0;
    var y_offset = 0;

    var i = 1;
    col = 0
    for (i == 1; i < max; i++) {

        if (i < 4) {
            row = 0;
            num = i - 1;
        }
        else if (i < 7) {
            row = 1;
            num = i - 4;
        }
        else if (i < 10) {
            row = 2;
            num = i - 7;
        }
          else if (i < 13) {
            row = 3;
            num = i - 10;
        }
           else if (i < 16) {
            row = 4;
            num = i - 13;
        }
           else if (i < 19) {
            row = 5;
            num = i - 16;
        }
           else if (i < 22) {
            row = 6;
            num = i - 19;
        }
           else if (i < 25) {
            row = 7;
            num = i - 22;
        }
           else if (i < 28) {
            row = 8;
            num = i - 25;
        }
          else if (i < 31) {
            row = 9;
            num = i - 28;
        }
        
        window.store['a' + i] = [];

        window.store['a' + i]['row'] = row;
        window.store['a' + i]['num'] = num;


        t = store['a' + i]['row'] * 125 + window.x;
        l = store['a' + i]['num'] * 220;

        $("#a" + i).css({ top: t, 'margin-left': l });
        $("#" + i + ".profile").css({ backgroundPosition: '-125px -75px' })
        
        //$('.profile_bg').css({ display: 'none' });
        $('#shield').css({ display: 'none' });



        /* $("#a" + i).hover(function() {
        //  $("#" + this.id + " .profile_bg").fadeOut(fadespeed);
        $("#" + this.id + " .overlay").animate({ top: '70' });
        $("#" + this.id + " .overlay_bg").animate({ marginTop: '25' });

        },
        function() {
        //top:topoffset

		     if (window.active == 0) {// $("#" + this.id + " .profile_bg").fadeIn(fadespeed);
        }

		     $("#" + this.id + " .overlay").animate({ top: '115' });
        $("#" + this.id + " .overlay_bg").animate({ marginTop: '70' });


		 });*/
        $("#a" + i).hoverIntent(openItem, shield);
        $('.rightarrow').click(nextrow);
        $('.leftarrow').click(prevrow);
    }   
    
    
    
    function nextrow(){
          /*var j = (-max);
            window.offset++;
            
            if(window.offset==5){$('.rightarrow').css({display:'none'});}
            if(window.offset!==0){$('.leftarrow').css({display:'block'});}
            for(j==(-max); j<max; j++){

                if(window.store['a'+j]){
           
                     window.store['a'+j]['row'] =(window.store['a'+j]['row'])-1;
                }
            
            }

            $('.speakers_mask').children().animate({marginTop:($('.speakers_mask').children().css('marginTop').replace("px", "")-125)+'px'});*/
    }
    
      function prevrow(){
       /* var k = (-max);
            window.offset=window.offset-1;
            if(window.offset==0){$('.leftarrow').css({display:'none'});}
             if(window.offset!==5){$('.rightarrow').css({display:'block'});}
            for(k==(-max); k<max; k++){

            if(window.store['a'+k]){
           
                window.store['a'+k]['row'] =(window.store['a'+k]['row'])+1;
            }
            
            }
            
            marg =$('.speakers_mask').children().css('marginTop').replace("px", "");
           marg = parseFloat(marg);
            $('.speakers_mask').children().animate({marginTop:(marg+125)+'px'});
         
    */
    }
    
    function openItem() {

        if (window.active == null) {


            $("#" + this.id + " .overlay").animate({ top: '70' });
            $("#" + this.id + " .overlay_bg").animate({ top: '70' });

            $("#" + this.id).click(function() {
                $("#" + this.id + ".profile").css({cursor:'default'});
                window.active = this.id;

                //$("#" + this.id).unbind();
                $("#" + this.id + ".profile").css({ 'z-index': '10' });

                $('#shield').css({ display: 'block' });



                if (window.store[this.id]['row'] == 9) {
                    topoffset = 125+(7*125) + window.x;
                } else {
                    var topoffset = (window.store[this.id]['row']+window.offset) * (125) + window.x;
                }

                if (window.store[this.id]['num'] == 2) {
                    $("#" + this.id + ".profile").animate({ width: '430', height: '240', 'marginLeft': '220', top: topoffset, backgroundPosition: 'left top' }, resizespeed, 'linear', function() { window.active = this.id; });

                }
                else {
                    $("#" + this.id + ".profile").animate({ width: '430', height: '240', top: topoffset, backgroundPosition: 'left top' }, resizespeed, 'linear', function() { window.active = this.id; });

                }
                $("#" + this.id + " .overlay").animate({ top: '155' });
                $("#" + this.id + " .overlay_bg").animate({ top: '155' });


            });
        }
        else {

        }
        

    }
    function shield() {
    
    
    if (window.active !== null) {

            $("#" + this.id).unbind('click');
            if (window.store[window.active]['num'] == 2) {
                var leftoffset = '440';
            } else {
                var leftoffset = (window.store[window.active]['num']) * (220);
            }
            if (window.store[window.active]['row'] == 9) {
                var topoffset = 250 + parseFloat(window.x) +parseFloat(7*125);
            } else {
                var topoffset = (parseFloat(window.store[window.active]['row'])+parseFloat(window.offset)) * (125) + window.x;
            }
             
            $("#" + window.active + ".profile").animate({
            backgroundPosition: '-125px -75px',
            width: '210',
            height: '115',
            'marginLeft': leftoffset,
            top: topoffset
            
            }, resizespeed, 'linear', function() {
            $("#" + window.active + ".profile").css({ 'z-index': '0' });

                $("#" + window.active + " .profile_bg").fadeIn(fadespeed);


                $('#shield').css({ display: 'none' });
            window.active = null;
            $("#" + this.id + ".profile").css({ cursor: 'hand', cursor: 'pointer' });

            });
            
        } else {
            $("#" + this.id + " .overlay").animate({ top: '115' });
            $("#" + this.id + " .overlay_bg").animate({ top: '115' });
        }
        
    }



});