﻿var tabShow = false;
var prevImage, totalImages , thumb , tim
var currentImage = 0;
var cellno, panelSelected, litSelected ,  self;

$(document).ready(function() {
    setLogo();
    $("*[class^=quote]").corner("8px");
    $(window).resize(function() { setLogo(); });

    // set background on selected menu
    var menuitem = window.location.pathname.split("/");
    if (menuitem.length > 2) { var menu = '#' + menuitem[1];  $(menu).addClass("selected"); }

    /* if gallery loaded
    if ($('.gallery_placeholder').length) { load_gallery(); }
    if ($('#grid_placeholder').length) { load_Nine_Lives(); }
    */
}); 

function setLogo() {
   
    var browserwidth = $(window).width();
    var logoleft;
    var logoOffset = 680;
    var leftM;
    var defWidth = 1095; //1095
    var offset =0 ;       
      
    // added april 19
    leftM = ((browserwidth - defWidth) / 2);
 
    // if browser width less than req - move right column
    
    //200
    if ((leftM <= 100) && (browserwidth > (defWidth - 1))) {
        //  alert(leftM);
        logoOffset = 570;
        leftM = 0; offset = 235;
        leftM += offset;
        $('#site_placeholder').css({ 'margin-left': leftM + 'px' });
    } else
    { $('#site_placeholder').css({ 'margin': '0 auto' }); }
    
    logoleft = (browserwidth / 2) - logoOffset;  // orignal value 680 570
    if ((logoleft < 0)) { logoleft = 0; };
    if (browserwidth < defWidth) { logoleft = -290; };
    $("#logo").css('left', logoleft);
    $("#toptab").css('left', (browserwidth / 2) - 215); //$("#toptab").css('left', (browserwidth / 2) - 68);
    if ((logoleft <= -10) && !(tabShow)) { tabShow = true; $("#toptab").animate({ top: '20' }, 500) };
    if ((logoleft > -10) && (tabShow)) { tabShow = false; $("#toptab").animate({ top: '-90' }, 100) };
   
};

/*********************** Gallery Code *************************/

function load_gallery() {

    // set timer
    tim = setTimeout('gallery_rotator()', 7000);
    totalImages = $('div.thumb a').size();
    //  grayscale thumbs
    grayscale($('div.thumb a'));
    // set first image to color
    prevImage = $('div.thumb a:first');
   // prevImage.addClass('activeThumb');
    grayscale.reset(prevImage);
    // set click attr
    $("div.thumb a").click(setActiveThumb);
  }

function setActiveThumb() {
    // clear timer
    clearTimeout(tim);
    // reset previous Image
    grayscale(prevImage);
    //prevImage.removeClass('activeThumb');
    prevImage = $(this);
    //
    $(this).addClass('activeThumb');
    //
    var largeImage = $(this).attr('href');
    var thumbIMG = $(this).find('img');
    var strCaption = thumbIMG.attr('alt');
    $("#main_view p").html(strCaption);
    grayscale.reset($(this));
    var mvi = $('#main_view img');  
        mvi.animate({opacity: 0.10}, 400, function() {mvi.attr({ src: largeImage });
        mvi.animate({ opacity: 1 }, 800, function() { });
         });       
    return false;
}

function gallery_rotator() {
    currentImage += 1; if (currentImage >= totalImages) { currentImage = 0; }
    thumb = $('#thumb' + currentImage);
     // reset previous Image
    grayscale(prevImage);
    prevImage.removeClass('activeThumb');
    prevImage = thumb;
    //
    // thumb.addClass('activeThumb');
    //
    var largeImage = thumb.attr('href');
    var thumbIMG = thumb.find('img');
    var strCaption = thumbIMG.attr('alt');
    $("#gallery_caption p").html(strCaption);
    grayscale.reset(thumb);
    var mvi = $('#main_view img');
    mvi.animate({opacity: 0.10}, 500, function() {
        mvi.attr({ src: largeImage });
        mvi.animate({ opacity: 1 }, 1000, function() { });
    });  
    tim = setTimeout('gallery_rotator()', 4000);

}

/******************** end of Gallery code *********************************/
/******************** Cats Nine Lives     *********************************/


function load_Nine_Lives() {          
           // hide panels
    $('*[id^=panel]').each(function() {
        $(this).css({ display: 'none' });
        $(this).find('div').css({ display: 'none' });
       
    });
        // hover
            //$('*[id^=cell]').hover(showPanel, hidePanel);     
            $('*[id^=cell]').mouseenter(showPanel).mouseleave(hidePanel);
}

function showPanel() {    
    cellno = $(this).attr('id').split('_');
    panelSelected = '#panel_' + cellno[2];
    litSelected = '#div_' + cellno[1];
    $(litSelected).css({ display: 'block' });
    $(this).css({ backgroundColor: '#efefef' });
    $(panelSelected).css({ backgroundColor: '#efefef',display: 'block' });
    // $(this).animate({ backgroundColor: '#1AADB6' }, 10)
    // $(panelSelected).fadeIn(10);
    
}

function hidePanel() {
    
    cellno = $(this).attr('id').split('_');
    panelSelected = '#panel_' + cellno[2];
    litSelected = '#div_' + cellno[1];
    $(litSelected).css({ display: 'none' });
    //$(this).animate({ backgroundColor: '#000' }, 200)
    $('*[id^=cell]').css({ backgroundColor: 'transparent' });
    $(panelSelected).css({  display: 'none' });
    //$(panelSelected).fadeOut(10);
}


/******************** End of Nine Lives   *********************************/

