$(window).load(function () {

	$("#cert").click(function() {
		if ($('#cert').attr('checked')) {
			$('#B1').attr('disabled','');
		}
		else {
			$('#B1').attr('disabled','disabled');
		}
	});

	
// NIVO SLIDER
$('#pensaSlide').nivoSlider({
	effect: 'random', // Specify sets like: 'fold,fade,sliceDown'
	startSlide: 0, 
	boxCols: 8,
	boxRows: 3,
	slices: 9,
	directionNav: false, // Next & Prev navigation
	controlNav: false, // 1,2,3... navigation
	keyboardNav: false, // Use left & right arrows  
	slideshowEnd: function(){startNews();}
});

//NAVIGATION W/ HOVER INTENT
var config = {    
	sensitivity: 5, // number = sensitivity threshold (must be 1 or higher)    
	interval: 100,  // number = milliseconds for onMouseOver polling interval  
	over: showMenu, // function = onMouseOver callback (REQUIRED)    
	timeout: 300, // number = milliseconds delay before onMouseOut    
	out: hideMenu // function = onMouseOut callback (REQUIRED)    
};

function showMenu() {
	if(!$(this).hasClass('first')) {
		$('div#newsItems ul li').removeClass('active');
	$("#sliderWrap").fadeOut();
	$("#newsDisplay").fadeOut();	
	$('ul:first',this).stop().slideDown(400);
	if($('#pensaSlide').length != 0) // no element found
		{$('#pensaSlide').data('nivoslider').stop();} //Stop the Slider
		
	
	}
}

function hideMenu() {
	if(!$(this).hasClass('first')) {
			$("#sliderWrap").fadeIn();
		$("#newsDisplay").fadeOut();
		$('ul:first',this).stop().slideUp(400);
		if($('#pensaSlide').length != 0) // no element found
		{$('#pensaSlide').data('nivoslider').start();} //Start the Slider

	}
}

$("ul.nav li").hoverIntent( config )

$("#newsItems ul li").click(function(){
		//clearInterval(timer);
		//if($('#pensaSlide').length != 0) // no element found

	$('#pensaSlide').data('nivoslider').stop(); //Stop the Slider
	
	$("#sliderWrap").fadeOut();
		
	$("#newsDisplay").fadeIn();
    //Set Variables
    var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
    var imgDesc = $(this).find('.block').html();  //Get HTML of the "block" container
    var imgDescHeight = $("#newsDisplay").find('.block').height(); //Find the height of the "block"

    if ($(this).is(".active")) {  //If the list item is active/selected, then...
        return false; // Don't click through - Prevents repetitive animations on active/selected list-item
    } else { //If not active then...
        //Animate the Description
        $("#newsDisplay img").animate({ opacity: 0}, 250 );
			$("#newsDisplay .block").animate({ opacity: 0, marginBottom: -

imgDescHeight }, 250 , function() {
			$("#newsDisplay .block").html(imgDesc).animate({ opacity: 0.85, 

marginBottom: "0" }, 250 );
			$("#newsDisplay img").attr({ src: imgTitle }).animate({ opacity: 1}, 

250 );
		});
		
		
    }
    //Show active list-item
    $("#newsItems ul li").removeClass('active'); //Remove class of 'active' on all list-items
    $(this).addClass('active');  //Add class of 'active' on the selected list
    return false;
})
.hover(function(){ //Hover effects on list-item
    $(this).addClass('hover'); //Add class "hover" on hover
    }, function() {
    $(this).removeClass('hover'); //Remove class "hover" on hover out
});

	


$("a.collapse").click(function(){
    $(".desc .block").slideToggle(); //Toggle the description (slide up and down)
    $("a.collapse").toggleClass("show"); //Toggle the class name of "show" (the hide/show tab)
	return false;
});	

$("a.btnPensa").click(function(){
	$("#newsItems ul li").removeClass('active'); //Remove class of 'active' on all list-items
	$("#newsDisplay").hide();
    $("#sliderWrap").show();
	
	$('#pensaSlide').nivoSlider();
	$('#pensaSlide').data('nivoslider').start(); //Start the Slider
	return false;
 });
 
$(function() {
	$(window).scroll(function() {
		if($(this).scrollTop() != 0) {
			$('#backToTop').show();	
		} else {
			$('#backToTop').hide();
		}
	});
 
	$('#backToTop').click(function() {
		$('body,html').animate({scrollTop:0},800);
	});	
}); 
	$("#dept_selection").hide();

	$("#dept_select, .form-radio-311").change(function() {
		var selection = $(this).val();
		if (selection) {
			$(".view iframe").fadeOut('Fast', function() {
				$(".view").html("<img src='http://www.cityofpensacola.com/images/ajax-loader.gif' />");
				$(".view").append("<iframe width='100%' height='1000px' id='iframe_311' scrolling='no'></iframe>");
				$("iframe#iframe_311").attr('src', selection);
				$("iframe#iframe_311").load(function() {
					$(".view img").remove();
					if (selection == "http://webpub.pensacolacitygov.com/GBAMSWEBCITIZEN/?FUI=PENSACOLA311") {
						$("#dept_selection").hide();
					}
				});
			});
		} else if (!selection) {
			$(".view iframe").fadeOut('Fast');
			$("#dept_selection").show();
		}
		});
});


