(function($){
    
	
	$(document).ready(function(){
		
		// Test for DivX player
		function DWPCheck()
			{
				dwpPlugin = new Object;
				dwpPlugin.version = "None";
				dwpPlugin.installed = false;
			
				var userAgent = navigator.userAgent;
				if (userAgent.search(/msie/i) != -1) // If IE
				{
					var dwp = null;
					try
					{
						dwp = new ActiveXObject('npdivx.DivXBrowserPlugin.1');
					} catch (e) { }
			
					if (dwp)
					{
						dwpPlugin.version = dwp.GetVersion();
						dwpPlugin.installed = true;
					}
			
				}
				else // Else every other browser
				{
					if (navigator.plugins != null && navigator.plugins.length > 0)
					{
						plugins = navigator.plugins;
						for (var i = 0; i < plugins.length; i++)
						{
							// Search for DivX Web Player and version number
							var re = /DivX(?: | Plus )Web Player[a-z ]*([0-9.]*)/;
							var results = re.exec(plugins[i].description);
			
							if (results)
							{
								dwpPlugin.installed = true;
								dwpPlugin.version = results[1];
			
								// End search
								i = plugins.length;
							}
						}
					}
				}
			
				// Perform different actions based on DWP x.y.z version
				switch (dwpPlugin.version.substr(0, 5))
				{
					case "None":
						return false;
						break;
					default:
						if (dwpPlugin.version.substr(0, 1) == "1") // If DWP 1.x
						{
							dwpPlugin.formats = new Array('AVI');
						}
						else // 2.x or higher
						{
							dwpPlugin.formats = new Array('MKV', 'AVI');
						}
						return true;
				}
			}
			
		DWPCheck();
		
		// if (dwpPlugin.installed == true) {	$("embed#backgroundvideo").hide(); };
		
		//hideMe / showMe
	
		$(".hideMe").hide();
		
		
	
		$(".showIt").toggle(function(){
			$(this).children(".indicator").html("-");
			$(this).next(".hideMe").fadeIn(500, function(){setSidebarHeight();});
			}, function(){
			$(this).children(".indicator").html("+");
			$(this).next(".hideMe").fadeOut(500);
		});
		
		// Show background picture on click of "Show Full Picture"
		$("#hide-content-btn").toggle(function(){
				$("#container, #bg-curtain").fadeOut();
				$(this).html("Show Content");
			}, function(){
				$("#container, #bg-curtain").fadeIn();
				$(this).html("Show Full Picture");
			});
		
		$("#searchresults").children("article").click(function(){
			window.location.href = $(this).find("h2 a").attr("href");
		});
		//create twitter feed in header 
		$("#tweettext").getTweet("toccoafalls").bind("twitterfail", function(){ $("#twitter").hide(); }); //front-page.php
		$("#toccoafalls-twitter").getTweet("toccoafalls", 3); // template-news.php
		$("#admissions-twitter").getTweet("tfcadmissions", 1); // template-admissions.php
		$("#studentlife-twitter").getTweet("tfcstudev", 3); // template-studentlife.php
		$("#athletics-twitter").getTweet("tfcathletics", 5); // template-athletics.php
		$("#toccoafalls-sidebar-twitter").getTweet("toccoafalls", 3); // single.php
		$("#alumni-twitter").getTweet("toccoafallsalum", 6); // single.php
		
		// Flickr for Athletics
			$('ul#athleticsflickr-feed').jflickrfeed({
    			limit: 16,
    			qstrings: {
        			id: '66277576@N05'
    			},
    			itemTemplate: '<li><a href="{{image_b}}" target="_blank" rel="fancybox"><img alt="{{title}}" src="{{image_s}}" /></a></li>'
			}, function(data){
				$("ul#athleticsflickr-feed a").fancybox();
			});
			
		// Flickr feed for Student Life 
			$('ul#studlifeflickr-feed').jflickrfeed({
    			limit: 16,
    			qstrings: {
        			id: '41612457@N08'
    			},
    			itemTemplate: '<li><a href="{{image_b}}" target="_blank" rel="fancybox"><img alt="{{title}}" src="{{image_s}}" /></a></li>'
			}, function(data){
				$("ul#studlifeflickr-feed a").fancybox();
			});
			
		// Flickr feed for News / Events Page
			$('ul#newsflickr-feed').jflickrfeed({
    			limit: 15,
    			qstrings: {
        			id: '41612457@N08'
    			},
    			itemTemplate: '<li><a href="{{image_b}}" target="_blank" rel="fancybox"><img alt="{{title}}" src="{{image_s}}" /></a></li>'
			}, function(data){
				$("ul#newsflickr-feed a").fancybox();
			});

		// To set height of sidebar equal to height of left content, unless left content is taller
		function setSidebarHeight () {
			var leftContentHeight = $("#left_content").height();
			var rightContentHeight = $("#right_content").outerHeight();
			if (leftContentHeight > rightContentHeight ) {
				$("#right_content").height(leftContentHeight);
			}
		}
		
		setSidebarHeight();
		
		// Initiate slider on home page
		
		$("#front-slider").wbSlider();
		$("#athletics-home-slider").wbSlider();
		$("#news-main-slider").wbSlider({"direction" : "up", "time" : 5000, "speed" : 2000});
		
		function horizMenu(){
		    var outsideW = $(".horiz-nav-wrap").width();
		    var totalWidths = 0;
		    var liNum = 0;
		    $(".horiz-nav-wrap ul li").each(function(){
		       totalWidths += $(this).width();
		       liNum++;
		    });
		    var leftover = outsideW - totalWidths;
		    var mainMenuMargin = (leftover / liNum / 2) - 1;
		 	$(".horiz-nav-wrap ul li").css({
    		    marginRight : mainMenuMargin,
				marginLeft : mainMenuMargin
    		});   
		};
		setTimeout(horizMenu, 50);
		
		// set height of News-Column on top-level pages equal to content
		
		function setNewsColHeight() {
			var pageContentHeight = $("div#sections-wrap").height();
			$("div.top-level-page.news-column").height(pageContentHeight);
		}
		setNewsColHeight();
		
		// Animate opacity of news items for Athletics (right side)
		
		var athSlideOpac = $(".athletics-slider-right .wbSlide").css("opacity");
		$(".athletics-slider-right .wbSlide").hover( function() {
			$(this).animate({
				opacity : 1.0 },200)
			},
			function () {
			$(this).animate({
			opacity : athSlideOpac
			},200)
		});
		
		//looping video for firefox (doesn't support the auto loop property)
	    $("#backgroundvideo").bind('ended', function(){
		    this.play();
	    });
	});
	
	
	
})(jQuery);
