/*
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, call these scripts
$(document).ready(function() {

	// Homepage image sizing
	function resizeHomepageImage() {
		var windowWidth = $(window).width();
		var imageBoxWidth = Math.max(660, windowWidth * .80);
		var imageBoxOffset = Math.max(-505, 0 - (imageBoxWidth*.50));
		var footerOffset = (Math.min(imageBoxWidth, 660) * 1.04) + 60;
		$('#main.homepage #homepageImg').width(windowWidth * .80).css('marginLeft', imageBoxOffset);
		$('.home footer').css('top', Math.max(Math.min(imageBoxWidth, 1010), 750));
	}
	
	//resizeHomepageImage();
	
	//$(window).resize(function() {
  	//	resizeHomepageImage();
	//});

	// Filmstrip functions
	$.scrollTo.defaults.axis = 'x';
	$.scrollTo(0);
	$('#advance_right').click(function(){$('#film_pod_container').stop().scrollTo('+=665px',300);});
	$('#advance_left').click(function(){$('#film_pod_container').stop().scrollTo('-=665px',300);});
	var myPods = $('.film_pod').size();
	podContainer = (myPods * 95) - 5;
	$('.film_pod:last').css('margin', '0');
	$('#film_thumbs_holder').css('width', podContainer + 'px');
	
	// Find the current film in the strip and scroll to it
	$('#film_pod_container').has(".film_current").scrollTo('.film_current', 0);
	
	
	// Site Design functions			
	$('div#designsWindow').scrollTo( 0, {axis:'y'} );
	$.scrollTo( 0, {axis:'y'} );
	$('.design_left').click(function(){$('#designsWindow').stop().scrollTo('0px',500, {axis:'y'});});
	$('.design_right').click(function(){$('#designsWindow').stop().scrollTo('645px',500, {axis:'y'});});
	$('.design_info').click(function(){$('#designsWindow').stop().scrollTo('1290px',500, {axis:'y'});});
	
	
	// Toggle the viewer text
	$('#postMore a').click(function() {
  	  $('section div').toggle(0, function() {
        if ($(this).is(':visible')) {
        	$('#postMore a').html('');
        	$('#postMore a').removeClass('viewShow');
        	$('#postMore a').addClass('viewHide');
        } else {
        	$('#postMore a').html('...more');
        	$('#postMore a').removeClass('viewHide');
        	$('#postMore a').addClass('viewShow');
        }
      });
    });

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