if (window.location.hostname == 'xide.hacks.ath.cx') {
	idiot = true;
} else {
	idiot = false;
}

google.load("jquery", "1.4.2");
google.load("jqueryui", "1");
google.load("swfobject", "2.2");

blinkingAccept = false;
playingMood="customize";
currentThumbsPage = 0;
slowCursor = false;
generes = new Array('pop', 'rock', 'metal', 'hiphop', 'rnb', 'soul', 'reggae', 'club', 'hits', 'swedish');
createSorting = false;
mouseX = 0;
mouseY = 0;

zeroClipboardObj = false;

function validateEmail(email) {
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	return email.match(re) 
}

function getHash() { /* Get hash without # */
	var hash = window.location.hash;
	if (hash.substr(0, 1) == '#') {
		return(hash.substr(1));
	} else {
		return(hash);
	}
}

function motionDetectionHasEnded(val) { // 800 x 400

	_gaq.push(['_trackEvent', 'MoodBooster', 'Finished', Math.floor(val) + '%']);

	goDistance = Math.floor(((viewportWidth / 2) - ($cursor.position().left + ($cursor.width() / 2))) / 100 * val);
	newCursorPos = Math.floor($cursor.position().left + goDistance + ($cursor.width() / 2));
	midScreen = Math.floor(viewportWidth / 2);

	slowCursor = true;
	track = nextTrack - 1;
	newTrack = Math.floor(newCursorPos / viewportWidth * customPlaylist.length);

	if (newCursorPos <= midScreen) {
		if (newTrack < track) {
			newTrack = track;
		}
	} else if (newCursorPos > midScreen) {
		if (newTrack > track) {
			newTrack = track;
		}
	}
	if (newTrack == track) {
		if (newCursorPos <= midScreen) {
			newTrack = track + 1;
		} else if (newCursorPos > midScreen) {
			newTrack = track - 1;
		}
	}
	nextTrack = newTrack + 1;
	renderTrackInfo(-1);
	playYouTube(newTrack);
}

function motionDetectionDenied() {
	switchView('player');
}

// VIEW COMPONENTS:

animSpeed = 200;
view = 'loader';

function toolbarComponent() {
	if (!idiot) {
		if (viewportHeight < 625) {
			extraTop = 1000;
		} else {
			extraTop = 0;
		}
		if (view == 'player') {
			extraTop = 0;
		}
		$toolbar.css({
			'display': 'block',
			'top': viewportHeight - 40 + extraTop,
			'left': 0
		});
		$toolbaryoutube.css({
			'display': 'block',
			'top': viewportHeight - 40 + extraTop,
			'left': viewportWidth - 68
		});
	}
}

function ornamentsComponent() {
	$ornamentLeft.animCSS({
		'display': 'block',
		'top': 0,
		'left': 0
	});
	$ornamentRight.animCSS({
		'display': 'block',
		'top': 0,
		'left': viewportWidth - $ornamentRight.width()
	});
}

function ornamentMidComponent() {
	var totHeight = 518;
	var topPos = Math.floor((viewportHeight / 2) - (totHeight / 2));
	$ornamentMid.animCSS({
		'display': 'block',
		'top': topPos + 260,
		'left': (viewportWidth / 2) - ($ornamentMid.width() / 2)
	});
}

function logo190x122Component() {
	$logo190x122.animCSS({
		'display': 'block',
		'top': 0,
		'left': Math.floor((viewportWidth / 2) - ($logo190x122.width() / 2))
	});
}

function logo259x164Component() {
	$logo259x164.animCSS({
		'display': 'block',
		'top': 20,
		'left': Math.floor((viewportWidth / 2) - ($logo259x164.width() / 2))
	});
}

function logo308x196Component() {
	if (idiot) {
		topPos = 50;
	} else {	
		var totHeight = 518;
		if (view == 'agecheck') {
			totHeight = 365;
		};
		var topPos = Math.floor((viewportHeight / 2) - (totHeight / 2));
	}
	$logo308x196.animCSS({
		'display': 'block',
		'top': topPos,
		'left': Math.floor((viewportWidth / 2) - ($logo308x196.width() / 2))
	});
}

function timelineComponent() {
	$timelineImg.css({'width': viewportWidth, 'height': 59});
	$timelineContainer.animCSS({
		'display': 'block',
		'top': 123,
		'left': 0
	});
	areaPerCopy = Math.floor(viewportWidth / $timelineCopyImages.length);
	copycounter = 0;
	$timelineCopyImages.each(function() {
		$(this).animCSS({
			'display': 'block',
			'top': 21,
			'left': (areaPerCopy * copycounter) + Math.floor(((areaPerCopy / 2) - ($(this).width() / 2)))
		});
		copycounter++;
	});
}

function sloganComponent() {
	var totHeight = 518;
	var topPos = Math.floor((viewportHeight / 2) - (totHeight / 2));
	$slogan.animCSS({
		'display': 'block',
		'top': topPos + 204,
		'left': Math.floor((viewportWidth / 2) - ($slogan.width() / 2))
	});
}

function legalComponent() {
	$legal.animCSS({
		'display': 'block',
		'top': viewportHeight - $legal.height() - 10,
		'left' : Math.floor((viewportWidth / 2) - ($legal.width() / 2))
	});
}

function cgcSelectComponent() {

	if (!idiot) {

		$cgcSelectContainer.animCSS({
			'top': 30,
			'left': Math.floor((viewportWidth / 2) - ($cgcSelectContainer.width() / 2)),
			'display': 'block'
		});

	} else {

		logo308x196Component();

	}

	/*

	if ((view == 'customize') || (view == 'clubs') || (view == 'guests')) {
		topPos = 200;
		$cgcSelectContainer.animCSS({
			'top': topPos,
			'left': Math.floor((viewportWidth / 2) - ($cgcSelectContainer.width() / 2)),
			'display': 'block'
		});
	} else {
		var totHeight = 518;
		var topPos = Math.floor((viewportHeight / 2) - (totHeight / 2));

		$imgMooddescrStd.css('display', 'block');
		$mooddescrContainer.animCSS({
			'top': topPos + 348,
			'left': Math.floor((viewportWidth / 2) - ($mooddescrContainer.width() / 2))
		});
		$cgcSelectContainer.animCSS({
			'top': topPos + 385,
			'left': Math.floor((viewportWidth / 2) - ($cgcSelectContainer.width() / 2)),
			'display': 'block'
		});
	}

	*/

}

function ageQuestionComponent() {
	var totHeight = 365;
	var topPos = Math.floor((viewportHeight / 2) - (totHeight / 2));
	$ageQuestionContainer.animCSS({
		'top': topPos + 203,
		'left': Math.floor((viewportWidth / 2) - ($ageQuestionContainer.width() / 2)),
		'display': 'block'
	});
}

function customizeComponent() {
	if (nextTrack == 0) {
		calculateCustomPlaylist();
		$customizeContainer.addClass('playonly');
	} else {
		$customizeContainer.removeClass('playonly');
	}
	$customizeContainer.animCSS({
		'top': '351px',
		'left': Math.floor((viewportWidth / 2) - ($customizeContainer.width() / 2)),
		'display': 'block'
	});
	// Make hover into active:
	$('span#selectCustomize').addClass('active');
	$('img.hover', $('span#selectCustomize')).show().siblings('img').hide();
	$mixCopy.animCSS({
		'top': '300px',
		'left': Math.floor((viewportWidth / 2) - ($mixCopy.width() / 2)),
		'display': 'block'
	});
	$('#dimPlay').css({
		'position': 'absolute',
		'top': 570 - 43,
		'height': viewportHeight - $toolbar.height(),
		'left': 0,
		'width': viewportWidth,
		'background': '#000'
	}).fadeTo(0, 0.8);
}

function trackInfoComponent() {
	$trackInfo.animCSS({
		'top': 198,
		'display': 'block',
		'left': 15,
		'width': viewportWidth - 15
	});
	renderTrackInfo(-1);
}

function playBgComponent() {
	$('img', $('div#playbg')).css({'width': viewportWidth, 'height': 116});
	$('div#playbg').animCSS({
		'display': 'block',
		'top': 238,
		'left': 0
	});
}

function youtubeComponent() {
	var w = viewportWidth - 231 - 231;
	var h = viewportHeight - 268 - $toolbar.height();
	$youtube0Container.width(w).height(h);
	$youtube0.width(w).height(h);
	player0.setSize(w, h);
	$youtube1Container.width(w).height(h);
	//$youtube1.width(w).height(h);
	//player1.setSize(w, h);
	$youtubeContainer.animCSS({
		'display': 'block',
		'top': 268,
		'left': 231,
		'height': h,
		'width': w
	});
}

