var IOS_DEVICE = false;
$(document).ready(function(){
	// Detects iOS device
	IOS_DEVICE = IfIOSDevice();
	
	if(IOS_DEVICE) {
		$('html').addClass('ios-device');
		$('html').addClass(IfIOSDevice())
	}
	
	// Detects language
	//window.mWheely.detectLang(); 
	
	// Loads dictionaries
	//window.mWheely.loadL10n();
	
	(function() {
		var overlay = document.getElementById('overlay');
		
		var content = document.getElementById('content');
		if (content) content.style.display = 'block';
		
		if (!overlay) { return; }
		else { overlay.style.display = 'none'; }
	})();	
	
	// tab switcher init
	(function() {
		var featuresSwitcher = new TabSwitcher({
			parentSelector: '.features'
		});	
		
		var endSwitcher = new TabSwitcher({
			parentSelector: '.end_block'
		});	
	})();
	
	// map init
	window.mapLoader = new MapLoader();
	
	// animations init
	(function() {
		var car = new Car();
		var dude = new Dude();
		var clouds = new Clouds();
		var scene = new Scene();
		var topMenu = new TopMenu();
	})();
	
	// twitter init
	(function() {
		var user, lang;
		
		if ($.cookie('lang')) {
			lang = $.cookie('lang');
		} else {
			lang = navigator.language.substr(0, 2);
		}
		
		switch (lang) {	
			case 'ru':
				user = 'wheelyru';
				break;

			default:
				user = 'wheely';
				break;
		}

		
		new TWTR.Widget({
		    version: 2,
		    type: 'profile',
		    id: 'twitter',
		    rpp: 1,
		    interval: 3000000,
		    width: 310,
		    height: 100,
		    theme: {
		        shell: {
		            background: '#ffffff',
		            color: '#000000'
		        },
		        tweets: {
		            background: '#ffffff',
		            color: '#000000',
		            links: '#000000'
		        }
		    },
		    features: {
		        scrollbar: false,
		        loop: false,
		        live: false,
		        behavior: 'all'
		    }
		}).render().setUser(user).start();
	})();
	
	// header menu
	var STD_NAV_ANIMATION_FACTOR = 5;
	var STD_NAV_ANIMATION_EASING = 'easeInOutQuad';
	(function() {
		var topBarResizer = new TopBarResizer();
	
		var linkTop = new ScrollToAnimation({
			selector: '#link-top',
			scrollTo: 0
		});
		var linkFeatures = new ScrollToAnimation({
			selector: '#link-features',
			scrollTo: 750
		});
		var linkTop = new ScrollToAnimation({
			selector: '#link-map',
			scrollTo: 1820
		});
		var linkFeatures = new ScrollToAnimation({
			selector: '#link-download',
			scrollTo: 3090
		});
		
	})();
	
	
	// Google analytics
	(function() {
		var _gaq = _gaq || [];
		_gaq.push(['_setAccount', 'UA-26005152-1']);
		_gaq.push(['_setDomainName', '.wheely.com']);
		_gaq.push(['_trackPageview']);
		
		(function() {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();
	})();
	
	/*var _stc = { id : 280 };
    (function() {
        var st = document.createElement('script'),
        s = document.getElementsByTagName('script')[0];
        st.type = 'text/javascript';
        st.async = true;
        st.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'st.sitetarget.ru/st.js';
        s.parentNode.insertBefore(st, s);
    })();	*/
	
	
	// Remove cookie on click on mobile version link
	(function() {
		$('#mobile-version').click(function() {
			$.cookie('noredirect', null, {
				domain: '.wheely.com'
			});
			//console.log('desktop click: ' + $.cookie('noredirect'));
			//return false;
		});
		
		//console.log('desktop start: ' + $.cookie('noredirect'));
	})();
	
	
	// Language switcher
	(function() {
		var langSwitcher = new LangSwitcher();
		$('.header-lang-switch a').click(function(event) {
			event.preventDefault();
			
			var id = $(this).parent().attr('id');
			var lang = id.split('lang-')[1];
			
			$.cookie('lang', lang);
			
			window.location.reload();
			
			return false;
			
		});
	})();
	
	// iOS position:fixed trick
	(function() {
		if (IfIOSDevice()) {
			var taxiFix = new IOSTaxiFix();
			var barFix = new IOSBarFix();
		}
	})();
	
	// scroll to top to remove address bar on iPhone
	(function() {
		if (IfIOSDevice()) {
			$(window).load(function() {
				setTimeout(function() {
					$(window).scrollTop(1);
				}, 50);
			});
		}
	})();
	
	// idle init
	(function() {
				
	})();
});

