//Virtual Page Views
function trackVirtualPageview(url){
	if ( url.indexOf('http') === 0 && url.indexOf('yandl.com') == -1 ){
		//external link, track under "virtualviews/"
		url = "virtualviews/" + url;
	}

	//Google Analytics Pageview
	_gaq.push(['_trackPageview', url]);
	//Visistat page view
	VSLT(url);
}
var eekeysEnabled = false,
	addColor_re = new RegExp("(.+)\\.(gif|png|jpg)", "g"),
	removeColor_re = new RegExp("(.+)_yellow\\.(gif|png|jpg)", "g");

$(document).keydown(function (e) {


		if ( e.which == 74 ){
			// j
			$('#client_frame').ysp('previous');
		}else if ( e.which == 75 ){
			//k
			$('#client_frame').ysp('next');
		}else if ( e.which == 78 ){
			//n
			$('.client_item.current .work_frame','#client_frame').ysp('previous');
		}else if ( e.which == 77 ){
			//m
			$('.client_item.current .work_frame','#client_frame').ysp('next');
		}else if ( e.which == 73 ){
			//i
			if ( $('body').hasClass('work') ){
				var fakeEvent = {target : $('.client_item.current .work_item a','#client_frame').eq($('.client_item.current .work_frame','#client_frame').ysp('state','currentItem'))};
				workClickHandler(fakeEvent);
			} else if ( $('body').hasClass('home') ){
				var fakeEvent = {target : $('.client_item.current .client-link','#client_frame')};
				itemClickHandler(fakeEvent);
			}
		}else if( e.which == 89 ){
			//y
			if ( !$('body').hasClass('yellow') ){
				$('body').addClass('yellow');
				var externalIconSrc = $('.external_link_icon').eq(0).attr('src'),
					pdfIconSrc = $('.pdf_link_icon').eq(0).attr('src');
				if ( externalIconSrc ){
					$('.external_link_icon').attr('src',externalIconSrc.replace(addColor_re, "$1_yellow.$2"));
				}
				if ( pdfIconSrc ){
					$('.pdf_link_icon').attr('src',pdfIconSrc.replace(addColor_re, "$1_yellow.$2"));
				}
				createCookie('colorTheme','yellow','365');
			}else{
				$('body').removeClass('yellow');
				var externalIconSrc = $('.external_link_icon').eq(0).attr('src'),
					pdfIconSrc = $('.pdf_link_icon').eq(0).attr('src');
				if ( externalIconSrc ){
					$('.external_link_icon').attr('src',externalIconSrc.replace(removeColor_re, "$1.$2"));
				}
				if ( pdfIconSrc ){
					$('.pdf_link_icon').attr('src',pdfIconSrc.replace(removeColor_re, "$1.$2"));
				}
				eraseCookie('colorTheme');
			}
		}else{
			if (eekeysEnabled){

			}else{
				if ( e.which == 69 && e.shiftKey ){
					// e + shift
					eekeysEnabled = true;

				}
			}
		}


});
$(document).ready(function(){
	$('#header_nav a, #footer_nav a').filter('.' + $('body').attr('class')).addClass('active');
	$('#client_bar a').hover(
		function(){
			$(this).stop(true,true).animate({'opacity':'1'},250);
		},function(){
			if (!$(this).hasClass('active')){
				$(this).stop(true,true).animate({'opacity':'.325'},250);
			}
	});
	$('#client_bar a').each(function(){
		if (!$(this).hasClass('active')){
				$(this).stop(true,true).animate({'opacity':'.325'},250);
			}
	});

	if( screen.width < 640 || screen.height < 640 ){
		$('.mobile-site','#header_nav').css("display","inline");
	}

	if ( readCookie('colorTheme') ){
		$('body').addClass(readCookie('colorTheme'));
		var externalIconSrc = $('.external_link_icon').eq(0).attr('src'),
			pdfIconSrc = $('.pdf_link_icon').eq(0).attr('src');
		if ( externalIconSrc ){
			$('.external_link_icon').attr('src',externalIconSrc.replace(addColor_re, "$1_yellow.$2"));
		}
		if ( pdfIconSrc ){
			$('.pdf_link_icon').attr('src',pdfIconSrc.replace(addColor_re, "$1_yellow.$2"));
		}
	}

	//Event Tracking
	//_gaq.push(['_trackEvent', category, action, label]);


});
$(window).load(function(){
	setTimeout(function() { window.scrollTo(0, 1) }, 100);
});
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

