Cufon.replace('.font-big',{ fontFamily: 'Klavika', hover: {color: '#ff004e'} });
Cufon.replace('.font-small',{ fontFamily: 'Klavika', hover: {color: '#ff004e'} });
Cufon.replace('.klavika',{ fontFamily: 'Klavika' }); 

$('#main-menu-container .font-big a').each(function(index){	
    $(this).hover(
        function () {
            Cufon.replace('.font-big',{ fontFamily: 'Klavika', color: '#927d94', hover: {color: '#ff004e'} });
            Cufon.replace($(this),{ fontFamily: 'Klavika', hover: {color: '#ff004e'} });
        }
    );
    $(this).mouseout(
        function () {
            Cufon.replace('.font-big',{ fontFamily: 'Klavika', color: '#ffffff', hover: {color: '#ff004e'} });
        }
    );
});

var focusFlag = 1;

$(function() {
   $(window).bind("focus",function(event){
        focusFlag = 1;
    }).bind("blur", function(event){
        focusFlag = 0;
    });
});

var timer_is_on=0;
var boxX=0;
var boxY=0;
var topX=0;
var topY=0;

function toggleParallax(state)
{
    if(timer_is_on==1 || state=='off')
    {
        clearTimeout("parallax()");
        timer_is_on=0;
    }
    else
    {
        setTimeout("parallax(40)",40);
        timer_is_on=1;
    }
}

function parallax(timeout)
{
    var pX=0;
    var pY=0;
   
    var mouseX=0;
    var mouseY=0;
    
    $(document).one("mousemove", function (event) {
        mouseX = event.pageX;
        mouseY = event.pageY;
        
        //$(document).mousemove(function(e){
            pX=(mouseX-boxX)/topX;
            pY=(mouseY-boxY)/topY;

            //$('#main-quote').html(timer_is_on +', '+mouseX +', '+mouseY +', '+boxX +', '+boxY +', '+topX +', '+topY);

            $('#top-content-background').css('background-position',(50+2*pX)+'% '+(5*pY-5)+'px' );

            $('#top-content-promo').css('padding-left',(boxX+(20*pX)));
            $('#top-content-promo').css('padding-top',(boxY+(20*pY)));
        //}); 

        if(timer_is_on==1)
        {
            setTimeout("parallax("+timeout+")",timeout);
        }
    });

    

}

function changeSlider(val,force)
{
    $("#slider").slider("value", val);
    $('*[class~="client-item"]').removeClass('client-item-active');

    if(force>=0)
    {
        handle=val+(4*force);
    }
    else
    {
        handle=val+(4*$('.navi .active').attr("href"));
    }

    $('#c'+handle).addClass('client-item-active');
    $('#c'+handle+' div a').addClass('client-item-active');
}

function changeTop(main,back,link)
{
    if(focusFlag==1)
    {
        toggleParallax('off');
        
        main=main.replace(/"/g, '');
        back=back.replace(/"/g, '');
        link=link.replace(/"/g, '');

        $('#top-content-promo').hide('slide','',400);
        $('#top-content-background').fadeOut(500,'linear',function() {
            $('#top-content-background').css({'background': 'url('+back+') no-repeat scroll center top transparent'});
            $('#top-content-promo img').attr('src',main);
            $('#top-content-promo a').attr('href',link);
        });

        $('#top-content-background').fadeIn(500,'linear');
        $('#top-content-promo').show('slide','',400); 
        
        toggleParallax();
    }
    else
    {
        $('#top-content-background').css({'background': 'url('+back+') no-repeat scroll center top transparent'});
        $('#top-content-promo img').attr('src',main);
        $('#top-content-promo a').attr('href',link);
    }
    
    
    //$('#main-quote').html('main: '+main + ' / back: ' + back + ' / link: ' + link)
}

$(function() {               
    $("#clients").scrollable().navigator();

    $("#slider").slider({
        range:"min",
        value:0,
        min: 0,
        max: 3,
        step: 1,
        animate: true,
        slide: function( event, ui ) {
            changeSlider(ui.value);
        }
    });
    
    boxX=parseInt($("#top-content-promo").css('padding-left'));
    boxY=parseInt($("#top-content-promo").css('padding-top'));
    topX=parseInt($("#top-content").width());
    topY=parseInt($("#top-content").height());
});