function doCreateSearch() {
	$createInstructionTwo.fadeOut(animSpeed);
	$createInstructionThree.fadeOut(animSpeed);

	_gaq.push(['_trackEvent', 'Selection', 'Create', 'Searchstring: ' + $('input', $createSearch).val()]);

	$.ajax({
		type: 'GET',
		async: true,
		url: '/youtubeapiproxy.php',
		data: {
			'q': $('input', $createSearch).val(),
			'format': 5,
			'max-results': 10,
			'v': 2,
			'alt': 'jsonc'
		},
		dataType: 'json',
		success: function(data) {

			$myul = $('ul#myplaylist');
			if ($myul.length == 0) {
				$myul = $('<ul id="myplaylist" />');
				$appContainer.append($myul);
			}
			if ($('li', $myul).length == 0) {
				$myul.hide();
				$myul.append('<li><ul id="prepartyplaylist" class="connectedSortable"><li class="ui-state-disabled"><img id="dragto0" src="imgs/dragto_preparty.png" /><img src="imgs/playlistseparator.png" style="display:none" /><div class="playlistseparator"></div></li></ul></li>');
				$myul.append('<li><ul id="partyplaylist" class="connectedSortable"><li class="ui-state-disabled"><img id="dragto1" src="imgs/dragto_party.png" /><img src="imgs/playlistseparator.png" style="display:none" /><div class="playlistseparator"></div></li></ul></li>');
				$myul.append('<li><ul id="afterpartyplaylist" class="connectedSortable"><li class="ui-state-disabled"><img id="dragto2" src="imgs/dragto_afterparty.png" /><img src="imgs/playlistseparator.png" style="display:none" /><div class="playlistseparator"></div></li></ul></li>');

				$('li ul', $myul).each(function() {
					$('li:first', this).click(function() {
						if ($(this).hasClass('minified')) {
							$('img:eq(1)', this).attr('src', 'imgs/playlistseparator.png');
							$(this).removeClass('minified');
							$(this).siblings().each(function() {
								$(this).show(animSpeed, function() {
									renderScrollBars();
								});
							});
						} else {
							$(this).addClass('minified');
							$('img:eq(1)', this).attr('src', 'imgs/playlistseparator_minified.png');
							$(this).siblings().each(function() {
								$(this).hide(animSpeed);
							});
							renderScrollBars();
						}
					});
				});

				$myul.animCSS({
					'display': 'block',
					'top': 300 + $createTop.height(),
					'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + $createMidLeft.width() + 402,
					'width': 389,
					'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())
				});

				$('#dragto0, #dragto1, #dragto2').each(function() {
					$(this).animCSS({
						'display': 'block',
						'margin-top': Math.floor((Math.floor(((viewportHeight - $createBottom.height() - $toolbar.height()) - 300 - $createTop.height()) / 3) - 16) / 2) - 2,
						'margin-bottom': Math.floor((Math.floor(((viewportHeight - $createBottom.height() - $toolbar.height()) - 300 - $createTop.height()) / 3) - 16) / 2) - 2
					});
				});

			}

			$('#createSearchResults').remove();
			$appContainer.append('<ul id="createSearchResults" class="connectedSortable"></ul>');
			$ul = $('ul#createSearchResults');
			$('ul#createSearchResults').animCSS({
				'display': 'block',
				'top': 300 + $createTop.height(),
				'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + $createMidLeft.width(),
				'width': 389,
				'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())
			});
			$.each(data['data']['items'], function(k, v) {
				$ul.append('<li class="createresult"><div class="result"><div class="resultcontent"><div class="resultimg"><img src="' + v['thumbnail']['sqDefault'] + '" /></div><div class="copy"><span class="title"><nobr>' + v['title'] + '</nobr><br /></span><span class="meta"><nobr>by ' + v['uploader'] + ' | ' + Math.floor(v['duration'] / 60) + ':' + String('00' + (v['duration'] % 60)).slice(-2) + ' | ' + v['viewCount'] + ' views</nobr></span><span class="youtubeid">' + v['id'] + '</span></div></div></div></li>');

				if ($.browser.msie) {
					$('br', $ul).each(function() { $(this).remove(); });
				}

				$.ajax({
					type: 'POST',
					async: true,
					url: 'backend.php',
					data: {
						'action': 'saveYoutubeMetadata',
						'youtubeId': v['id'],
						'title': v['title']
					},
					dataType: 'json'
				});

			});
			$('li.createresult').each(function() {
				/*
				$(this).hover(function() {
					$searchResultPlayHover.css({
					}).html('<img src="imgs/searchResultPlayHover.png" />');
				}, function() {
					$searchResultPlayHover.css({
					}).html('<img src="imgs/searchResultPlayHover.png" />');
				});
				*/
			});
			$('li.createresult img').each(function() {
				/*
				$(this).mouseenter(function() {
					$searchResultPlayHover.css({
						'top': $(this).offset().top,
						'left': $(this).offset().left,
						'display': 'block'
					});
					searchPreview = $('span.youtubeid', $(this).closest('li.createresult')).text();
				});
				*/
			});
			renderScrollBars();
			$('ul#createSearchResults, ul#prepartyplaylist, ul#partyplaylist, ul#afterpartyplaylist').sortable({
				connectWith: '.connectedSortable',
				items: 'li:not(.ui-state-disabled)',
				helper: 'clone',
				appendTo: 'body',
				zIndex: 10000,
				placeholder: 'ui-state-highlight',
				cursor: 'move',
				scroll: false,
				start: function(e, ui) {
					createSorting = true;
				},
				stop: function(e, ui) {
					createSorting = false;
					$('ul#createSearchResults li').each(function() {
						$(this).css('background', '');
						$('div.copy', this).css('color', '');
					});
					$('ul#myplaylist ul').each(function() {
						if ($('ul#myplaylist ul li').length <= 3) {
							$(this).removeClass('activated');
							$('li:first img:first', this).show().siblings().hide();
							$(this).parent().css('margin-top', 0);
						} else {

							var txt = '<span class="partymood">' + $(this).attr('id').toUpperCase().replace('PLAYLIST', '') + '</span>';
							var songs = ($('li', this).length - 1);
							if (songs == 0) {
								txt = txt + '<span class="songscounter"><span>no songs added yet</span></span>';
							} else {
								txt = txt + '<span class="songscounter"><span>' + songs + ' songs</span></span>';
							}
							$('div.playlistseparator', this).html(txt);

							$(this).addClass('activated');
							$('li:first img:first', this).hide().siblings().show();

							if ($(this).attr('id') == 'prepartyplaylist') {
								p = 0;
							}
							if ($(this).attr('id') == 'partyplaylist') {
								p = 33;
							}
							if ($(this).attr('id') == 'afterpartyplaylist') {
								p = 66;
							}

							$('li:first', this).siblings().each(function() {

								$(this).css('background', timelineColors[p]);
								$('div.copy', this).css('color', '#fff');
								p = p + Math.floor(33 / ($(this).siblings().length));

							});
						}
						if ($('li:first', this).hasClass('minified')) {
							$('li:first', this).siblings().each(function() {
								$(this).hide(animSpeed);
							});
						}
					});
					renderScrollBars();
				},
				change: function(event, ui) {
				}
			}).disableSelection();
			$createLeftAreaBg.animCSS({
				'display': 'block',
				'top': 300 + $createTop.height(),
				'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + $createMidLeft.width(),
				'width': 389,
				'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())
			});
			$('img', $createLeftAreaBg).animCSS({
				'width': 389,
				'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())
			});
			$('img', $createRightAreaBg).animCSS({
				'width': 389,
				'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())
			});
			$createRightAreaBg.animCSS({
				'display': 'block',
				'top': 300 + $createTop.height(),
				'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + $createMidLeft.width() + 402,
				'width': 389,
				'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())
			});

			$('ul#createSearchResults, ul#myplaylist').mousewheel(function(event, delta) {
				if ($('ul li', this).length == 3) return;

				/*
				$searchResultPlayHover.hide();
				*/

				contentHeight = 0;

				if ($(this).attr('id') == 'createSearchResults') {
					$('li', this).each(function() {
						contentHeight = contentHeight + $(this).outerHeight();
					});

				} else {
					if ($('li', this).length == 3) {
						$scrollBar.css('display', 'none');
						return;
					}
					$('ul', this).each(function() {
						var minified = false;
						$('li', this).each(function() {
							if (!minified) {
								contentHeight = contentHeight + $(this).outerHeight();
								if ($(this).hasClass('minified')) {
									minified = true;
								}
							}
						});
					});
				}

				if (contentHeight <= $(this).height()) {
					$('li:first', this).css('margin-top', 0);
					return;
				}

				vel = Math.abs(delta) * 3;
				m = parseInt($('li:first', this).css('margin-top'));
				if (delta > 0) {
					m = m + vel;
				} else {
					m = m - vel;
				}
				if (m > 1) m = 0;
				if (m < (0 - contentHeight + $(this).height())) m = 0 - contentHeight + $(this).height();
				$('li:first', this).css('margin-top', m);

				renderScrollBars();
				$('div#createSearch input').val('').hide();
			});
		}
	});
}


function sideinfoComponent() {
	$('div#sideinfoCustomize, div#sideinfoClub, div#sideinfoGuest', $sideinfoContainer).css({'display': 'none'});
	if (playingMood == 'customize') $('div#sideinfoCustomize', $sideinfoContainer).css({'display': 'block'});
	if (playingMood == 'club') $('div#sideinfoClub', $sideinfoContainer).css({'display': 'block'});
	if (playingMood == 'guest') $('div#sideinfoGuest', $sideinfoContainer).css({'display': 'block'});

	$sideinfoContainer.animCSS({
		'top': 267,
		'left': 21, // 'left': viewportWidth - 21 - $sideinfoContainer.width(),
		'display': 'block'
	});
	generecount = 0;
	$('span.genereval', $sideinfoContainer).each(function() {
		var v = $('select#' + generes[generecount] + 'Rate').val();
		if (v == null) v = 0;
		$(this).html(v + '%');
		generecount++;
	});
}

function smallMenuComponent() {
	if (!idiot) {
		$smallMenuBg.animCSS({
			'top': '186',
			'left': viewportWidth - $smallMenu.width(),
			'width': $smallMenu.width(),
			'height': 40,
			'display': 'block'
		});
		$('img', $smallMenuBg).css({
			'width': $smallMenu.width(),
			'height': 40
		});
		$smallMenu.animCSS({
			'top': 186,
			'left': viewportWidth - $smallMenu.width()
		});
		/*
		if (($.browser.msie) && ($.browser.version.substring(0, 2) == '6.')) {
			$smallMenu.fadeIn();
		} else {
			$smallMenu.fadeTo(animSpeed, 0.5);
		}
		*/
		$smallMenu.fadeIn();
	}
}

function cursorComponent() {
	$cursor.animCSS({
		'display': 'block',
		'top': 100,
		'left': Math.floor(0 - ($cursor.width() / 2)) 
	});
	$timelinePulse.css({'position': 'absolute', 'top': 7, 'left': Math.floor(($cursor.width() / 2) - ($timelinePulse.width() / 2)) - 13});
	cursorDragWidth = 30;
	$cursorDrag.css({'width': cursorDragWidth, 'height': $cursor.height(), 'cursor': 'move'});
	//$cursorDrag.css({'position': 'absolute', 'top': 0, 'left': Math.floor(($cursor.width() / 2) - (cursorDragWidth / 2))});
	$cursorDrag.css({'position': 'absolute', 'top': 0, 'left': 105 }); //105 är hårdkodat ifrån uträkningen ovan (som blir fel ibland)

	positionCursor();
}

initMoveDone = false;
initMoveStarted = false;
function positionCursor() {
	if (!initMoveDone) {

		marginleft = 6;
		marginright = 6;

		if (!initMoveStarted) {
			initMoveStarted = true;
			$cursor.animate({
				'left': Math.floor(viewportWidth - marginright - ($cursor.width() / 2))
			}, 2000, function() {
				$cursor.animate({
					'left': 0 - ($cursor.width() / 2) + 2 + marginleft
				}, 2000, function() {
					initMoveDone = true;
					initMoveStarted = false;
					positionCursor();
				});
			});
		}
	
	} else if ((view != 'moodsensor') || ((view == 'moodsensor') && (slowCursor == true))) {

		pixelsPerTrack = (viewportWidth - marginleft - marginright) / customPlaylist.length;

		currentTime = activePlayer.getCurrentTime();
		duration = activePlayer.getDuration();

		if ((currentTime != 0) && (duration != 0)) {
			var s = animSpeed;
			if (slowCursor) s = 3000;
			$cursor.animate({
				'left': Math.floor((pixelsPerTrack * (nextTrack - 1)) + (pixelsPerTrack * (currentTime / duration)) - $cursor.width() / 2) + 2 + marginleft
			}, s, function() {
				if (slowCursor) {
					slowCursor = false;
					switchView('player');
				}
			});
		}
		if ((duration != 0) && (currentTime > 3) && (currentTime < 13)) {
			$dragMe.animCSS({
				'display': 'block',
				'top': $cursor.position().top - $dragMe.height() + 10,
				'left': Math.floor((pixelsPerTrack * (nextTrack - 1)) + (pixelsPerTrack * (currentTime / duration))) + 10 + marginleft
			});
		} else {
			if ($dragMe.is(':visible')) {
				$dragMe.fadeOut(animSpeed);
			}
		}
	}
}


function thumbsComponent() {
	$thumbsContainer.animCSS({
		'display': 'block',
		'top': 300,
		'left': 0,
		'width': viewportWidth,
		'height': viewportHeight - 300 - $toolbar.height()
	});

	var cols = Math.floor(viewportWidth / 194);
	var rows = Math.floor(((viewportHeight + 25) - $thumbsContainer.position().top - 60 - $toolbar.height()) / 164);
	if (cols < 1) cols = 1;
	if (rows < 1) rows = 1;
	var pages = Math.ceil($('li', $thumbsContainer).length / (cols * rows));
	totalThumbsPages = pages;

	if (currentThumbsPage >= pages) {
		currentThumbsPage = pages - 1;
	}

	if (currentThumbsPage != 0) {
		$prev.animCSS({
			'display': 'block',
			'top': 175,
			'left': -5
		});
	} else {
		$prev.fadeOut(animSpeed);
	}

	if (pages > (currentThumbsPage + 1)) {
		$next.animCSS({
			'display': 'block',
			'top': 175,
			'left': viewportWidth - $next.width() + 5
		});
	} else {
		$next.fadeOut(animSpeed);
	}

	var licounter = 0;
	$('li', $thumbsContainer).each(function() {

		thumbspage = Math.floor(licounter / (cols * rows));
		posinpage = licounter - (thumbspage * (cols * rows));

		liy = Math.floor(posinpage / cols);
		lix = posinpage - (liy * cols);

		$(this).animate({
			'left': ((lix * 194) + ((viewportWidth - ((cols) * 194)) / 2)) + (thumbspage * viewportWidth) - (currentThumbsPage * viewportWidth),
			'top': (liy * 164) + 60
		});

		licounter++;
	});

}

function dimComponent() {
	$dim.css({
		'width': viewportWidth,
		'height': viewportHeight
	});
	if (($.browser.msie) && ($.browser.version.substring(0, 2) == '6.')) {
		$dim.show();
	} else {
		$dim.fadeTo(animSpeed, 0.7);
	}
}

function bigBottleComponent() {
	$bigBottleContainer.animCSS({
		'display': 'block',
		'top': 268, // 305
		'left': (viewportWidth - $bigBottleContainer.width() - 57)
	});
}

function endQuestionComponent() {
	$endQuestionContainer.animCSS({
		'display': 'block',
		'top': 313,
		'left': Math.floor((viewportWidth / 2) - ($endQuestionContainer.width() / 2))
	});
}

