// JavaScript Document
jQuery(document).ready(function($){
	$("#menu ul li a").append('<span></span>');
	$("#menu ul li ul").each(function(){
		var liw = 0;
		$("li", this).each(function(){
			liw += parseInt($(this).width());
		});
		if(liw + 24 > $(this).width()) {
			$("li a", this).css("padding", "0px 15px");
			$(this).width(liw + 24 - 6 * $("li", this).length);
		}
	});
	$("#menu>ul>li").each(function(){
		if(!$("ul", this).length){
			$("a span", this).hide();
		}
	});
	
	/*********************************************************
							MS IE 6
	*********************************************************/
	if($.browser.msie && $.browser.version < 7) {
		$("img[src$='.png']").each(function(i){
			$(this)
				.attr("width", parseInt($(this).width()))
				.attr("height", parseInt($(this).height()));
			$(this)
				.css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + $(this).attr("src") + "')")
				.attr("src", "/kugaudo/assets/templates/kugaudo/img/spacer.gif");
		});
	}
	
	
	/*********************************************************
							...
	*********************************************************/
	/*$("#content h1, #content h2, #content h3").each(function(){
		if(!$("img", this).length) {
			$(this).gradienttext({
				colors: ['#FFF', '#FFF', '#919191'],
				style: 'vertical',
				shadow:             true,
				shadow_color:       '#000000',
				shadow_offset_x:    1,
				shadow_offset_x:    1,
				shadow_blur:        1
			});
		}
	});*/
	
	$(".tabs ul li a").click(function(){
		var ul = $(this).parent().parent();
		
		$("#" + $("li.active a", ul).attr("rel")).hide();
		$("li", ul).removeClass("active");
		
		$(this).parent().addClass("active");
		$("#" + $(this).attr("rel")).show();
		
		return false;
	});
	
	/*********************************************************
							Carousel
	*********************************************************/
	
	if($("#carousel .container li").length > 1) {
		$("#carousel .container").jcarousel({
				auto: 10,
				scroll: 1,
				wrap: 'circular',
				// This tells jCarousel NOT to autobuild prev/next buttons
				buttonNextHTML: null,
				buttonPrevHTML: null,
				//
				initCallback: carousel_initCallback//,
				//itemVisibleInCallback: carousel_itemVisibleInCallback
		});
	}
});

function carousel_initCallback(carousel) {	
	jQuery('#carousel .nav a.next').bind('click', function() {
		carousel.next();
		return false;
	});
	
	jQuery('#carousel .nav a.prev').bind('click', function() {
		carousel.prev();
		return false;
	});

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
}
