
document.documentElement.className = 'js';
(function (a) {
    a.fn.fancyZoom = function (p) {
        var p = p || {
        };
        var m = p && p.directory? p.directory: "/images/images";
        var e = false;
        if (a("#zoom").length == 0) {
            //var f = a.browser.msie? "gif": "png";
            var f = "png";
            var k = '<div id="zoom" style="display:none;">                   <table id="zoom_table" style="border-collapse:collapse; /*width:100%; height:100%;*/">                     <tbody>                       <tr>                         <td class="ztl" style="background:url(' + m + "/tl." + f + ') 0 0 no-repeat; width:20px; height:20px; overflow:hidden;" />                         <td class="tm" style="background:url(' + m + "/tm." + f + ') 0 0 repeat-x; height:20px; overflow:hidden;" />                         <td class="ztr" style="background:url(' + m + "/tr." + f + ') 100% 0 no-repeat; width:20px; height:20px; overflow:hidden;" />                       </tr>                       <tr>                         <td class="ml" style="background:url(' + m + "/ml." + f + ') 0 0 repeat-y; width:20px; overflow:hidden;" />                         <td class="mm" style="background:#fff; vertical-align:top; padding:10px;">                           <div id="zoom_content">                           </div>                         </td>                         <td class="mr" style="background:url(' + m + "/mr." + f + ') 100% 0 repeat-y;  width:20px; overflow:hidden;" />                       </tr>                       <tr>                         <td class="zbl" style="background:url(' + m + "/bl." + f + ') 0 100% no-repeat; width:20px; height:20px; overflow:hidden;" />                         <td class="bm" style="background:url(' + m + "/bm." + f + ') 0 100% repeat-x; height:20px; overflow:hidden;" />                         <td class="zbr" style="background:url(' + m + "/br." + f + ') 100% 100% no-repeat; width:20px; height:20px; overflow:hidden;" />                       </tr>                     </tbody>                   </table>                   <a href="#" title="Close" id="zoom_close" style="position:absolute; top:0; left:0;">                     <img src="' + m + "/closebox." + f + '" alt="Close" style="border:none; margin:0; padding:0;" />                   </a>                 </div>';
            a("body").append(k);
            a("html").click(function (q) {
                if (a(q.target).parents("#zoom:visible").length == 0) {
                    l();
                }
            });
            a(document).keyup(function (q) {
                if (q.keyCode == 27 && a("#zoom:visible").length > 0) {
                    l();
                }
            });
            a("#zoom_close").click(l);
        }
        var o = a("#zoom");
        var j = a("#zoom_table");
        var i = a("#zoom_close");
        var h = a("#zoom_content");
        var b = a("td.ml,td.mm,td.mr");
        this.each(function (q) {
            a(a(this).attr("href")).hide();
            a(this).click(n);
        });
        return this;
        function n(w) {
            if (e) {
                return false;
            }
            e = true;
            var q = a(a(this).attr("href"));
            var u = p.width;
            var v = p.height;
            var r = window.innerWidth ||(window.document.documentElement.clientWidth || window.document.body.clientWidth);
            var E = window.innerHeight ||(window.document.documentElement.clientHeight || window.document.body.clientHeight);
            var C = window.pageXOffset ||(window.document.documentElement.scrollLeft || window.document.body.scrollLeft);
            var B = window.pageYOffset ||(window.document.documentElement.scrollTop || window.document.body.scrollTop);
            var F = {
                width: r, height: E, x: C, y: B
            };
            var r =(u || q.width()) + 60;
            var E =(v || q.height()) + 60;
            var z = F;
            var A = Math.max((z.height / 2) -(E / 2) + B, 0);
            var D =(z.width / 2) -(r / 2);
            var s = w.pageY;
            var t = w.pageX;
            i.attr("curTop", s);
            i.attr("curLeft", t);
            i.attr("scaleImg", p.scaleImg? "true": "false");
            a("#zoom").hide().css({
                position: "absolute", top: s + "px", left: t + "px", width: "1px", height: "1px"
            });
            g();
            i.hide();
            if (p.closeOnClick) {
                a("#zoom").click(l);
            }
            if (p.scaleImg) {
                h.html(q.html());
                a("#zoom_content img").css("width", "100%");
            } else {
                h.html("");
            }
            a("#zoom").animate({
                top: A + "px", left: D + "px", opacity: "show", width: r, height: E
            },
            500, null, function () {
                if (p.scaleImg != true) {
                    h.html(q.html());
                }
                d();
                i.show();
                e = false;
            });
            return false;
        }
        function l() {
            if (e) {
                return false;
            }
            e = true;
            a("#zoom").unbind("click");
            g();
            if (i.attr("scaleImg") != "true") {
                h.html("");
            }
            i.hide();
            a("#zoom").animate({
                top: i.attr("curTop") + "px", left: i.attr("curLeft") + "px", opacity: "hide", width: "1px", height: "1px"
            },
            500, null, function () {
                if (i.attr("scaleImg") == "true") {
                    h.html("");
                }
                d();
                e = false;
            });
            return false;
        }
        function c(s) {
            a("#zoom_table td").each(function (u) {
                var t = a(this).css("background-image").replace(/ \.(png | gif | none) \"\) $ /, "." + s + '")');
                a(this).css("background-image", t);
            });
            var r = i.children("img");
            var q = r.attr("src").replace(/ \.(png | gif | none) $ /, "." + s);
            r.attr("src", q);
        }
        function g() {
            if (a.browser.msie && parseFloat(a.browser.version) >= 7) {
                c("gif");
            }
        }
        function d() {
            if (a.browser.msie && a.browser.version >= 7) {
                c("png");
            }
        }
    };
})(jQuery);
var KCPL = new Object()
KCPL.months=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
KCPL.days=["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday", "Saturday"];
KCPL.slideshows = new Array()
KCPL.today =new Date();
KCPL.Event = function(ekEvent){
        this.Date = null;
        this.title = ekEvent[evt_name];
        this.ekId = ekEvent[evt_id];
        this.location = null;
        this.type = null;
        this.setDate(ekEvent);
        this.setType($.trim(ekEvent[evt_key2]))
        this.setLocation($.trim(ekEvent[evt_key1]))
    }
    