function emailFormComponent() {
	var toppos = Math.floor((viewportHeight / 2) - ($emailFormContainer.height() / 2));
	$emailFormContainer.animCSS({
		'display': 'block',
		'top': toppos,
		'left': Math.floor((viewportWidth / 2) - ($emailFormContainer.width() / 2))
	});
};

function backToVideoComponent() {
	$backToVideo.animCSS({
		'display': 'block',
		'top': 255,
		'left': 21
	});
}

function startBottlesComponent() {
	$startBottles.animCSS({
		'display': 'block',
		'top': Math.floor((viewportHeight / 2) - ($startBottles.height() / 2)),
		'left': Math.floor((viewportWidth / 2) - ($startBottles.width() / 2))
	});
}

function moodSensorComponent() {
	$moodSensorContainer.css({
		'display': 'block',
		'top': 300,
		'left': Math.floor((viewportWidth / 2) - ($moodSensorContainer.width() / 2))
	});
}

function saveListComponent() {
	$saveList.animCSS({
		'display': 'block',
		'top': 300,
		'left': Math.floor((viewportWidth / 2) - ($saveList.width() / 2))
	});
	$('span#selectCreate').addClass('active');
	$('img.hover', $('span#selectCreate')).show().siblings('img').hide();
}

function shareMyListComponent() {
	$shareMyList.animCSS({
		'display': 'block',
		'top': 300,
		'left': Math.floor((viewportWidth / 2) - ($shareMyList.width() / 2))
	});
	$shareMyList.animate({ // Fulhack för att queue:a upp functionen efter ovanstående animCSS...
		'top': 300
	}, function() {
		if (zeroClipboardObj == false) {
			zeroClipboardObj = new ZeroClipboard.Client();
			zeroClipboardObj.setHandCursor(true);
			zeroClipboardObj.glue('copyMyListUrl');
			zeroClipboardObj.addEventListener('onMouseOver', function() {
				$('div#copyMyListUrlHover').show();
			});
			zeroClipboardObj.addEventListener('onMouseOut', function() {
				$('div#copyMyListUrlHover').hide();
			});
		} else {
		}
		zeroClipboardObj.setText('http://www.xidemood.se/?s=user' + userplaylist);
		zeroClipboardObj.show();
		zeroClipboardObj.reposition();
	});
	$('span#selectCreate').addClass('active');
	$('img.hover', $('span#selectCreate')).show().siblings('img').hide();
	$shareMyListUrl.html('http://www.xidemood.se/?s=user' + userplaylist);
	$shareMyListTitle.html($('div#saveListNameInput input').val()).css('top', 80 - $shareMyListTitle.height());
}

function createComponent() {
	$('span#selectCreate').addClass('active');
	$('img.hover', $('span#selectCreate')).show().siblings('img').hide();
	$createTop.animCSS({
		'display': 'block',
		'top': 300,
		'left': Math.floor((viewportWidth / 2) - ($createTop.width() / 2))
	});
	$('div#forstoringsglas').animCSS({
		'display': 'block',
		'left': Math.floor((viewportWidth / 2) - ($createTop.width() / 2)) + 453,
		'top': 354
	});
	$createBottom.animCSS({
		'display': 'block',
		'top': viewportHeight - $createBottom.height() - $toolbar.height(),
		'left': Math.floor((viewportWidth / 2) - ($createTop.width() / 2))
	});
	$createMidLeft.animCSS({
		'display': 'block',
		'top': 300 + $createTop.height(),
		'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2))
	});
	$('img', $createMidLeft).animCSS({
		'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height()),
		'width': 96
	});
	$createMidMid.animCSS({
		'display': 'block',
		'top': 300 + $createTop.height(),
		'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + 485
	});
	$('img', $createMidMid).animCSS({
		'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height()),
		'width': 12
	});
	$createMidMidArrow.animCSS({
		'display': 'block',
		'top': 300 + $createTop.height() + (((viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())) / 2) - 12,
		'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + 485
	});
	$createMidRight.animCSS({
		'display': 'block',
		'top': 300 + $createTop.height(),
		'left': (Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + $createBottom.width()) - $createMidRight.width()
	});
	$('img', $createMidRight).animCSS({
		'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height()),
		'width': 95
	});
	if ($('ul#createSearchResults li').length == 0) {
		$createInstructionTwo.animCSS({
			'display': 'block',
			'top': 300 + $createTop.height() + 20,
			'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + $createMidLeft.width() + 86
		});
		$createLeftAreaBg.hide();
	} else {
		$createLeftAreaBg.animCSS({
			'display': 'block',
			'top': 300 + $createTop.height(),
			'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + $createMidLeft.width(),
			'width': 389,
			'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())
		});
		$('img', $createLeftAreaBg).animCSS({
			'width': 389,
			'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())
		});
	}
	if ($('ul#myplaylist ul li').length == 0) {
		$createInstructionThree.animCSS({
			'display': 'block',
			'top': 300 + $createTop.height() + 25,
			'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + $createMidLeft.width() + 489
		});
		$createRightAreaBg.hide();
	} else {
		$createRightAreaBg.animCSS({
			'display': 'block',
			'top': 300 + $createTop.height(),
			'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + $createMidLeft.width() + 402,
			'width': 389,
			'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())
		});
		$('img', $createRightAreaBg).animCSS({
			'width': 389,
			'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())
		});
	}
	if ($.browser.msie) {
		$createSearch.animCSS({
			'display': 'block',
			'top': 300 + 51,
			'left': Math.floor((viewportWidth / 2) - ($createTop.width() / 2)) + 101
		});
	} else {
		$createSearch.animCSS({
			'display': 'block',
			'top': 300 + 53,
			'left': Math.floor((viewportWidth / 2) - ($createTop.width() / 2)) + 101
		});
	}
	$('ul#createSearchResults').animCSS({
		'display': 'block',
		'top': 300 + $createTop.height(),
		'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + $createMidLeft.width(),
		'width': 389,
		'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())
	});
	$createDoneButton.animCSS({
		'display': 'block',
		'top': 300 + $createTop.height() + (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height()) + 11,
		'left': (Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + $createBottom.width()) - $createMidRight.width() - 115
	});
	$('ul#myplaylist').animCSS({
		'top': 300 + $createTop.height(),
		'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + $createMidLeft.width() + 402,
		'width': 389,
		'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())
	});
	$('ul#createSearchResults').animate({
		'top': 300 + $createTop.height(),
		'left': Math.floor((viewportWidth / 2) - ($createBottom.width() / 2)) + $createMidLeft.width(),
		'width': 389,
		'height': (viewportHeight - $createBottom.height() - $toolbar.height()) - (300 + $createTop.height())
	}, animSpeed, function() {
		renderScrollBars();
	});
	$('#dragto0, #dragto1, #dragto2').each(function() {
		$(this).css({
			'padding-top': Math.floor((Math.floor(((viewportHeight - $createBottom.height() - $toolbar.height()) - 300 - $createTop.height()) / 3) - 16) / 2) - 2,
			'padding-bottom': Math.floor((Math.floor(((viewportHeight - $createBottom.height() - $toolbar.height()) - 300 - $createTop.height()) / 3) - 16) / 2) - 2
		});
	});

	renderScrollBars();

}

// VIEW FUNCTIONALITY:

function renderScrollBars() {

	$('ul#createSearchResults, ul#myplaylist').each(function() {

		contentHeight = 0;

		if ($(this).attr('id') == 'createSearchResults') {
			$scrollBar = $scrollBarLeft;
			$('li', this).each(function() {
				contentHeight = contentHeight + $(this).outerHeight();
			});

		} else {
			$scrollBar = $scrollBarRight;
			if ($('li', this).length == 3) {
				$scrollBar.css('display', 'none');
				return;
			}
			$('ul', this).each(function() {
				var minified = false;
				$('li', this).each(function() {
					if (!minified) {
						contentHeight = contentHeight + $(this).outerHeight();
						if ($(this).hasClass('minified')) {
							minified = true;
						}
					}
				});
			});
		}

		if (contentHeight <= $(this).height()) {
			$scrollBar.css('display', 'none');
			return;
		} else {

			scrollBarHeight = $(this).height() / contentHeight * $(this).height();
			if (scrollBarHeight < 35) scrollBarHeight = 35;

			moveSpace = $(this).height() - scrollBarHeight;

			scrollPos = (0 - parseInt($('li:first', this).css('margin-top'))) / (contentHeight - $(this).height());
			if (scrollPos > 1) scrollPos = 1;

			$scrollBar.css({
				'top': $(this).offset().top + scrollPos * moveSpace,
				'left': $(this).offset().left + $(this).width() - 10,
				'height': scrollBarHeight,
				'display': 'block'
			});
		
		}

	});

}

resizeTimer = -1;
function resize() {
	if (typeof(viewportWidth) != 'undefined') {
		if (($(window).width() != viewportWidth) || ($(window).height() != viewportHeight)) { // Utan denna koll så körs eventet ibland bara man lägger till nått i vyn.
			if (resizeTimer != -1) {
				clearTimeout(resizeTimer);
			}
			resizeTimer = setTimeout(function() {
				resizeTimer = -1;
				renderView();
			}, 300);
		}
	}
}

function renderView() {
	viewportWidth = $(window).width();
	viewportHeight = $(window).height();
	$appContainer.css({
		'width': viewportWidth,
		'height': viewportHeight
	});

	if (view == 'start') {
		//cgcSelectComponent();
		//logo308x196Component();
		//sloganComponent();
		//ornamentMidComponent();
		startBottlesComponent();
		ornamentsComponent();
	} else if (view == 'agecheck') {
		ornamentsComponent();
		logo308x196Component();
		ageQuestionComponent();
		legalComponent();
	} else if (view == 'customize') {
		if (nextTrack == 0) {
			//logo259x164Component();
			cgcSelectComponent();
		} else {
			logo190x122Component();
			timelineComponent();
			playBgComponent();
			trackInfoComponent();
			smallMenuComponent();
			backToVideoComponent();
		}
		ornamentsComponent();
		customizeComponent();
		renderDragButtons();
		toolbarComponent();
	} else if (view == 'create') {

		if ($.browser.msie) {
			$('div#app').addClass('runningie');
		}

		if (nextTrack == 0) {
			//logo259x164Component();
			cgcSelectComponent();
		} else {
			logo190x122Component();
			timelineComponent();
			playBgComponent();
			trackInfoComponent();
			smallMenuComponent();
			backToVideoComponent();
		}
		ornamentsComponent();
		createComponent();
		toolbarComponent();
		renderScrollBars();
	} else if (view == 'savelist') {
		if (nextTrack == 0) {
			//logo259x164Component();
			cgcSelectComponent();
		} else {
			logo190x122Component();
			timelineComponent();
			playBgComponent();
			trackInfoComponent();
			smallMenuComponent();
			backToVideoComponent();
		}
		ornamentsComponent();
		toolbarComponent();
		saveListComponent();

	} else if (view == 'sharemylist') {

		if (nextTrack == 0) {
			//logo259x164Component();
			cgcSelectComponent();
		} else {
			logo190x122Component();
			timelineComponent();
			playBgComponent();
			trackInfoComponent();
			smallMenuComponent();
			backToVideoComponent();
		}
		ornamentsComponent();
		toolbarComponent();
		shareMyListComponent();

	} else if (view == 'player') {
		youtubeComponent();
		logo190x122Component();
		timelineComponent();
		playBgComponent();
		ornamentsComponent();
		cursorComponent();
		if (nextTrack == 0) {
			playYouTube(nextTrack);
			prepareNextTrack();
		}
		trackInfoComponent();
		smallMenuComponent();
		sideinfoComponent();
		bigBottleComponent();
		toolbarComponent();
	} else if (view == 'moodsensor') {
		logo190x122Component();
		timelineComponent();
		playBgComponent();
		trackInfoComponent();
		smallMenuComponent();
		backToVideoComponent();
		ornamentsComponent();
		moodSensorComponent();
		toolbarComponent();
	} else if ((view == 'guests') || (view == 'clubs')) {
		if (nextTrack == 0) {
			logo259x164Component();
			cgcSelectComponent();
		} else {
			logo190x122Component();
			timelineComponent();
			playBgComponent();
			trackInfoComponent();
			smallMenuComponent();
			backToVideoComponent();
		}
		ornamentsComponent();
		thumbsComponent();
		toolbarComponent();
	} else if (view == 'end') {
		logo190x122Component();
		dimComponent();
		endQuestionComponent();
		toolbarComponent();
	} else if (view == 'emailform') {
		emailFormComponent();
		ornamentsComponent();
		$('input#emailInput').val('').focus();
		toolbarComponent();
	}

}

