var $time = 10000;
var $t = false;
$(document).ready(function(){
	var sitewidth = $("div#container").width()
	var siteoffset = $("ul#links>li:first").offset().left;
	$("ul#links>li").each(function(){
		var positionleft = $(this).offset().left-siteoffset-45;
		if(positionleft > (sitewidth-881)){
			$(this).children("ul").css('marginLeft', "-"+positionleft+"px");
		}
	});
	$("form#convert .submit").click(function(){
		var amount = $("form#convert input[name='amount']").val();
		var cfrom = $("form#convert select[name='from']").val();
		var cto = $("form#convert select[name='to']").val();
		var ratio = cto/cfrom;
		var converted = amount*ratio;
		$("form#convert input[name='value']").val((amount*ratio).toFixed(4));
	});
	$("ul#fader li:not(:first)").hide();
	$("div#feats ul#buttons a").click(function(){
		fadeToSlide($(this).parent().index());
	});
	$t = setTimeout('slideTimer()', $time);
	var clients = $("div#clients div.carousel ul li").length;
	$("div#clients a.left").click(function(){
		$("div#clients div.carousel ul").stop(true, true);
		var leftamount = $("div#clients div.carousel ul").css('left');
		if(leftamount == '0px')
		$("div#clients div.carousel ul").animate({left: '-'+(209*clients-209)+'px'}, 500);
		else
			$("div#clients div.carousel ul").animate({left: '+=209px'}, 500);
	});
	$("div#clients a.right").click(function(){
		$("div#clients div.carousel ul").stop(true, true);
		var leftamount = $("div#clients div.carousel ul").css('left');
		var maxamount = '-'+(209*clients-209)+'px';
		if(leftamount == maxamount)
			$("div#clients div.carousel ul").animate({left: '0px'}, 500);
		else
			$("div#clients div.carousel ul").animate({left: '-=209px'}, 500);
	});
	$("div#bar span:not(:first)").hide();
	$t = setTimeout('nextTwitter()', 8000);
});
function nextTwitter(){
	currentshow = $("div#bar span:visible").index();
	totalspan = $("div#bar span").length;
	nextshow = currentshow+1;
	if(nextshow > totalspan)
		nextshow = 0;
	$("div#bar span:visible").fadeOut(800, function(){
		$("div#bar span:eq("+nextshow+")").fadeIn(800);
	});
	$t = setTimeout('nextTwitter()', 8000);
}

function rotateEvery(sec)
{
	var Quotation=new Array()

	// QUOTATIONS
	Quotation[0] = 'Currencies 4 You gave us an outstanding service from start to finish - they have catered for our every need, and continue to do so with the regular transfers overseas division which we have also taken advantage of. Now we can relax and enjoy our home knowing our mortgage will be paid each month. We cant thank you enough<br><br><b>Sammy Lewis</b><br>Overseas property purchase';
	Quotation[1] = 'Currencies 4 You, as individuals and a team have been friendly and provided me with a second to none service. Moving to the other side of the world can be a daunting task, but you really stuck to your word and made the money side of things so simple. Its such a relief to have the confidence to know whenever I need another dollar youre just a phone call away.<br><br><b>Margaret Dillon</b><br>Moved to California';
	Quotation[2] = 'I am very happy with the service I was given, extremely professional, but also very quick. From my initial contact, to paying my deposit for my property took less than 4 hours! I cant thank you enough and will definitely be recommending this service to my friends and family. I will use your company again and again and again!<br><br><b>Charles D Anthony</b><br>French Property Buyer';
	Quotation[3] = 'Why didnt I know about you sooner? Thanks Guys, I worked out you are saving me over &pound;1200 a year just on transfer fees, let alone what you save me on the rates each week.<br><br><b>Danny Santon</b><br>Importer';
	Quotation[4] = 'Currencies 4 You are a contributing factor to our survival in this economic climate, I can only thank you for the professionalism and excellent customer service you continue to provide our business.<br><br><b>Matthew Coleman</b><br>Financial Director';
	Quotation[5] = 'You have provided me with an unbeatable exchange rate every time, ensuring a smooth transaction and saving me both time and money. I cant see any reason why anyone should look elsewhere.<br><br><b>Lisa Harding</b><br>Managing Director';
	Quotation[6] = 'Working with you has been brilliant, not only are my clients extremely happy with the service you provide them with but also the speed and accuracy of the transactions allows us to have the confidence and peace of mind that the funds will be here when required, never missing a deadline. Keep up the good work.<br><br><b>Jose</b><br>Spanish Real Estate';
	Quotation[7] = 'Being recommended to use your services by my friends estate agency I was not too sure as I have always said no to using currency companies, but giving you the chance is probably the best decision I have made as a director. The professionalism is beyond what I expected. The service for me and the exchange rates are definitely reasons to keep this relationship we have going.<br><br><b>Vincent</b><br>French Property Agent';
	Quotation[8] = 'Where do I start? Well firstly I would like to thank you for the service you provide us and more importantly our clients. Secondly the affiliation programme you offer is super, and the fact you advertise our properties for free, and even help sell them tops it all off.<br><br><b>Ethan</b><br>Florida Realty';

	var which = Math.round(Math.random()*(Quotation.length - 1));
	document.getElementById('textrotator').innerHTML = Quotation[which];
	
	setTimeout('rotateEvery('+sec+')', sec*1000);
}

function slideTimer()
{
	var slideindex = $("ul#fader li:visible").index();
	var slidetotal = $("ul#fader li").length;
	slidenext = slideindex+1;
	if(slidenext == slidetotal)
		slidenext = 0;
	fadeToSlide(slidenext);
	$t = setTimeout('slideTimer()', $time);
}
function fadeToSlide(slideno)
{
	var $currentslide = $("ul#fader li:visible");
	var $slideto = $("ul#fader li:eq("+slideno+")");
	if($currentslide.index() != slideno)
	{
		$("ul#fader li").stop(true, true);
		$("ul#fader li").find('span').stop(true, true);
		$currentslide.find('span').fadeTo(300, 0, 'linear', function(){
			$slideto.find('span').hide();
			$currentslide.fadeTo(500, 0, 'linear');
			$("div#feats ul#buttons li.active").removeClass("active");
			$("div#feats ul#buttons li:eq("+slideno+")").addClass("active");
			$slideto.fadeTo(500, 1, 'linear', function(){
				$currentslide.hide();
				$slideto.show();
				$slideto.find('span').fadeTo(1000, 1, 'linear');
			});
		});
	}
}
