var carousel_size = 0;
$(document).ready(function(){
	//flowplayer("player", {src: "/flash/flowplayer-3.1.1.swf", wmode: 'opaque'},  { 
	//	clip: { autoBuffering: false }, plugins: {controls: null},canvas:  {background: '#000000',backgroundGradient: 'none'}
	//});
	
	jQuery('.news-slideshow').jcarousel({
        auto: 4,
		scroll: 1,
		size: carousel_size,
		visible: 1,
		animation: 'slow',
        wrap: 'last',
		initCallback: mycarousel_initCallback
    });
	
	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();
	    });
	};

	
	/*
	 * gallery
	 */
	var galleryTotalWidth = 0;
	var maxScrollSpeed = 10000;
	var scrollDirection, hiddenArea, windowCenter, deadZoneStart, deadZoneEnd, scrollSpeed;
	
	// count and set gallery-wraper width
	jQuery.each(jQuery.makeArray($("#gallery .content li")), function() {
		galleryTotalWidth = galleryTotalWidth + 126; // image width + margins
   	});
	 
	// resize gallery
	$('#gallery .content ul').width(galleryTotalWidth);
	
	hiddenArea = galleryTotalWidth - $(window).width();
	deadZoneStart = $(window).width() / 4;
	deadZoneEnd = deadZoneStart * 3;
	windowCenter = $(window).width() / 2;
	
	$("#gallery .content ul").mouseover(function(e){
		if((deadZoneStart < e.screenX) && (e.screenX < deadZoneEnd )){
			scrollSpeed = maxScrollSpeed;
		} else {
			scrollSpeed = maxScrollSpeed / 3;
		}
		if(e.screenX > (windowCenter + deadZoneStart)){
			//if($("#gallery .content ul").offset().left > - hiddenArea){
				$("#gallery .content ul").animate({
					"left": "-" + hiddenArea + "px"
				}, {
					duration: scrollSpeed
				});
			//}
		} else if (e.screenX < (windowCenter - deadZoneStart)) {
			//if ($("#gallery .content ul").offset().left < 0) {
				$("#gallery .content ul").animate({
					"left": "0px"
				}, {
					duration: scrollSpeed
				});
			//}
		};
    }).mouseout(function(){
		$("#gallery .content ul").stop(1000);
    });
	
	$("#tabs").tabs({fx:{opacity: "toggle"}});
	var tabs_count = $("#tabs .ui-tabs-nav").find("li").length + 1;
	$("#tabs .ui-tabs-nav").find("li").each(function(){
		$(this).css("width", "" + parseInt(100/tabs_count - 1) + "%");
	});
});

