$(function(){
	$('#slides').slides({
		preload: true,
		preloadImage: 'library/loading.gif',
		play: 6000,
		pause: 2500,
		hoverPause: true,
		generatePagination: true
	});
});
$(document).ready(function(){
	closetimer = 0;
	if($("#nav")) {
		$("#nav b").mouseover(function() {
			clearTimeout(closetimer);
			if(this.className.indexOf("clicked") != -1) {
				$(this).parent().next().slideUp(500);
				$(this).removeClass("clicked");
			} else {
				$("#nav b").removeClass();
				$(this).addClass("clicked");
				$("#nav ul:visible").slideUp(500);
				$(this).parent().next().slideDown(500);
			}
			return false;
		});
		$("#nav").mouseover(function() {
			clearTimeout(closetimer);
		});
		$("#nav").mouseout(function() {
			closetimer = window.setTimeout(function(){
				$("#nav ul:visible").slideUp(500);
				$("#nav b").removeClass("clicked");
			}, 2000);
		});
	}
	//(0 off 1 on)
        var auto_slide = 1;
        var hover_pause = 1;
        var key_slide = 1;
        
       //velocidad tiempo slide
        var auto_slide_seconds = 2000;
       
       
        $('#slider_ul li:first').before($('#slider_ul li:last')); 
        
       //checa si esta activo el autoslide
        if(auto_slide == 1){
           //establesco el intervalo de tiempo para llamar a mi funcion 
            var timer = setInterval('slide("right")', auto_slide_seconds); 
            
            //cambio el valor del campo oculto,tiene informacion del tiempo de intervalo
            $('#hidden_auto_slide_seconds').val(auto_slide_seconds);
        }
  
       //checar si el evento hover esta activo
        if(hover_pause == 1){ 
            $('#slider_ul').hover(function(){
            //evento hover parar intervalo
                clearInterval(timer);
            },function(){
            //reasignar intervalo
                timer = setInterval('slide("right")', auto_slide_seconds); 
            });
  
        }
	$(".giveonline").fancybox({
		'width'				: 800,
		'height'			: 450,
		'autoScale'			: false,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'overlayOpacity'	: '0.7',
		'overlayColor'		: '#000',
		'type'				: 'iframe'
	});
	$(".tellafriend").fancybox({
		'width'				: 350,
		'height'			: 400,
		'autoScale'			: false,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'overlayOpacity'	: '0.7',
		'overlayColor'		: '#000',
		'type'				: 'iframe'
	});
	$("#livestreamcountdown").click(function(){
 		$(".prev").hide("fade", null, 1000);
 		$(".next").hide("fade", null, 1000);
 		$("#slidesnav .link").hide("fade", null, 1000);
 		$("#livestreaming").show( "fade", {direction: "vertical"}, 1000 );
		});
	$("#noteson").click(function(){
    	$("#fb_feed").toggle("fade", null, 1);
    	$("#notes").toggle( "fade", {direction: "vertical"}, 1 );
    	});
	$("#golivenowbutton").click(function(){
 		$(".prev").hide("fade", null, 1000);
 		$(".next").hide("fade", null, 1000);
 		$("#slidesnav .link").hide("fade", null, 1000);
 		$("#livestreaming").show( "fade", {direction: "vertical"}, 1000 );
		});
	$("#sawgrassdirections").click(function(){
 		$("#socialfeeds").animate({opacity: 0});
 		$("#sawgrasscampusmap").show("fade", null, 0);
 		$("#samplecampusmap").hide("fade", null, 0);
 		$('#campusesinfo').animate({
			left: 10,
			width: 954
		});
	});
	$("#sampledirections").click(function(){
 		$("#socialfeeds").animate({opacity: 0});
 		$("#sawgrasscampusmap").hide("fade", null, 0);
 		$("#samplecampusmap").show("fade", null, 0);
 		$('#campusesinfo').animate({
			left: 10,
			width: 954
		});
	});
	$("#closebutton").click(function(){
 		$("#socialfeeds").animate({opacity: 1.0});
 		$('#campusesinfo').animate({
			left: -100,
			width: 390
		});
	});
	jQuery('#twitterSocial').twitterSearch({
		term:'from:cbglades',
		title: ' ',
		titleLink: ' ',
		birdLink: ' ',
		avatar: false,
		pause:true
	});
});

function initialize() {
	var sawgrasslatlng = new google.maps.LatLng(26.2350369, -80.294197);
	var sawgrassOptions = {
		zoom: 15,
		center: sawgrasslatlng,
		disableDefaultUI: true,
		zoomControl: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("sawgrassmapcanvas"), sawgrassOptions);
	sawgrassMarker = new google.maps.Marker({
		map:map,
		draggable:false,
		position: sawgrasslatlng
	});
	
	var samplelatlng = new google.maps.LatLng(26.2701207, -80.2350406);
	var sampleOptions = {
		zoom: 15,
		center: samplelatlng,
		disableDefaultUI: true,
		zoomControl: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("samplemapcanvas"), sampleOptions);
	sampleMarker = new google.maps.Marker({
		map:map,
		draggable:false,
		position: samplelatlng
	});
}

function slide(where) {
	var item_width = $('#slider_ul li').outerWidth() + 10;
	
	if (where == 'left') {
		var left_indent = parseInt($('#slider_ul').css('left')) + item_width;
	} else {
		var left_indent = parseInt($('#slider_ul').css('left')) - item_width;
	}
	
	$('#slider_ul:not(:animated)').animate({'left' : left_indent},500,function() {
		if (where == 'left'){
			$('#slider_ul li:first').before($('#slider_ul li:last'));
		} else {
			$('#slider_ul li:last').after($('#slider_ul li:first'));
		}
		
		$('#slider_ul').css({'left' : '-203px'});
	});
}
