jQuery.noConflict();

/*
 * jQuery hashchange event - v1.3 - 7/21/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);

function form_input_classes(){

    jQuery('input[type="text"]').addClass('text');
    jQuery('input[type="password"]').addClass('text');
    jQuery('input[type="checkbox"]').addClass('checkbox');
    jQuery('input[type="radio"]').addClass('radiobutton');
    jQuery('input[type="submit"]').addClass('submit');
    jQuery('input[type="image"]').addClass('buttonImage');

}

function form_labelize(){    jQuery(".labelize input:text").clearingInput(); } 

// =================================================
// = Callback functions for Homepage Hero Carousel =
// =================================================

function setActive(carousel, item, idx, state){
    switch (state){
        case "next":
            jQuery('#rotator .jcarousel-item-' + (idx-1) + ' p').fadeIn("fast");
            jQuery('#rotator .jcarousel-item-' + (idx-1)).fadeTo(200,1.0);
        break;
        case "prev":
            jQuery('#rotator .jcarousel-item-' + (idx+1)).fadeTo(200,1.0);
            jQuery('#rotator .jcarousel-item-' + (idx+1) + ' p').fadeIn("fast");
        break;
        case "init":
            makeButtonsRotator(carousel,state);
            jQuery('#rotator .jcarousel-item-1 p').show();
            jQuery('#rotator .jcarousel-item-1').css({"opacity": 1.0});

    }
}
function removeActive(carousel, item, idx, state){
    if(state == "next"){
        jQuery('#rotator li p').fadeOut("fast");
        jQuery('#rotator .jcarousel-item-' + (idx-2)).css("opacity",0.5);
    }
    else if (state == "prev"){
        jQuery('#rotator li p').fadeOut("fast");
        jQuery('#rotator .jcarousel-item-' + (idx+2)).fadeTo(200,0.5);
    }
}

function setVisible(carousel,state){
   jQuery('#rotator-wrapper-inner').removeClass("loading");
   jQuery('#rotator .jcarousel-item').css({"opacity": 0.5});
}

// ======================
// = For Homepage Touts =
// ======================
function makeButtons(carousel,state){
    jQuery('#hp-touts h3').after('<p id="prev"><a href="#">Previous</a></p>').after('<p id="next"><a href="#">Next</a></p>');
    jQuery('#prev').live('click',function(){
        carousel.prev();
        return false;
    });
    jQuery('#next').live('click',function(){
        carousel.next();
        return false;
 });
}
// ==================
// = For Video Page =
// ==================
function makeButtonsVideo(carousel,state){
    jQuery('#video-thumbs').prepend('<p id="video-pager"><a id="prev-vid">&lt; Previous</a> <a id="next-vid">Next &gt;</a></p>');
    jQuery('#prev-vid').live('click',function(){
        carousel.prev();
        return false;
    });
    jQuery('#next-vid').live('click',function(){
        carousel.next();
        return false;
    });
}
// =============================
// = For Homepage Hero Rotator =
// =============================
function makeButtonsRotator(carousel,state){
    jQuery('#rotator-wrapper').append('<p id="rot-prev"><a href="#">Previous</a></p>').append('<p id="rot-next"><a href="#">Next</a></p>');
    jQuery('#rot-prev').live('click',function(){
        carousel.prev();
        return false;
    });
    jQuery('#rot-next').live('click',function(){
        carousel.next();
        return false;
    });
}

// ==================
// = Document.Ready =
// ==================
jQuery(document).ready(function() {
    form_input_classes();
    form_labelize();
    Cufon.replace('#tagline, .hp-section h3, #sidebar h3, .stat, #global-nav li, .action-button, #mission', {fontFamily: 'Akzidenz Grotesk'});
    jQuery('#rotator li p').removeClass('active-no-js');
    //jQuery('#rotator-wrapper-inner').addClass('loading');
    jQuery('#rotator-wrapper-inner').jcarousel({
        start: 0,
        scroll: 1,
        visible: 3,
        wrap: "circular",
        itemLoadCallback: setVisible,
        initCallback: setActive,
        buttonNextHTML: null,
        buttonPrevHTML: null,
        itemVisibleInCallback: {
        onBeforeAnimation: removeActive,
        onAfterAnimation: setActive
        }
});
    if (jQuery('#hp-touts ul li').length > 3){
        jQuery('#hp-touts ul').jcarousel({
         start: 1,
         scroll: 3,
         visible: 3,
         wrap: "circular",
         initCallback: makeButtons,
         buttonNextHTML: null,
         buttonPrevHTML: null
        });
    }
    if (jQuery('#video-thumbs .vt-wrap li').length > 3){
        jQuery('#video-thumbs .vt-wrap').jcarousel({
         start: 1,
         scroll: 3,
         visible: 3,
         wrap: "circular",
         initCallback: makeButtonsVideo
        });
    }
    if (jQuery('#projects-photos li').length > 1){
        jQuery('#photos-wrap').append("<p id='project-prev'><a href='#'>Previous</a></p>").append("<p id='project-next'><a href='#'>Next</a></p>");
        jQuery('#projects-photos').cycle({
         speed: 500,
         fx: 'scrollHorz',
         timeout: 0,
         next: '#project-next',
         prev: '#project-prev'
        });
    }
    if (jQuery('#projects-testimonials li').length > 1){
        jQuery('#testimonials-wrap').append("<p id='quote-prev'><a href='#'>Previous</a></p>").append("<p id='quote-next'><a href='#'>Next</a></p>");
        jQuery('#projects-testimonials').cycle({
         speed: 500,
         fx: 'scrollHorz',
         timeout: 0,
         next: '#quote-next',
         prev: '#quote-prev'
        });
    }
    jQuery('#hp-touts ul li').not('.csstransitions #hp-touts ul li').hover(
        function(){
         jQuery(this.children[1]).animate({top: 0}, 500,'swing');
        },
        function(){
         jQuery(this.children[1]).animate({top: 107}, 250,'swing');
        }
    );
    if (jQuery('#rotator-kids li').length > 1){
        jQuery('#rotator-wrapper-kids').append('<div id="rotator-kids-pager">');
        jQuery('#rotator-kids').cycle({
         speed: 500,
         timeout: 5000,
         pager: '#rotator-kids-pager' 
        });
        }
    jQuery('#quiz-slides').cycle({
        next: '.cycle-next',
        prev: '.cycle-prev',
        timeout: 0,
        speed: 500
    });
    if (jQuery('.photoset .slides .photo').length > 1){
        jQuery('.photoset').prepend("<a href='#' class='cycle-prev'>").prepend("<a href='#' class='cycle-next'>");
        jQuery('.photoset .slides').cycle({
            next: '.cycle-next',
            prev: '.cycle-prev',
            timeout: 0,
            speed: 500
        });
    }
    
}); //end document.ready