/*
Bones Scripts File
Author: Eddie Machado

This file should contain any js scripts you want to add to the site.
Instead of calling it in the header or throwing it inside wp_head()
this file will be called automatically in the footer so as not to
slow the page load.

*/

// IE8 ployfill for GetComputed Style (for Responsive Script below)
if (!window.getComputedStyle) {
	window.getComputedStyle = function(el, pseudo) {
		this.el = el;
		this.getPropertyValue = function(prop) {
			var re = /(\-([a-z]){1})/g;
			if (prop == 'float') prop = 'styleFloat';
			if (re.test(prop)) {
				prop = prop.replace(re, function () {
					return arguments[2].toUpperCase();
				});
			}
			return el.currentStyle[prop] ? el.currentStyle[prop] : null;
		}
		return this;
	}
}

// as the page loads, call these scripts
jQuery(document).ready(function($) {
	
	//$('html').css('margin-top','0px !important');

	$('.easingsliderlite-viewport').after('<span class="slide-title">VNA</span>')
	$('.easingsliderlite-viewport').append('<p class="slide-text">VNA</p>');
	$('.easingsliderlite-viewport').append('<span class="arrow-down"></span>');
	$('.service a').append('<span class="service-title"></span>');
	
	// initial set
	$('.slide-title').html($('.easingsliderlite-slide.active img').attr('title'));
	$('.slide-text').html($('.easingsliderlite-slide.active img').attr('alt'));
	$('.service-title').each(function(){
		$(this).html($(this).parent().find('img').attr('alt'));
	});
	
	// hide portion of home text
	var homeText = $('.home .entry-content').html();
	var homeText1 = homeText.substr(0,1200);
	var homeText2 = homeText.substr(1200, homeText.length);
	$('.home .entry-content').html(homeText1);
	$('.home .entry-content p:last-child').append(' <a class="read-more">... read more ...</a>');
	
	$('.read-more').bind('click', function() {
		$('.read-more').css('display', 'none');
	  	$('.home .entry-content').html(homeText);
	});
	
	// interval as to not mess with plugin
	setInterval(function(){
		$('.slide-title').html($('.easingsliderlite-slide.active img').attr('title'));
		$('.slide-text').html($('.easingsliderlite-slide.active img').attr('alt'));
		 }, 500);
	
	/* getting viewport width */
	var responsive_viewport = $(window).width();
	
	/* if is below 481px */
	if (responsive_viewport < 481) {
	
	} /* end smallest screen */
	
	/* if is larger than 481px */
	if (responsive_viewport > 481) {
	
	} /* end larger than 481px */
	
	/* if is above or equal to 768px */
	if (responsive_viewport >= 768) {
	
		/* load gravatars */
		$('.comment img[data-gravatar]').each(function(){
			$(this).attr('src',$(this).attr('data-gravatar'));
		});
		
	}
	
	/* off the bat large screen actions */
	if (responsive_viewport > 1030) {
	
	}
	
	// creates the mobile menu
	$('<select />').appendTo('#mobile-menu');
	
	// Create default option "Go to..."
	$('<option />', {
		 'selected': 'selected',
		 'value'   : '',
		 'text'    : ' Menu'
	}).appendTo('#mobile-menu select');
	
	// Populate dropdown with menu items
	$('.main-menu a').each(function() {
		var el = $(this);
		$('<option />', {
			 'value'   : el.attr('href'),
			 'text'    : el.text()
		}).appendTo('#mobile-menu select');
	});
	
	$('.members-menu a').each(function() {
		var el = $(this);
		$('<option />', {
			 'value'   : el.attr('href'),
			 'text'    : el.text()
		}).appendTo('#mobile-menu select');
	});
	
	$("#mobile-menu select").change(function() {
		window.location = $(this).find("option:selected").val();
	});

 
}); /* end of as page load scripts */


/*! A fix for the iOS orientationchange zoom bug.
 Script by @scottjehl, rebound by @wilto.
 MIT License.
*/
(function(w){
	// This fix addresses an iOS bug, so return early if the UA claims it's something else.
	if( !( /iPhone|iPad|iPod/.test( navigator.platform ) && navigator.userAgent.indexOf( "AppleWebKit" ) > -1 ) ){ return; }
	var doc = w.document;
	if( !doc.querySelector ){ return; }
	var meta = doc.querySelector( "meta[name=viewport]" ),
		initialContent = meta && meta.getAttribute( "content" ),
		disabledZoom = initialContent + ",maximum-scale=1",
		enabledZoom = initialContent + ",maximum-scale=10",
		enabled = true,
		x, y, z, aig;
	if( !meta ){ return; }
	function restoreZoom(){
		meta.setAttribute( "content", enabledZoom );
		enabled = true; }
	function disableZoom(){
		meta.setAttribute( "content", disabledZoom );
		enabled = false; }
	function checkTilt( e ){
		aig = e.accelerationIncludingGravity;
		x = Math.abs( aig.x );
		y = Math.abs( aig.y );
		z = Math.abs( aig.z );
		// If portrait orientation and in one of the danger zones
		if( !w.orientation && ( x > 7 || ( ( z > 6 && y < 8 || z < 8 && y > 6 ) && x > 5 ) ) ){
			if( enabled ){ disableZoom(); } }
		else if( !enabled ){ restoreZoom(); } }
	w.addEventListener( "orientationchange", restoreZoom, false );
	w.addEventListener( "devicemotion", checkTilt, false );
})( this );