/*
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.

*/


// as the page loads, cal these scripts
$(document).ready(function() {

	// drop down menu on mobile
	$("nav select").change(function() {
  		window.location = $(this).find("option:selected").val();
	});

	// replace logo with sun on bones page
	$('.page-template-page-bones-php #logo img, .page-template-page-update-bones-php #logo img').fadeOut().attr("src", "http://themble.com/wp-content/themes/themblev3/library/images/bones/bones-logo.png").fadeIn();
	// remove footer text on Bones page (there's no need for it)
	$('.page-template-bones-php .foot-bones').hide();
	
	// support page sidebar
	$("a.more").click(function() {
		if( $('.more-to-view').hasClass('visible')) {
	    	var elem = $(this);
	    	$('.more-to-view.visible').slideToggle('fast', function() { 
	        	$(this).removeClass('visible');
	        	if ($('li').index(elem.parent()) != $('li').index($(this).parent()))
	        	elem.parent().find('.more-to-view').slideToggle("fast").addClass('visible');        
	    	});
		} else {
	        $(this).parent().find('.more-to-view').slideToggle("fast").addClass('visible');  
		}
		return false;
	});
	
	// replace logo with genesis on genesis page
	$('.page-template-page-bones-genesis-php #logo img').fadeOut().attr("src", "http://themble.com/wp-content/themes/themblev3/library/images/genesis/genesis-logo.png").fadeIn();
	
 
}); /* end of as page load scripts */

// lets use Modernizr to load social scripts only if it's not mobile
if (matchMedia('screen and (min-width: 481px)').matches) {
    /*
    Code supplied from: https://gist.github.com/1025811
    */
    (function(doc, script) {
        var js, 
            fjs = doc.getElementsByTagName(script)[0],
            frag = doc.createDocumentFragment(),
            add = function(url, id) {
                if (doc.getElementById(id)) {return;}
                js = doc.createElement(script);
                js.src = url;
                id && (js.id = id);
                frag.appendChild( js );
            };
        
        // Google+ button
        add('https://apis.google.com/js/plusone.js');
        // Facebook SDK
        add('//connect.facebook.net/en_US/all.js#xfbml=1&appId=281185725226956', 'facebook-jssdk');
        // Twitter SDK
        add('//platform.twitter.com/widgets.js');
        add('//twitter.com/javascripts/blogger.js');
        add('//twitter.com/statuses/user_timeline/thembleteam.json?callback=twitterCallback2&count=1');
    
        fjs.parentNode.insertBefore(frag, fjs);
    }(document, 'script'));
    
} /* end Modernizr polyfill */