function renderTrackInfo(track) {
	if (track == -1) {
		track = nextTrack - 1;
	}
	if (typeof(customPlaylist[track]) != 'undefined') {
		var html = '';

		html = '<nobr>'
		if ((trackInfoDisplayNext == false) || (typeof(customPlaylist[track + 1]) == 'undefined')) {
			html = html + '<span class="songcounter">Song <span class="songnr">' + (track + 1) + '</span>/<span class="songnr">' + customPlaylist.length + '</span></span> ';
			html = html + '<span class="trackinfocontrollers"><img src="/imgs/empty.gif" width="130" height="13" /></span>';
			if (customPlaylist[track].artistname == 'YouTube') {
				html = html + ' <b>Now: <span class="highlight">' + customPlaylist[track].trackname + '</span></b>';
			} else {
				html = html + ' <b>Now: <span class="highlight">' + customPlaylist[track].artistname + ' - ' + customPlaylist[track].trackname + '</span></b>';
			}
			if (!draggingTimeline) {
				secsLeft = parseInt(activePlayer.getDuration()) - parseInt(activePlayer.getCurrentTime());
				minsLeft = Math.floor(secsLeft / 60);
				secsLeft = secsLeft - (minsLeft * 60);
				if (secsLeft < 10) secsLeft = '0' + secsLeft;
				html = html + ' <span class="timer">(-' + minsLeft + ':' + secsLeft + ')</span>';
			}
		} else {
			html = html + '<span class="songcounter">Song <span class="songnr">' + (track + 1) + '</span>/<span class="songnr">' + customPlaylist.length + '</span></span> ';
			html = html + '<span class="trackinfocontrollers"><img src="/imgs/empty.gif" width="130" height="13" /></span>';
			if (customPlaylist[track + 1].artistname == 'YouTube') {
				html = html + '<b>Next:</b> ' + customPlaylist[track + 1].trackname;
			} else {
				html = html + '<b>Next:</b> ' + customPlaylist[track + 1].artistname + ' - ' + customPlaylist[track + 1].trackname;
			}
		}
		html = html + '</nobr>';

		$trackInfo.html(html);
		var e = $('span.trackinfocontrollers', $trackInfo);
		if (e.length == 1) {
			if ($.browser.webkit) {
				$trackInfoControllers.css({
					'position': 'absolute',
					'display': 'block',
					'top': e.offset().top + 3,
					'left': e.offset().left + 120 - $trackInfoControllers.width()
				});
			} else {
				$trackInfoControllers.css({
					'position': 'absolute',
					'display': 'block',
					'top': e.offset().top - 1,
					'left': e.offset().left + 120 - $trackInfoControllers.width()
				});
			}
		} else {
			$trackInfoControllers.css('display', 'none');
		}

		setTrackInfoColor();
	}
}

function prepareNextTrack() {
	nextTrack++;
	renderTrackInfo(-1);
}

dragButtonsFirstTime = true;
function renderDragButtons() {
	var dragTop = 25;
	var dragHeight = 120;
	var fallSpeed = 1000;

	if (dragButtonsFirstTime) {
		for (var i in generes) {
			$('img#' + generes[i] + 'Button').css('top', dragTop);
		}
		dragButtonsFirstTime = false;
	}

	for (var i in generes) {
		$('img#' + generes[i] + 'Button').animate({'top': Math.floor((100 - $('select#' + generes[i] + 'Rate').val()) / 100 * dragHeight) + dragTop}, fallSpeed);
	}

	renderNumbers();

}

function renderNumbers() {
	var nr = 0;
	var tot = 0;
	for (var i in generes) {
		nr = $('select#' + generes[i] + 'Rate').val();
		if (nr == null) nr = 0;
		$('span#' + generes[i] + 'Nr').html(nr + '%');
		tot = tot + nr;
	}
	if (tot == 0) {
		$('#dimPlay').fadeTo(0, 0.8);
	} else {
		$('#dimPlay').fadeOut();
	}
}

function calculateCustomPlaylist() {

	playingMood = "customize";

	var totalRate = 0;
	var rates = new Array();
	for (i in generes) {
		rates[i] = parseInt($('select#' + generes[i] + 'Rate').val())
		totalRate = totalRate + rates[i];
	}
	if (totalRate == 0) {
		for (i in generes) {
			rates[i] = 1;
			totalRate++;
		}
	}

	playlist = [];
	var genere = 0;
	var songCounter = 0;
	for (var epoch = 0; epoch <= 2; epoch++) {
		if (epoch == 0) songsPerEpoch = 30;
		if (epoch == 1) songsPerEpoch = 40;
		if (epoch == 2) songsPerEpoch = 30;
		for (var i = 0; i < songsPerEpoch; i++) {
			if (songCounter < nextTrack) {
				playlist.push(customPlaylist[songCounter]);
			} else {

				found = 0;
				while (found == 0) {

					r = Math.floor(Math.random() * totalRate);
					gtop = 0;
					for (ii in generes) {
						gtop = gtop + rates[ii];
						if (r < gtop) {
							genere = ii;
							break;
						}
					}

					if (typeof(customizeTracks[epoch][genere]) == 'undefined') {
						// console.log('INGA LÅTAR: ' + epoch + ':' + genere);
					} else {
						epochGenereTracks = customizeTracks[epoch][genere];

						// HÄR: Rensa bort det som redan finns i playlist ur epochGenereTracks

						trackIndex = Math.floor(Math.random() * epochGenereTracks.length);
						playlist.push(epochGenereTracks[trackIndex]);

					}

					// Nån koll om vi hittade nått i denna genere/epoch, annars nytt försök...
					found = 1;

				}
			}
			songCounter++;

		}
	}
	customPlaylist = playlist;
}

function switchView(v) {
	if (v == view) return;

	if ((v == 'clubs') || (v == 'guests')) {

		currentThumbsPage = 0;
		
		// Make hover into active:
		if (v == 'clubs') {
			$('span#selectClub').addClass('active');
			$('img.hover', $('span#selectClub')).show().siblings('img').hide();
			thumbs = clubs;
			upcomingImg = 'imgs/upcoming_club.png';
			headerImg = 'imgs/clubsheader.png';
		} else {
			$('span#selectGuest').addClass('active');
			$('img.hover', $('span#selectGuest')).show().siblings('img').hide();
			thumbs = guests;
			upcomingImg = 'imgs/upcoming_guest.png';
			headerImg = 'imgs/guestsheader.png';
		}
		html = '<center><img src="' + headerImg + '" /></center><br><ul>';
		for (var i = 0; i < thumbs.length; i++) {
			if (typeof(thumbs[i]['id']) == 'undefined') {
				if (thumbs[i]['name'] == 'Dogge Doggelito') {
//					html = html + '<li><img src="/files/dogge.jpg" /><br /><span class="thumbtxt"><nobr>' + thumbs[i]['date']['day'] + '/' + thumbs[i]['date']['month'] + ' <span class="thename">' + thumbs[i]['name'] + '</span></nobr></span></li>';
					html = html + '<li><img src="/files/dogge.jpg" /><br /><span class="thumbtxt"><nobr>' + ' <span class="thename">' + thumbs[i]['name'] + '</span></nobr></span></li>';
				} else {
//					html = html + '<li><img src="' + upcomingImg + '" /><br /><span class="thumbtxt"><nobr>' + thumbs[i]['date']['day'] + '/' + thumbs[i]['date']['month'] + ' <span class="thename">' + thumbs[i]['name'] + '</span></nobr></span></li>';
					html = html + '<li><img src="' + upcomingImg + '" /><br /><span class="thumbtxt"><nobr>' + ' <span class="thename">' + thumbs[i]['name'] + '</span></nobr></span></li>';
					}
				} else {
				html = html + '<li class="thumb-' + v + '" data-id="' + thumbs[i]['id'] + '"><img src="' + thumbs[i]['img'] + '" width="168" height="110" /><img class="thumbhover" style="display:none" src="imgs/hover_guest_clubs.';
				if (($.browser.msie) && ($.browser.version.substring(0, 2) == '6.')) {
					html = html + 'gif';
				} else {
					html = html + 'png';
				}
//				 html = html + '" /><br /><span class="thumbtxt"><nobr>' + thumbs[i]['date']['day'] + '/' + thumbs[i]['date']['month'] + ' <span class="thename">' + thumbs[i]['name'] + '</span></nobr></span><div class="descr" style="display:none">' + thumbs[i]['description'] + '</div></li>';
				 html = html + '" /><br /><span class="thumbtxt"><nobr>' + ' <span class="thename">' + thumbs[i]['name'] + '</span></nobr></span><div class="descr" style="display:none">' + thumbs[i]['description'] + '</div></li>';
				$('li#thumb' + thumbs[i]['id']).css({
					'cursor': 'pointer'
				});
			}
		}
			
		html = html + '</ul>';
		$thumbsContent.html(html);
		
		$('li', $thumbsContent).each(function() {
			$(this).mouseenter(function() {
				$('img.thumbhover', this).css({
					'position': 'absolute',
					'top': 0,
					'left': 13
				}).fadeIn(animSpeed);
			});
			$(this).mouseleave(function() {
				$('img.thumbhover', this).fadeOut(animSpeed);
			});
		});
		$('li.thumb-clubs').each(function() {
			$(this).css({'cursor': 'pointer'}).click(function() {
				clubOrGuestName = $('span.thumbtxt span.thename', this).html();
				_gaq.push(['_trackEvent', 'Selection', 'Club', clubOrGuestName]);
				$('#sideinfoClubImg').html('<img src="' + $($('img', this)[0]).attr('src') + '" width="168" height="110" />');
				$('#sideinfoClubDescr').html($('div.descr', this).html());
				$('#sideinfoClubDescr a').each(function() {
					$(this).attr('target', 'blank');
				});
				$.ajax({
					type: "POST",
					url: "backend.php",
					async: true,
					data: {
						'action': 'clubPlaylist',
						'id': $(this).attr('data-id')
					},
					dataType: 'json',
					success: function(data) {
						playingMood = "club";
						customPlaylist = data['playlist'];
						switchView('player');
						nextTrack = 0;
						playYouTube(nextTrack);
						prepareNextTrack();
					}
				});
			});
		});
		$('li.thumb-guests').each(function() {
			$(this).css({'cursor': 'pointer'}).click(function() {
				clubOrGuestName = $('span.thumbtxt span.thename', this).html();
				_gaq.push(['_trackEvent', 'Selection', 'Guest', clubOrGuestName]);
				$('#sideinfoGuestImg').html('<img src="' + $($('img', this)[0]).attr('src') + '" width="168" height="110" />');
				$('#sideinfoGuestDescr').html($('div.descr', this).html());
				$('#sideinfoGuestDescr a').each(function() {
					$(this).attr('target', 'blank');
				});
				$.ajax({
					type: "POST",
					url: "backend.php",
					async: true,
					data: {
						'action': 'guestPlaylist',
						'id': $(this).attr('data-id')
					},
					dataType: 'json',
					success: function(data) {
						playingMood = "guest";
						customPlaylist = data['playlist'];
						switchView('player');
						nextTrack = 0;
						playYouTube(nextTrack);
						prepareNextTrack();
					}
				});
			});
		});

	}


	// Remove stuff in current view
	if (view == 'start') {
		$ornamentMid.fadeOut(animSpeed);
		$slogan.fadeOut(animSpeed);
		$imgMooddescrStd.show();
		$imgMooddescrGuests.hide();
		$imgMooddescrClubs.hide();
		$imgMooddescrCustomize.hide();
		$mooddescrContainer.fadeOut(animSpeed);
		$logo308x196.fadeOut(animSpeed);
		$startBottles.fadeOut(animSpeed);
	} else if (view == 'agecheck') {
		$ageQuestionContainer.fadeOut(animSpeed);
		$legal.fadeOut(animSpeed);
		$logo308x196.fadeOut(animSpeed);
	} else if (view == 'agecheck') {
	} else if (view == 'customize') {
		if ((v != 'clubs') && (v != 'guests') && (v != 'moodsensor') && (v != 'create')) {
			$logo259x164.fadeOut(animSpeed);
			$cgcSelectContainer.fadeOut(animSpeed);
			$backToVideo.fadeOut(animSpeed);
		}
		$customizeContainer.fadeOut(animSpeed);
		/*
		$mooddescrContainer.fadeOut(animSpeed);
		*/
		$('#dimPlay').fadeOut();
		$mixCopy.fadeOut(animSpeed);
		$('span#selectCustomize').removeClass('active');
		$('img.hover', $('span#selectCustomize')).hide().siblings('img').show();

	} else if (view == 'create') {
		$logo308x196.fadeOut();

		if ((v != 'clubs') && (v != 'guests') && (v != 'moodsensor') && (v != 'customize') && (v != 'savelist')) {
			$logo259x164.fadeOut(animSpeed);
			$cgcSelectContainer.fadeOut(animSpeed);
			$backToVideo.fadeOut(animSpeed);
		}

		$scrollBarRight.fadeOut(animSpeed);
		$scrollBarLeft.fadeOut(animSpeed);

		$createTop.fadeOut(animSpeed);
		$createBottom.fadeOut(animSpeed);
		$createMidLeft.fadeOut(animSpeed);
		$createMidMid.fadeOut(animSpeed);
		$createMidMidArrow.fadeOut(animSpeed);
		$createMidRight.fadeOut(animSpeed);
		$createInstructionTwo.fadeOut(animSpeed);
		$createInstructionThree.fadeOut(animSpeed);
		$createDoneButton.fadeOut(animSpeed);
		$createSearch.fadeOut(animSpeed, function() {
			$('input', this).val('').hide();
		});
		$createInstructionTwo.fadeOut(animSpeed);
		$createInstructionThree.fadeOut(animSpeed);
		$createLeftAreaBg.fadeOut(animSpeed);
		$createRightAreaBg.fadeOut(animSpeed);
		$('ul#createSearchResults, ul#myplaylist').fadeOut(animSpeed, function() {
			$(this).html('');
		});
		$('span#selectCreate').removeClass('active');
		$('img.hover', $('span#selectCreate')).hide().siblings('img').show();

	} else if (view == 'savelist') {

		$saveList.fadeOut(animSpeed);
		$('span#selectCreate').removeClass('active');
		$('img.hover', $('span#selectCreate')).hide().siblings('img').show();

	} else if (view == 'sharemylist') {

		if ((v != 'clubs') && (v != 'guests') && (v != 'moodsensor') && (v != 'customize') && (v != 'savelist')) {
			$logo259x164.fadeOut(animSpeed);
			$cgcSelectContainer.fadeOut(animSpeed);
			$backToVideo.fadeOut(animSpeed);
		}

		$shareMyList.fadeOut(animSpeed);
		$('span#selectCreate').removeClass('active');
		$('img.hover', $('span#selectCreate')).hide().siblings('img').show();

		$('input').each(function() {
			$(this).val('').hide();
			$('.inputErrors').hide();
		});

		zeroClipboardObj.hide();

	} else if (view == 'clubs') {
		$('span#selectClub').removeClass('active');
		$('img.hover', $('span#selectClub')).hide().siblings('img').show();
		if (v != 'clubs') {
			$thumbsContainer.fadeOut(animSpeed);
		}
		if ((v != 'guests') && (v != 'customize') && (v != 'moodsensor') && (v != 'create')) {
			$logo259x164.fadeOut(animSpeed);
			$cgcSelectContainer.fadeOut(animSpeed);
			$backToVideo.fadeOut(animSpeed);
		}
	} else if (view == 'guests') {
		$('span#selectGuest').removeClass('active');
		$('img.hover', $('span#selectGuest')).hide().siblings('img').show();
		if (v != 'clubs') {
			$thumbsContainer.fadeOut(animSpeed);
		}
		if ((v != 'clubs') && (v != 'customize') && (v != 'moodsensor') && (v != 'create')) {
			$logo259x164.fadeOut(animSpeed);
			$cgcSelectContainer.fadeOut(animSpeed);
			$backToVideo.fadeOut(animSpeed);
		}

	} else if (view == 'loader') {
		$loaderContainer.fadeOut(animSpeed);
	} else if (view == 'player') {
		$youtubeContainer.css('top', 5000);
		$bigBottleContainer.fadeOut();
		if (v != 'end') {
			$sideinfoContainer.fadeOut(animSpeed);
		}
	} else if (view == 'end') {
		if (v != 'player') {
			$trackInfoControllers.fadeOut();
			$timelineContainer.fadeOut();
			$logo190x122.fadeOut();
			$smallMenuBg.fadeOut();
			$smallMenu.fadeOut();
			$sideinfoContainer.fadeOut();
			$trackInfo.fadeOut();
			$cursor.fadeOut();
			$('div#playbg').fadeOut();
		}
		$dim.fadeOut();
		$endQuestionContainer.fadeOut();
	} else if (view == 'moodsensor') {
		$backToVideo.fadeOut();
		$moodSensorContainer.html('<div id="moodSensor"></div>').hide();
	}

	if (v == 'moodsensor') {
		swfobject.embedSWF(
			'PartyBooster.swf',
			'moodSensor', '800', '400', '10.0.0', null, null, { wmode: 'window', bgcolor: '#000000' }
		);
	}

	view = v;
	renderView();
}

