$(document).ready(function(){

    $('#mycarousel').jcarousel({
        auto: 5,
		animation: 800,
        wrap: 'both',
        initCallback: mycarousel_initCallback
    });
	
    $("a[rel*=external]").attr( "target", "_blank");
	
	$(".popup a").hover(function() {
	$(this).next("span").stop(true, true).animate({opacity: "show", top: "-60"}, "slow");
	}, function() {
	$(this).next("span").animate({opacity: "hide", top: "-70"}, "fast");
	});
 
	 $("#content .brust-botton a").hover(function() {
	$(this).next("em").stop(true, true).animate({opacity: "show", left: "-190"}, "slow");
	}, function() {
	$(this).next("em").animate({opacity: "hide", left: "-220"}, "fast");
	});

	$("#content .readmore").click(function() {
		$("#content .readmore").animate({opacity: "hide"}, "fast");								  
		$(this).next().css({display: "show"});
		$(this).next().animate({opacity: "show"}, "slow");
	});
	
	simple_tooltip("input","tooltip");
	simple_tooltip("a","tooltip");
	simple_tooltip("textarea","tooltip");	
	alertBlack();
	
	$('.default-value').each(function() {
		var default_value = this.value;
		$(this).css('color', '#666'); // this could be in the style sheet instead

		$(this).focus(function() {
			if(this.value == default_value) {
				this.value = '';
				$(this).css('color', '#000');
			}
		});
		$(this).blur(function() {
			if(this.value == '') {
				$(this).css('color', '#666');
				this.value = default_value;
			}
		});
	});

});

function alertBlack() {
	$("#alertBlack").one('click',function() {	
			$('#alertBlack').fadeOut("fast");
	});		
}

function simple_tooltip(target_items, name){
 $(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
		var my_tooltip = $("#"+name+i);

		if($(this).attr("title") != "" && $(this).attr("title") != "undefined" ){

		$(this).removeAttr("title").mouseover(function(){
					my_tooltip.css({opacity:0.8, display:"none"}).fadeIn("fast");
		}).mousemove(function(kmouse){
				var border_top = $(window).scrollTop();
				var border_right = $(window).width();
				var left_pos;
				var top_pos;
				var offset = 20;
				if(border_right - (offset *2) >= my_tooltip.width() + kmouse.pageX){
					left_pos = kmouse.pageX+offset;
					} else{
					left_pos = border_right-my_tooltip.width()-offset;
					}

				if(border_top + (offset *2)>= kmouse.pageY - my_tooltip.height()){
					top_pos = border_top +offset;
					} else{
					top_pos = kmouse.pageY-my_tooltip.height()-offset;
					}

				my_tooltip.css({left:left_pos, top:top_pos});
		}).mouseout(function(){
				my_tooltip.css({left:"-9999px"});
		});

		}

	});
}
function mycarousel_initCallback(carousel)
{

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
 
