$(document).ready(function() {

	//this is the useful function to scroll a text inside an element...

	function startScrolling(scroller_obj, velocity, start_from){
		//bind animation to the children inside the scroller element
		scroller_obj.children().bind('marquee', function(event,c) {
			//text to scroll
			var ob = $(this);
			//scroller width
			var sw = parseInt(ob.parent().width());
			//text width
			var tw = parseInt(ob.width());
			//text left position relative to the offset parent
			var tl = parseInt(ob.position().left);
			//velocity converted to calculate duration
			var v  = velocity>0 && velocity<100 ? (100-velocity)*100 : 5000;
			//same velocity for different text's length in relation with duration
			var dr = (v*tw/sw)+v;
			//is it scrolling from right or left?
			switch(start_from){
			case 'right':
				//is it the first time?
				if(typeof c == 'undefined'){
					//if yes, start from the absolute right
					ob.css({ left: sw });
					sw = -tw;
				}else{
					//else calculate destination position
					sw = tl - (tw + sw);
				};
				break;
			default:
				if(typeof c == 'undefined'){
					//start from the absolute left
					ob.css({ left: -tw });
				}else{
					//else calculate destination position
					sw += tl + tw;
				};
			}
			//attach animation to scroller element and start it by a trigger
			ob.animate(	{left:sw},
						{	duration:dr,
							easing:'linear',
							complete:function(){ob.trigger('marquee');},
							step:function(){
								//check if scroller limits are reached
								if(start_from == 'right'){
									if(parseInt(ob.position().left) < -parseInt(ob.width())){
										//we need to stop and restart animation
										ob.stop();
										ob.trigger('marquee');
									};
								}else{
									if(parseInt(ob.position().left) > parseInt(ob.parent().width())){
										ob.stop();
										ob.trigger('marquee');
									};
								};
							}
						});
		}).trigger('marquee');
		//pause scrolling animation on mouse over
		scroller_obj.mouseover(function(){
			$(this).children().stop();
		});
		//resume scrolling animation on mouse out
		scroller_obj.mouseout(function(){
			$(this).children().trigger('marquee',['resume']);
		});
	};

	//the main app starts here...

	//change the cursor type for each scroller
	$('.scroller').css("cursor","pointer");

	//settings to pass to function
	var scroller			= $('.scroller');	// element(s) to scroll
	var scrolling_velocity 	= 5; 				// 1-99
	var scrolling_from 		= 'left';			// 'right' or 'left'

	//call the function and start to scroll..
	startScrolling( scroller, scrolling_velocity, scrolling_from );

	//create a new scroller but it starts from left...
	//$('#fast_scroller').css("cursor","pointer");
	//startScrolling( $('#fast_scroller'), 75, 'left');

});


function slideSwitch() {
    var $active = $('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});




// News
$(function(){
	$('.news-container').vTicker();
});


$(function() {
$(".comment_button").click(function() {

var test = $("#message").val();
var dataString = 'message='+ test;

if(test=='')
{
alert("Please Enter Some Text");
}
else
{
$("#flash").show();
$("#flash").fadeIn(400).html('<span class="loading engtext">Sending ...</span>');

$.ajax({
type: "POST",
url: "livechat.asp",
data: encodeURI(dataString),
cache: false,
success: function(html){
$("#display").after(html);
document.getElementById('message').value='';
document.getElementById('message').focus();
$("#flash").hide();
}
});
} return false;
});
});

