/*
 * jQuery (TY) Drop Down Mega Menu 
 * http://tumharyyaaden.site50.net/
 *
 * Copyright (c) 2009 Ronak Patel 
 * Desisaswat@gmail.com
 * Dual licensed under the MIT and GPL licenses.
 *
 * Date: 2010-05-19 00:00:01 -0500 (Wed, 19 May 2010)
 * Version: 0.1
 */

jQ(document).ready(function(){

    jQ(".tiptip").tipTip(); //Initiate tipTip Tooltip, Titles to Tooltip
	
	//Top Navigation Background Animation, inlcude bgpos.js!
	jQ('#top_navi a') //Top Navigation Background Animation, inlcude bgpos.js!
		.css( {backgroundPosition: "-230px 0"} )
		.mouseover(function(){
			jQ(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:310});
		})
		.mouseout(function(){
			jQ(this).stop().animate({backgroundPosition:"(-230px 0)"}, {duration:310});
		});
		
	jQ('#top_navi .menuboth div a') //Top Navigation, Drop down Links Background Animation, inlcude bgpos.js!
		.css( {backgroundPosition: "-500px -10px"} )
		.mouseover(function(){
			jQ(this).stop().animate({backgroundPosition:"(0 -10px)", paddingLeft:"21"}, {duration:500});
		})
		.mouseout(function(){
			jQ(this).stop().animate({backgroundPosition:"(-500px -10px)", paddingLeft:"12"}, {duration:400});
		});
	
	//Drop-Down Menu	
	jQ('.menuboth').mouseover(function(){
													  
		var containerID = '#'+jQ('a:first-child', this).attr('menudata'); //Get Menu container ID
		var tall = jQ('a:first-child', this).attr('menuheight'); //Get Menu container Height
		var wide = jQ('a:first-child', this).attr('menuwidth'); //Get Menu container Width
		
		jQ(containerID).stop().animate({height:tall, width:wide}, {queue:false, duration:500, easing:'easeOutBounce'});
	});
	
	//Hide Drop-Down Menu
	jQ('.menuboth').mouseout(function(){
							  
		var containerID = '#'+jQ('a:first-child', this).attr('menudata');
		
		jQ(containerID).stop().animate({height:0,width:0},{queue:false, duration:400, easing: 'easeOutBounce'});
	});

		
	//SearchBox Text Value change function
	var searchfocus = false;		//Set if SearchBox is in focus
	
	jQ("#searchtxt, #topsearchtxt").click(function(){
		if (this.value=='Search Here...') {
			jQ(this).val(''); 
			searchfocus = true;		//Don't fade footer if SearchBox is in focus, ignore scroll fade
		}
	})
	.blur(function(){
		if ((this.value==' ')||(this.value=='')) {
			jQ(this).val("Search Here..."); 
			searchfocus = false; 		//Fade footer if SearchBox is in blur and if page is not scrolled down
			
			var scrollTop = jQ(window).scrollTop();
			if(scrollTop <= 100) {jQ('#fixedfooter').stop().animate({'opacity':'0.3'},400);}
		}
		
	});
		
	//Phonebook search URL with variables http://phonebook.uconn.edu/results.php?status=any&basictext=NAME (nonstudent/student)
	jQ('#phonebtn').click(function(){
		var phoneurl = "http://phonebook.uconn.edu/results.php?status=any&basictext=" + jQ('#searchtxt').val();
		//window.location.replace(usearchurl); //NO BACK History
		window.location = phoneurl;
	});
	
	jQ('#topphonebtn').click(function(){
		var phoneurl = "http://phonebook.uconn.edu/results.php?status=any&basictext=" + jQ('#topsearchtxt').val();
		window.location = phoneurl;
	});
	
	//UConn search URL 
	jQ('#usearchbtn').click(function (){usearchf();});
	
	function usearchf(){
		var usearchurl = "http://www.uconn.edu/search.php?cx=004595925297557218349%3A65_t0nsuec8&page_id=160&cof=FORID%3A10&ie=UTF-8&&q=" + jQ('#searchtxt').val();
		window.location = usearchurl;
	}
	
	jQ('#topusearchbtn').click(function (){topusearchf();});
	
	function topusearchf(){
		var usearchurl = "http://www.uconn.edu/search.php?cx=004595925297557218349%3A65_t0nsuec8&page_id=160&cof=FORID%3A10&ie=UTF-8&&q=" + jQ('#topsearchtxt').val();
		window.location = usearchurl;
	}
	
});
