$(document).ready(function() {
    
    Cufon.replace('h2', {hover: true});
    Cufon.replace('#homeContent .about', {hover: true});
    Cufon.replace('#mainContent h1');
	Cufon.replace('.caseStudyContent h1');
	Cufon.replace('.caseStudyContent h3');
	Cufon.replace('.caseStudyExamples h5', {hover: true});
    //Cufon.replace('#footer h3');

    $("#search input.search").focus(function() {
        if(this.defaultValue == this.value){
            this.value = "";
        }
    });
    
    $("#search input.search").blur(function() {
        if(this.value == ""){
            this.value = this.defaultValue;
        }
    });
    
    /*-- DROP DOWN MENUS --------------------*/
	$("#topNav > li").hoverIntent({
			sensitivity: 4,
			interval: 200,
			over: dd_show, 
			timeout: 100,
			out: dd_hide
    });
    /*----------------------------------------------*/


    /*-- HOMEPAGE FLASH --------------------*/
    var flashvars = {};
    var params = {};
    params.wmode = "transparent";

    var attributes = {};
    attributes.id = "flashContent";
    attributes.name = "flashContent";

    swfobject.embedSWF("flash/bskyRotator.swf", "flashContent", "517", "349", "9.0.0","/expressInstall.swf", flashvars, params, attributes);    
    /*----------------------------------------------*/


    /*-- FOOTER NEWS ROTATOR --------------------*/
    $("#footer #news li:not(:first)").hide();
    setInterval("newsFade()", 4000);
    /*----------------------------------------------*/ 
    
    
    
    /*-- HOMEPAGE CLIENT SLIDER --------------------*/
    $("#clientSlider ul li:nth-child(3n)").css("marginRight", 30);
    var sliderList = $("#homeContent .clients ul");
    var sliderWidth = Math.ceil($("#clientSlider ul li").length / 3) * 350;
    var sliderMargin = 0;
    var sliderMarginStr = '';
    sliderList.css("width", sliderWidth);
    $("#nextBtn a").click(function(){
        if(sliderWidth + sliderMargin > 350){
            sliderMargin = sliderMargin - 350;
            sliderMarginStr = sliderMargin + 'px';
            sliderList.animate({marginLeft:sliderMarginStr},1000);
            return false;
        }else{
            return false;
        }
    });
    $("#prevBtn a").click(function(){
        if(sliderMargin < 0){
            sliderMargin = sliderMargin + 350;
            sliderMarginStr = sliderMargin + 'px';
            sliderList.animate({marginLeft:sliderMarginStr},1000);
            return false;
        }else{
            return false;
        }
    });
    /*----------------------------------------------*/
    
    
    /*-- HOMEPAGE CASE STUDY POPUP --------------------*/
    var colorboxCounter = 0;
    $("#clientSlider li").each(function(i) {
        colorboxCounter++;
        $("#case-study-pop"+colorboxCounter).colorbox({width:"960px", inline:true, href:"#case-study"+colorboxCounter});
	});
	/*-- PARTNERS POPUP --------------------*/
	$(".case-study-sponsors a").each(function(i) {
        colorboxCounter++;
        $(".sponsor_logo"+colorboxCounter).colorbox({width:"550px", inline:true, href:"#sponsor_logo_div"+colorboxCounter});
    });
	/*-- CLIENTS POPUP --------------------*/
	$(".case-study-clients a").each(function(i) {
        colorboxCounter++;
        $(".clients_logo"+colorboxCounter).colorbox({width:"960px", inline:true, href:"#clients_logo_div"+colorboxCounter});
    });
    /*----------------------------------------------*/   


	/* The below piece was causing JS errors.  It was looking
		for the easySlider function, which is not being used anywhere.
		Commenting out for now.
		
    /* CASE STUDY SLIDER -----------------------------
    $("#slider").easySlider({
	    auto: true, 
		continuous: true,
		numeric: true
    });
    ----------------------------------------------------- */ 

    /*-- COLLAPSING TEXT --------------------*/
	
	/*
	$('.demo9').collapser({
		target: 'next',
		targetOnly: 'p',
		expandHtml: 'BlueSky is attending the 2010 Shop.org Annual Summit in Dallas, TX, September 27-29.',
		collapseHtml: 'BlueSky is attending the 2010 Shop.org Annual Summit in Dallas, TX, September 27-29.',
		expandClass: 'expArrow',
		collapseClass: 'collArrow'
	});
	*/
	
	
	/*----------------------------------------------*/
	
	
});

function newsFade(){
    var $active = $("#footer #news li.active");
    if ( $active.length == 0 ) $active = $("#footer #news li:first");

    var $next =  $active.next().length ? $active.next() : $("#footer #news li:first");
    
    $active.fadeOut(250);
    $next.addClass('active')
        .fadeIn(1250, function() {
            $active.removeClass('active');
        });
    
}

function dd_show(){
    $(this).find("div.subNav").slideDown(250).show(500);
}

function dd_hide(){
    $(this).find("div.subNav").slideUp(500);
}

