jQuery(document).ready(function(){
    if ($.browser.mozilla) {
        $("div#header-slider-inner").css({
            margin: '51px 0 0 1px'
        });
    }
    if(jQuery('.sidebar-testimonials').length>0){
        avio_cycle();
    }
    avio_faq();
    avio_portfolio();
    avio_dd_menu();
    avio_tweets(3,"MarkDijkstra");
    avio_animate();
    avio_login();
    avio_scroll_top();
    if(jQuery('.50Slider').length>0){
        avio_50_slider();
    }
    if(jQuery('#piecemaker').length>0){
        avio_piecemaker();
    }
    if(jQuery('.nivoSlider').length>0){
        avio_nivo_slider();
    }
    if(jQuery('.coinSlider').length>0){
        avio_coin_slider();
    }
    

});
function avio_piecemaker(){
    var flashvars={};

    flashvars.cssSource="css/piecemaker.css";
    flashvars.xmlSource="piecemaker.xml";
    var params={};

    params.play="true";
    params.menu="false";
    params.scale="showall";
    params.wmode="transparent";
    params.allowfullscreen="true";
    params.allowscriptaccess="always";
    params.allownetworking="all";
    swfobject.embedSWF('piecemaker.swf','piecemaker','960','480','1',null,flashvars,params,null);
}
function avio_coin_slider(){
    jQuery('#header-slider-inner').hide(1);
    setTimeout(function(){
        jQuery('#header-slider-inner, .cs-buttons').fadeIn(400);
    },500);
    $('.coinSlider').coinslider({
        width:958,
        height:398,
        spw:7,
        sph:5,
        delay:3000,
        sDelay:30,
        opacity:0.7,
        titleSpeed:500,
        effect:'random',
        navigation:true,
        links:true,
        hoverPause:true
    });
}
function avio_50_slider(){
    jQuery('.slide50 img').hide(1);
    setTimeout(function(){
        jQuery('.slide50 img').fadeIn(400);
    },500);
    jQuery('.50Slider').cycle({
        fx:'fade',
        timeout:5000,
        speed:200,
        pause:true,
        cleartype:!$.support.opacity,
        cleartypeNoBg:true,
        pager:'#nav50'
    });
}
function avio_cycle(){
    jQuery('.sidebar-testimonials').cycle({
        fx:'fade',
        speed:500,
        timeout:5000
    });
}
function avio_portfolio(){
    jQuery(".jcap-caption").hover(function(){
        img_wdt=jQuery('.jcap').width()-40;
        img_hgt=jQuery('.jcap').height()-40;
        jQuery(this).css({
            backgroundImage:"none"
        }).stop(true,true).animate({
            height:img_hgt,
            width:img_wdt
        },300).children('div').stop(true,true).delay(200).fadeIn(1);
    },function(){
        jQuery(this).delay(100).css({
            backgroundImage:""
        }).animate({
            height:'10px',
            width:'10px'
        },300).children('div').hide(10);
    });
}
function avio_faq(){
    jQuery("a.faqa").toggle(function(){
        jQuery(this).prev('p').slideDown(100);
        jQuery(this).prev('span').removeClass('plus').addClass('min');
    },function(){
        jQuery(this).prev('p').slideUp(100);
        jQuery(this).prev('span').removeClass('min').addClass('plus');
    });
}
function avio_equalHeight(group){
    tallest=0;
    group.each(function(){
        thisHeight=jQuery(this).height();
        if(thisHeight>tallest){
            tallest=thisHeight;
        }
    });
group.height(tallest);
}

function avio_dd_menu(){
    jQuery("ul#header-menu li").hover(function(){
        jQuery(this).stop().find('ul:first').css({
            visibility:"visible",
            display:"none"
        }).animate({
            height:'toggle'
        },200);
    },function(){
        jQuery('ul:first',this).css('visibility','hidden');
    });
    jQuery('.second-lvl').parent("li").addClass('arrowdown');
    jQuery('.third-lvl').parent("li").addClass('arrowright');
    jQuery(".second-lvl").hover(function(){
        jQuery(this).parent("li").addClass("active");
    },function(){
        jQuery(this).parent("li").removeClass("active");
    });
}
function avio_animate(){
    jQuery(".content-3col .readmore").hover(function(){
        jQuery(this).stop().animate({
            width:"156px"
        },150);
    },function(){
        jQuery(this).stop().animate({
            width:"62px"
        },150);
    });
}
function avio_login(){
    jQuery.fn.center=function(absolute){
        return this.each(function(){
            var t=jQuery(this);
            t.css({
                position:absolute?'absolute':'fixed',
                left:'50%',
                top:'50%'
            }).css({
                marginLeft:'-'+(t.outerWidth()/2)+'px',
                marginTop:'-'+(t.outerHeight()/2)+'px'
                });
            if(absolute){
                t.css({
                    marginTop:parseInt(t.css('marginTop'),10)+jQuery(window).scrollTop(),
                    marginLeft:parseInt(t.css('marginLeft'),10)+jQuery(window).scrollLeft()
                    });
            }
        });
};

jQuery("#login-box").center();
jQuery("#login, .login-top").click(function(){
    jQuery('body').append('<div id="overlay" />');
    jQuery('#overlay').fadeTo('fast',0.3);
    jQuery("#login-box").stop().fadeIn();
});
jQuery("#login-close").click(function(){
    jQuery('#overlay').fadeOut();
    jQuery("#login-box").fadeOut();
});
}
function avio_nivo_slider(){
    jQuery('#header-slider-inner').hide(1);
    setTimeout(function(){
        jQuery('#header-slider-inner').fadeIn(400);
    },500);
    jQuery('#header-slider-inner').nivoSlider({
        effect:'random',
        slices:15,
        animSpeed:600,
        pauseTime:6000,
        directionNav:true,
        directionNavHide:true,
        controlNav:true,
        keyboardNav:true,
        pauseOnHover:true,
        manualAdvance:false,
        captionOpacity:0.8,
        beforeChange:function(){},
        afterChange:function(){},
        slideshowEnd:function(){}
    });
}

function avio_tweets(tws,username){
    getTwitters('sidebar-tweets',{
        id:username,
        clearContents:false,
        count:tws,
        timeout:200,
        withFriends:true,
        ignoreReplies:false,
        newwindow:true,
        template:'<a href="http://twitter.com/%screen_name%">%user_screen_name%</a> said: "%text%" - <span>%time%</span>'
    });
}
function avio_scroll_top(){
    jQuery('#top').click(function(){
        jQuery('html, body').animate({
            scrollTop:0
        },'slow');
    });
}
function avio_switch_view(){
    jQuery("a.switch_thumb").toggle(function(){
        jQuery(this).addClass("swap");
        jQuery("ul.display").fadeOut("fast",function(){
            jQuery(this).fadeIn("fast").removeClass("display").addClass("thumb_view");
        });
    },function(){
        jQuery(this).removeClass("swap");
        jQuery("ul.thumb_view").fadeOut("fast",function(){
            jQuery(this).fadeIn("fast").addClass("display").removeClass("thumb_view");
        });
    });
}
