// JavaScript Document

// rollover buttons

pathArray = window.location.pathname.split( '/' );
if (pathArray[1] == 'portfolio') {
	var curNav = '';
} else {
	var curNav = 'btn_media';
}

function initButtons() {
$(function() {
	// color any disabled buttons
	$("#disabled").css("opacity","0.3");
	
	// OPACITY OF BUTTON SET TO 0%
	$(".over_img").css("opacity","0");
	
	// ON MOUSE OVER
	$(".over_img").hover(function () {
	
	// SET OPACITY TO 100%
	$(this).stop().animate({
	opacity: 1.0
	}, 300);
	},
	
	// ON MOUSE OUT
	function () {
	
		// SET OPACITY BACK TO 50%
		$(this).stop().animate({
		opacity: 0
		}, 300);
	});
	
	// OPACITY OF BUTTON SET TO 0%
	$(".scrollLink").css("opacity","0.5");
	
	// ON MOUSE OVER
	$(".scrollLink").hover(function () {
	
	// SET OPACITY TO 100%
	$(this).stop().animate({
	opacity: 1.0
	}, 300);
	},
	
	// ON MOUSE OUT
	function () {
	
		// SET OPACITY BACK TO 50%
		$(this).stop().animate({
		opacity: 0.5
		}, 300);
	});
	
	// OPACITY OF BUTTON SET TO 0%
	
	$(".halfItem").css("opacity","0.6");
	$(".navItem").css("opacity","0");
	
	// ON MOUSE OVER
	$(".navItem").hover(function (event) {
		
	// SET OPACITY TO 100%
	if (event.target.id == curNav) {
		op2 = 1.0;
	} else {
		op2 = 0;	
	}
	
	$(this).stop().animate({
	opacity: 1.0
	}, 300);
	},
	
	// ON MOUSE OUT
	function () {
	
		// SET OPACITY BACK TO 50%
		$(this).stop().animate({
		opacity: op2
		}, 300);
	});
	
	
	// OPACITY OF BUTTON SET TO 0%
	$(".whoScrollLink").css("opacity","0.7");
	
	// ON MOUSE OVER
	$(".whoScrollLink").hover(function () {
	
	// SET OPACITY TO 100%
	$(this).stop().animate({
	opacity: 1.0
	}, 300);
	},
	
	// ON MOUSE OUT
	function () {
	
		// SET OPACITY BACK TO 50%
		$(this).stop().animate({
		opacity: 0.7
		}, 300);
	});
	
	// OPACITY OF BUTTON SET TO 0%
	$(".whoRefreshBtn").css("opacity","0.7");
	
	// ON MOUSE OVER
	$(".whoRefreshBtn").hover(function () {
	
	// SET OPACITY TO 100%
	$(this).stop().animate({
	opacity: 1.0
	}, 300);
	},
	
	// ON MOUSE OUT
	function () {
	
		// SET OPACITY BACK TO 50%
		$(this).stop().animate({
		opacity: 0.7
		}, 300);
	});
});
}

function swapNav(id) {
	var classes = Array('btn_industry','btn_audience','btn_media','btn_case','btn_clients');
	for (i=0;i<classes.length;i++) {
		if (id == classes[i]) {
			removeClass(document.getElementById(id), "navItem");
			curNav = id;
		} else {
			addClass(document.getElementById(classes[i]),'navItem');
		}
	}
	initButtons();
}

$(function() {
	initButtons();
});




/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

$(function () {
	
	$('.dropdown').each(function () {
		$(this).parent().eq(0).hoverIntent({
			timeout: 100,
			over: function () {
				var current = $('.dropdown:eq(0)', this);
				current.css('display','inline');
				current.css('top','-300px');
				current.css('z-index','99');
				current.animate({top: 38}, 200, function() {  });
				//current.slideDown(200);
				$('#contact').animate({opacity: 0.3}, 200, function() {  });
				$('#searcher').animate({top: -70}, 200, function() {  });
			},
			out: function () {
				var current = $('.dropdown:eq(0)', this);
				current.fadeOut(200);
				$('#contact').stop().animate({opacity: 100}, 200, function() { });
			}
		});
	});
	
	$('.dropdown a').hover(function () {
		$(this).stop(true).animate({paddingLeft: '25px'}, {speed: 200, easing: 'easeOutBack'});
	}, function () {
		$(this).stop(true).animate({paddingLeft: '0'}, {speed: 200, easing: 'easeOutBounce'});
	});
	
	pic1 = new Image(310, 672);
	pic1.src = "images/dropdown.png"; 
	
	pic2 = new Image(4, 40);
	pic2.src = "images/dropselectionleft.png"; 
	
	pic3 = new Image(394, 40);
	pic3.src = "images/dropselectionright.png";
});

//Scrollbar Function
// execute your scripts when the DOM is ready. this is mostly a good habit
$(document).ready(function() {
	// initialize scrollable
	$(".scrollable").scrollable();
	$(".scrollFolio").scrollable({ circular: true});
	$(".stickyScroll").scrollable({ circular: false, mousewheel: false }).navigator({

		// select #flowtabs to be used as navigator
		navi: "#navigator",

		// select A tags inside the navigator to work as items (not direct children)
		naviItem: 'a',

		// assign "current" class name for the active A tag inside navigator
		activeClass: 'current',

		// make browser's back button work
		history: true

	});
	$(".scrollableVid").scrollable();
	$(".whoScrollable").scrollable();
});

