﻿//Define Kpw object only if it's not already defined
if ("undefined" == typeof Kpw) {
	Kpw = {};
}

//Intialiaze Kpw Default
$(document).ready(function(){
	Kpw.Default.init()
});

//Kpw Default Object
Kpw.Default = {
    bindEvents: function() {

        $('div.heroBanner ul#banner').cycle({
            fx: 'fade',
            timeout: 6000,
            speed: 2500,
            pager: '#bannerNavigation',

            // callback fn that creates a thumbnail to use as pager anchor
            pagerAnchorBuilder: function(idx, slideElement) {
                return '<a href="#">' + $(slideElement).children().children(".imageAnchor").attr('title') + '</a>';
            }
        });

        $("div.contentNavigation div.badges img.advicePromo").hover(
            function() {
                $(this).attr("src", "images/default/expertPromo_over.jpg");
            },
            function() {
                $(this).attr("src", "images/default/expertPromo.jpg");
            }
        );

        $("div.contentNavigation div.badges img.weddingPromo").hover(
            function() {
                $(this).attr("src", "images/default/featuredweddingPromo_over.jpg");
            },
            function() {
                $(this).attr("src", "images/default/featuredweddingPromo.jpg");
            }
        );

        $("div.contentNavigation div.badges img.blogPromo").hover(
            function() {
                $(this).attr("src", "images/default/blogPromo_over.jpg");
            },
            function() {
                $(this).attr("src", "images/default/blogPromo.jpg");
            }
        );
    },
    init: function() {
        //bind events
        Kpw.Default.bindEvents();
        Kpw.Default.Tabs.init();
    },
    Tabs: {
        init: function() {
            //tabs
            $("div.default div.contentTabs ul li.photoTab a").bind("click", Kpw.Default.Tabs.showPhoto);
            $("div.default div.contentTabs ul li.videoTab a").bind("click", Kpw.Default.Tabs.showVideo);

        },
        showVideo: function() {
            //need video to be "visible" (height = 0), for the video to load properly
            //now make it visible
            $("div.videoTab").css({ "height": "503px" });
            $("div.vendorGallery").addClass("hide");
            $("div.default div.contentTabs ul li.photoTab a").removeClass("selected");

            $("div.videoTab").removeClass("hide");
            $("div.default div.contentTabs ul li.videoTab a").addClass("selected");

            $("div.default div.contentTabs ul li.photoTab a").bind("click", Kpw.Default.Tabs.showPhoto);
            $("div.default div.contentTabs ul li.videoTab a").unbind("click");
        },
        showPhoto: function() {

            $("div.vendorGallery").removeClass("hide");
            $("div.default div.contentTabs ul li.photoTab a").addClass("selected");

            $("div.videoTab").addClass("hide");
            $("div.default div.contentTabs ul li.videoTab a").removeClass("selected");

            $("div.default div.contentTabs ul li.videoTab a").bind("click", Kpw.Default.Tabs.showVideo);
            $("div.default div.contentTabs ul li.photoTab a").unbind("click");
        }
    }
}
