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

*/

/* imgsizer (flexible images for fluid sites) */
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[i].origWidth=images[i].offsetWidth;images[i].origHeight=images[i].offsetHeight;imgCache.push(images[i]);c.ieAlpha(images[i]);images[i].style.width="100%";}
if(imgCache.length){c.resize(function(){for(var i=0;i<imgCache.length;i++){var ratio=(imgCache[i].offsetWidth/imgCache[i].origWidth);imgCache[i].style.height=(imgCache[i].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;},resize:function(func){var oldonresize=window.onresize;if(typeof window.onresize!='function'){window.onresize=func;}else{window.onresize=function(){if(oldonresize){oldonresize();}
func();}}}}

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

	$("ul.menu").superfish({ 
		animation: {height:'show'},   // slide-down effect without fade-in 
		delay:     600,               // 0.4 second delay on mouseout 
		pathClass:  'active' 
	});
	
	// setup colorbox to handle specific links
	//$("a.colorbox").colorbox({width:"600px", height:"80%", iframe:true});
	
	// add feature transition and navigation
	function initfeature() {
		$(".feature-excerpts article").each(function(index) {
			if (index == 0) $(this).show().addClass('current');
			else $(this).hide();
		});
		$(".feature-navi ul li:first").addClass('current');
	}
	
	function gotofeature(index) {
		$(".feature-navi .current").removeClass('current');
		$(".feature-navi li").eq(index).addClass('current');
		var current = $(".feature-excerpts .current");
		var next = $(".feature-excerpts ARTICLE").eq(index);
		
		current.hide().removeClass('current');
		next.show().addClass('current');
	}
	
	function nextfeature() {
		var features = $(".feature-excerpts ARTICLE");
		var current = $(".feature-excerpts .current");
		if (current.next('ARTICLE').length == 0) var index = 0;
		else var index = current.index() +1;
		gotofeature(index);
	}
	
	$(".feature-navi li A").click(function() {
		window.clearInterval(slideInterval);
		var index = $(this).parent().index();
		gotofeature(index);
	});
	
	initfeature();
	var slideInterval = window.setInterval(nextfeature, 5000);
	
}); /* end of as page load scripts */

// addthis configuration
var addthis_share = {
	templates: {
		twitter: 'check out {{url}} (from @CentrePolicyDev)'
	}
}