KCPL.Event.prototype = {
    monthConversion:{Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sep:8,Oct:9,Nov:10,Dec:11},
    locations:[{id:"main_library", search:"Main Library", name:"Main Library",code:'ml'},{id:"clendenin", search:"Clendenin", name:"Clendenin Branch Library",code:'cn'},{id:"cross_lanes", search:"Cross Lanes", name:"Cross Lanes Branch Library",code:'cl'},{id:"dunbar",search:"Dunbar", name:"Dunbar Branch Library",code:'du'},{id:"elk_valley", search:"Elk Valley", name:"Elk Valley Branch Library",code:'ev'},{id:"glasgow",search:"Glasgow", name:"Glasgow Branch Library",code:'gl'},{id:"marmet",search:"Marmet", name:"Marmet Branch Library",code:'ma'},{id:"nitro",search:"Nitro", name:"Nitro Library",code:'ni'},{id:"riverside", search:"Riverside", name:"Riverside Public Library",code:'rv'},{id:"st_albans",search:"St Albans", name:"St. Albans Branch Library",code:'sa'},{id:"sissonville",search:"Sissonville", name:"Sissonville Branch Library",code:'si'}],
    setLocation: function(evt){
   
        var loc=[{id:"main_library", search:"Main Library", name:"Main Library",code:'ml'},{id:"clendenin", search:"Clendenin", name:"Clendenin Branch Library",code:'cn'},{id:"cross_lanes", search:"Cross Lanes", name:"Cross Lanes Branch Library",code:'cl'},{id:"dunbar",search:"Dunbar", name:"Dunbar Branch Library",code:'du'},{id:"elk_valley", search:"Elk Valley", name:"Elk Valley Branch Library",code:'ev'},{id:"glasgow",search:"Glasgow", name:"Glasgow Branch Library",code:'gl'},{id:"marmet",search:"Marmet", name:"Marmet Branch Library",code:'ma'},{id:"nitro",search:"Nitro", name:"Nitro Library",code:'ni'},{id:"riverside", search:"Riverside", name:"Riverside Public Library",code:'rv'},{id:"st_albans",search:"St Albans", name:"St. Albans Branch Library",code:'sa'},{id:"sissonville",search:"Sissonville", name:"Sissonville Branch Library",code:'si'}];
        for (var i in this.locations){
            if(this.locations[i].search==evt){
                 this.location=this.locations[i]
                }
 
            }
            if(this.location==null) {
                this.location = {id:"unknown", search:"unknown", name:"please call 304-343-4646 for location", code:"uk"}
                }
        },
        setType: function(evt){
                if(evt){
                    if(evt=='Storytime program'){
                        this.type ='Childrens Program'
                       }
                    else if(evt=='All Ages '){
                        this.type ='All Ages'}
                    else{this.type = evt}
                    }
                else{this.type='All Ages'}
        },
setDate: function(evt){
        var t, h = 0, hrs, m, y, d, min = 0;
        t =evt[evt_time].replace(/[&nbsp;]/g, "");                           //t is the stripped version of the evt_time string from the EK array (e).  Form is 99:99 XX 
        if(t){h = t.slice(0, t.indexOf(":"))};                                 //h is string value representing the starting hour of the event
        hrs = parseInt(h);                                                     //hrs is the integer value of the string h.  Converted to military time and used to set the hour of the start_time property of the event
        m = this.monthConversion[evt[evt_date].slice(0,3)];           //m is the integer representing the month of the start_time property of the event
        y = parseInt(evt[evt_date].slice((evt[evt_date].length-5)));         //y is the integer value of the year of event start_time
        d = parseInt(evt[evt_date].slice(4, (evt[evt_date].length-6)));      //d is the interger value of the day of the event start_time
        if(t){min = parseInt(t.slice((t.indexOf(":")+1), t.lastIndexOf(" ")))};//d is the interger value of the minutes of the event start_time
        if(hrs !="12" && t.search("P")!=-1){                                   //use info from the evt_time string to convert the integer value of the hour portion of the string to military time
            hrs = hrs + 12;
        }
        if(hrs =="12"&& t.search("A")!=-1){ 
            hrs =12;
        }
        this.Date = new Date(y, m, d, hrs, min);
        }
}
KCPL.qlink = {};  
    KCPL.getRandomInteger= function(low, high){
        var x = high - low;
        return Math.floor((Math.random()*x)+low);
    }
    KCPL.buildElement = function(el, cn, id){
        var node = document.createElement(el);
        if(cn){
            node.className=cn;
        }
        if(id){
            node.id = id
        }
        return node;
    }
    
    KCPL.buildGmapAddress = function(e){
        var ss=document.getElementById('street').value+' '+document.getElementById('city').value + ' ' + document.getElementById('state').value + ' ' + document.getElementById('zip').value
               document.getElementById('saddr').value = ss;
         if(document.getElementById('daddr').value=='select'){
                 
                   return false
            }
     }
    //QuickSwitch(qa, qb) is a general utility function used site-wide to open/close quick-links-style drawer controls. currently only used on the index page.
    //this function and the classSwitch are prime candidates for replacement by functions of the jQuery library
    KCPL.quickSwitch= function (qa, qb){
        if(KCPL.qlink.id ){
            if(KCPL.qlink.id==qa){
                if(KCPL.qlink.ref.style.display== 'none'){
                    KCPL.qlink.ref.style.display = 'block'
                }
                else{
                    KCPL.qlink.ref.style.display = 'none'
                }
            }
            else{
                KCPL.qlink.ref.style.display = 'none';
                KCPL.qlink.id = qa;
                if(qb){KCPL.qlink.text = document.getElementById(qb).innerHTML;}
                KCPL.qlink.ref = document.getElementById(qa);
                KCPL.qlink.ref.style.display = 'block';
            }
        }
        else{
            KCPL.qlink.id = qa;
            if(qb){KCPL.qlink.text = document.getElementById(qb).innerHTML;}
            KCPL.qlink.ref = document.getElementById(qa)
            KCPL.qlink.ref.style.display  = 'block';
        }
    }

    var blink ={};
    function BlurbSwitch(id){
        if(blink.id){
            if(blink.id==id){
                bs=document.getElementById(id);
                if(bs.className=='blurb'){
                    bs.className='visible'
                }
            else{
                bs.className='blurb'
                }
            }
        else{
            document.getElementById(blink.id).className='blurb'
            bs=document.getElementById(id);
            if(bs.className=='blurb'){
                bs.className='visible'
                }
            else{
               bs.className='blurb'
               }
            }
            blink.id=id
        }
        else{
            blink.id=id
            bs=document.getElementById(id);
            if(bs.className=='blurb'){
                bs.className='visible'
                }
            else{
                bs.className='blurb'
                }
        }
    }

    function ClassSwitch(buttext,featureID){
        if(featureID){cs=document.getElementById(featureID)}
        else{cs = document.getElementById('feature')}
        if(document.getElementById(buttext).innerHTML=='view expanded list'){document.getElementById(buttext).innerHTML = 'view compact list'}
        else{document.getElementById(buttext).innerHTML='view expanded list'}
        if(cs.className=='expanded'){
            cs.className='standard'}
        else if(cs.className=='standard'){cs.className='expanded'}
        return false
    }  
    
