var ROOT = "";

$(function() {
		   
		   
	if(jQuery.isFunction($.fn.fancybox))
	{
		$("a.cms_flash_video").fancybox({
			'autoScale':true,
			'width':680,
			'height':383,
			'centerOnScroll':true,
			'titleShow':false,
			'type':'iframe'
		});
	}
	
	if($("#twitterfeed"))
		$("#twitterfeed .feed").load(ROOT + '/_engine/scripts/latest-tweet.php');

  /*$('.jcarousel-skin-studies').jcarousel({
    scroll: 1,
    initCallback: mycarousel_initCallback,
    itemLoadCallback: function(carousel, state) {
      $('.jcarousel-controls a').removeClass('current');
      $('.jcarousel-controls a').eq((carousel.first-1)).addClass('current');;
    }
  });*/
  
	$("a.revealcontent").bind("click",function(){
		if($(this).hasClass("selected"))
			$(this).removeClass("selected");
		else
			$(this).addClass("selected");
		$(this).parent().next().slideFadeToggle("fast");
		
		return false;
	});
  
  $("#searchresults li a")
  	.mousemove(
		function(e){  
			var obj = $(this).next();
			obj.css("top", (e.pageY - obj.height() - 15) + "px");
			obj.css("left", (e.pageX) + "px");
    	})
	.hover(
		function(){
			var obj = $(this).next();
			obj.show();
			$("#searchresults .t").not(obj).hide();	
		},
		function(){
			$(this).next().hide();
		}
	);
	
	$('#portfoliosearch label').click(function(){
		setupLabel();
	});
	setupLabel(); 
	
	
	// open external links in new window
	$('a[rel*=external]').click( function() {
        window.open(this.href);
        return false;
    });
	
	
	
});

jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
  return this.animate({opacity: "toggle", height: "toggle"}, speed, easing, callback);  
}; 


function clearCb(type, val)
{
	if(val == 0)
		$("#" + type + " .all input").attr("checked", false);
	else
		$("#" + type + " .ind input").attr("checked", false);
}

function setupLabel()
{
	if ($('#portfoliosearch input').length)
	{
		$('#portfoliosearch label').each(function(){ 
			$(this).removeClass('on');
		});
		$('#portfoliosearch label input:checked').each(function(){ 
			$(this).parent('label').addClass('on');
		});                
	}
}


function mycarousel_initCallback(carousel)
{
	$('.jcarousel-controls a').bind('click', function() {
	  carousel.scroll($.jcarousel.intval($(this).text()));
	  $('.jcarousel-controls a').removeClass('current');
	  $(this).addClass('current');
	  return false;
	});
}

