(function($) {

    $(function() {

        (function() {
;           //fix for Tubepress to make sure menus and popups work.
            var wmodeString = "<param name='wmode' value='opaque'>"
            $('object').prepend(wmodeString);
            $('embed').attr('wmode', 'opaque');

            var flashObject = $('object');
            flashObject.each(function(){
                var object = $(this);
                var flashParent = object.wrap('<div>').parent();
                object.remove().appendTo(flashParent);
            });

            //Front Page Cycle
                        // Product Rotator

            // The transition fx.
            var fx = 'fade';

            // The inactive and active dot urls.
            var inactiveDotUrl = WP.template_url + "/images/inactive-square.png",
                activeDotUrl = WP.template_url + "/images/active-square.png";

            var dotContainer = $(".pager");
            var slides = $("#slides");
            // Create as many dots as there are slides.
            slides.children().each(function() {
                $("<img>", {
                    src: inactiveDotUrl,
                    alt: "square"
                }).appendTo($("<a>", {
                    href: "#"
                }).appendTo(dotContainer));
            });

            // Find all the created dots.
            var dots = dotContainer.find("img");

            // Moves the dot to correspond with the current slide.
            var dotHandler = function(current, next) {
                var offset = $(next).prevAll().size();
                dots.attr("src", inactiveDotUrl);
                dots.eq(offset).attr("src", activeDotUrl);
            };

            // Start the cycle plugin.
            slides.cycle({
                fx: fx,
                after: dotHandler,
                cleartypeNoBg: true,
                speed: 1200
            });

            // This is for the awesomeness that is IE 7.
            slides.cycle("pause");
            slides.children().eq(0)
            .css({
                width: 940,
                height: 200
            });
            slides.cycle("resume");

            // Bind navigation controls to each dot.
            dotContainer.find("a").click(function() {
                var offset = $(this).prevAll().size();
                slides.cycle("stop");
                slides.cycle({
                    fx: fx,
                    after: dotHandler,
                    startingSlide: offset
                });
                slides.cycle("stop");
                return false;
            });

            //Contact Forms

            $('input#send-button').live('click',function() {
                var formData = $('form#contact-form').serialize();
                $.post(
                    WP.url+'/contact-ajax',
                    formData,
                    function(){
                        alert ('Thank you, we\'ll get back to you shortly!');
                        $('form#contact-form input[type=text], form#contact-form textarea').val('').text('');
                        parent.$.colorbox.close();
                    }
                );
                return false;
            }
            );

            $('div.slickr-flickr-gallery a').livequery(function(){
                $(this).attr('rel', 'sidebar-gallery');
                 $(this).lightbox();
            });

        })();

    });

})(jQuery);


