$(document).ready(function() {
   	
	$('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
	
	if(jQuery('#designs').children().size()>3){
		jQuery('#designs').addClass('jcarousel-skin-plh');
		jQuery('#designs').jcarousel();
	}
	
	if(jQuery('#renderings').children().size()>1){
		jQuery('#renderings').addClass('jcarousel-skin-plhelevations');
		var num = ($('#renderings').children().size());
		$('#renderings').before("<ul id='controls'>");
		for(var i=0; i<num; i++){
		//alert(i);
		var n=i+1;
		$('#controls').append("<li class='jcarousel-control'><a href='#'>"+n+"</a></li>");
		if(i==0){
		$('.jcarousel-control').addClass('active');	
		}
		}
		$('#renderings').before("</ul");
		//*/
		jQuery('#renderings').jcarousel({
		scroll: 1,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
		});
	}
	});


	function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		$('.jcarousel-control').each(function(i){
			$(this).removeClass('active');							   
		});
		$(this).parent().addClass('active');
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });
	};