$(function(){
    // JCAROUSEL
	function mycarousel_initCallback(carousel) {
		jQuery('#member-strip ul a').bind('click', function() {
			carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr("rel")))
			return false;
		});
	};
	$('.carousel').show();
	 $('#mycarousel, #mycarousel2').jcarousel({
    	wrap: 'circular',
		scroll: 1,
		auto: 5
    });
		

	// PANEL SLIDE
	$(".btn-slide").click(function(){
		$("#panel").slideToggle("slow");
		$(this).toggleClass("active"); return false;
	});
	
	$(".btn-slide2").click(function(){
		$("#panel2").slideToggle("slow");
		$(this).toggleClass("active"); return false;
	});
	
	// READ MORE SECTION ON HOMEPAGE
	$('.content_more_block, div.readevenmore').css('display', 'none');
	$('#homeSubNav a.readmore').click(function(){
		var $target = $(this).attr('href');
		if($($target).is(':visible'))
			var thiss = 1;
		$('.content_more_block:visible, div'+$target+'2').hide();
		$('a.readevenmore').css('background-position', '0 0');
		if(!thiss)
			$($target).fadeIn(300);
		return false;
	});
	$('#read_more_section a.readevenmore').click(function(){
		var $target = $(this).attr('href');
		if($($target).is(':visible')) {
			$(this).css('background-position', '0 0');
			$($target).slideUp();
		}
		else {
			$(this).css('background-position', '0 -9px');
			$($target).slideDown();
		}
		return false;
	});
	// SUBNAVIGATION
	$('#subNavigationHeader a').click(function(){
		var $target = $(this).attr('href');
		if(!$($target).is(':visible')) {
			$('#subNavigationHeader a').removeClass('active');
			$(this).addClass('active');
			$('.subNavigationCat:not('+$target+')').hide();
			$($target).slideDown('slow');
		}
		return false;
	});
	
	
	// SLIDING BOXES
	//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
	//Vertical Sliding
	$('.boxgrid.slidedown').hover(function(){
		$(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
		
	});
	
	
	// PREVENT SELECTION OF ELEMENTS WHEN USING JCAROUSEL
	$.extend($.fn.disableTextSelect = function() {
        return this.each(function(){
            if($.browser.mozilla){//Firefox
                $(this).css('MozUserSelect','none');
            }else if($.browser.msie){//IE
                $(this).bind('selectstart',function(){return false;});
            }else{//Opera, etc.
                $(this).mousedown(function(){return false;});
            }
        });
    });
    $('#mycarousel, #mycarousel2, #homeContactForm h3, #homeImgGalleryText').disableTextSelect();//No text selection on elements with this class or id
});

// HANDLE SUBNAVIGATION CLICKS ON PORTFOLIO PAGE
function show_portfolio(name,start) {
	var targetOffset = $("#list").offset().top;
	$('html,body').animate({scrollTop: targetOffset}, 800);
	$.get("/portfolio.php?name="+name+"&start="+start,function(data){
		$('#projects').html(data);
		$('.boxgrid.slidedown').hover(function(){
			$(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:300});
		}, function() {
			$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
		});
	});
}

// CUFON START
Cufon.replace('#homeQuoteBtn a');
Cufon.replace('h2');
Cufon.replace('#mainContents h3');
Cufon.replace('#pageTitle h2');
Cufon.replace('#footerLinks h4');
Cufon.replace('.mainR .box3 .t1');
Cufon.replace('#topNav', {
	hover: {
		color: '#c9b798'
	}
});
Cufon.replace('#HomeTopNav', {
	hover: {
		color: '#c9b798'
	}
});
Cufon.replace('#quoteBtn a');
Cufon.replace('#homeSubNav .boxBlockTxt a');
Cufon.replace('#homeVideoGallery h3');
Cufon.replace('#homeContactForm h3');
Cufon.replace('#homeVideoGallery .txt');
Cufon.replace('#homeContactForm .txt');
Cufon.replace('#read_more_section h2');
Cufon.replace('#subNavigationHeader, #footerLinks .box h4', {
	color: '-linear-gradient(#f0f0f0, #909090)'
	/*
	hover: {
		color: '-linear-gradient(#909090, #f0f0f0)'
	}
	*/
});
//Cufon.replace('#homeImgGalleryContents span.h4');
