var isMobile = function() {
	var _htmlClasses = document.getElementsByTagName('html')[0].className;
	var classAry = _htmlClasses.split(" ");
	var isDesktop = _htmlClasses.match(/mac|win/);
	if (classAry.indexOf('ipad') != -1 || window.location.hash == "#nomobile" || isDesktop) {
		classAry.push("bypass");
		document.getElementsByTagName('html')[0].className = classAry.join(" ");
		return false;
	};
	return true;
}

if (isMobile()) {
	MOBILIZE.init({
		tpl: 'mobile/_green_landing.html'
	});	

	dep('shared/js/jquery.js', function() {
			var page = $('.iphone body, .android body');

			var isAndroidTablet = function() {
				if (!$('html').hasClass('android')) {
					return false;
				}
				var ua  = navigator.userAgent.match(/Safari|Mobile/);
				ua = ua == null ? '' : ua[0];
				if (ua == "Safari" && $('html').hasClass('android')) {
					$('html')
						.removeClass('android android android')
						.addClass('android-tablet');
					return true;
				}
			};

			page.bind('mobilize-portrait', function(event) {
					// XXX: there's a wierd glitch that doesn't re-render the styles if you move from landscape to portrait
					$('body').load('mobile/_green_landing.html');
				})
				.bind('mobilize-template-loaded', function(event) {
					$('.android #phone-pic').replaceWith('<img src="mobile/images/green_android.png" />');
					$('.android #app-download')
						.attr('href','http://crashplan.com/redirect/en/mobile/green-android-download');
				})
				.show();
	});

} else {

	dep('shared/js/jquery.js', 
		'shared/js/jquery-ui.js', 
		'/common/js/jquery.c42.js', 
		'shared/js/jquery.c42.header.js', 
		'shared/js/jquery.c42.footer.js', 
		'shared/js/jquery.c42.prourls.js', 
		'/common/js/jquery.platformSelector.js',

		function() {
			
			$('body').fixProUrls();
			$('#header').header();
			$('#footer').footer();
						
			var slide = 1;
			var selectedSlide = false;
			
			switchSlide();
			var slideTimer = setInterval( switchSlide, 10000 );
			
			$("#download-btn-container").platformSelect();
			
			$(".slide-nav").click(function(e){
				selectedSlide = true;
				e.preventDefault();
				clearInterval(slideTimer);
				selectedSlide = $(this).attr("id");
				switchSlide(selectedSlide);
			});
			
			function switchSlide(){
				$(".slide").css("display","none");
				$(".slide-nav").removeClass("slide-nav-selected");
				if(selectedSlide){
					$("#"+selectedSlide).addClass("slide-nav-selected");
					$("#"+selectedSlide+"-section").fadeIn();
				}else{
					if( slide > 3){ slide = 1; }
					$("#slide-"+slide).addClass("slide-nav-selected");
					$("#slide-"+slide+"-section").fadeIn();
					slide++;
				}
				displayDownloadBtn();
			}
			
			function displayDownloadBtn(){
				if($(".app-store-btns").is(":visible")){
					$("#download-btn-container").hide();
				}else{
					$("#download-btn-container").show();
				}
			}
		
		});
}
