$(document).ready(function()
{
	
	
	//*********************clear text from input field********************************
	
	
	var clearMePrevious = '';
	
	// clear input on focus
	$('.clearMeFocus').focus(function()
	{
		if($(this).val()==$(this).attr('title'))
		
		{
			
			clearMePrevious = $(this).val();
			
			$(this).val('');
			
		}
		
	});
	
	// if field is empty afterward, add text again
	$('.clearMeFocus').blur(function()	 
	{
		if($(this).val()=='')
		
		{
			
			$(this).val(clearMePrevious);
			
		}
		
	});

	
	
	//*****************************Accordion***************************************
	
	
	var icons = 
	{
		
			header: "ui-icon-circle-plus",
			
			headerSelected: "ui-icon-circle-minus"
			
	};

	$("#accordion").accordion(
	{
		
		autoHeight: false,
		
		navigation: true,
		
		collapsible: true,
		
		icons:icons

	});
	
	
	//*************************Modal Window****************************************
	
	
		$("#dialog-modal").dialog(
		{
			
			autoOpen: false,
			
			height: 304,
			
			width: 430,
			
			modal: true
			
		});
		
		
		$(".getMap").click(function() 
		{
			
			$("#dialog-modal").dialog("open");
			
			return false;
			
		});
		
		$(".getCampus").click(function() 
		{
			
			$("#dialog-modal").dialog("open");
			
			return false;
			
		});

	
	

		$("#dialog-login").dialog(
		{
			
			autoOpen: false,
			
			height: 315,
			
			width: 380,
			
			modal: true
			
		});
		
		$("#getlogin").click(function()
		{
			
			$("#dialog-login").dialog("open");
			
			return false;
			
		});
	
	
	//*****************************SWFObject***************************************
	
	
   
		$("#gtmap").flash(
		{    
			swf: 'Map/map.swf',
			
			width: '400',
			
			height: '355'
			
			// these arguments will be passed into the flash document   
			/*flashvars: {   
					name1: 'jQuery',   
					name2: 'SWFObject',   
					name3: 'Plugin'   
			} */  
		});  
	
	
	//*****************************Sliding Panel***********************************
	
	
	$(".trigger").click(function()
	{
	
		$(".panel").toggle("fast");
		
		$(this).toggleClass("active");
		
		return false;
		
	});
	
	// Expand Panel
	$("#open").click(function()
	{
		
		$("div#panel").slideDown("slow");
	
	});	
	
	// Collapse Panel
	$("#close").click(function()
	{
		
		$("div#panel").slideUp("slow");	
		
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#toggle a").click(function () 
	{
		
		$("#toggle a").toggle();
		
	});	
	
	//*****************************vimeo swap**************************************
	
	
	$(".thumb").click(function()
	{
		var $id = $(this).attr("id");
		$("#vimeo").attr('src', 'http://player.vimeo.com/video/' + $id + '?title=0&amp;byline=0&amp;portrait=0&amp;color=b3d335');
		//alert($("#vimeo").attr("src"));
	});
	
	$(".video_thumb").click(function()
	{
		var $id = $(this).attr("id");
		$("#vimeo").attr('src', 'http://player.vimeo.com/video/' + $id + '?title=0&amp;byline=0&amp;portrait=0&amp;color=b3d335'); 
		
	});
	
	$(".sm_video_thumb").click(function()
	{
		var $id = $(this).attr("id");
		$("#vimeo").attr('src', 'http://player.vimeo.com/video/' + $id + '?title=0&amp;byline=0&amp;portrait=0&amp;color=b3d335'); 
		
	});
	
	
	
	//****************************slideshow****************************************
	
	
		var slideWidth = 965;
		
		var slides = $('.slide');
		
		var slide_length = slides.length;
		
		var controlOpacity = 0.3;
		
		var slideTimer = 3000;
		
		 // Remove scrollbar in JS
		$('#slidesContainer').css('overflow', 'hidden');
		
		 // Stack images on top of each other
		slides.css({
				   
						'position' : 'absolute',
						
						'top' : '0',
						
						'left': '0',
						
						'width' : slideWidth
						
						});
		
		//create slideshow and controls only is there is more than 1 slide
		if (slide_length > 1) 
		{				
			 
			 //Create navigation controls
			$('#slideshow')
			
				.append('<span class="control" id="leftControl"><img src="structure_gfx/_prev.png" width="55" height="29" /></span>')
				
				.append('<span class="control" id="rightControl"><img src="structure_gfx/_next.png" width="55" height="29" /></span>');
			
			$('.control').css({cursor: "pointer", opacity: controlOpacity});
			
			//Create a rollover effect on the controls
			$('.control').hover(
								function()
								{
									
									$(this).css('opacity','1.0');
									
								},
								function()
								{
									
									$(this).css('opacity',controlOpacity);
									
								}
			);
			
			// Create event listeners for .controls clicks
			$('#rightControl.control').bind('click', function()
			{
				
				gallery("fwd");
				clearInterval(timer);
				timer = setInterval('gallery("fwd")',slideTimer);
			});
			
			$('#leftControl.control').bind('click', function()
			{
				
				gallery("back");
				clearInterval(timer);
				timer = setInterval('gallery("fwd")',slideTimer);
			});
				
			//Execute the slideShow, set 4 seconds for each images  
			 slideShow(slideTimer);
		}
});

	function gallery(direction) 
	{  
	   
		 //if no IMGs have the show class, grab the first image  
		 var current = ($('.slide.show')?  $('.slide.show') : $('.slide:first'));
		 
	   
		 if(direction == "fwd") 
		 {			
			//Get next image, if it reached the end of the slideshow, rotate it back to the first image  
			var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('.slide:first') :current.next()) : $('.slide:first'));
			
			
		 }
		 else if (direction == "back")
		 {
			 //Get next image, if it reached the begining of the slideshow, rotate it back to the last image  
			var next = ((current.prev().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('.slide:last') :current.prev()) : $('.slide:last'));
			
			
		 };       
		 
		 //enable the next image
		 next.show();      
		 
		 //Set the fade in effect for the next image, show class has higher z-index
		 next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);         
	   
		 //Hide the current image and disable the image  
		 current.animate({opacity: 0.0}, 1000, function(){current.hide()}).removeClass('show');
	   
	};
	
	function slideShow(speed) 
	{ 
	
		 //Set the opacity of all images to 0  
		  $('.slide').css({opacity: 0.0});
		  
		  // disable all the images
		  $('.slide').hide();
		   
		 //Get the first image and display it (set it to full opacity)  
		 $('.slide:first').addClass('show').css({opacity: 1.0});  
		 
		 //enable the first image
		 $('.slide:first').show();
		   
		 //Call the gallery function to run the slideshow      
		 var timer = setInterval('gallery("fwd")', speed);  
		   
		 //pause the slideshow on mouse over  
		 $('#slideshow').hover(  
			 function () 
			 {  
				 clearInterval(timer);
				 
			 },    
			 function () 
			 {  
				 timer = setInterval('gallery("fwd")',speed); 
				 
			 }  
		);  
	 };
	 
	
