// NOTE
//	This is the main Javascript file for the 
//	"SWR - Smart Sustainable Wast Management" website
//  All scripts here use JQuery
	
// ========================================================================*/

$(document).ready(function(){

// ========= HEADER ===========

	// ADD HOVER TO TOP NAVIGATION LIST (FOR IE)
	$('#mainNavigation li').hover(function() {
		$(this).addClass('hover');
			}, function() {
		$(this).removeClass('hover');
	});
	
	// REMOVE LAST BACKGROUND DIVIDER ON MAIN NAV
	$("#header #mainNavigation li:last").css({background:"none"});
		

// ========= CONTENT FOR ALL PAGES ===========		
	
	// function to replace submit button with graphic
	var submitButtonReplacement = {
		initialize: function(classname){
			this.allButtons = $('input.'+classname);
			this.replaceButtons();
		},
		replaceButtons: function(){
			this.allButtons.each( function() {
				var input = $(this);
				$('<a href="#"><em></em>' + this.value + '</a>')
					.attr('id', this.id)
					.insertBefore(this)
					.click( function() {
						input.click(); 
						return false;
					});
				input.hide();
			});
		}
	}
	
	$(document).ready(function(){
		submitButtonReplacement.initialize('.replaceSubmit, #sendbutton3, #sendbutton, #sendbutton2');
	});
	
	
// ========= CONTENT FOR SPECIFIC PAGES ===========	

	// HOMEPAGE BANNER
	$(document).ready(function(){
		$('#home #banner p.title span').flipv_up();
		lastBlock = $("#a1");
		maxWidth = 721;
	        minWidth = 50;	
	
	        $("#banner .section").hover(
	         function(){
	          $(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:700 });
		  $(this).animate({width: maxWidth+"px"}, { queue:false, duration:700});
		  lastBlock = this;
	         }
	        );
	});	
	
	// HOMEPAGE TABS 
	// for for news feed
	$(function () {
		var tabContainers = $('#latestNews > dl, ul.caseStudiesList, #news #leftColumn dl, #leftColumn ul.imageList');
		tabContainers.hide().filter(':first').show();		
		$('#latestNews ul a, #caseStudies #leftColumn ul.pagination a, #caseStudies #leftColumn .pagination ul a, #leftColumn ul.pagination a, #news #leftColumn .pagination ul a, #leftColumn .pagination ul a').click(function () {
			tabContainers.hide();
			tabContainers.filter(this.hash).show();
			$('#latestNews ul li, #caseStudies #leftColumn ul.pagination li, #caseStudies #leftColumn .pagination ul a, #leftColumn ul.pagination li, #leftColumn .pagination ul li').removeClass('selected');
			$(this).parent().addClass('selected');
			return false;
		}).filter(':first').click();
	});
	
	// CASE STUDY CAROUSEL FOR THUMBS
	jQuery(document).ready(function() {
	    jQuery('#caseStudyThumbs').jcarousel();
	});
	
	// FAQ
	$(document).ready(function () {
	    $('dl#faqList dd .textArea').hide();
	        $('dl#faqList dt').click(function () {
			$(this).next("dd:has('.textArea')").children().slideToggle(400).parents().prev().toggleClass('open');
	    });

	    $('dl#faqList dt').hover(function() {
	        $(this).addClass('hover');
	    }, function() {
	        $(this).removeClass('hover');	
	    });       	
	});
});

