$(document).ready(function() {

	
	/* Starting Kwicks (PanelBox */
	$('.kwicks').kwicks( {
		max : 870,
		spacing : 0
	});
	
    $('.portfolioLink').click(function(){
       $('.tabContent').hide();
       $($(this).attr('href')).show();
       return false;
    });
    
    $('.fancybox').fancybox();
    
	/* Starting Partners Rollover Fade */
	$('.rollOverImageLink').fadeTo('fast',0.2);
    $('.rollOverImageLink').hover(function(){
        $(this).stop().fadeTo('fast',1.0); 
    },function(){
        $(this).stop().fadeTo('fast',0.2); 
    });

	
	/* PanelBox Rollover Image Switch Event Handler. */
	$('#kwick_1').hover(function() {
		pbSwt('1', 'hosting', '1');
	},function() {
		pbSwt('1', 'hosting', '0');
	});
	
	$('#kwick_2').hover(function() {
		pbSwt('2', 'webdesign', '1');
	},function() {
		pbSwt('2', 'webdesign', '0');
	});

	$('#kwick_3').hover(function() {
		pbSwt('3', 'marketing', '1');
	},function() {
		pbSwt('3', 'marketing', '0');
	});
	
	$('#kwick_4').hover(function() {
		pbSwt('4', 'commerce', '1');
	},function() {
		pbSwt('4', 'commerce', '0');
	});
	
	$('#kwick_5').hover(function() {
		pbSwt('5', 'seo', '1');
	},function() {
		pbSwt('5', 'seo', '0');
	});

	$('#kwick_6').hover(function() {
		pbSwt('6', 'saas', '1');
	},function() {
		pbSwt('6', 'saas', '0');
	});

	$('#kwick_7').hover(function() {
		pbSwt('7', 'cloud', '1');
	},function() {
		pbSwt('7', 'cloud', '0');
	});

	$('#kwick_8').hover(function() {
		pbSwt('8', 'business', '1');
	},function() {
		pbSwt('8', 'business', '0');
	});

	sY = 24;
	/* height of li.sub */
	fY = 165;
	/* height of maximum sub lines * sub line height */
	
	animate(fY)
	
	$("#slide .sub").click(function() {
		if (this.className.indexOf('clicked') != -1) {
			animate(sY)
			$(this).removeClass('clicked').css("background", "#eee url(http://www.cubicstream.com/images/out.gif) no-repeat 5px 8px").css("color", "#000");
		}
		else {
			animate(sY)
			$('.clicked').removeClass('clicked').css("background", "#eee url(http://www.cubicstream.com/images/out.gif) no-repeat 5px 8px").css("color", "#000");
			$(this).addClass('clicked');
			animate(fY)
		}
	});
	
	function animate(pY) {
		$('.clicked').animate({
			"height": pY + "px"
		},
		500);
	}
	
	$("#slide .sub").hover(function() {
		$(this).css("background", "#ddd url(http://www.cubicstream.com/images/down.gif) no-repeat 5px 8px").css("color", "#c00");
	},
	function() {
		if (this.className.indexOf('clicked') == -1) {
			$(this).css("background", "#eee url(http://www.cubicstream.com/images/out.gif) no-repeat 5px 8px").css("color", "#000");
		}
	}); 
	
    $('.headerFade').innerfade({ speed: 'slow', timeout: 8000, type: 'random', containerheight: '217px' }); 

});

/* Switch Image (and Animations) on PanelBox */
function pbSwt(uID, imageSrc, stateInt) {
	$('#k' + uID + 'img').attr('src','http://www.cubicstream.com/images/icons/' + imageSrc + '_' + stateInt + '.png');
}

function str_replace (search, replace, subject, count) {
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}

/* Digg Setup */
Digg.setAPIKey("CubicStream");