

jQuery(document).ready(function() {

    //search box
    jQuery("td.ms-sbcell input").val('Enter Search Term');
    jQuery("td.ms-sbcell input").focus(function() {
        if (jQuery(this).val() == 'Enter Search Term') {
            jQuery(this).val('');
        }
    });

    jQuery("td.ms-sbcell input").blur(function() {
        if (jQuery(this).val() == '') {
            jQuery(this).val('Enter Search Term');
        }
    });



    //home page

    jQuery('.well').bind({
        mouseover: function() {
            jQuery(this).children(':last').show();
            jQuery(this).children(':first').hide();
        },
        mouseout: function() {
            jQuery(this).children(':last').hide();
            jQuery(this).children(':first').show();
        }
    });


    //accordion 
    var heightArray = new Array();

    getHeight();

    jQuery('#accordion .section_head').click(function() {
        var index = jQuery(this).next().attr('id').split('_');
        jQuery(this).next().css({ height: heightArray[index[1]] });


        jQuery(this).next().toggle('fast');

        var src = jQuery(this).children('img').attr("src");
        if (src.indexOf("_active") == -1) {
            src = jQuery(this).children('img').attr("src").match(/[^\.]+/) + "_active.gif";
        } else {
            src = jQuery(this).children('img').attr("src").replace("_active", "");
        }
        jQuery(this).children('img').attr("src", src);
        return false;
    }).next().hide();

    //submenu arrow
    jQuery('#submenu_mid li a').bind({
        mouseover: function() {
            var src = jQuery(this).children('img').attr("src");
            if (src.indexOf("_active") == -1) {
                src = jQuery(this).children('img').attr("src").match(/[^\.]+/) + "_active.png";
            }

            jQuery(this).children('img').attr("src", src);
        },
        mouseout: function() {
            if (!jQuery(this).hasClass('active')) {
                var src = jQuery(this).children('img').attr("src");
                src = jQuery(this).children('img').attr("src").replace("_active", "");
                jQuery(this).children('img').attr("src", src);
            }
        }
    });


    //contact btn
    jQuery('.side_contact').click(function() {

        jQuery('#pull_quote_box').animate({ height: 'toggle' }, 'fast', function() {  });

        var src = jQuery(this).children('img').attr("src");
        if (src.indexOf("_active") == -1) {

            src = jQuery(this).children('img').attr("src").match(/[^\.]+/) + "_active.png";
        } else {
            src = jQuery(this).children('img').attr("src").replace("_active.png", ".png");

            jQuery(this).children('img').attr("src", src);
        }

        jQuery(this).children('img').attr("src", src);
    });

    //highlight top level nav
   /* var currentURL = jQuery().SPServices.SPGetCurrentSite();
   
    alert(currentURL);
    jQuery('.parent').each(function() {
        alert(jQuery(this).find('a[href=$"' + currentURL + '"]').html());

    }); */

});

function getHeight(){
	jQuery("#accordion .content").each(function(i) { 
			jQuery(this).attr('id','c_'+i);
			theHeight = jQuery(this).outerHeight(); 
			heightArray[i] = theHeight; 
		});
}

function loadCaseStudyNav(sitename) {

    var where = "";  //<Query><Where><Contains><FieldRef Name='Team_Association'/><Value Type='text'>" + team + "</Value></Contains></Where></Query>";

    jQuery().SPServices.defaults.webURL = sitename;


    jQuery().SPServices({
        operation: "GetListItems",
        async: false,
        listName: 'Pages',
        viewName: '',
        //CAMLQuery: where,
        completefunc: function(data, Status) {

            //alert(data.responseText);
            jQuery(data.responseXML).find("[nodeName='z:row']").each(function() {




                var image = jQuery(this).attr('ows_SmallImage');
                var title = jQuery(this).attr('ows_Title');


//alert(image);
//alert(title);

                var page = jQuery(this).attr('ows_FileLeafRef').substr(jQuery(this).attr('ows_FileLeafRef').indexOf('#') + 1);
                var active = '';


                if (location.href.match(page) != null) {
                    active = 'cs_active';
                }
                //replace alt with class and title
                if (image != undefined) {
                    image = image.replace('alt=""', 'alt="' + title + '" class="case_thumb ' + active + '"');
                    image = image.replace('style="border:0px solid"', '');
                    jQuery('.case_study_menu ul').append('<li>' + image + '</li>')
                }




            });

        }

    });






}