KCPL.Projector = function (id, intv){
        var oInstance = this
        this.container = $(id)
        this.items = this.container.children('.items')
        if(this.container.hasClass('fast')) { this.interval =5000 }else if(this.container.hasClass('medium')){this.interval=10000} else {this.interval =25000}
        this.slidecount = this.items.children().length
         $('.prev',id).bind('click', function (e){oInstance.manualPrev(); return false})
          $('.next',id).bind('click', function (e){oInstance.manualNext(); return false})
          $('.csp',id).bind('click', function (e){oInstance.change(this);return false})
          if( this.items.children('div:first').hasClass('current')){}
          else{
          this.items.children('div:first').addClass('current')}
          this.items.mouseover(function(e){oInstance.stop()})
          this.items.mouseout(function(e){oInstance.start()})
          //this.items.children('div').mouseover(function(e){oInstance.stop()})
          //this.items.children('div').mouseout(function(e){oInstance.start()})
       this.start()
    }

KCPL.Projector.prototype = {
    timer: null,
    
    change: function (slide){
        this.items.children().hide()
        this.container.children('.pn').children('.control').children('.current').removeClass('current');
        $(slide).addClass('current');
        this.items.children('.current').fadeOut()
        this.items.children('.current').removeClass('current'); 
        $($(slide).attr('href')).addClass('current').fadeIn() ;
        this.stop();
        this.start();
        return false
        },
    manualNext: function(){this.next();this.stop();this.start();return false},
    manualPrev: function(){this.prev();this.stop();this.start();return false},
    next: function (){
        this.items.children().hide()
        if(this.items.children().index(this.items.children('.current'))+1!= this.slidecount){
            this.container.children('.pn').children('.control').children('.current').removeClass('current').next().addClass('current');
             this.items.children('.current').fadeOut();
         this.items.children('.current').removeClass('current').next().addClass('current').fadeIn();
            }
        else{
            this.container.children('.pn').children('.control').children('.current').removeClass('current');
            this.container.children('.pn').children('.control').children().eq(1).addClass('current');
            this.items.children('.current').fadeOut();
            this.items.children('.current').removeClass('current');
            this.items.children().eq(0).addClass('current').fadeIn();
            }
        return false
        },
    
    prev: function (){
      this.items.children().hide()
          if(this.items.children().index(this.items.children('.current'))+1!=1){
            this.container.children('.pn').children('.control').children('.current').removeClass('current').prev().addClass('current');
                   this.items.children('.current').fadeOut();
    this.items.children('.current').removeClass('current').prev().addClass('current').fadeIn();
            }
        else{
            this.container.children('.pn').children('.control').children('.current').removeClass('current');
           this.container.children('.pn').children('.control').children().eq(this.slidecount).addClass('current');
                   this.items.children('.current').fadeOut();
    this.items.children('.current').removeClass('current');
            this.items.children().eq(this.slidecount-1).addClass('current').fadeIn();
            }
        return false
        },
    
    start: function(){
        var oInstance= this
           this.timer = setInterval(function (){oInstance.next()}, this.interval)
           $(oInstance.container).children('.paused').css('visibility','hidden')
        },
    
    stop: function (){
        var oInstance= this
        clearInterval(this.timer)
                   $(oInstance.container).children('.paused').css('visibility','visible')
        }
}

