$(document).ready(function() {
	
	/* Funny mouseovers =) */
	$('.history img.normal').each(function(i) {
	
		$(this).data('normalSrc', $(this).attr('src'));
	
		$(this).hover(function() {
			var imgToShow = $(this).next('.over:hidden');
			if(imgToShow.length) {
				$(this).attr('src', imgToShow.attr('src'));				
			}	
		}, function() {
			$(this).attr('src', $(this).data('normalSrc'));						
		});
		
	});
	
	/* Homepage header slideshow  */
	if($('#headerSlideshow').length) {
		$('#headerSlideshow').cycle('fade');
	}
	
	/* IE PNG fix multiple filters */
    if (!$) return;
    $.fn.extend({
        fixPNG: function(sizingMethod, forceBG) {
                if (!($.browser.msie)) return this;
                var emptyimg = "empty.gif"; //Path to empty 1x1px GIF goes here
                sizingMethod = sizingMethod || "scale"; //sizingMethod, defaults to scale (matches image dimensions)
                this.each(function() {
                        var isImg = (forceBG) ? false : jQuery.nodeName(this, "img"),
                                imgname = (isImg) ? this.src : this.currentStyle.backgroundImage,
                                src = (isImg) ? imgname : imgname.substring(5,imgname.length-2);
                        this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + sizingMethod + "')";
                        if (isImg) this.src = emptyimg;
                        else this.style.backgroundImage = "url(" + emptyimg + ")";
                });
                return this;
        }
    });
	
	/* FancyZoom init */
	
	if($('.our-work-list').length) {
		$('.our-work-list li a').fancyZoom({scaleImg: true, directory: '/wp-content/themes/edurotheme/js/images', closeOnClick: true});
	}
	
	/* Menu nvav */
	
	if($('.our-work').length) {
		$('#menu-primary-menu li a').each(function() {
			
			if($(this).text() == 'Our Work') {
				
				$(this).closest('li').addClass('current-menu-item');
			
			}
		
		});
	}
	
	/* Homepage clickables */
	
	$('.homepageFeature').click(function() {
		window.location = $($(this).find('a')[0]).attr('href');
	});
	
	/* "Our Work" gallery */
	
	if($('.scrollable').length) {
		
		$('.scrollable').scrollable(); 
		
		$(".items > div > div").click(function() {
		
			var imgEl = $(this).find('img')[0];
		 
			// see if same thumb is being clicked
			if ($(this).hasClass("active")) { return; }
		 
			// calclulate large image's URL based on the thumbnail URL (flickr specific)
			var url = $(imgEl).attr("src");//.replace("_t", "");
		 
			// get handle to element that wraps the image and make it semi-transparent
			var wrap = $("#image_wrap").fadeTo("medium", 0.5);
		 
			// the large image from www.flickr.com
			var img = new Image();
			
			// add a cpation
			var caption = $(imgEl).attr('title');
		 
		 
			// call this function after it's loaded
			img.onload = function() {
		 
				// make wrapper fully visible
				wrap.fadeTo("fast", 1);
		 
				// change the image
				wrap.find("img").attr("src", url);
				
				// apply the new caption
				wrap.find('span.caption').html(caption);
				// if(caption.html()) ? caption.removeClass('hidden') : caption.addClass('hidden');		
		 
			};
		 
			img.src = url;
		 
			// activate item
			$(".items div > div").removeClass("active");
			$(this).addClass("active");
		 
		// when page loads simulate a "click" on the first image
		}).filter(":first").click();
	
	}
		

});
