﻿slideshow_speed = 2000;
slideshow_timeout = 20000;

$(window).load(function () {

    getBackHome();

});

jQuery(document).ready(function () {

    //remove border from last navigation list item
    jQuery("ul#navigation li:last").css("background", "none");

    //setup the navigation hover effects
    jQuery("ul#navigation li").mouseenter(function () {

        liWidth = jQuery(this).width() + 50; //add 50 pixels for the left+right padding

        pos = jQuery(this).position();

        toAdd = (liWidth - 78) / 2;

        jQuery("ul#navigation li#hover").stop().animate({ left: (pos.left + toAdd) + "px" }, 700, "swing");

    });

    //same, but for lower level items
    jQuery("ul#navigation li ul li").mouseenter(function () {

        liWidth = jQuery(this).parent().parent().width() + 50; //add 50 pixels for the left+right padding

        pos = jQuery(this).parent().parent().position();

        toAdd = (liWidth - 78) / 2;

        jQuery("ul#navigation li#hover").stop().animate({ left: (pos.left + toAdd) + "px" }, 700, "swing");

    });

    jQuery("ul#navigation li").mouseleave(function () {

        getBackHome();

    });

    //if there is no active active in the navigation, hide the hover element
    if (!jQuery("ul#navigation li.active")[0]) {
        jQuery("ul#navigation li#hover").css({ "display": "none" });
    }


    //setup slideshow
    if (jQuery("#featured")[0]) {
        $('#slides').cycle({
            fx: 'scrollHorz',
            speed: slideshow_speed,
            timeout: slideshow_timeout,
            delay: -2000,
            next: '#arrowRight',
            prev: '#arrowLeft',
            pager: '#slideNav',
            easing: 'backinout',
            cleartype: true,
            cleartypeNoBg: true
        });
    }


    //strip the bottom border from the last post on the landing page
    jQuery("div.post:last").css({ "border": "0px" });


    //setup active effects for the contact form
    jQuery("form#contact input:not(#submit), form#contact textarea").focus(function () {

        jQuery(this).addClass("active");

    }).blur(function () {

        jQuery(this).removeClass("active");

    });

    //setup active effects for the new comment form
    jQuery("form#newComment input, form#newComment textarea").focus(function () {

        jQuery(this).addClass("active");

    });

    jQuery("form#newComment input, form#newComment textarea").blur(function () {

        jQuery(this).removeClass("active");

    });

    //setup hover effect for sidebar links
    jQuery(".sidebar a").hover(function () {

        jQuery(this).addClass("hover");

    }, function () {

        jQuery(this).removeClass("hover");

    })

    //setup submenus 

    jQuery("#navigation li").hover(function () {

        jQuery(this).find("ul").fadeIn();

    }, function () {

        jQuery(this).find("ul").fadeOut();

    })

});

function getBackHome() {

    pos = jQuery("ul#navigation li.active").position();

    if (pos) {

        liWidth = jQuery("ul#navigation li.active").width() + 50;

        toAdd = (liWidth - 78) / 2;

        jQuery("ul#navigation li#hover").stop().animate({ left: (pos.left + toAdd) + "px" }, 700, "swing")

    }

}