var mainMenuTimeout;
var clearMenuItem;
function inspiration_text(message) {
    jQuery.ajax( {url: "/Inspiration/Save.ajax?word=" + escape(message) } );
	return;
}
(function($) {
    (jQuery).fn.reverse = [].reverse;


    // comboboxes
    function setupComboBoxes(cssSelector, cssClass) {
        jQuery(cssSelector).combobox({
            comboboxContainerClass: "combobox-container " + cssClass + "-container",
            comboboxValueContainerClass: "combobox-value-container " + cssClass + "-value-container",
            comboboxValueContentClass: "combobox-value-content " + cssClass + "-value-content",
            comboboxDropDownClass: "combobox-dropdown " + cssClass + "-dropdown",
            comboboxDropDownButtonClass: "combobox-dropdown-button " + cssClass + "-dropdown-button",
            comboboxDropDownItemClass: "combobox-item " + cssClass + "-item",
            comboboxDropDownItemHoverClass: "combobox-item-hover " + cssClass + "-item-hover",
            comboboxDropDownGroupItemHeaderClass: cssClass + "-item-header",
            comboboxDropDownGroupItemContainerClass: cssClass + "-item-group-container",
            animationType: "",
            width: "",
            mouseOutTime: 1500
        });
    }

    (jQuery)(document).ready(function() {

        $(".footer-signup-btn").click(function() {
			var signupEmail = $(".footer-signup-box").attr("value");
            window.location = "http://agencyq.us1.list-manage.com/subscribe?u=54b8be63dd286b97555c47a79&id=8a1334e998&MERGE0=" + signupEmail + "";
            return false;
        });

        // comboboxes
        setupComboBoxes('.case-study-combobox', 'case-study-combobox');
        setupComboBoxes('.awards-combobox', 'awards-combobox');
        setupComboBoxes('.news-combobox', 'news-combobox');
        // menu effects
        (jQuery)('.main-navigation-primary-item')
		    .each(
			    function() {
			        // set the active item
			        this.onmouseover = function() {
			            (jQuery)(this).siblings().removeClass('main-navigation-primary-item-hover');
			            clearMenuItem = this;
			            clearTimeout(mainMenuTimeout);
			            (jQuery)(this).addClass('main-navigation-primary-item-hover');
			        }
			        this.onmouseout = function() { mainMenuTimeout = setTimeout(function() { (jQuery)(clearMenuItem).removeClass('main-navigation-primary-item-hover') }, 1) }
			    }
		    );
        (jQuery)('.main-navigation-primary-submenu-item')
		    .each(
			    function() {
			        // set the hover style
			        this.onmouseover = function() { (jQuery)(this).addClass('main-navigation-primary-submenu-item-hover'); }
			        this.onmouseout = function() { (jQuery)(this).removeClass('main-navigation-primary-submenu-item-hover'); }
			    }
		    );
        // end menu effects


        // footer effects
        /*
        $(function(){
        var originalBodyHeight = $(document.body).height();
    	    
        positionFooter(); 
        function positionFooter(){
        if(originalBodyHeight < $(window).height()){
        $(".footer-content-container").css({position: "absolute",top:($(window).scrollTop()+$(window).height()-$(".footer-content-container").height()-8)+"px"})
    				
        $(".main-content-container").css({minHeight: $(window).height()-$(".footer-content-container").height() - $(".header-content-container").height()+"px"})
        }	
        }
    	 
		    $(window)
        .scroll(positionFooter)
        .resize(positionFooter)
        });
        */
        // end footer effects

        (jQuery)('.portfolio-wrapper').ImageGallery();


        (jQuery)(".ui-accordion").accordion({ header: "h3", active: false, autoHeight: false, collapsible: true, icons: { 'header': 'more-icon', 'headerSelected': 'less-icon'} });

        if ((jQuery)('.news-item').length > 5) {
            (jQuery)('.news-item').each(function(i, el) {
                if (i > 4) {
                    (jQuery)(el).addClass('news-item-extra');
                }
            });
        }
        else {
            (jQuery)('.news-see-more-link').hide();
        }
        // show more news	        
        (jQuery)('.news-see-more-link').each(function() {
            this.onclick = function() {
                (jQuery)('.news-item-extra').each(function(i, el) {
                    if (i < 5) {
                        (jQuery)(el).removeClass('news-item-extra');
                    }
                });

                if ((jQuery)('.news-item-extra').length == 0) {
                    (jQuery)(this).hide();
                }
                return false;
            }
        });
        if ((jQuery)(".careers-page").length > 0 && window.location.hash.indexOf("#") > -1) {
            el = (jQuery)('.job-post a');
            el = jQuery.grep(el, function(n, i) {
                return ('#' + n.name == window.location.hash);
            });
            par = (jQuery)(el).parents('.job-post h3');
            if (par.length > 0) {
                (jQuery)(par).click();
            }
            setTimeout(function() { window.location.href = window.location.hash }, 300);
        }
        if ((jQuery)(".news-page").length > 0 && window.location.hash.indexOf("#") > -1) {
            el = (jQuery)('.news-item a');
            el = jQuery.grep(el, function(n, i) {
                return ('#' + n.name == window.location.hash);
            });
            par = (jQuery)(el).parents('.news-item h3');
            if (par.length > 0) {
                (jQuery)(par).click();
                (jQuery)(par).parents('.news-item').prevAll('.news-item-extra').andSelf().reverse().each(
                    function(i, n) {
                        (jQuery)(n).removeClass('news-item-extra');
                    });
                if ((jQuery)('.news-item-extra').length == 0) {
                    (jQuery)('.news-see-more-link').hide();
                }
            }
            setTimeout(function() { window.location.href = window.location.hash }, 300);
        }
    });
})(jQuery);

jQuery(document).ready(function () {
    var value;
    var defaultValue;
    jQuery(".footer-signup-box").focus(function () {
        value = jQuery(this).attr("value");
        defaultValue = "Enter your email";

        if (value == defaultValue) {
            jQuery(this).val("");
        }
    });

    jQuery(".footer-signup-box").blur(function () {
        var test = jQuery(this).attr("value");

        if (test == "") {
            jQuery(this).val(defaultValue);
        }
    });
});

