/* gb added */
$(document).ready(function () {
	/*==============================Search Start==================================================*/
	
	//  look for IE7 or less on Vista or less
	// Windows NT 6.0
		
	if(((navigator.appVersion.indexOf("Windows NT 5")!=-1) || 
		(navigator.appVersion.indexOf("Windows NT 6")!=-1)) && 
		((navigator.appVersion.indexOf("MSIE 7")!=-1) || 
			(navigator.appVersion.indexOf("MSIE 6")!=-1) || 
			(navigator.appVersion.indexOf("MSIE 5")!=-1))) {
				$('.topic-list').css({
				'padding' : '0px 0px 7px 9px',
				'margin' : '20px 0 8px'
				});
				$('.topic-list li').css({
					'padding-bottom' : '11px',
					'margin' : '0'
				});
				$('.container .list').css({
					'padding' : '9px 0px 0px 9px',
					'margin-top' : '6px',
					'letter-spacing' : '0.9'
				});
				$('.container .list li').css({
					'padding-bottom' : '4px'
				});
	}
		
	function doGlobalUCSearch(){
		// form: #uc-search-form

	}
		
	$('#search-ahc-form').attr({
		onsubmit : "return doGlobalUCSearch();"
	});
	
	/*Jquery validate keyword Plugin ///Author: GB*/
	 jQuery.fn.ws_validatekeyword = function (options) {
        var settings = $.extend({
            message: "Please type in a keyword.",
			matchphrase: "Search UC",
			target: "uc-searchbox",
			form: "uc-search-form"
        }, options);

        this.each(function () {
            var id = $(this).attr("id");			
			$("#" + id).click(function () {
            	var t = $("#" + settings.target);
				var match = /^search$/i;	
				var search_phrase = $(t).val();  
				if (search_phrase.match(match) 
					|| search_phrase == settings.matchphrase 
					|| search_phrase == settings.message 
					|| search_phrase == '' ) {
					$(t).ws_watermark({ message: settings.message });
					return false;
				} else {
					if(settings.form == "uc-search-form") {
						$("#formInputBox").val($("#uc-searchbox").val());		
					}					
					$('#' + settings.form).submit();	
				}
            });			
        });
        return this;
    };	
	
	$("#go").ws_validatekeyword();		
	$("#search").ws_validatekeyword({matchphrase: "Enter Keyword", target: "search-ahc"});	
		
	$("#uc-searchbox").keyup(function(e) {
		if(e.keyCode == 13) {
			$("#uc-searchbox").ws_validatekeyword();	
		}
	});	
	$("#search-ahc").keyup(function(e) {
		if(e.keyCode == 13) {
			gotoGSearch();			
		}
	});
	$("#search").click(function() {
		gotoGSearch();	
	});
	function gotoGSearch() {
		var pKey = $("#search-ahc").val();	
		window.location="http://search.uc.edu/search?q="+pKey+"&btnG=Google+Search&access=p&sort=date:D:L:d1&output=xml_no_dtd&ie=UTF-8&oe=UTF-8&client=ahc_frontend&proxystylesheet=ahc_frontend&site=AHC";		
	 }
	
	/*==============================Search End==================================================*/
	/*==============================Watermark Start===============================================*/
	/*Jquery watermark Plugin ///Author: Amit Gaur, GB*/
    jQuery.fn.ws_watermark = function (options) {
        var settings = $.extend({
            message: "Search UC"
        }, options);

        this.each(function () {
            var id = $(this).attr("id");
            $("#" + id).val(settings.message);
            $("#" + id).focusin(function () {
                $(this).val("");
            });
            $("#" + id).focusout(function () {
                var count = $(this).val();
                if (count == 0) {
                    $(this).val(settings.message);
                }
            });
        });
        return this;
    };

    /* search and keyword watermarks */
    $("#search-ahc").ws_watermark({ message: "Enter Keyword" });
    $("#uc-searchbox").ws_watermark();
	
	/*==============================Watermark End===============================================*/
    /*==============================Tools DropDown Start===========================================*/
	
	//Find sub and fade it in
    function tools_hover_over() {
        $(this).find(".tools").fadeTo('normal',0.95).slideDown(); 
    }
	
    //On Hover Out
    function tools_hover_out() {
        $(this).find(".tools").slideUp();
    }
	
    //Set custom configurations
    var tools_config = {
        sensitivity: 6, // number = sensitivity threshold (must be 1 or higher)
        interval: 50, // number = milliseconds for onMouseOver polling interval
        over: tools_hover_over, // function = onMouseOver callback (REQUIRED)
        timeout: 500, // number = milliseconds delay before onMouseOut
        out: tools_hover_out // function = onMouseOut callback (REQUIRED)
    };
    $("ul.add-nav li .tools").css({ 'opacity': '0' }); //Fade sub nav to 0 opacity on default
    $("ul.add-nav li").hoverIntent(tools_config); //Trigger Hover intent with custom configurations	
    /*==============================Tools DropDown End============================================*/	
	/*==============================Search DropDown Start ==========================================*/
	
	function search_options_show(){
		$(".uc-search-options").fadeTo("normal",0.95).slideDown();	
	}	
	function search_options_hide(){
		$(".uc-search-options").slideUp();	
	}	
	$("#uc-searchbox").click(function(){
		search_options_show();
	});
	$("#uc-searchbox").focus(function(){
		search_options_show();
	});
	$("#a-close").click(function(){
		search_options_hide();
	});	
	
	$("#radio-uc").click(function(){
		var searchboxval = $("#uc-searchbox").val();
		if(searchboxval == "Please type in a keyword." ||
			searchboxval == "Last Name, First Name") { 
			$("#uc-searchbox").ws_watermark();	
		}		
		$('#uc-search-form').attr({
			method :  "get",
			action : "http://search.uc.edu/search"
		});
		$("#gsclient").val("ucmain_frontend");
		$("#gsproxystylesheet").val("ucmain_frontend");
		$("#formInputBox").val("");
	});
	
	$("#radio-people").click(function(){
		var searchboxval = $("#uc-searchbox").val();
		if(searchboxval == "Please type in a keyword." ||
			searchboxval == "Search UC") { 
			$("#uc-searchbox").ws_watermark({ message: "Last Name, First Name" });	
		}		
		$('#uc-search-form').attr({
			method :  "post",
			action : "http://ucdirectory.uc.edu/PeopleSearch.asp"
		});		
	});	
	/*==============================Search DropDown End===========================================*/	
	
});
