
$(document).ready(function() {
     jQuery(function () {
			var scrollDiv = document.createElement('div');
			jQuery(scrollDiv).attr('id', 'toTop').html('^ Back to Top').appendTo('body');
			jQuery(window).scroll(function () {
			        if (jQuery(this).scrollTop() != 0) {
			            jQuery('#toTop').fadeIn();
			        } else {
			            jQuery('#toTop').fadeOut();
			        }
			    });
			    jQuery('#toTop').click(function () {
			        jQuery('body,html').animate({
			            scrollTop: 0
			        },
			        900);
	 	    });
	 });
	//jQuery.easing.def = "easeOutElastic";

	$('.map-pin').hover(function(){

		$('.map-bubble').remove();
		$('.map-ripple').remove();

		$(this).append('<div class="map-ripple"></div>');
		$(this).append('<div class="map-bubble"><img src="images/clients/map-'+$(this).attr('rel')+'.png"></div>');

		if ($.browser.mozilla){
			$('.map-ripple').hide();
			$('.map-ripple').fadeIn(500);
		}

		// IE opacity, remove it
		if($.browser.msie){
			$('.map-bubble',this).hide();
			$('.map-bubble',this).show();
		} else {
			$('.map-bubble',this).css('opacity','0');
			$('.map-bubble',this).stop(true,true).animate({
				opacity:1,
				marginTop: "+=20px"
			},250);
		}

	},function(){

		// Again, IE disable animations
		if($.browser.msie){
			$('.map-ripple',this).remove();
			$('.map-bubble',this).remove();
		} else {
			$('.map-ripple',this).remove();
			$('.map-bubble',this).stop(true,true).animate({
				opacity:0,
				marginTop: "-=20px"
			},250,function(){
				$(this).remove();
			});
		}
	});

    // Input Focus Value
    $('input[type="text"]').focus(function() {
        if (this.value == this.defaultValue){
    	    this.value = '';
		}
		if(this.value != this.defaultValue){
	        this.select();
	    }
    });
    $('input[type="text"]').blur(function() {
        if ($.trim(this.value) == ''){
		    this.value = (this.defaultValue ? this.defaultValue : '');
		}
    });



});

function startSpinningCounter(n,h){

	$('#'+n+' ul li').stop(true,true).animate({
		backgroundPosition: "0px 2000px"
	},2000,'linear');

}


function showInfoUK(){
	$('#switch-us').fadeOut(300,function(){
		$('#switch-uk').fadeIn(300);
	});
	if(parseFloat($('#contact-switch-slider').css('margin-left')) > 50){
		$('#contact-switch-slider').animate({
			marginLeft: "-=70px"
		}, 150);

	}

	$('#pin-us').empty();
	$('#pin-uk').append('<div class="map-ripple"></div>');
}


function shuffleCounterNumbers(div,numHeight){
	rcNum = $('#'+div+' ul li');

	i = 0;
	while(i < 8){
		ranPos = (Math.random(50000)+'').substr(2,3);
		$(rcNum[i]).css('background-position','0px '+ranPos+'px');
		i++;
	}
}



function dropMapPins(){

	var mapPins = $('.map-pin');

	i = 0;
	var pinAnimation = setInterval(function(){

		if(i < mapPins.length){

			mT = parseFloat($(mapPins[i]).css('margin-top'));

			$(mapPins[i]).css('margin-top', '-400px');

			$(mapPins[i]).animate({
				marginTop: mT+'px',
				opacity : 1
			},300,function(){ $(this).css('opacity','none'); });


			i++;
		} else {
			clearInterval(pinAnimation);
		}
	},100);


};


