// default

//
var step = 3;
var scrollTimer;

//
$.postJSON = function (url, data, callback) {
	$.post(url, data, callback, 'json');
};

//
$(function(){

	// css navigation dropdown/flyout replacement for ie 6
	if($.browser.msie && $.browser.version < 7){
		$('#nav ul>li').hover(function(){ $(this).children('ul:first').css({display:'block'})},function(){ $(this).children('ul:first').css({display:'none'})});
		$('li>a').hover(function(){$(this).parent('li').addClass('hover')},function(){$(this).parent('li').removeClass('hover')});
	}
	
	// event tracker for outgoing links/file downloads
	$('a').each(function(){
		var path;
		
		if(path = $(this).attr('href')){
			var outgoing 	= /^(http|https)/i;
			var ext 		= /[^/].(?:doc|eps|jpg|jpeg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3|mp4)/i;
			
			if (path.match(outgoing) && !path.match(document.domain) ) {
				$(this).click(function(){
					_gaq.push(['_trackEvent', 'Link', 'Outgoing', $(this).attr('href')]);
				});
			} else if(path.match(ext)){
				$(this).click(function(){
					_gaq.push(['_trackEvent', 'File', 'Download', $(this).attr('href')]);
				});	
			}
		}
	});
	
	// homepage
	$('#home').cycle({ 
		fx:				'fade', 
		speed:			1500,
		timeout:		4000,
		pause:			0
	 });
	 
	 // zoom
	 $('.zoom').jqzoom({
		zoomType: 'standard',  
        lens:true,  
        preloadImages: true,
		preloadText: '',
        alwaysOn:false,
		zoomWidth: 290,
		zoomHeight: 200,
		position : 'left',
		yOffset : 320,
		xOffset : 20,
		title :false
	 });
	 
	
	// mousewheel
	$('.user-content').mousewheel(function(event, delta) {
		if (delta > 0)
			$(this).scrollTop($(this).scrollTop() - (delta*18));
		else if (delta < 0)
			$(this).scrollTop($(this).scrollTop() - (delta*18));
		return false; // prevent default
	});
	
	if($('.user-content').html()){
		$('.user-content').scrollTop(1);
		if($('.user-content').scrollTop() != 1){
			$('.up,.down').hide();
		} else {
			$('.up').bind('mousedown', scrollUp).bind('mouseup', scrollClear);
			$('.down').bind('mousedown', scrollDown).bind('mouseup', scrollClear);
		}
	}
	
	//
	$('#websiteOverlay').alignCenter();
	
	//windowshade
	$('.windowshade').each(function(){
		$(this).find('.string').bind('click', function(){
			$(this).parent('p').siblings('.shade').slideToggle();
			return false;
		});
	});
	
	//
	$('.hide').hide();
	
});

function scrollUp(){
	$('.user-content').scrollTop($('.user-content').scrollTop() - step);
	scrollTimer = setTimeout("scrollUp()",10);
}

function scrollDown(){
	$('.user-content').scrollTop($('.user-content').scrollTop() + step);
	scrollTimer = setTimeout("scrollDown()",10);
}

function scrollClear(){
	clearTimeout(scrollTimer);
}
