var xTimer;
var xSlideTop=0;
var xWaitTimeline=5000;
var xOrigWaitTimeline=xWaitTimeline;

function xResumeAnimation(){
    xAnimate=1;
    xSlideTopF();
}
function xSlideTopFB(){
    if(xAnimate == 0 || xAnimate == 1){
        jQuery('.xDotA').removeClass('xDotSelected');
        jQuery('.xDotB').removeClass('xDotSelected');
        jQuery('.xDotC').removeClass('xDotSelected');
        jQuery('.xDotD').removeClass('xDotSelected');
        jQuery('.xDotE').removeClass('xDotSelected');

        switch(xSlideTop){
            case 0:
                jQuery('.xDotA').addClass('xDotSelected');
                break;
            case 283:
                jQuery('.xDotB').addClass('xDotSelected');
                break;
            case 566:
                jQuery('.xDotC').addClass('xDotSelected');
                break;
            case 849:
                jQuery('.xDotD').addClass('xDotSelected');
                break;
            case 1132:
                jQuery('.xDotE').addClass('xDotSelected');
                break;
            default:
                jQuery('.xDotA').addClass('xDotSelected');
                break;
        }
    }

    if(xAnimate == 0){
        clearTimeout(xTimer);
        xTimer = 0;
        jQuery('.xSlidex').animate({
            marginTop:-xSlideTop
        },500,'swing',xResumeAnimation);
    }else if(xAnimate==1){
        jQuery('.xSlidex').animate({
            marginTop:-xSlideTop
        },500);
        xSlideTopF();
    }
}
function xSlideTopF(){
    if(xSlideTop >=283*4){
        xSlideTop=0;
    }else{
        xSlideTop = xSlideTop + 283;
    }
    clearTimeout(xTimer);
    xTimer = setTimeout('xSlideTopFB()', xWaitTimeline);
}
jQuery(document).ready(function($){
    $("a.zoom").fancybox({
        'zoomSpeedIn'		:	500,
        'zoomSpeedOut'		:	500
    });
    Cufon.replace('.xTitle,.xLogoB, .xBlogPosts .xPost h2, .xBlogPost .xPost h2, .xBlogPost .xPost h3');
    $('#s').click(function(){
        if($('#s').val()=="Search here..."){
            $('#s').val('');
        }
    });
    var xContactSubmit = true;
    $(".xContentC .xForm .xButton").click(function(){
        xContactSubmit = true;
        if($('.xText #Name').val()==""){
            $('.xFName').html('You must add a name');
            xContactSubmit= false;
        }else{
            $('.xFName').html(' ');
        }
        if($('.xText #Email').val()==""){
            $('.xFEmail').html('You must add a Email');
            xContactSubmit= false;
        }else{
            $('.xFEmail').html(' ');
        }
        if(xContactSubmit==true){
            $(".xContentC .xForm #formx").submit();
        }
        
    });
    $(".xSlideshowButton a").click(function(){
        $(".xSlideshow").animate({
            height: "283px"
        }, 1500,'swing',function(){
            $('.xFeatured').css('width','118px');
            $('.xFeatured').css('margin-left','238px');
        } );
        $(".xSlideshowButton a").animate({
            opacity: "0",
            height:"0px"
        }, 500,'swing',function(){
            xAnimate=1;
            xSlideTop=0;
            xSlideTopF();
            
        } );
    });
    $('.xDotA').addClass('xDotSelected');
    $('.xDotA').click(function(){
        xWaitTimeline=0;
        xAnimate=1;
        xSlideTop=1132;
        xSlideTopF();
        xWaitTimeline=xOrigWaitTimeline;
    });
    $('.xDotB').click(function(){
        xWaitTimeline=0;
        xAnimate=1;
        xSlideTop=0;
        xSlideTopF();
        xWaitTimeline=xOrigWaitTimeline;
    });
    $('.xDotC').click(function(){
        xWaitTimeline=0;
        xAnimate=1;
        xSlideTop=283;
        xSlideTopF();
        xWaitTimeline=xOrigWaitTimeline;
    });
    $('.xDotD').click(function(){
        xWaitTimeline=0;
        xAnimate=1;
        xSlideTop=566;
        xSlideTopF();
        xWaitTimeline=xOrigWaitTimeline;
    });
    $('.xDotE').click(function(){
        xWaitTimeline=0;
        xAnimate=1;
        xSlideTop=849;
        xSlideTopF();
        xWaitTimeline=xOrigWaitTimeline;
    });

    $('.xArrowDown').click(function(){
        xWaitTimeline=0;
        xAnimate=1;
        if(xSlideTop==1132){
            xSlideTop = 849;
        }else{
            xSlideTop = xSlideTop - 283;
        }
        xSlideTopF();
        xWaitTimeline=xOrigWaitTimeline;
    });
    $('.xArrowUp').click(function(){
        xWaitTimeline=0;
        xAnimate=1;
        if(xSlideTop==1132){
            xSlideTop = 283;
        }else{
            if(xSlideTop==849){
                xSlideTop = 0;
            }else{
                xSlideTop = xSlideTop+(283*2);
            }
        }
        xSlideTopF();
        xWaitTimeline=xOrigWaitTimeline;
    });
    xSlideTopF();
});

