/*/////////////////////////////////////////////////////////////////////////////////////////////////////*/
/* rwtessential.js.min */
/* @group rwtSetHeight plugin v1.0.0 05-13-10 14:27 modified from seyDoggy (Adam Merrifield) */
(function(jQuery) { jQuery.fn.rwtSetHeight = function() { var tallest = 0; jQuery(this).each(function(){ if (jQuery(this).outerHeight(true) > tallest) tallest = jQuery(this).outerHeight(true); }); jQuery(this).height(tallest); }; })(jQuery);/* @end */
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
jQuery(document).ready(function($){
		$('.filesharing-item').wrapAll('<div class="portfolio col-3" />');
		$('.filesharing-item').rwtSetHeight();
		$('.movie-thumbnail-frame').rwtSetHeight();

		// custom classes added to fileshare and movie index items to allow for rounded corners 
		$('.filesharing-item').addClass('portfolio-item one-third column');
		
		$('.movie-thumbnail-frame').addClass('css3');/* add rounded corners to movie index items */
		// custom classes added to the blog page
		$("ul.blog-tag-cloud li:first-child").addClass("first");
		
		
		$('#main-nav ul li ul').addClass('navSub');
		$('#main-nav ul > li > ul').parents('li').attr("class", "parent");
		$('#main-nav ul > li.parent').prepend('<span class="subIndicator"></span>');
		$("#main-nav ul li ul li .subIndicator").remove();
		$('#main-nav ul > li.parent').hover(function() {
		  $('.subIndicator').addClass('pretty-hover');
		}, function() {
		  $('.subIndicator').removeClass('pretty-hover');
		});

	});
jQuery(document).ready(function(jQuery){	
	if (jQuery('#myExtraContent4').length){
		jQuery('#extraContainer4').addClass('show4'); 		
	}	
	else if (jQuery('#extraContainer4').length)
	{
		jQuery('.footer-upper').remove();
			
	}

	
});

	
jQuery(document).ready(function($){

		
	/* DROP PANEL */
	$('#panelReveal, #panelCloser').click(function(e){
		e.preventDefault();
		$('#myExtraContent1').slideToggle();
		$('#panelCloser').toggleClass('reveal');		
	});	
		
		
	
	jQuery(document).ready(function($){
	$("#panelCloser").prependTo("#extraContainer1 .container");
	$(".footerUpper").prependTo(".footer-upper");
	
	});
	
	jQuery(document).ready(function($){
	var parentHeight = $('#masthead').height();
	var childHeight = $('#main-nav').height();
	$('#main-nav').css('margin-top', (parentHeight - childHeight) / 2);
	
	});
	jQuery(document).ready(function($){
	jQuery('img.imageStyle').each(function(){
	    jQuery(this).addClass('scale-with-grid');
	});
	});
	
	
	/* Style for JS-enabled */
	
	$('body').addClass('js-enabled');
	
	
	/* Keep track of the width for use in mobile browser displays */
	var currentWindowWidth = $(window).width();
	$(window).resize(function(){
		currentWindowWidth = $(window).width();
	});
	
	
	
	/* FLEX SLIDER */
	var $flexSlider = $('.flexslider');
	$flexSlider.flexslider({
		animation: "slide",
		controlsContainer: ".flex-container",
		prevText: "&larr;",
		nextText: "&rarr;",
		pausePlay:true,
		pauseOnHover:true,
		before:	function($slider){
			$slider.find('.flex-caption').fadeOut('fast');			
		},
		after: function($slider){
			$slider.find('.flex-caption').fadeIn();			
		}
	});
	$('.height-expand').each(function(){
		$(this).height($(this).prev().height());
	});
	
	
	
	/* PRETTY PHOTO */
	$("a[data-rel^='prettyPhoto']").prettyPhoto({
		social_tools: '',
		overlay_gallery: false
	});
	$("a[rel^='prettyPhoto']").prettyPhoto({
		overlay_gallery: false
	});
	
	/* MOBILE MENU */
    $('.mobileNavTab').click(function(e){
    	e.preventDefault();
    	var $menu = $($(this).attr('href'));
    	$menu.toggleClass('menu-open'); //toggle()
    	
    	if(typeof $navClose !== 'undefined' && !$menu.hasClass('menu-open') ){
    		console.log('hide');
    		$navClose.hide();
    	}
    });
	

	
    
    //IPHONE, IPAD, IPOD
    var deviceAgent = navigator.userAgent.toLowerCase();    
	var is_iOS = deviceAgent.match(/(iphone|ipod|ipad)/);
	
	if (is_iOS) {
        
        $('#main-nav').prepend('<a href="#" class="nav-close">&times;</a>'); // Close Submenu
        
        var $navClose = $('.nav-close');
        $navClose.hide().click(function(e){
        	e.preventDefault();
        	if(currentWindowWidth >= 767){
        		$(this).hide();
        	}
        });
		
        $('#main-nav > ul > li').hover(function(e){
        	e.preventDefault();
        	if(currentWindowWidth < 767){
        		$navClose.css({ 
        			top : $(this).position().top + 33,
        			left : '',
        			right : 0
        		}).show();
        	}
        	else{
        		$navClose.css({
        			left : $(this).position().left + parseInt($(this).css('marginLeft')),
        			top : '',
        			right : 'auto'
        		}).show();
        	}
        });
              
	}
	
	
	//NON-IOS
	if(!is_iOS){
		//iOS doesn't like CSS3 transitioning preloader, so don't use it
		$('.preload').preloadImages({
	        showSpeed: 200   // length of fade-in animation, should be .2 in CSS transition
	    });	   
		$('.video-container').addClass('video-flex');
	}
	
	
	//ANDROID
	var is_Android = deviceAgent.match(/(android)/);
	if(is_Android){
		//Do something special with Android
	}
    
	
	//HTML5 Fallbacks
	if(!Modernizr.input.placeholder){
		$('.fallback').show();
	}
		
});