KCPL.ekEvent = function(d, ti, id, l, t){
        this.startDate = d;
        this.title = ti;
        this.ekId = id;
        this.location = l;
        this.type = (t) ? t : 'All Ages';
    }

KCPL.loadCalendar = function(){
if($('.calendar').html()){
var calendar = new KCPL.ScheduleLoader(evtArray, '#calendar')
}
}
   
KCPL.dateHighliter = function(){
    $('#'+KCPL.days[KCPL.today.getDay()]).css('background-color','#fff1ad')
    }
   
KCPL.removeDefaultSearchText = function(){
    var s1=document.getElementById('searchdata1');
    if(s1){
        s1.onfocus=function(){if(this.value=='enter title, subject, or author here' || this.value==' enter author, title, or subject here' || this.value==' enter title, subject, or author here')this.value=''}
        }
    }
   
//this system of registering functions to be triggered by window.onload may be handled better by jQuery

$(function(){
            KCPL.loadCalendar()

            
            $('div.photo a').fancyZoom({scaleImg: true, closeOnClick: true})
$('a:first','.sub_sect').focus(function(event){
   $('.sub_sect').css('background-color','white')
   $(this).parent().css('background-color','#eeeeee')
   $('ul:first','.sub_sect').hide('fast')
   $(this).next('ul').show('fast')
    });
    $('a:first','.sub_sect').mouseenter(function(event){
   $('.sub_sect').css('background-color','white')
   $(this).parent().css('background-color','#eeeeee')
   $('ul:first','.sub_sect').hide('fast')
   $(this).next('ul').show('fast')
    });

$('ul:first','.sub_sect').mouseleave(function(event){
    var zippy =this
    $('.sub_sect').css('background-color','white');
  $(zippy).hide('fast')
    });
$('.col2').mouseleave(function(event){
    var zippy =this
    $('.sub_sect').css('background-color','white');
    $('ul:first','.sub_sect').hide('fast')
    });    
    
$(".aux").click(function (event) {
      $("#aux").toggle( 'fast')
      return false
    });
$("body").click(function (event) {
      $("#aux").hide( 'fast')
    });
$('#aux').click(function(event){
    event.stopPropagation()
    })

        var ss = $('.things')
        for (var i=0; i<ss.length; i++){
            KCPL.slideshows[ss[i].id] = new KCPL.Projector('#'+ss[i].id);
             }
        })
$(KCPL.dateHighliter)   
$(KCPL.removeDefaultSearchText)   
//$(KCPL.loadCalendar)