// YOUTUBE FUNCTIONALITY:

function playYouTube(track) {
	_gaq.push(['_trackEvent', 'YouTube', 'Play', customPlaylist[track].artistname + ' - ' + customPlaylist[track].trackname]);
	activePlayer.loadVideoById(customPlaylist[track].youtube);
}

playersReady = 0;
function onYouTubePlayerReady(playerid) {
	playersReady++;
	if (playerid == 'youtube0') {
		$youtube0 = $('#youtube0');
		player0 = $youtube0[0];
	} else if (playerid == 'youtube1') {
		//$youtube1 = $('#youtube1');
		//player1 = $youtube1[0];
	}

	if (playersReady == 1) {
		// Både youtubeplayerserna är laddade, så gå till första vyn i appen!
		activePlayer = player0;
		//passivePlayer = player1;

		player0.addEventListener('onStateChange', 'player0stateChange');
		//player1.addEventListener('onStateChange', 'player1stateChange');
		player0.addEventListener('onError', 'player0error');
		//player1.addEventListener('onError', 'player1error');

		// switchView('agecheck');

		var re = new RegExp('^([0-9]+),([0-9]+),([0-9]+),([0-9]+),([0-9]+)$');
		var m = re.exec(getHash());
		if (m == null) {

			var re = new RegExp('^user([0-9]+)$');
			var m = re.exec(getHash());
			if (m != null) {

				$.ajax({
					type: "POST",
					url: "backend.php",
					async: true,
					data: {
						'action': 'getUserPlayList',
						'id': m[1]
					},
					dataType: 'json',
					success: function(data) {
						playingMood = "userplaylist";
						customPlaylist = data['playlist'];
						switchView('player');
						nextTrack = 0;
						playYouTube(nextTrack);
						prepareNextTrack();
					}
				});


			} else {
				if (idiot) {
					switchView('create');
				} else {
					switchView('agecheck');
				}
			}

		} else {
			$selectHitsRate.val(parseInt(m[1]));
			$selectPopRockRate.val(parseInt(m[2]));
			$selectHipHopRnbRate.val(parseInt(m[3]));
			$selectHouseRate.val(parseInt(m[4]));
			$selectSwedishSummerRate.val(parseInt(m[5]));
			switchView('customize');
		}
	}
}

function player0stateChange(newState) {
	if ($youtube0Container.hasClass('passive')) {
		onPassivePlayerStateChange(player0, newState);
	} else {
		onActivePlayerStateChange(player0, newState);
	}
}
function player1stateChange(newState) {
	if ($youtube1Container.hasClass('passive')) {
		onPassivePlayerStateChange(player1, newState);
	} else {
		onActivePlayerStateChange(player1, newState);
	}
}

function player0error(err) {
	if ($youtube0Container.hasClass('passive')) {
		onPassivePlayerError(player0, err);
	} else {
		onActivePlayerError(player0, err);
	}
}

function player1error(err) {
	if ($youtube1Container.hasClass('passive')) {
		onPassivePlayerError(player1, err);
	} else {
		onActivePlayerError(player1, err);
	}
}

function onActivePlayerStateChange(player, state) {
	activePlayerState = state;
	if (state == -1) { 
	} else if (state == 0) {
		if (typeof(customPlaylist[nextTrack]) != 'undefined') {
			playYouTube(nextTrack);
			prepareNextTrack();
		} else {
			switchView('end');
		}
	} else if (state == 1) {
		$trackInfoPlayController.css('display', 'none');
		$trackInfoPauseController.css('display', 'inline');
		$trackInfoNextController.css('display', 'inline');
		renderTrackInfo(-1);
	} else if (state == 2) {
		$trackInfoPlayController.css('display', 'inline');
		$trackInfoPauseController.css('display', 'none');
		$trackInfoNextController.css('display', 'inline');
		renderTrackInfo(-1);
	} else if (state == 3) {
	} else if (state == 5) {
	}
}
function onPassivePlayerStateChange(player, state) {
	passivePlayerState = state;

	player.pauseVideo(); // Pause on all events, so we make sure it is paused!
	player.seekTo(0);

	if (state == -1) {
	} else if (state == 0) { 
	} else if (state == 1) {
	} else if (state == 2) {
	} else if (state == 3) {
	} else if (state == 5) { 
	}
}

function onActivePlayerError(player, err) {
	_gaq.push(['_trackEvent', 'YouTube', 'LoadError', customPlaylist[nextTrack - 1].artistname + ' - ' + customPlaylist[nextTrack - 1].trackname]);
	playYouTube(nextTrack);
	prepareNextTrack();
}

function onPassivePlayerError(player, err) {
}

customPlaylist = [];
customizeTracks = {};
clubs = [];
guests = [];
nextTrack = 0;

// CURSOR

function setTrackInfoColor() {
	procPos = Math.floor(100 * ((parseInt($cursor.css('left')) + Math.floor($cursor.width() / 2)) / viewportWidth));
	$trackInfoHighlight = $('span.highlight', $trackInfo);
	if (procPos <= 25) {
		$trackInfo.css('color', '#324708');
		$trackInfoHighlight.css('color', '#75a21d');
	} else if (procPos <= 50) {
		$trackInfo.css('color', '#453a0a');
		$trackInfoHighlight.css('color', '#e6c321');
	} else if (procPos <= 75) {
		$trackInfo.css('color', '#4d1830');
		$trackInfoHighlight.css('color', '#bc266a');
	} else if (procPos <= 100) {
		$trackInfo.css('color', '#5e2d14');
		$trackInfoHighlight.css('color', '#ec7131');
	}
	if (procPos <= 17) {
		if (!$bigBottle0.is(':visible')) {
			$bigBottles.hide();
			$bigBottle0.show();
		}
	} else if (procPos <= 33) {
		if (!$bigBottle1.is(':visible')) {
			$bigBottles.hide();
			$bigBottle1.show();
		}
	} else if (procPos <= 50) {
		if (!$bigBottle2.is(':visible')) {
			$bigBottles.hide();
			$bigBottle2.show();
		}
	} else if (procPos <= 67) {
		if (!$bigBottle3.is(':visible')) {
			$bigBottles.hide();
			$bigBottle3.show();
		}
	} else if (procPos <= 83) {
		if (!$bigBottle4.is(':visible')) {
			$bigBottles.hide();
			$bigBottle4.show();
		}
	} else if (procPos <= 100) {
		if (!$bigBottle5.is(':visible')) {
			$bigBottles.hide();
			$bigBottle5.show();
		}
	}
}