//Image Preloader
jQuery.fn.preloadImages = function(options){

    var defaults = {
        showSpeed: 200
    };

    var options = jQuery.extend(defaults, options);

	return this.each(function(){
		var $container = jQuery(this);
		var $image = $container.find('img');

		$image.addClass('loading');	//hide image while loading
         
		$image.bind('load error', function(){
			$image.removeClass('loading'); //allow image to display (will fade in with CSS3 trans)
			
			setTimeout(function(){ 
				$container.removeClass('preload'); //remove the preloading class to swap the bkg
			}, options.showSpeed);
			
		});
		
		if($image[0].complete || (jQuery.browser.msie )) { 
			$image.trigger('load');	//IE has glitchy load triggers, so trigger it automatically
		}
    });
}
var imgSizer = {
     Config : {
          imgCache : []
          ,spacer : "/path/to/your/spacer.gif"
     }
     ,collate : function(aScope) {
          var isOldIE = (document.all && !window.opera && !window.XDomainRequest) ? 1 : 0;
          if (isOldIE && document.getElementsByTagName) {
               var c = imgSizer;
               var imgCache = c.Config.imgCache;
               var images = (aScope && aScope.length) ? aScope : document.getElementsByTagName("img");
               for (var i = 0; i < images.length; i++) {
                    images.origWidth = images.offsetWidth;
                    images.origHeight = images.offsetHeight;
                    imgCache.push(images);
                    c.ieAlpha(images);
                    images.style.width = "100%";
               }
               if (imgCache.length) {
                    c.resize(function() {
                         for (var i = 0; i < imgCache.length; i++) {
                              var ratio = (imgCache.offsetWidth / imgCache.origWidth);
                              imgCache.style.height = (imgCache.origHeight * ratio) + "px";
                         }
                    });
               }
          }
     }
     ,ieAlpha : function(img) {
          var c = imgSizer;
          if (img.oldSrc) {
               img.src = img.oldSrc;
          }
          var src = img.src;
          img.style.width = img.offsetWidth + "px";
          img.style.height = img.offsetHeight + "px";
          img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
          img.oldSrc = src;
          img.src = c.Config.spacer;
     }
     // Ghettomodified version of Simon Willison's addLoadEvent() -- http://simonwillison.net/2004/May/26/addLoadEvent/
     ,resize : function(func) {
          var oldonresize = window.onresize;
          if (typeof window.onresize != 'function') {
               window.onresize = func;
          } else {
               window.onresize = function() {
                    if (oldonresize) {
                         oldonresize();
                    }
                    func();
               }
          }
     }
}




