﻿function page_init(){
    $(document).pngFix();
    init_thumbs();
    init_arrows();
    init_slideshow();
}

function init_thumbs()
{
    $('.project_thumb').hover(
        function() {
            $(this).children('.project_caption').stop().animate({backgroundColor:'#efefea'}, 400 );
        },
        function(){
            $(this).children('.project_caption').stop().animate({backgroundColor:'#ffffff'}, 400 );
        }
    );
}

function init_slideshow()
{
	$('#slides').cycle({
		fx:'fade',
		timeout:8000,
		pager:'.pager',
		next:'#next', 
        prev:'#prev' 
	});
}

function init_arrows()
{
    var enterFlag = false;
    var arrowWidth = $('.slider').width();
    var toPos = '7px';
    $('#next').hover( 
        function() {
            enterFlag = true;
            $(this).children('.slider').animate({ 
                        right: toPos
                        }, {duration:500, easing:"easeOutQuad", queue:false} );
        },
        function() {
            $(this).children('.slider').animate({ 
                        right: -arrowWidth + 'px'
                        }, {duration:500, easing:"easeInQuad", queue:false} );
        }
    );
    $('#prev').hover( 
        function() {
            enterFlag = true;
            $(this).children('.slider').animate({ 
                        left: toPos
                        }, {duration:500, easing:"easeOutQuad", queue:false} );
        },
        function() {
            $(this).children('.slider').animate({ 
                        left: -arrowWidth + 'px'
                        }, {duration:500, easing:"easeInQuad", queue:false} );
        }
    );
    $('#next, #prev').mousemove( 
        function(e) {
            if(enterFlag) {
                $(this).children('.slider').css("top", e.pageY-165);
                enterFlag = false;
            } else {
                $(this).children('.slider').animate({ 
                        top: e.pageY-165
                        }, {duration:500, easing:"easeOutQuad", queue:false} );
            }
        }
    );
}
