﻿var theInt = null;
var $crosslink, $navthumb;
var curclicked = 0;

var megaConfig = {
    interval: 200,
    sensitivity: 4,
    over: addMega,
    timeout: 400,
    out: removeMega
};

function addMega() {
    $(this).addClass("hovering");
}

function removeMega() {
    $(this).removeClass("hovering");
}

theInterval = function(cur) {
    clearInterval(theInt);

    if (typeof cur != 'undefined')
        curclicked = cur;

    $crosslink.removeClass("active-thumb");
    $navthumb.eq(curclicked).parent().addClass("active-thumb");
    $(".stripNav ul li a").eq(curclicked).trigger('click');

    theInt = setInterval(function() {
        $crosslink.removeClass("active-thumb");
        $navthumb.eq(curclicked).parent().addClass("active-thumb");
        $(".stripNav ul li a").eq(curclicked).trigger('click');
        curclicked++;
        if (6 == curclicked)
            curclicked = 0;

    }, 5000);
};

$(function() {
    $('.btn').each(function() {
        var b = $(this);
        var tt = b.text() || b.val();
        b.text('').css({ cursor: 'pointer' }).prepend('<i></i>').append($('<span>').text(tt).append('<i></i><span></span>'));
        $("<div class='clearer' style='clear:left;'></div>").insertAfter(b);
    });
    $('#countynews li:last-child').css(
                { background: "none", padding: 0 }
            );
    $('#shelters li:last-child').css(
                { background: "none", padding: 0 }
            );
    $('a.lightbox').lightBox({
        imageLoading: '/images/lightbox-ico-loading.gif',
        imageBtnClose: '/images/lightbox-btn-close.gif',
        imageBtnPrev: '/images/lightbox-btn-prev.gif',
        imageBtnNext: '/images/lightbox-btn-next.gif',
        imageBlank: '/images/lightbox-blank.gif',
        fixedNavigation: true
    });
    $('a#ctl00_Landmarks1_LandmarkRotator').lightBox({
        imageLoading: '/images/lightbox-ico-loading.gif',
        imageBtnClose: '/images/lightbox-btn-close.gif',
        imageBtnPrev: '/images/lightbox-btn-prev.gif',
        imageBtnNext: '/images/lightbox-btn-next.gif',
        imageBlank: '/images/lightbox-blank.gif',
        fixedNavigation: true
    }).attr('title', $('a#ctl00_Landmarks1_LandmarkRotator img').attr('alt'));
    $('#colA ol.slideshow').cycle({
        fx: 'fade',
        speed: 500,
        timeout: 3000,
        pause: 1
    });
    $('a.print').click(function() {
        window.print();
        return false;
    });
    $("li.mega").hoverIntent(megaConfig);

    $("#main-photo-slider").codaSlider();

    $navthumb = $(".nav-thumb");
    $crosslink = $(".cross-link");

    $navthumb.click(function() {
        var $this = $(this);
        theInterval($this.parent().attr('href').slice(1) - 1);
        return false;
    });
    $('A[rel="external"]').click(function() {
        window.open($(this).attr('href'));
        return false;
    });

    $('.panel .wrapper A[href^="http:/"]').click(function() {
        window.open($(this).attr('href'));
        return false;
    });
    
    $('ul.ads A[href^="http:/"]').click(function() {
        window.open($(this).attr('href'));
        return false;
    });
    $('A[rel="document"]').click(function() {
        window.open($(this).attr('href'));
        return false;
    });
    theInterval();
});

function quickSelect(linkName) {
    location.href = "#"+linkName;
}

function pop_window(url, strName, intHeight, intWidth, intScroll, intButtons, intResize, intMenuBar) {
    if (intButtons != 1) {
        intButtons = 0;
    }
    if (intMenuBar != 1) {
        intMenuBar = 0;
    }
    if (navigator.userAgent.indexOf("MSIE") == -1) {
        newwindow2 = window.open(url, strName, 'toolbar=' + intButtons + ',location=0,directories=0,status=' + intResize + ',menubar=' + intMenuBar + ',scrollbars=' + intScroll + ',resizable=' + intResize + ',width=' + intWidth + ',height=' + intHeight);
        newwindow2.moveTo(24, 24);
        newwindow2.focus();
    } else {
        newwindow2 = window.open(url, strName, 'toolbar=' + intButtons + ',location=0,directories=0,status=' + intResize + ',menubar=' + intMenuBar + ',scrollbars=' + intScroll + ',resizable=' + intResize + ',width=' + intWidth + ',height=' + intHeight);
        newwindow2.moveTo(24, 24);
        newwindow2.focus();
    }
} 
