// On startup
$j = jQuery.noConflict();

$j(document).ready(function() {
	

	$j("a.fancybox").fancybox({
		'overlayShow':		false,
		'titleShow':		false
	});
	
	
	/*
	$j('.fade'). cycle({
		speed: 1000,
		timeout: 4000,
		autostop: 2,
		autostopCount: 4,
		height: '90px'
	});
	*/
	
	
	$j("div.preview_image").mouseover(function(){
		$j(this).animate({
			opacity: 0.5
		}, 300);
	});
	$j("div.preview_image").mouseout(function(){
		$j(this).animate({
			opacity: 1
		}, 300);
	});
	
	// $j("body").css("background", "#000");
	
	$j(".social img").mouseover(function(){
		var a = $j(this).attr('src').split('.');
		var im = a[0] + '_h.' + a[1];
		$j(this).attr('src', im);
	});
	
	$j(".social img").mouseout(function(){
		var a = $j(this).attr('src').split('_h');
		var im = a[0] + a[1];
		$j(this).attr('src', im);
	});


	


});



// $j Anything-Slider ----------------------------------

function formatText(index, panel) 
{
	return index + "";
}

$j(function () {

    $j('.anythingSlider').anythingSlider({
        easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
        autoPlay: true,                // This turns off the entire FUNCTIONALY, not just if it starts running or not.
        delay: 4000,                    // How long between slide transitions in AutoPlay mode
        startStopped: false,            // If autoPlay is on, this can force it to start stopped
        animationTime: 600,             // How long the slide transition takes
        hashTags: true,                 // Should links change the hashtag in the URL?
        buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
		startText: "Go",             	// Start text
  		stopText: "Stop",               // Stop text
  		navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
    });
    
    $j("#slide-jump").click(function(){
       $j('.aslider').anythingSlider(6);
    });
    
});



// Sidebar work list ---------------------------------------

var num_projects_per_page 	= 5;
var num_sidebar_projects 	= 0;
var project_height			= 95;
var current_top_project		= 0;
var animation_speed			= 300;
var scroll_num				= 4;


function view_work(url) 
{
	if (current_top_project > 0) {
		window.location = url + "?work=" + current_top_project;
	}
	else {
		window.location = url;
	}
}

function init_scroll_position()
{
	var distance = project_height * (current_top_project) ;
	$j('#left div.work_list').css('top', "-" + distance + "px");
}			

function current_bottom_work()
{
	return current_top_project + num_projects_per_page;
}

function check_nav()
{
	if (can_scroll_up()) {
		$j('#work_list_nav_up').css('background-position', '0 -30px');
	}
	else {	
		$j('#work_list_nav_up').css('background-position', '0 0');		
	}

	if (can_scroll_down()) {
		$j('#work_list_nav_down').css('background-position', '0 -30px');		
	}
	else {
		$j('#work_list_nav_down').css('background-position', '0 0');		
	}
}	

function can_scroll_down()
{
	return (current_top_project > 0);
}			

function can_scroll_up()
{
	return (current_bottom_work() < num_sidebar_projects);
}			

function scroll_down()
{
	var distance = project_height * (current_top_project + scroll_num);

	$j("#left div.work_list").animate({ 
		left: 0,
		top: -distance
	}, animation_speed );

	current_top_project += scroll_num;					
	check_nav();					
}			

function scroll_up()
{
	var distance = project_height * (current_top_project - scroll_num);

	$j("#left div.work_list").animate({ 
		left: 0,
		top: -distance
	}, animation_speed );

	current_top_project -= scroll_num;					
	check_nav();
}