$(document).ready(function()
{ 
 
 	//****************************Tooltip*****************************************
	
 
		// initialize tooltip 
		$(".help[title]").tooltip(
		{ 
			tip: '#tooltip',		// use single tooltip element for all tips   
			
			offset: [0, 2], 		// tweak the position       
			
			effect: 'slide' 		// use "slide" effect
			
		}).dynamic( 
		{ 							// add dynamic plugin 
		
			bottom: { 				// customized configuration on bottom edge  
			
				direction: 'down', 	// slide downwards
				
				bounce: true 		// bounce back when closed 
				
			} 
		}); 
		 

 
		
		$(".help-left[title]").tooltip(
		{
			
			tip: '#tooltip-side',
			
			offset:[2,-6],
			
			effect: 'fade',
			
			position: "center left"
			
		});
		
		
		$(".help-right[title]").tooltip(
		{
			
			tip: '#tooltip-side',
			
			offset:[2,-6],
			
			effect: 'fade',
			
			position: "center right"
			
		});
		

	
	//****************************icon links***************************************
	
	
	
	$(".calendar_event:odd").css({'background-color':'#eff9ff'});
	
	$(".video_list:odd").css({'background-color':'#eff9ff'});
	
	//$(".vimeo").prepend('<img src="structure_gfx/_watch.jpg" width="20" height="20" />&nbsp;');
	
	//$("a[href*='.mp3']").prepend('<img src="structure_gfx/_download.jpg" width="20" height="20" />&nbsp;');
	
	$("a[href*='.pdf']").prepend('<img src="structure_gfx/_pdf.png" width="20" height="20" />&nbsp;');
	
	$("a[href*='.xml']").prepend('<img src="structure_gfx/_rss.png" width="20" height="20" />&nbsp;');
	
});
