//
jQuery.noConflict();

// variables
var GB_ROOT_DIR = "/js/greybox/";

// script for shortening page to set height
function adjust_page_height(){
	if (jQuery('.InternalPages.Homepage').length == 0) {
	    jQuery('.ColOne').height(0);
	    jQuery('.ColOne').height(jQuery('.InternalPages').height()-170 );
	}
}

// script for toggling side menus
function enableSideMenus () {
    jQuery('.HasSubmenu').bind('click', function(){
        var papa = jQuery(this).parents('li')[0];
        jQuery('.SubSubMenu', papa).toggle();
        jQuery('span', this).toggleClass('Open');
        if (/##/.test(jQuery(this).attr('href'))){
            return false;
        }
    });

    if(jQuery('a.Selected').parents('li.Parent')[0]){
        jQuery('.SubSubMenu', jQuery('a.Selected').parents('li.Parent')[0]).show();
        if (jQuery('a.Selected').parents('.SubSubMenu').length){

            jQuery('.HasSubmenu', jQuery('a.Selected').parents('li.Parent')[0]).addClass('Selected');
            jQuery('.HasSubmenu span', jQuery('a.Selected').parents('li.Parent')[0]).addClass('Open');
        }
    }
}

// script for toggling header search box style
function enableSearchBox () {
    jQuery('.HasPlaceholder').focus(function(){
        if (this.value.toLowerCase() == this.title.toLowerCase() || this.value == ''){
            this.value = ''; jQuery(this).css({color: '##333'});
        }
    }).blur(function(){
        if (this.value == ''){ this.value = this.title; }
        if (this.value == '' || this.value.toLowerCase() == this.title.toLowerCase()){
            jQuery(this).css({color: '##999'});
        }
    }).each(function(){
        if (this.value.toLowerCase() == this.title.toLowerCase() || this.value == ''){
            jQuery(this).css({color: '##999'});
        } else {
            jQuery(this).css({color: '##333'});
        }
    });	
}

// run functions at page load
jQuery(function(){
    adjust_page_height();
    setTimeout("adjust_page_height()", 3000 );
    enableSideMenus();
    enableSearchBox();
});

