// Constructor
	const BASE_URL = '';

// Screen
	function initScreen() {
		$(window).resize(resizeVideo);
		if ("onorientationchange" in window) {
			window.addEventListener("orientationchange", resizeVideo, false);
		}
		resizeVideo();
	}
	function resizeVideo() {
		var resizeW = $("#youtube_video").width();
		var resizeH = Math.ceil((resizeW/16) * 9) + 30;
		$("#youtube_video").css("height", resizeH);
	}

// Background
	function initBg() {
		if ($('body').hasClass('desktop')) {
			
			var bgImgs = "";
			bgImgs += 'url(' + BASE_URL + 'assets/img/bg/clouds/1.png) no-repeat fixed, ';
			bgImgs += 'url(' + BASE_URL + 'assets/img/bg/clouds/2.png) no-repeat fixed, ';
			bgImgs += 'url(' + BASE_URL + 'assets/img/bg/clouds/3.png) no-repeat fixed, ';
			bgImgs += 'url(' + BASE_URL + 'assets/img/bg/clouds/4.png) no-repeat fixed, ';
			bgImgs += 'url(' + BASE_URL + 'assets/img/bg/clouds/5.png) no-repeat fixed, ';
			bgImgs += 'url(' + BASE_URL + 'assets/img/bg/clouds/2.png) no-repeat fixed, ';
			bgImgs += 'url(' + BASE_URL + 'assets/img/bg/stars/1.png) no-repeat fixed, ';
			bgImgs += 'url(' + BASE_URL + 'assets/img/bg/stars/1.png) no-repeat fixed, ';
			bgImgs += 'url(' + BASE_URL + 'assets/img/bg/stars/1.png) no-repeat fixed, ';
			bgImgs += 'url(' + BASE_URL + 'assets/img/bg/stars/1.png) no-repeat fixed, ';
			bgImgs += 'url(' + BASE_URL + 'assets/img/bg/stars/2.png) no-repeat fixed, ';
			bgImgs += 'url(' + BASE_URL + 'assets/img/bg/stars/2.png) no-repeat fixed, ';
			bgImgs += 'url(' + BASE_URL + 'assets/img/bg/stars/1.png) no-repeat fixed, ';
			bgImgs += '#ad9f82 url(' + BASE_URL + 'assets/img/bg/gradient.jpg) repeat-x left top scroll';
			$('body').css('background', bgImgs);
			
			$(window).scroll(adjustBg);
			$(window).resize(adjustBg);
			adjustBg();
		}
	}
	function adjustBg() {
		var windowHeight = $(window).height();
		var position = $(window).scrollTop();
		var bgPos = "";
		
		bgPos += '80% ' + 		((windowHeight * 0.15) - position * 0.2) + 'px, ';
		bgPos += '25% ' + 		((windowHeight * 0.10) - position * 0.5) + 'px, ';
		bgPos += '-100px ' + 	((windowHeight * 0.50) - position * 0.4) + 'px, ';
		bgPos += '50% ' + 		((windowHeight * 0.90) - position * 0.3) + 'px, ';
		bgPos += '115% ' + 		((windowHeight * 0.75) - position * 0.6) + 'px, ';
		bgPos += '85% ' + 		((windowHeight * 1.75) - position * 0.5) + 'px, ';
		
		bgPos += '65% ' + ((windowHeight * 0.08) - position * 0.7) + 'px, ';
		bgPos += '60% ' + ((windowHeight * 0.45) - position * 0.6) + 'px, ';
		bgPos += '80% ' + ((windowHeight * 0.55) - position * 0.5) + 'px, ';
		bgPos += '20% ' + ((windowHeight * 0.65) - position * 0.4) + 'px, ';
		bgPos += '30% ' + ((windowHeight * 0.55) - position * 0.3) + 'px, ';
		bgPos += '70% ' + ((windowHeight * 0.85) - position * 0.4) + 'px, ';
		bgPos += '15% ' + ((windowHeight * 1.50) - position * 0.3) + 'px, ';
		
		bgPos += 'top left';
		
		$('body').css('background-position', bgPos);
	}
	
// Jukebox
	function initJukebox() {
		if ($('body').hasClass('desktop')) {
			swfobject.embedSWF(BASE_URL+'assets/swf/jukebox.swf', 'jukebox_swf', '295', '80', '9.0.0', false, {xml:BASE_URL+'assets/xml/jukebox.xml'}, {menu:'false', wmode:'transparent'});
		}
	}
	
// Email Form
// https://docs.topspin.net/tiki-index.php?page=Email+For+Media+REST+API
// http://app.topspin.net/store/therosebuds.spinshop.com?campaign=http://app.topspin.net/api/v1/artist/5221/campaign/10126020&fan=http://app.topspin.net/api/v1/fan/show/27370741?artist_id=5221&auth=68067f58a879756997847770fd674f9a&has_media=true
	function initEmailForm() {
		$('#free').slideDown();
		setFormInput('#email', 'Enter Email');
		$('#email_form').submit(function() {
			if (!isValidEmail($('#email').val())) {
				alert('Please enter a valid email address.');	
				return false;
			}
			$('form input').attr('disabled', 'disabled');
			$.ajax({
				url: "http://app.topspin.net/api/v1/fan/create_fan",
				type: "GET",
				dataType: 'jsonp',
				data: ({'fan':
					{
						email: $('#email').val(),
						source_campaign: 'https://app.topspin.net/api/v1/artist/5221/campaign/10126020', 
						referring_url: 'http://therosebuds.com',
						confirmation_target: 'http://www.topspindownloads.com/confirm/',
						artist_id: '5221'
					}
				}), success: function($data) {
					//alert($data.success);
					alert("You've been emailed the download information.");
					$('form input').removeAttr('disabled');
					$('#email').val('Enter Email');
				}
			});
			return false;
		});
	}
	
	function setFormInput($input, $label) {
		$($input).val($label);
		$($input).focus(function() {
			if ($(this).val() == $label) { $(this).val(''); }
		});
		$($input).blur(function() {
			if ($(this).val() == '') { $(this).val($label); }
		});
	}
	function isValidEmail($email) {
		var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		return regex.test($email);
	}

// Document is Ready
	$(document).ready(function() {
		initScreen();
		initBg();
		initJukebox();
		initEmailForm();
		
	});

