(function(jQuery) {
	jQuery.fn.fadeIn = function(speed, callback) { 
		return this.animate({opacity: 'show'}, speed, function() { 
			if (jQuery.browser.msie)  
				this.style.removeAttribute('filter');  
			if (jQuery.isFunction(callback)) 
				callback();  
		}); 
	}; 
	 
	jQuery.fn.fadeOut = function(speed, callback) { 
		return this.animate({opacity: 'hide'}, speed, function() { 
			if (jQuery.browser.msie)  
				this.style.removeAttribute('filter');  
			if (jQuery.isFunction(callback)) 
				callback();  
		}); 
	}; 
	 
	jQuery.fn.fadeTo = function(speed,to,callback) { 
		return this.animate({opacity: to}, speed, function() { 
			if (to == 1 && jQuery.browser.msie)  
				this.style.removeAttribute('filter');  
			if (jQuery.isFunction(callback)) 
				callback();  
		}); 
	}; 
})(jQuery);


function HomeLeftColumn() {
    jQuery(this).click(function() {
		jQuery('div.HomeLeftColumn ul.TabMenu a').removeClass('Selected');
		jQuery(this).addClass('Selected');
		jQuery('div.HomeLeftColumn div.TabBody div.TabContainer').hide();
        var e = "div#" + jQuery(this).attr('title');
		jQuery(e).fadeIn('slow', function() {});
		var RSSTitle = jQuery(this).attr("title") + " RSS Feed";
		var RSSPath = jQuery(this).attr("title");
		switch (RSSPath){
		case 'News':
		  var Path = '/index.php/rss_feeds/newsfeed/';
		  break;
		case 'Events':
		  var Path = '/index.php/rss_feeds/eventsfeed/';
		  break;
		default:
		  var Path = '/index.php/rss_feeds/newsfeed/';
		}
		jQuery("div.HomeLeftColumn div.RssFeed a").attr({ href: Path, alt: RSSTitle });
        return false;
    });
}

function HomeMiddleColumn() {
    jQuery(this).click(function() {
		jQuery('div.HomeMiddleColumn ul.TabMenu a').removeClass('Selected');
		jQuery(this).addClass('Selected');
		jQuery('div.HomeMiddleColumn div.TabBody div.TabContainer').hide();
        var e = "div#" + jQuery(this).attr('title');
		jQuery(e).fadeIn('slow', function() {});
		var RSSTitle = jQuery(this).attr("title") + " RSS Feed";
		var RSSPath = jQuery(this).attr("title");
		switch (RSSPath){
		case 'Videos':
		  var Path = 'http://gdata.youtube.com/feeds/base/users/sdlplive/uploads';
		  break;
		case 'Photos':
		  var Path = 'http://api.flickr.com/services/feeds/photos_public.gne?id=37865532@N05&lang=en-us&format=rss_200';
		  break;
		default:
		  var Path = 'http://gdata.youtube.com/feeds/base/users/sdlplive/uploads';
		}
		jQuery("div.HomeMiddleColumn div.RssFeed a").attr({ href: Path, alt: RSSTitle });
        return false;
    });
}

function HomeRightColumn() {
    jQuery(this).click(function() {
		jQuery('div.HomeRightColumn ul.TabMenu a').removeClass('Selected');
		jQuery(this).addClass('Selected');
		jQuery('div.HomeRightColumn div.TabBody div.TabContainer').hide();
        var e = "div#" + jQuery(this).attr('title');
		jQuery(e).fadeIn('slow', function() {});
        return false;
    });
}

jQuery(document).ready(function(){
	// Home Columns
	jQuery("div.HomeLeftColumn ul.TabMenu a").livequery(HomeLeftColumn);
	jQuery("div.HomeMiddleColumn ul.TabMenu a").livequery(HomeMiddleColumn);
	jQuery("div.HomeRightColumn ul.TabMenu a").livequery(HomeRightColumn);
	
	// Top Nav
	var userAgent = navigator.userAgent.toLowerCase();
	if(jQuery.browser.mozilla){
		jQuery(".en_MainMenuLeft li, .en_MainMenuRight li").bind("mouseover",function(){
			this.className += "_over over";
		}).bind("mouseout",function(){
			this.className = this.className.replace("_over over", "");
		});
	}
	else{
		jQuery(".en_MainMenuLeft li, .en_MainMenuRight li").bind("mouseenter",function(){
			this.className += "_over over";
		}).bind("mouseleave",function(){
			this.className = this.className.replace("_over over", "");
		});
	}
	
	// Top Search Dropdown
	jQuery('.InputFocus').each(function() {
		var default_value = this.value;
		jQuery(this).focus(function() {
			if(this.value == default_value) {
				this.value = '';
				jQuery('.AdvancedSearch').fadeIn('slow', function() {});}
		});
		jQuery(this).blur(function() {
			if (this.value=='' || this.value==' ' || this.value=='  ') {
				this.value = default_value;
				jQuery('.AdvancedSearch').fadeOut('slow', function() {});}
		});
	});
	
	// Bottom Search Dropdown
	jQuery('.InputFocus2').each(function() {
		var default_value2 = this.value;
		jQuery(this).focus(function() {
			if(this.value == default_value2) {
				this.value = '';
				jQuery('.AdvancedSearch2').fadeIn('slow', function() {});}
		});
		jQuery(this).blur(function() {
			if (this.value=='' || this.value==' ' || this.value=='  ') {
				this.value = default_value2;
				jQuery('.AdvancedSearch2').fadeOut('slow', function() {});}
		});
	});
	
	//Google Map
	jQuery('a.MapAll').livequery('click', function(event) { 
        loadMapAll();
        return false; 
    });
	
	jQuery('a.MapMP').livequery('click', function(event) { 
		loadMapMP();
        return false; 
    });
	
	jQuery('a.MapMLA').livequery('click', function(event) { 
		loadMapMLA();
        return false; 
    });
	
	jQuery('a.MapCouncillor').livequery('click', function(event) { 
		loadMapCouncillor();
        return false; 
    });
	
	//Contact Map	
	jQuery('a.load_map').livequery('click', function(event) {
        loadContactMap();
        return false; 
    });
	
	//Modal Window
	jQuery('a[name=modal]').click(function(e) {
		var id = jQuery(this).attr('href');
		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(window).width();
		jQuery('#popup_bg').css({'width':maskWidth,'height':maskHeight});	
		jQuery('#popup_bg').fadeIn(1000, function() {});
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
		jQuery(id).css("top", (jQuery(window).scrollTop() + 38) + "px");
		jQuery(id).css('left', winW/2-jQuery(id).width()/2);
		jQuery(id).fadeIn(2000, function() {});
		jQuery('#popup_bg').fadeTo("slow",0.3);
		return false;
	});
	jQuery('a.close_popup').click(function(e) {										   
		jQuery('#popup_bg, .window').fadeOut('fast', function() {});
		return false;
	});	
	jQuery(document).keypress(function(e){
		if(e.keyCode==27){
			jQuery('#popup_bg, .window').fadeOut('fast', function() {});}
	});
	
	//External Form
	jQuery('.external').each(function() {
		jQuery(this).attr('target', '_blank');
		return false;
	});
	
	//Print Friendly
	jQuery('#CampaignPrint a').click(function(e) {										   
		window.print();
		return false;
	});	
							 
});