function oneSecCron() {
	if ((nextTrack != 0) && (!draggingTimeline) && (!calibrating)) {
		positionCursor();
		setTrackInfoColor();
		if (trackInfoDisplayNext == false) {
			renderTrackInfo(-1);
		}
	}
	setTimeout("oneSecCron()", 1000);
}
trackInfoDisplayNext = false;
fiveSecCronController = -1;
function fiveSecCron() {
	if (trackInfoDisplayNext == false) {
		trackInfoDisplayNext = true;
	} else {
		trackInfoDisplayNext = false;
	}
	renderTrackInfo(-1);
	fiveSecCronController = setTimeout("fiveSecCron()", 5000);
}
calibrating = false;
function calibrateCron() {
	if ((nextTrack != 0) && (!draggingTimeline) && (view != 'moodsensor')) {
		calibrating = true;

		calTo = $cursor.position().left + 10;
		$cursor.animate({
			'left': calTo
		}, animSpeed, function() {
			calTo = $cursor.position().left - 20;
			$cursor.animate({
				'left': calTo
			}, animSpeed, function() {
				positionCursor();
				calibrating = false;
			});
		});

		

	}
	setTimeout("calibrateCron()", 35000);
}

isScrolling = false;
function listScroller() {
	isScrolling = true;
	var $left = $('ul#createSearchResults');
	var $right = $('ul#myplaylist');
	var $lifirst = false;
	$list = false;
	if ((mouseX > $left.offset().left) && (mouseX < ($left.offset().left + $left.width()))) {
		$list = $left;
	} else if ((mouseX > $right.offset().left) && (mouseX < ($right.offset().left + $right.width()))) {
		$list = $right;
	}
	if ($list != false) {
		$lifirst = $('li:first', $list);
		listTop = $list.offset().top;
		listHeight = $list.height();
		if (mouseY < (listTop + 20)) {

			mt = parseInt($lifirst.css('margin-top'));
			nymt = mt + 5;
			if (nymt > 0) nymt = 0;

			$lifirst.css('margin-top', nymt);

			setTimeout('listScroller()', 50);
			renderScrollBars();

		} else if (mouseY > (listTop + listHeight - 20)) {

			mt = parseInt($lifirst.css('margin-top'));
			nymt = mt - 5;

			contentHeight = 0;

			if ($list.attr('id') == 'createSearchResults') {
				$('li', $list).each(function() {
					contentHeight = contentHeight + $(this).outerHeight();
				});

			} else {
				$('ul', $list).each(function() {
					var minified = false;
					$('li', this).each(function() {
						if (!minified) {
							contentHeight = contentHeight + $(this).outerHeight();
							if ($(this).hasClass('minified')) {
								minified = true;
							}
						}
					});
				});
			}

			if (nymt < (0 - contentHeight + listHeight)) nymt = 0 - contentHeight + listHeight;

			$lifirst.css('margin-top', nymt);

			setTimeout('listScroller()', 50);
			renderScrollBars();

		} else {
			isScrolling = false;
		}
	} else {
		isScrolling = false;
	}
}


// INITIALIZE:

