// JavaScript Document

var whitneybk = { src: '/wp-content/themes/TD/js/whitney-book.swf' };

sIFR.activate(whitneybk);

sIFR.replace(whitneybk, {
  selector: '#about.parent-pageid-157 h1',
  css: '.sIFR-root { background-color: #fff; color: #94367f; letter-spacing: 0; font-size: 24px; leading: 0; font-weight: normal; }',
  wmode: 'transparent' 
});

sIFR.replace(whitneybk, {
  selector: '#work.single h1, #work.category #awards h3',
  css: '.sIFR-root { background-color: #fff; color: #EB8523; font-size: 20px; leading: 0; }',
  wmode: 'transparent' 
});

sIFR.replace(whitneybk, {
  selector: '#news h2',
  css: '.sIFR-root { background-color: #fff; color: #CD2036; font-size: 24px; }', 
  wmode: 'transparent' 
});

sIFR.replace(whitneybk, {
  selector: '#contact.page-id-130 h2',
  css: ['.sIFR-root { background-color: #fff; color: #808285; font-size: 20px; }', 
  		'a { text-decoration: none; }',
		'a:link { color: #808285; }',
		'a:hover { color: #808285; border-bottom: 1px solid #ccc }'],
  wmode: 'transparent' 
});

sIFR.replace(whitneybk, {
  selector: '#contact h2, #about h2',
  css: ['.sIFR-root { background-color: #fff; color: #808285; font-size: 24px; }', 
  		'a { text-decoration: none; }',
		'a:link { color: #808285; }',
		'a:hover { color: #808285; border-bottom: 1px solid #ccc }'],
  wmode: 'transparent' 
});

/** Background Position Plug-in  * @author Alexander Farkas * v. 1.21 */

(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);

$(document).ready(function () {	
	$("body").addClass("hasJS");
	
	$("#work.single .section .wp-caption, #identity.section .wp-caption").wrapAll('<div class="scrollable"><div class="items">');	
	$(".scrollable").append('<a class="prevPage browse left"></a><a class="nextPage browse right"></a>');
	
	var oneOf = $(".wp-caption").size();
	$(".wp-caption-text").append("<span class='of'>1 / " + oneOf + "</span>"); 
	
	$("div.scrollable").scrollable({
    	onBeforeSeek: function() {
			$(".wp-caption-text").hide(); 	
	    },
		onSeek: function() { 
			$(".wp-caption-text").fadeIn(); 	
			var firstNo = this.getIndex() + 1;
			$("span.of").empty().replaceWith("<span class='of'>" + firstNo + " / " + this.getPageAmount() + "</span>"); 
	    }, 
	    size: 1, loop: true, keyboard: true
	}).mousewheel()/*.autoscroll(10000);*/
	
	$("ul.tabs").tabs("div.panes > div", { effect: 'slide' });	
	
	$("a#overlay").overlay({expose: '#fff'});
	
	//stick the footer at the bottom of the page if we're on an iPad/iPhone due to viewport/page bugs in mobile webkit
	if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod'){
    	$("#footer").addClass("ipad");
		$("#wrapper").addClass("ipad");
    };
	
	if (typeof document.body.style.maxHeight != "undefined") {
	$('#header ul li:not(.current-cat):not(.current_page_item) a')
		.css( {backgroundPosition: "0 -12px"} )
		.mouseover(function(){
			$(this).stop().animate(
				{backgroundPosition:"(0 0)"}, 
				{duration:500})
			})
		.mouseout(function(){
			$(this).stop().animate(
				{backgroundPosition:"(0 -12px)"}, 
				{duration:500})
			});
	
		$(".work-thumbnails")
 		.css( {backgroundPosition: "0 119px"} )
		.mouseover(function(){
			$(this).stop().animate(
				{backgroundPosition:"(0 165px)"}, 
				{duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate(
				{backgroundPosition:"(0 119px)"}, 
				{duration:500})
		});
		} else {  // IE6, older browsers 
	}

});