// tooltip
function initTooltips() {
$(function() {
	var tooltip = $('.tooltip');
	tooltip.css("opacity","0");
	$("a[rel]").hover(function() {
		
		document.getElementById('tooltip').innerHTML = this.rel;
		
		x = mouseX;
		x-= (document.getElementById('tooltip').offsetWidth)/2;
		y = mouseY;
		y-= (document.getElementById('tooltip').offsetHeight);
		y-=10;
		newY = y-10;
		endY = y-20;
		
		/*
		myPos = findPos(this);
		x = myPos[0];
		y = myPos[1];
		y-=20;
		newY = y-10;
		endY = y-20;
		*/

		tooltip.css("top",y+'px');
		tooltip.css("left",x+'px');
		tooltip.stop().animate({
			opacity: 1.0,
			top: newY
		}, 300);
	   
	},
	
	// ON MOUSE OUT
	function () {
		// SET OPACITY BACK TO 50%
		tooltip.stop().animate({
			opacity: 0,
			top: endY
		}, 300, function(){
					
					tooltip.css("top",'-100%');
					tooltip.css("left",'-100%');
					
				});
	});
});
}

$(function() {
	initTooltips();
	mouseInit();
});

// get x/y position for thumbnail
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
					curleft += obj.offsetLeft
					curtop += obj.offsetTop
			}
	}
	
	return [curleft,curtop];
}

$(function() {
	$(".swapLink").click(function(){
		image = $(this).attr("rel");
		$("#swapper").ImageSwitch({NewImage: image});
	});
}); 



// text scroller for snapshot pages
$(function() {
	var scrollnum = 90;
	$('.scrollNext').click(function(){
		var text = $('#text');
		var h = document.getElementById('text').offsetHeight;
		if (document.getElementById('text').style.top) {
			var topper = parseFloat(document.getElementById('text').style.top);
		} else {
			var topper = 0;
		}
		if ((h+topper) > scrollnum) {
			topper-=scrollnum
			text.stop().animate({
				opacity: 1.0,
				top: topper
			}, 300);
		}
	});
	$('.scrollPrev').click(function(){
		var text = $('#text');
		var h = document.getElementById('text').offsetHeight;
		if (document.getElementById('text').style.top) {
			var topper = parseFloat(document.getElementById('text').style.top);
		} else {
			var topper = 0;
		}
		if ((topper) < 0) {
			topper+=scrollnum;
			text.stop().animate({
				opacity: 1.0,
				top: topper
			}, 300);
		}
	});
}); 

function track(href,evt) {
	_gaq.push(['_trackEvent', href, evt]);
}

function goSearch() {
	$('#contact').animate({opacity: 0.30}, 200, function() {  });
	$('#searcher').animate({top: 38}, 200, function() {  });
}

function noSearch() {
	$('#contact').animate({opacity: 1.0}, 200, function() {  });
	$('#searcher').animate({top: -70}, 200, function() {  });
}

function show(id) {
	document.getElementById(id).style.display='block';
}
function hide(id) {
	document.getElementById(id).style.display='none';
}

function setService(name) {
	document.forms['contactForm'].elements['service'].value=name;
	document.getElementById('cover').style.display='none';
	var ids = Array('rich','glyne','deb','michaela','sandra','gayle');
	document.getElementById(name).className="enabled";
	for (i=0; i<ids.length; i++) {
		if (ids[i] != name) {
			theid = ids[i];
			theid.className="disabled"; //For Most Browsers
		}
	}
}

var mouseX = 0;
var mouseY = 0;
function mouseInit() {
	if (window.Event) {
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = getCursorXY;
}

function getCursorXY(e) {
	mouseX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
	mouseY = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
}

function relLink(string) {
	if (window.location.hash) {
		window.location=string+window.location.hash;
	} else {
		window.location=string;
	}
}

var shareTimer;
var shareMove=0;

$(function() {
	var shareBox = $('#shareBox');
	shareBox.css("opacity","0");
	
	$(".shareLink").hover(function() {
		
		if (shareMove==0) {
			shareMove=1;
			y = 545;
			newY = 518;
			
			shareBox.css("top",y+'px');
			shareBox.css("display","block");
	
			shareBox.stop().animate({
				opacity: 1.0,
				top: newY
			}, 300);
		}
			   	
	},
	
	// ON MOUSE OUT
	function () {
		// SET OPACITY BACK TO 50%
		/*
		tooltip.stop().animate({
			opacity: 0,
			top: endY
		}, 300, function(){
					
					tooltip.css("top",'-100%');
					tooltip.css("left",'-100%');
					
				});
		*/
	});
	
	$(".shareLink").mouseover(function() {
		clearTimeout(shareTimer);
		shareTimer = setTimeout( shareTime, 3000 );
	}, function(){ });

	$("#shareBox").mouseover(function() {
		clearTimeout(shareTimer);
		shareTimer = setTimeout( shareTime, 3000 );
	}, function(){ });
	
});

function shareTime() {
	$(function() {
		var shareBox = $('#shareBox');
	
		shareBox.stop().animate({
			opacity: 0.0,
			top: 495
		}, 300, function() {
			shareMove=0;
			shareBox.css("display","none")});
	});
}