function initialize() {

	ZeroClipboard.setMoviePath('http://' + document.domain + '/zeroclipboard/ZeroClipboard.swf' );

	$('*').each(function() {
		if ($(this).attr('id') != 'shareMyListUrl') {
			$(this).disableSelection();
		}
	});

(function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(f){var d=[].slice.call(arguments,1),g=0,e=true;f=c.event.fix(f||window.event);f.type="mousewheel";if(f.wheelDelta){g=f.wheelDelta/120}if(f.detail){g=-f.detail/3}d.unshift(f,g);return c.event.handle.apply(this,d)}})(jQuery);

	if (!$.browser.msie) {
		$('img.ie, img.ie6').each(function() {
			$(this).remove();
		});
	} else { // If IE...
		$('img.notie').each(function() {
			$(this).remove();
		});
		if ($.browser.version.substring(0, 2) == '6.') { // If IE6...
			$('img.notie6').each(function() {
				$(this).remove();
			});
		} else { // If IE7>
			$('img.ie6').each(function() {
				$(this).remove();
			});
		}
	}

	jQuery.fn.animCSS = function(styles) {
		var $this = $(this[0]);
		var fadeIn = false;
		if ($this.is(':visible')) {
			if (typeof(styles['display']) != 'undefined') {
				delete styles['display'];
			}
			$this.animate(styles, animSpeed);
		} else {
			if (typeof(styles['display']) != 'undefined') {
				if (styles['display'] == 'block') {
					fadeIn = true;
				}
				delete styles['display'];
			}
			$this.css(styles);
			$this.fadeIn();
		}
	}

	$.ajax({
		type: "POST",
		url: "backend.php",
		async: true,
		data: {
			'action': 'getTimelineColors'
		},
		dataType: 'json',
		success: function(data) {
			timelineColors = data['colors'];
		}
	});

	$.ajax({
		type: "POST",
		url: "backend.php",
		async: true,
		data: {
			'action': 'customizeTracks'
		},
		dataType: 'json',
		success: function(data) {
			customizeTracks = data;

			$.ajax({
				type: "POST",
				url: "backend.php",
				async: true,
				data: {
					'action': 'guestsandclubs'
				},
				dataType: 'json',
				success: function(data) {
					clubs = data['guestsandclubs'];
					guests = data['guestsandclubs'];
				}
			});

		}
	});
	
	$('img.hover').each(function() {
		$(this).parent().mouseenter(function() {
			$('img.hover', this).show().siblings('img').hide();
		});
		$(this).parent().mouseleave(function() {
			if (!$(this).hasClass('active')) {
				$('img.hover', this).hide().siblings('img').show();
			}
		});
	});

	// Some global vars to be used throughout the app
	// (to reduce the nr of jQueries slowing down our app by searching the DOM):

	$appContainer = $('div#app');
	$ornamentLeft = $('div#ornamentLeft', $appContainer);
	$ornamentRight = $('div#ornamentRight', $appContainer);
	$ornamentMid = $('div#ornamentMid', $appContainer);
	$logo308x196 = $('div#logo308x196', $appContainer);
	$logo259x164 = $('div#logo259x164', $appContainer);
	$logo190x122 = $('div#logo190x122', $appContainer);
	$slogan = $('div#slogan', $appContainer);
	$trackInfo = $('div#trackInfo', $appContainer);
	$legal = $('div#legal', $appContainer);
	$timelineContainer = $('div#timelineContainer', $appContainer);
	$timelineImg = $('img#timelineBg', $timelineContainer);
	$timelineCopyImages = $('img.timelineCopy', $timelineContainer);
	$loaderContainer = $('div#loaderContainer', $appContainer);
	/*
	$mooddescrContainer = $('div#mooddescrContainer', $appContainer);
	$imgMooddescrStd = $('img#mooddescr', $mooddescrContainer);
	$imgMooddescrGuests = $('img#mooddescr_guests', $mooddescrContainer);
	$imgMooddescrClubs = $('img#mooddescr_clubs', $mooddescrContainer);
	$imgMooddescrCustomize = $('img#mooddescr_customize', $mooddescrContainer);
	*/
	$cgcSelectContainer = $('div#cgcSelectContainer', $appContainer);
	$ageQuestionContainer = $('div#ageQuestionContainer', $appContainer);
	$customizeContainer = $('div#customizeContainer', $appContainer);
	$selectHitsRate = $('select#hitsRate', $customizeContainer);
	$selectPopRockRate = $('select#popRockRate', $customizeContainer);
	$selectHipHopRnbRate = $('select#hipHopRnbRate', $customizeContainer);
	$selectHouseRate = $('select#houseRate', $customizeContainer);
	$selectSwedishSummerRate = $('select#swedishSummerRate', $customizeContainer);
	$youtubeContainer = $('div#youtubeContainer', $appContainer);
	$youtube0Container = $('div#youtube0Container', $youtubeContainer);
	$youtube1Container = $('div#youtube1Container', $youtubeContainer);
	$smallMenuBg = $('div#smallmenubg');
	$smallMenu = $('div#smallmenu');
	$cursor = $('div#cursor', $appContainer);
	$cursorDrag = $('img#cursorDrag', $cursor);
	$timelinePulse = $('img#timelinepulse', $cursor);
	$sideinfoContainer = $('div#sideinfoContainer', $appContainer);
	$thumbsContainer = $('div#thumbsContainer', $appContainer);
	$thumbsContent = $('div#thumbsContent', $thumbsContainer);
	$dim = $('div#dim', $appContainer);
	$endQuestionContainer = $('div#endQuestionContainer', $appContainer);
	$emailFormContainer = $('div#emailFormContainer', $appContainer);
	$backToVideo = $('div#backToVideo', $appContainer);
	$next = $('div#next', $appContainer);
	$prev = $('div#prev', $appContainer);
	$bigBottleContainer = $('div#bigBottle', $appContainer);
	$bigBottles = $('img.bigBottle', $bigBottleContainer);
	$bigBottle0 = $($bigBottles[0]);
	$bigBottle1 = $($bigBottles[1]);
	$bigBottle2 = $($bigBottles[2]);
	$bigBottle3 = $($bigBottles[3]);
	$bigBottle4 = $($bigBottles[4]);
	$bigBottle5 = $($bigBottles[5]);
	$startBottles = $('div#startBottles');
	$trackInfoControllers = $('div#trackInfoControllers');
	$trackInfoPlayController = $('span#trackInfoPlayController', $trackInfoControllers);
	$trackInfoPauseController = $('span#trackInfoPauseController', $trackInfoControllers);
	$trackInfoNextController = $('span#trackInfoNextController', $trackInfoControllers);
	$dragMe = $('div#dragMe');
	$moodSensorContainer = $('div#moodSensorContainer');
	$toolbar = $('div#toolbar');
	$toolbaryoutube = $('div#toolbaryoutube');
	$createTop = $('div#createTop');
	$createBottom = $('div#createBottom');
	$createMidLeft = $('div#createMidLeft');
	$createMidMid = $('div#createMidMid');
	$createMidMidArrow = $('div#createMidMidArrow');
	$createMidRight = $('div#createMidRight');
	$createLeftAreaBg = $('div#createLeftAreaBg');
	$createRightAreaBg = $('div#createRightAreaBg');
	$createInstructionTwo = $('div#createInstructionTwo');
	$createInstructionThree = $('div#createInstructionThree');
	$createSearch = $('div#createSearch');
	$createDoneButton = $('div#createDoneButton');
	$saveList = $('div#saveList');
	$saveListButton = $('div#saveListButton');
	$shareMyList = $('div#shareMyList');
	$shareMyListUrl = $('div#shareMyListUrl');
	$shareMyListTitle = $('div#shareMyListTitle');
	$playMyListButton = $('div#playMyListButton');
	$acceptBox = $('div#acceptBox');
	// $searchResultPlayHover = $('div#searchResultPlayHover');
	$scrollBarLeft = $('div#scrollBarLeft');
	$scrollBarRight = $('div#scrollBarRight');
	$mixCopy = $('div#mixCopy');

	$('div#scrollBarLeft, div#scrollBarRight').each(function() {
		$(this).mousedown(function(e) {
			$(this).addClass('scrolling');
			$(this).data('mouseDiff', e.pageY - $(this).offset().top);
			return false;
		});
	});

	/*
	$searchResultPlayHover.mouseleave(function() {
		$searchResultPlayHover.css({
			'display': 'none'
		});
		$(this).html('<img src="imgs/searchResultPlayHover.png" />');
	}).disableSelection().click(function() {
		$(this).css('top', parseInt($(this).css('top')) - 0).css('left', parseInt($(this).css('left')) - 0).html('<div style="width:55; height:31; overflow:hidden"><object style="height: 55px; width: 56px"><param name="movie" value="http://www.youtube.com/v/' + searchPreview + '?version=3?version=3&autoplay=1&loop=1&disablekb=1&color1=0xb1b1b1&color2=0xcfcfcf&iv_load_policy=3&feature=player_embedded"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/' + searchPreview + '?version=3?version=3&autoplay=1&loop=1&disablekb=1&color1=0xb1b1b1&color2=0xcfcfcf&iv_load_policy=3&feature=player_embedded" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="55" height="56"></object></div>');
		$('div, object', this).hover(function() { }, function() {
			$searchResultPlayHover.css({
				'display': 'none'
			}).html('<img src="imgs/searchResultPlayHover.png" />');
		});
	});
	*/


	$acceptBox.click(function() {
		$('img:visible', this).hide().siblings().show();
	});

	$playMyListButton.click(function() {

		$.ajax({
			type: "POST",
			url: "backend.php",
			async: true,
			data: {
				'action': 'getUserPlayList',
				'id': userplaylist
			},
			dataType: 'json',
			success: function(data) {
				playingMood = "userplaylist";
				customPlaylist = data['playlist'];
				switchView('player');
				nextTrack = 0;
				playYouTube(nextTrack);
				prepareNextTrack();
			}
		});

	});

	$('.saveListInputs').each(function() {
		$('input', this).val('');
		$(this).click(function() {
			$('input', this).css('display', 'inline').blur(function() {
				if ($(this).val() == '') {
					$(this).css('display', 'none');
				}
			}).focus();
		});
	});
	$saveListButton.click(function() {
		if ($('div#saveListNameInput input').val() != '') {
			if ($('div#saveListCreatorInput input').val() != '') {
				if (validateEmail($('div#saveListEmailInput input').val())) {
					if (($('img#acceptBoxYes:visible').length == 1) && (blinkingAccept == false)) {

						$.ajax({
							type: "POST",
							url: "backend.php",
							async: true,
							data: {
								'action': 'setUserPlayListMetadata',
								'id': userplaylist,
								'creator': $('div#saveListCreatorInput input').val(),
								'email': $('div#saveListEmailInput input').val(),
								'listname': $('div#saveListNameInput input').val()
							},
							dataType: 'json',
							success: function(data) {
							}
						});

						switchView('sharemylist');

					} else {
						blinkingAccept = true;

						$('img#acceptBoxNo').fadeOut(70, function() {
							$('img#acceptBoxNo').fadeIn(70, function() {
								$('img#acceptBoxNo').fadeOut(70, function() {
									$('img#acceptBoxNo').fadeIn(70, function() {
										$('img#acceptBoxNo').fadeOut(70, function() {
											$('img#acceptBoxNo').fadeIn(70, function() {
												$('img#acceptBoxNo').fadeOut(70, function() {
													$('img#acceptBoxNo').fadeIn(70, function() {
														blinkingAccept = false;
													});
												});
											});
										});
									});
								});
							});
						});
					}
				} else {
					$('div#saveListEmailInput input').val('').hide();
					$('img#saveListEmailInputError').css('display', 'block');
				}
			} else {
				$('img#saveListCreatorInputError').css('display', 'block');
			}
		} else {
			$('img#saveListNameInputError').css('display', 'block');
		}
	});

	$createDoneButton.click(function() {
		var prepartyplaylist = '';
		$('ul#prepartyplaylist li span.youtubeid').each(function() {
			if (prepartyplaylist != '') {
				prepartyplaylist = prepartyplaylist + ',';
			}
			prepartyplaylist = prepartyplaylist + $(this).text();
		});
		var partyplaylist = '';
		$('ul#partyplaylist li span.youtubeid').each(function() {
			if (partyplaylist != '') {
				partyplaylist = partyplaylist + ',';
			}
			partyplaylist = partyplaylist + $(this).text();
		});
		var afterpartyplaylist = '';
		$('ul#afterpartyplaylist li span.youtubeid').each(function() {
			if (afterpartyplaylist != '') {
				afterpartyplaylist = afterpartyplaylist + ',';
			}
			afterpartyplaylist = afterpartyplaylist + $(this).text();
		});
		$.ajax({
			type: "POST",
			url: "backend.php",
			async: true,
			data: {
				'action': 'saveUserPlayList',
				'preparty': prepartyplaylist,
				'party': partyplaylist,
				'afterparty': afterpartyplaylist
			},
			dataType: 'json',
			success: function(data) {
				_gaq.push(['_trackEvent', 'Selection', 'Create', 'List Created']);
				if (data['error'] == '') {
					userplaylist = data['id'];
					if (idiot) {

						$.ajax({
							type: "POST",
							url: "backend.php",
							async: true,
							data: {
								'action': 'getUserPlayList',
								'id': userplaylist
							},
							dataType: 'json',
							success: function(data) {
								playingMood = "userplaylist";
								customPlaylist = data['playlist'];
								switchView('player');
								nextTrack = 0;
								playYouTube(nextTrack);
								prepareNextTrack();
							}
						});

					} else {
						switchView('savelist');
					}
				}
			}
		});
	});

	$('div#forstoringsglas').click(function() {
		doCreateSearch();
	});
	$createSearch.click(function() {
		$('input', this).css('display', 'inline').focus().keyup(function(e) {
			if (e.keyCode == 13) {
				$(this).blur();
				doCreateSearch();
			}
		}).blur(function() {
			if ($(this).val() == '') {
				$(this).hide();
			}
		});
	});


	$trackInfoPlayController.click(function() {
		activePlayer.playVideo();
	}).hover(function() {
		$(this).css('color', '#fff');
	}, function() {
		$(this).css('color', '#6e6e6e');
	});
	$trackInfoPauseController.click(function() {
		activePlayer.pauseVideo();
	}).hover(function() {
		$(this).css('color', '#fff');
	}, function() {
		$(this).css('color', '#6e6e6e');
	});
	$trackInfoNextController.click(function() {
		_gaq.push(['_trackEvent', 'YouTube', 'Interrupted', customPlaylist[nextTrack - 1].artistname + ' - ' + customPlaylist[nextTrack - 1].trackname]);
		if (typeof(customPlaylist[nextTrack]) == 'undefined') {
			activePlayer.pauseVideo();
			switchView('end');
		} else {
			playYouTube(nextTrack);
			prepareNextTrack();
		}
	}).hover(function() {
		$(this).css('color', '#fff');
	}, function() {
		$(this).css('color', '#6e6e6e');
	});

	$prev.click(function() {
		if (currentThumbsPage != 0) {
			currentThumbsPage--;
			renderView();
		}
	});
	$next.click(function() {
		if (totalThumbsPages > (currentThumbsPage + 1)) {
			currentThumbsPage++;
			renderView();
		}
	});

	timelineCopyCounter = 0;
	$timelineCopyImages.each(function() {
		$(this).css('cursor', 'pointer').attr('data-timelineCopyCounter', timelineCopyCounter);
		$(this).click(function() {
			_gaq.push(['_trackEvent', 'Timeline', 'Clicked', '']);
			newTrack = Math.floor(($(this).position().left + ($(this).width() / 2)) / viewportWidth * customPlaylist.length);
			nextTrack = newTrack + 1;
			renderTrackInfo(-1);
			playYouTube(newTrack);
		});
		timelineCopyCounter++;
	});

	/*
	$smallMenu.mouseenter(function() {
		if (($.browser.msie) && ($.browser.version.substring(0, 2) == '6.')) {
		} else {
			$smallMenu.fadeTo(animSpeed, 1);
		}
	});
	$smallMenu.mouseleave(function() {
		if (($.browser.msie) && ($.browser.version.substring(0, 2) == '6.')) {
		} else {
			$smallMenu.fadeTo(animSpeed, 0.5);
		}
	});
	*/

	$('#selectCustomize').mouseenter(function() {
		if (view != 'start') return;
		/*
		$imgMooddescrStd.hide();
		$imgMooddescrCustomize.show();
		*/
	});
	$('#selectCustomize').mouseleave(function() {
		if (view != 'start') return;
		/*
		$imgMooddescrCustomize.hide();
		$imgMooddescrStd.show();
		*/
	});

	$('#selectClub').mouseenter(function() {
		if (view != 'start') return;
		/*
		$imgMooddescrStd.hide();
		$imgMooddescrClubs.show();
		*/
	});
	$('#selectClub').mouseleave(function() {
		if (view != 'start') return;
		/*
		$imgMooddescrClubs.hide();
		$imgMooddescrStd.show();
		*/
	});

	$('#selectGuest').mouseenter(function() {
		if (view != 'start') return;
		/*
		$imgMooddescrStd.hide();
		$imgMooddescrGuests.show();
		*/
	});
	$('#selectGuest').mouseleave(function() {
		if (view != 'start') return;
		/*
		$imgMooddescrGuests.hide();
		$imgMooddescrStd.show();
		*/
	});

	//$('p.facebook').hover(function() {
	$('.facebook, .twitter').hover(function() {
		// $(this).css('color', '#fff');
	}, function() {
		// $(this).css('color', '#3b5998');
	}).click(function() {
		if ((view == 'sharemylist') || (playingMood == 'userplaylist')) {

			url = 'http%3A%2F%2Fwww.xidemood.se?s=user' + userplaylist;

		} else if (playingMood == 'customize') {
			url = 'http%3A%2F%2Fwww.xidemood.se?s=customize' + $selectHitsRate.val() + '%2C' + $selectPopRockRate.val() + '%2C' + $selectHipHopRnbRate.val() + '%2C' + $selectHouseRate.val() + '%2C' + $selectSwedishSummerRate.val();
		} else {
			re = new RegExp('[^a-z]', 'g');
			re2 = new RegExp('_+');
			url = 'http%3A%2F%2Fwww.xidemood.se?s=' + clubOrGuestName.toLowerCase().replace(re, '_').replace(re2, '_');
		}
		
		if ($(this).hasClass('facebook')) {
			_gaq.push(['_trackEvent', 'Facebook', 'Shared', 'url']);
			window.open('http://www.facebook.com/sharer.php?u=' + url);
		}
		if ($(this).hasClass('twitter')) {
			window.open('http://twitter.com/home?status=' + url);
		}
	});

	// Load youtube players:

	for (var i = 0; i <= 0; i++) {
		swfobject.embedSWF(
			'http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=youtube' + i,
			'youtube' + i, '425', '356', '8', null, null,
			{
				allowScriptAccess: 'always'
			},
			{ 
				id: 'youtube' + i
			}
		);
	}

	// Buttons changing views in the application:

	$('#selectOverAge', $ageQuestionContainer).click(function() {
		_gaq.push(['_trackEvent', 'Age', 'Old', 'Too old']);
		hash = getHash();
		v = 'customize';

		var re = new RegExp('customize([0-9]+),([0-9]+),([0-9]+),([0-9]+),([0-9]+)');
		var m = re.exec(getHash());
		if (m == null) {

			re = new RegExp('[^a-z]', 'g');
			re2 = new RegExp('_+');
			/*
			for (i = 0; i < clubs.length; i++) {
				jmfr = clubs[i]['name'].toLowerCase().replace(re, '_').replace(re2, '_');
				if (hash == jmfr) {

					v = '';

					$('#sideinfoClubImg').html('<img src="' + clubs[i]['img'] + '" width="168" height="110" />');
					$('#sideinfoClubDescr').html(clubs[i]['description']);
					$('#sideinfoClubDescr a').each(function() {
						$(this).attr('target', 'blank');
					});

					$.ajax({
						type: "POST",
						url: "backend.php",
						async: true,
						data: {
							'action': 'clubPlaylist',
							'id': clubs[i]['id']
						},
						dataType: 'json',
						success: function(data) {
							playingMood = "club";
							customPlaylist = data['playlist'];
							switchView('player');
							nextTrack = 0;
							playYouTube(nextTrack);
							prepareNextTrack();

							i = clubs.length; // Avbryt loopen
						}
					});
					
				}
			}
			*/
			if (v != '') { // Om ingen club matchade...
				for (i = 0; i < guests.length; i++) {
					jmfr = guests[i]['name'].toLowerCase().replace(re, '_').replace(re2, '_');

					if (hash == jmfr) {

						v = '';

						$('#sideinfoGuestImg').html('<img src="' + guests[i]['img'] + '" width="168" height="110" />');
						$('#sideinfoGuestDescr').html(guests[i]['description']);
						$('#sideinfoGuestDescr a').each(function() {
							$(this).attr('target', 'blank');
						});

						$.ajax({
							type: "POST",
							url: "backend.php",
							async: true,
							data: {
								'action': 'guestPlaylist',
								'id': guests[i]['id']
							},
							dataType: 'json',
							success: function(data) {
								playingMood = "guest";
								customPlaylist = data['playlist'];
								switchView('player');
								nextTrack = 0;
								playYouTube(nextTrack);
								prepareNextTrack();

								i = clubs.length; // Avbryt loopen

							}
						});
						
					}

				}
			}

		} else {
			$selectHitsRate.val(parseInt(m[1]));
			$selectPopRockRate.val(parseInt(m[2]));
			$selectHipHopRnbRate.val(parseInt(m[3]));
			$selectHouseRate.val(parseInt(m[4]));
			$selectSwedishSummerRate.val(parseInt(m[5]));
			playingMood = "customize";
			calculateCustomPlaylist();
			v = 'player';
		}

		if (v != '') {
			switchView(v);
		}
	});
	$('#selectUnderAge', $ageQuestionContainer).click(function() {
		_gaq.push(['_trackEvent', 'Age', 'Young', 'Too young']);
		$('#tooYoung').css({
			'display': 'block',
			'top': $('#ageQuest').offset().top,
			'left': Math.floor((viewportWidth / 2) - ($('#tooYoung').width() / 2))
		});
	});
	$('#selectGuest, #startBottles_guests').click(function() {
		switchView('guests');
	}).hover(function() {
		$('#startDescrGuests').css('display', 'block');
	}, function() {
		$('#startDescrGuests').css('display', 'none');
	});
	$('#selectClub, #startBottles_clubs').click(function() {
		switchView('clubs');
	}).hover(function() {
		$('#startDescrClubs').css('display', 'block');
	}, function() {
		$('#startDescrClubs').css('display', 'none');
	});
	$('#selectCustomize, #startBottles_customize').click(function() {
		switchView('customize');
	}).hover(function() {
		$('#startDescrCustomize').css('display', 'block');
	}, function() {
		$('#startDescrCustomize').css('display', 'none');
	});
	$('#selectCreate').click(function() {
		switchView('create');
	});
	$('span#play', $appContainer).click(function() {

		googleAnalyticsValue = $('select#hitsRate').val() + '%'
		generecount = 0;
		$('span.genereval', $sideinfoContainer).each(function() {
			if (generecount == 1) googleAnalyticsValue = googleAnalyticsValue + ',' + $('select#popRockRate').val() + '%';
			if (generecount == 2) googleAnalyticsValue = googleAnalyticsValue + ',' + $('select#hipHopRnbRate').val() + '%';
			if (generecount == 3) googleAnalyticsValue = googleAnalyticsValue + ',' + $('select#houseRate').val() + '%';
			if (generecount == 4) googleAnalyticsValue = googleAnalyticsValue + ',' + $('select#swedishSummerRate').val() + '%';
			generecount++;
		});
		_gaq.push(['_trackEvent', 'Selection', 'Customize', googleAnalyticsValue]);

		switchView('player');
	});
	$('span#smallmenu_customize').click(function() {
		switchView('customize');
	});
	$('span#smallmenu_create').click(function() {
		switchView('create');
	});
	$('span#smallmenu_clubs').click(function() {
		switchView('clubs');
	});
	$('span#smallmenu_guests').click(function() {
		switchView('guests');
	});
	$('span#smallmenu_mood').click(function() {
		switchView('moodsensor');
	});
	$('span#continueplay').click(function() {
		googleAnalyticsValue = $('select#hitsRate').val() + '%'
		generecount = 0;
		$('span.genereval', $sideinfoContainer).each(function() {
			if (generecount == 1) googleAnalyticsValue = googleAnalyticsValue + ',' + $('select#popRockRate').val() + '%';
			if (generecount == 2) googleAnalyticsValue = googleAnalyticsValue + ',' + $('select#hipHopRnbRate').val() + '%';
			if (generecount == 3) googleAnalyticsValue = googleAnalyticsValue + ',' + $('select#houseRate').val() + '%';
			if (generecount == 4) googleAnalyticsValue = googleAnalyticsValue + ',' + $('select#swedishSummerRate').val() + '%';
			generecount++;
		});
		_gaq.push(['_trackEvent', 'Selection', 'ContinueCustomize', googleAnalyticsValue]);

		switchView('player');
	});
	$('span#playFromStart').click(function() {
		nextTrack = 0;

		googleAnalyticsValue = $('select#hitsRate').val() + '%'
		generecount = 0;
		$('span.genereval', $sideinfoContainer).each(function() {
			if (generecount == 1) googleAnalyticsValue = googleAnalyticsValue + ',' + $('select#popRockRate').val() + '%';
			if (generecount == 2) googleAnalyticsValue = googleAnalyticsValue + ',' + $('select#hipHopRnbRate').val() + '%';
			if (generecount == 3) googleAnalyticsValue = googleAnalyticsValue + ',' + $('select#houseRate').val() + '%';
			if (generecount == 4) googleAnalyticsValue = googleAnalyticsValue + ',' + $('select#swedishSummerRate').val() + '%';
			generecount++;
		});
		_gaq.push(['_trackEvent', 'Selection', 'CustomizeFromStart', googleAnalyticsValue]);

		calculateCustomPlaylist();
		switchView('player');
	});

	$('div#logo190x122').click(function() {
		//switchView('end');
	});
	$('span#replay').click(function() {
		nextTrack = 0;
		switchView('player');
	});
	$('span#newmood').click(function() {
		nextTrack = 0;
		switchView('customize');
	});
	$backToVideo.click(function() {
		switchView('player');
	});

	draggingButton = false;
	draggingTimeline = false;
	$('.dragButton').mousedown(function(e) {
		e.preventDefault();
		draggingButton = this;
	});
	$cursorDrag.mousedown(function(e) {
		e.preventDefault();
		draggingTimeline = true;
	});
	$(document).keydown(function(e) {
		if (view == 'create') {
			if ((e.which ==	38) || (e.which == 40)) {
				var $list = $('ul#createSearchResults');
				var listHeight = $list.height();
				var $lifirst = $('li:first', $list);
				mt = parseInt($lifirst.css('margin-top'));
				if (e.which ==	40) {
					nymt = mt - 30;

					contentHeight = 0;
					$('li', $list).each(function() {
						contentHeight = contentHeight + $(this).outerHeight();
					});

					if (nymt < (0 - contentHeight + listHeight)) nymt = 0 - contentHeight + listHeight;

				} else if (e.which == 38) {
					nymt = mt + 30;
					if (nymt > 0) nymt = 0;
				}
				$lifirst.css('margin-top', nymt);
				renderScrollBars();
			}
		}


	});
	$('body').mouseup(function(e) {
		$('div#scrollBarLeft, div#scrollBarRight').each(function() {
			$(this).removeClass('scrolling');
		});
		if (draggingTimeline) {
			_gaq.push(['_trackEvent', 'Timeline', 'Dragged', '']);
			pixelsPerTrack = viewportWidth / customPlaylist.length;
			newTrack = Math.floor(e.pageX / pixelsPerTrack);
			while (typeof(customPlaylist[newTrack]) == 'undefined') {
				newTrack--;
			}
			if (newTrack != (nextTrack - 1)) {
				_gaq.push(['_trackEvent', 'YouTube', 'Interrupted', customPlaylist[nextTrack - 1].artistname + ' - ' + customPlaylist[nextTrack - 1].trackname]);
				nextTrack = newTrack;
				playYouTube(newTrack);
				prepareNextTrack();
			}
			draggingTimeline = false;
			positionCursor();
			trackInfoDisplayNext = true; // Byts ju i fiveSecCron() innan något uppdateras.
			clearTimeout(fiveSecCronController);
			fiveSecCron();
		}
		if (draggingButton !== false) {
			draggingButton = false;
			trackInfoDisplayNext = false; // Byts ju i fiveSecCron() innan något uppdateras.
			clearTimeout(fiveSecCronController);
			fiveSecCron();
		}
		return true;
	});
	$('body').mousemove(function(e) {
		mouseX = e.pageX;
		mouseY = e.pageY;
		if ((createSorting) && (!isScrolling)) {
			var $left = $('ul#createSearchResults');
			var $right = $('ul#myplaylist');
			var $lifirst = false;
			$list = false;
			if ((e.pageX > $left.offset().left) && (e.pageX < ($left.offset().left + $left.width()))) {
				$list = $left;
			} else if ((e.pageX > $right.offset().left) && (e.pageX < ($right.offset().left + $right.width()))) {
				$list = $right;
			}
			if ($list != false) {
				listTop = $list.offset().top;
				listHeight = $list.height();
				if (e.pageY < (listTop + 20)) {
					listScroller();
				} else if (e.pageY > (listTop + listHeight - 20)) {
					listScroller();
				}
			}
		}
		var scrolling = false;
		contentHeight = 0;
		if ($scrollBarLeft.hasClass('scrolling')) {
			var $ul = $('ul#createSearchResults');
			var $lifirst = $('li:first', $ul);
			var $scrollBar = $scrollBarLeft;

			$('li', $ul).each(function() {
				contentHeight = contentHeight + $(this).outerHeight();
			});

			scrolling = true;
		}
		if ($scrollBarRight.hasClass('scrolling')) {
			var $ul = $('ul#myplaylist');
			var $lifirst = $('li:first', $ul);
			var $scrollBar = $scrollBarRight;

			$('ul', $ul).each(function() {
				var minified = false;
				$('li', this).each(function() {
					if (!minified) {
						contentHeight = contentHeight + $(this).outerHeight();
						if ($(this).hasClass('minified')) {
							minified = true;
						}
					}
				});
			});

			scrolling = true;
		}
		if (scrolling) {

			newScrollBarY = e.pageY - $scrollBar.data('mouseDiff');

			if (newScrollBarY < $ul.offset().top) {
				newScrollBarY = $ul.offset().top;
			}
			scrollBarHeight = $ul.height() / contentHeight * $ul.height();
			if (scrollBarHeight < 35) scrollBarHeight = 35;

			scrollMoveSpace = $ul.height() - scrollBarHeight;
			contentMoveSpace = contentHeight - $ul.height();

			if (newScrollBarY > $ul.offset().top + scrollMoveSpace) {
				newScrollBarY = $ul.offset().top + scrollMoveSpace;
			}

			scrollPos = newScrollBarY - $ul.offset().top;

			$scrollBar.css({
				'top': newScrollBarY
			});
			$lifirst.css({
				'margin-top': 0 - Math.floor((scrollPos / scrollMoveSpace) * contentMoveSpace)
			});
		
		}


		if (draggingTimeline) {
			$cursor.css({
				left: Math.floor(e.pageX - ($cursor.width() / 2))
			});
			pixelsPerTrack = viewportWidth / customPlaylist.length;
			newTrack = Math.floor(e.pageX / pixelsPerTrack);
			trackInfoDisplayNext = false;
			clearTimeout(fiveSecCronController);
			renderTrackInfo(newTrack);
		}
		if (draggingButton !== false) {
			var newTop = e.pageY - $(draggingButton).parent().position().top - Math.floor($(draggingButton).height() / 2);
			if (newTop < 25) newTop = 25;
			if (newTop > 145) newTop = 145;
			$(draggingButton).css('top', newTop);

			var rate = 100 - Math.floor((newTop - 25) / 118 * 100);

			genere = $(draggingButton).attr('id').substring(0, $(draggingButton).attr('id').length - 6);
			$('#' + genere + 'Rate').val(rate);

			renderNumbers();
			calculateCustomPlaylist();
			trackInfoDisplayNext = true;
			clearTimeout(fiveSecCronController);
			renderTrackInfo(-1);

		}
		return true;
	});

	$('#sendEmailInput').click(function() {
		$.ajax({
			type: "POST",
			url: "backend.php",
			async: true,
			data: {
				'action': 'addVip',
				'email': $('input#emailInput').val()
			},
			dataType: 'json',
			success: function(data) {
				$("#sendEmailInput").remove();
				$('img#emailFormThanks').fadeIn();
			}
		});
	});


	// onResize:


	$(window).resize(function() {
		resize();
	});

	// cronJob:

	oneSecCron();
	fiveSecCron();
	calibrateCron();

	$('a', $('span.order')).each(function() {
		$(this).click(function() {
			_gaq.push(['_trackEvent', 'Toolbar', 'Systembolaget', 'Link' + $(this).index()]);
			return true;
		});
	});

}

google.setOnLoadCallback(initialize);