// HOME PAGE TABS		
function services() {
	$("#showServices").show();
	$("#btnServices").addClass("current");
	
	$("#showVisitors").hide();
	$("#btnVisitors").removeClass("current");
	
	$("#showCommunity").hide();
	$("#btnCommunity").removeClass("current");
	
	$("#showCalendar").hide();
	$("#btnCalendar").removeClass("current");
}
function visitors() {
	$("#showServices").hide();
	$("#btnServices").removeClass("current");
	
	$("#showVisitors").show();
	$("#btnVisitors").addClass("current");
	
	$("#showCommunity").hide();
	$("#btnCommunity").removeClass("current");
	
	$("#showCalendar").hide();
	$("#btnCalendar").removeClass("current");
}
function community() {
	$("#showServices").hide();
	$("#btnServices").removeClass("current");
	
	$("#showVisitors").hide();
	$("#btnVisitors").removeClass("current");
	
	$("#showCommunity").show();
	$("#btnCommunity").addClass("current");
	
	$("#showCalendar").hide();
	$("#btnCalendar").removeClass("current");
}
function calendar() {
	$("#showServices").hide();
	$("#btnServices").removeClass("current");
	
	$("#showVisitors").hide();
	$("#btnVisitors").removeClass("current");
	
	$("#showCommunity").hide();
	$("#btnCommunity").removeClass("current");
	
	$("#showCalendar").show();
	$("#btnCalendar").addClass("current");
}


// FOOTER NAVIGATION
function expand() {
	$("#footerNav").slideToggle("slow");
	$('html, body').animate({scrollTop: $(document).height()}, 700);
}

// FOOTER NAVIGATION
function expandVideo() {
	$("#footerNavVideo").slideToggle("slow");
	$('html, body').animate({scrollTop: $(document).height()}, 100);
}



//TRANSFER FROM PENSASLIDE TO NEWS
function startNews(){

	var timer = window.setInterval('slideSwitchTimed()', 6000);
	$('ul.nav li:not(:first)').hover(function(){
		clearInterval(timer);
	});
	
	
	$("#newsItems ul li").click(function(){
		clearInterval(timer);
		//if($('#pensaSlide').length != 0) // no element found

	$('#pensaSlide').data('nivoslider').stop(); //Stop the Slider
	
	$("#sliderWrap").fadeOut();
		
	$("#newsDisplay").show('fade');
    //Set Variables
    var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
    var imgDesc = $(this).find('.block').html();  //Get HTML of the "block" container
    var imgDescHeight = $("#newsDisplay").find('.block').height(); //Find the height of the "block"

    if ($(this).is(".active")) {  //If the list item is active/selected, then...
        return false; // Don't click through - Prevents repetitive animations on active/selected list-item
    } else { //If not active then...
        //Animate the Description
        $("#newsDisplay img").animate({ opacity: 0}, 250 );
			$("#newsDisplay .block").animate({ opacity: 0, marginBottom: -

imgDescHeight }, 250 , function() {
			$("#newsDisplay .block").html(imgDesc).animate({ opacity: 0.85, 

marginBottom: "0" }, 250 );
			$("#newsDisplay img").attr({ src: imgTitle }).animate({ opacity: 1}, 250 );
		});
		
		
    }
    //Show active list-item
    $("#newsItems ul li").removeClass('active'); //Remove class of 'active' on all list-items
    $(this).addClass('active');  //Add class of 'active' on the selected list
    return false;
})
.hover(function(){ //Hover effects on list-item
    $(this).addClass('hover'); //Add class "hover" on hover
    }, function() {
    $(this).removeClass('hover'); //Remove class "hover" on hover out
});



	
	$('#pensaSlide').data('nivoslider').stop(); //Stop the Slider
	
	$("#sliderWrap").hide();
		
	$("#newsDisplay").fadeIn();
	
	//Set Variables
    var imgTitle = $('#newsItems ul li:first').find('a').attr("href"); //Get Main Image URL
    var imgDesc = $('#newsItems ul li:first').find('.block').html();  //Get HTML of the "block" container
    var imgDescHeight = $("#newsDisplay").find('.block').height(); //Find the height of the 

"block"
	
	$("#newsDisplay img").animate({ opacity: 0}, 250 );
		$("#newsDisplay .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 

250 , function() {
		$("#newsDisplay .block").html(imgDesc).animate({ opacity: 0.85, marginBottom: 

"0" }, 250 );
		$("#newsDisplay img").attr({ src: imgTitle }).animate({ opacity: 1}, 250 );
	});
	
	$("#sliderWrap").delay(200).slideUp(800);
	
	//Show active list-item
    $('#newsItems ul li:first').addClass('active');  //Add class of 'active' on the selected list
	
	//$(function() {
		//setInterval( 'slideSwitchTimed()', 6000 );
	//});
	

}

function slideSwitchTimed() {
	$active = $('#newsItems ul li.active').next();
	
	if ( $active.length == 0 ) $active = $('#newsItems ul li:first'); //goes back to start when finishes
	
	var $prev = $('#newsItems ul li.active');
	$prev.removeClass('active');
	$active.addClass('active');

	//Set Variables
	var imgTitle = $active.find('a').attr("href"); //Get Main Image URL
	var imgDesc = $active.find('.block').html(); //Get HTML of the "block" container
	var imgDescHeight = $(".main_image").find('.block').height(); //Find the height of the "block"
	
	if ($(this).is(".active")) { //If the list item is active/selected, thenō
		return false; // Don't click through  Prevents repetitive animations on active/selected list-item
	} else { //If not active thenō
	//Animate the Description
		$("#newsDisplay img").animate({ opacity: 0}, 250 );
		$("#newsDisplay .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 

250 , function() {
			$("#newsDisplay .block").html(imgDesc).animate({ opacity: 0.85, 

marginBottom: "0" }, 250 );
			$("#newsDisplay img").attr({ src: imgTitle }).animate({ opacity: 1}, 

250 );
		});
	}
	return false;
}	
