﻿var ulindex = -1;
var ulllindex = -1;
var IsSearchingArtist = false;
var PlayerInstance = null;
var GenreMaster = null;
var modified = false;

var ArtistModified = false;
var PlaylistIsSearchingArtist = false;

var PlaylistIsSearchingSong = false;
var SongModified = false;

function setPlayerInstance(guid) {
	PlayerInstance = guid;
}

function setGenreMaster(guid) {
	if (guid.length == 36) {
		GenreMaster = guid.toLowerCase();
	}
}

function StartGenreDescriptionScrollText(thediv) {
    var genrewidth = $(thediv).width();
    if (genrewidth > 200) {
        $(thediv).SetScroller({ velocity: 80,
            direction: 'horizontal',
            startfrom: 'right',
            loop: 'infinite',
            movetype: 'linear',
            onmouseover: 'play',
            onmouseout: 'play',
            onstartup: 'play',
            cursor: 'default'
        });
    }
}


function StopGenreDescriptionScrollText(thediv) {
    $(thediv).RemoveScroller();
   }

   function GenreNameScrolling(thename) {

   	if ($(thename).children().width() > $(thename).width()) {

   		$(thename).SetScroller({ velocity: 80,
   			direction: 'horizontal',
   			startfrom: 'right',
   			loop: 'infinite',
   			movetype: 'linear',
   			onmouseover: 'play',
   			onmouseout: 'play',
   			onstartup: 'play',
   			cursor: 'default'
   		});
   	}
   }

   function GenreNameStopScrolling(thename) {
   	$(thename).RemoveScroller();
   }



   $(document).ready(function () {

   	$('#guest_yes').live('click', function () {
   		closePopUp();
   		popupHide();
   		offset = $('#tabb').offset();
   		resetCaptcha();
   		popupShow($('#create_acc_box').show(), offset.left, offset.top);
   	});

   	$(document).click(function () {
   		$('#PlaylistSongUl').hide();
   		$('#PlaylistArtistUl').hide();
   		ulindex = -1;
   		ulllindex = -1;
   	});

   	$.ajaxSetup({
   		cache: false,
   		timeout: 30000
   	});
   	jQuery.fn.exists = function () { return jQuery(this).length > 0; };
   	var offset = $('#tabb').offset();
   	var AddGenresTimer;
   	var AddGenresFlag = 0;
   	$('#AddToPlaylistSelect').sSelect();

   	//-----------------------------------------------------------------------------------------------------
   	function LogIn(LogOnModel) {
   		$.post("/Account/JsonLogOn", //for MVC
			LogOnModel,
			function (MVC) {
				if (MVC.result) {
					if (LogOnModel.indexOf("RememberMe") == -1) {
						LogOnModel += "&RememberMe=false"
					}
					$.ajax({
						url: '/dnn/AjaxMembership.asmx/LogIn',
						type: 'POST',
						cache: false,
						data: LogOnModel,
						success: function (xml) {
							$('body').html('');
							//							try {
							//								var DNN = $.parseJSON($(xml).find('string').text());
							//								if (!DNN.LoggedIn) {
							//									alert('Invalid DNN login! (MVC logged in successfully!) \r\n' + DNN.Message);
							//								}

							//							}
							//							catch (err) {
							//								alert('Invalid DNN login! (MVC logged in successfully!)');

							//							}
							window.location.reload();
						},
						error: function () {
							window.location.reload();
						}
					});
				}
				else {
					alert('Invalid Username or Password!');
				}
			},
			"json"
		);
   	};

   	//-----------------------------------------------------------------------------------------------------

   	function SelectGenres() {
   		//   		$('#dragmetoscroll').css({ 'height': '100%', 'top': '0' });
   		$('#genreTree').html($('#pleaseWait').show());
   		popupShow($('#genre_selection').show(), offset.left, offset.top);
   		$.getJSON('/Genre/Names/' + getSelectedStationId(), function (data) {
   			var genreTree = '';
   			var i = data.length;
   			for (var x in data) {

   				if (data[x].SubGenres.length == 0) {
   					genreTree += '<li class="menu_head ' + (x % 2 == 1 ? 'dark' : 'light') + '_gray" ><div class="menu_head_left"><input type="checkbox" style="margin-left:27px;" class="subg" id="' + data[x].Genre_ID + '" isPlaylist="false" name="' + data[x].Genre_ID + '"/><span style="cursor:default; height:16px; display:inline-block; overflow:hidden; width:110px;" onmouseover="GenreNameScrolling(this);" onmouseout="GenreNameStopScrolling(this);"><span style="position:relative; white-space:nowrap; overflow:visible;"> ' + data[x].Name + ' </span></span></div><div class="menu_head_right_small_line"><div class="level2_rightR"><select class="subg_weight" id="' + data[x].Genre_ID + '_Weight" style="margin-top:5px;" ><option>1</option><option>2</option><option>3</option><option>4</option><option selected>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select></div><div class="level2_rightL"><p class="genreDescription">' + data[x].Description + '</p></div></div><div class="clb"></div></li>';
   				}
   				else {
   					genreTree += '<li class="menu_head ' + (x % 2 == 1 ? 'dark' : 'light') + '_gray" ><div class="menu_head_left"><span class="menu_expand" id="g' + data[x].Genre_ID + '"><img class="img_menu_icon" id="img_menu_icon' + data[x].Genre_ID + '" src="/images/item_c_icon.png" /> </span><input type="checkbox" class="subg" id="' + data[x].Genre_ID + '" isPlaylist="false" name="' + data[x].Genre_ID + '" /> <span style="cursor:default; height:16px; display:inline-block; overflow:hidden; width:110px;" onmouseover="GenreNameScrolling(this);" onmouseout="GenreNameStopScrolling(this);"><span style="position:relative; white-space:nowrap; overflow:visible;"> ' + data[x].Name + ' </span></span></div><div class="menu_head_right_small_line"><div class="level2_rightR"><select class="subg_weight" id="' + data[x].Genre_ID + '_Weight" style="margin-top:5px;" ><option>1</option><option>2</option><option>3</option><option>4</option><option selected>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select></div><div class="level2_rightL"><p class="genreDescription"><span style="overflow:visible; width:200px"><span class="currentGenreDescription">' + data[x].Description + '</span></span></p></div></div><div class="clb"></div></li>';
   					genreTree += ' <li id="menu_body' + data[x].Genre_ID + '" class="submenu"><ul>';
   					//genreTree += '<li class="' + (x % 2 ? 'light' : 'dark') + '_gray"><div class="li_level2"><input type="checkbox" class="subg" id="' + data[x].Genre_ID + '" name="' + data[x].Genre_ID + '" /><span> All ' + data[x].Name + ' </span></div><div class="menu_head_right_small_line"><div class="level2_rightR"><select class="subg_weight" id="' + data[x].Genre_ID + '_Weight" style="margin-top:5px;" ><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option selected>10</option></select></div><div class="level2_rightL"><p class="genreDescription">An equal mix for all Sub Genres Below</p></div></div><div class="clb"></div></li>';
   					for (var y in data[x].SubGenres) {
   						genreTree += '<li class="' + ((parseInt(x) + parseInt(y)) % 2 == 1 ? 'light' : 'dark') + '_gray"><div class="li_level2"><input type="checkbox" style="margin-left:15px;" class="subg" id="' + data[x].SubGenres[y].Genre_ID + '" isPlaylist="false" name="' + data[x].SubGenres[y].Genre_ID + '" /><span style="cursor:default;  height:16px; overflow:hidden; width:110px;" onmouseover="GenreNameScrolling(this);" onmouseout="GenreNameStopScrolling(this);"><span style="position:relative; white-space:nowrap; overflow:visible;"> ' + data[x].SubGenres[y].Name + ' </span></span></div><div class="menu_head_right_small_line"><div class="level2_rightR"><select class="subg_weight" id="' + data[x].SubGenres[y].Genre_ID + '_Weight" style="margin-top:5px;"><option>1</option><option>2</option><option>3</option><option>4</option><option selected>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select></div><div class="level2_rightL"><p class="genreDescription"><span style="overflow:visible; width:200px"><span class="currentGenreDescription">' + data[x].SubGenres[y].Description + '</span></span></p></div></div><div class="clb"></div></li>';
   					}
   					genreTree += '</ul></li>';
   				}

   				//                var genrewidth = $("#currentGenreDescription" + data[x].Genre_ID).width();
   				//                alert(genrewidth);
   				//                if (genrewidth > 100) {
   				//                    $("#currentGenreDescription" + data[x].Genre_ID).html("<MARQUEE WIDTH=100% scrollamount=1>" + data[x].Description + "</MARQUEE>");
   				//                }

   			}
   			$.getJSON('/User/Playlists/', function (dataPlaylists) {
   				for (var z in dataPlaylists) {
   					genreTree += '<li class="menu_head ' + ((parseInt(z) + i) % 2 == 1 ? 'dark' : 'light') + '_gray" ><div class="menu_head_left"><input type="checkbox" style="margin-left:27px;" class="subg" id="' + dataPlaylists[z].Playlist_ID + '" isPlaylist="true" name="' + dataPlaylists[z].Playlist_ID + '" /> <span style="cursor:default; overflow:hidden; width:110px;" onmouseover="GenreNameScrolling(this);" onmouseout="GenreNameStopScrolling(this);"><span style="position:relative; white-space:nowrap; overflow:visible;"> ' + dataPlaylists[z].Name + ' </span></span></div><div class="menu_head_right_small_line"><div class="level2_rightR"><select class="subg_weight" id="' + dataPlaylists[z].Playlist_ID + '_Weight" style="margin-top:5px;" ><option>1</option><option>2</option><option>3</option><option>4</option><option selected>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select></div><div class="level2_rightL"><p class="genreDescription">Playlist</p></div></div><div class="clb"></div></li>';
   				}
   				$('#pleaseWait').hide().appendTo('body');
   				$('#genreTree').html(genreTree);
   				$('.genreDescription').each(function () {

   					$(this).html("<div class='horizontalartist_scrollerx alabala' onmouseover='StartGenreDescriptionScrollText(this);' onmouseout='StopGenreDescriptionScrollText(this);'  style='white-space:nowrap; float: left; height: 17px; cursor: default; position: relative; overflow:hidden;'><div class='scrollingtext' style='position: relative; height: 17px; white-space:nowrap; overflow:visible; '><span style='overflow:visible;'><span>" + $(this).text() + "</span></span></div></div>");
   				});

   				$(".submenu").hide();
   				//   				var vartest1 = $('#genreTree').height();

   				//   				if (vartest1 <= 420) {
   				//   					$('#dragmetoscroll').css('height', '100%');
   				//   				}
   				//   				else if (vartest1 > 420) {
   				//   					var diftest = 100 - ((vartest1 - 420) * 0.23);
   				//   					if (diftest > 0) {
   				//   						$('#dragmetoscroll').css('height', diftest + '%');
   				//   					}
   				//   					else {
   				//   						$('#dragmetoscroll').css('height', '72px');
   				//   					}
   				//   				}
   				$('.subg_weight').attr('disabled', true);
   				var img1 = "/images/item_c_icon.png";
   				var img2 = "/images/item_o_icon.png";
   				$(".menu_expand").click(function () {

   					var id = $(this).attr('id').substring(1);
   					var menuBody = $("#menu_body" + id);
   					var imgIcon = $("#img_menu_icon" + id);
   					if ($(imgIcon).attr('src') == img1) {
   						$(".submenu").slideUp("fast");
   						$(".img_menu_icon").attr('src', img1);
   					}
   					$(menuBody).slideToggle("fast", function () {
   						//   						var vartest1 = $('#genreTree').height();

   						//   						if (vartest1 <= 420) {
   						//   							$('#dragmetoscroll').css({ 'height': '100%', 'top': '0' });
   						//   						}
   						//   						else if (vartest1 > 420) {
   						//   							var diftest = 100 - ((vartest1 - 420) * 0.23);
   						//   							if (diftest > 0) {
   						//   								$('#dragmetoscroll').css('height', diftest + '%');
   						//   								if (($('#dragmetoscroll').position().top + $('#dragmetoscroll').height()) > 388) {
   						//   									$('#dragmetoscroll').css('top', (388 - $('#dragmetoscroll').height()));
   						//   								}
   						//   							}
   						//   							else {
   						//   								$('#dragmetoscroll').css('height', '72px');
   						//   							}
   						//   						}
   					});
   					$(imgIcon).attr('src', imgIcon.attr('src') == img1 ? img2 : img1);

   					return true;
   				});
   				$('.subg').click(function () {
   					$('#' + $(this).attr('id') + '_Weight').attr('disabled', !$(this).attr('checked'));
   				});

   			});

   		});
   	}

   	function SelectGenresNewStation() {
   		//   		$('#dragmetoscroll').css({ 'height': '100%', 'top': '0' });
   		$('#genreTree').html($('#pleaseWait').show());
   		popupShow($('#genre_selection').show(), offset.left, offset.top);
   		$.getJSON('/Genre/Names/' + getSelectedStationId(), function (data) {
   			var genreTree = '';
   			var i = data.length;
   			for (var x in data) {

   				if (data[x].SubGenres.length == 0) {
   					genreTree += '<li class="menu_head ' + (x % 2 == 1 ? 'dark' : 'light') + '_gray" ><div class="menu_head_left"><input type="checkbox" style="margin-left:27px;" class="subg" id="' + data[x].Genre_ID + '" isPlaylist="false" name="' + data[x].Genre_ID + '" /> <span style="cursor:default; display:inline-block; height:16px; overflow:hidden; width:110px;" onmouseover="GenreNameScrolling(this);" onmouseout="GenreNameStopScrolling(this);"><span style="position:relative; white-space:nowrap; overflow:visible;"> ' + data[x].Name + ' </span></span></div><div class="menu_head_right_small_line"><div class="level2_rightR"><select class="subg_weight" id="' + data[x].Genre_ID + '_Weight" style="margin-top:5px;" ><option>1</option><option>2</option><option>3</option><option>4</option><option selected>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select></div><div class="level2_rightL"><p class="genreDescription">' + data[x].Description + '</p></div></div><div class="clb"></div></li>';
   				}
   				else {
   					genreTree += '<li class="menu_head ' + (x % 2 == 1 ? 'dark' : 'light') + '_gray" ><div class="menu_head_left"><span class="menu_expand" id="g' + data[x].Genre_ID + '"><img class="img_menu_icon" id="img_menu_icon' + data[x].Genre_ID + '" src="/images/item_c_icon.png" /> </span><input type="checkbox" class="subg" id="' + data[x].Genre_ID + '" isPlaylist="false" name="' + data[x].Genre_ID + '" /> <span style="cursor:default; height:16px; display:inline-block; overflow:hidden; width:110px;" onmouseover="GenreNameScrolling(this);" onmouseout="GenreNameStopScrolling(this);"><span style="position:relative; white-space:nowrap; overflow:visible;"> ' + data[x].Name + ' </span></span></div><div class="menu_head_right_small_line"><div class="level2_rightR"><select class="subg_weight" id="' + data[x].Genre_ID + '_Weight" style="margin-top:5px;" ><option>1</option><option>2</option><option>3</option><option>4</option><option selected>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select></div><div class="level2_rightL"><p class="genreDescription"><span style="overflow:visible; width:200px"><span class="currentGenreDescription">' + data[x].Description + '</span></span></p></div></div><div class="clb"></div></li>';
   					genreTree += ' <li id="menu_body' + data[x].Genre_ID + '" class="submenu"><ul>';
   					//genreTree += '<li class="' + (x % 2 ? 'light' : 'dark') + '_gray"><div class="li_level2"><input type="checkbox" class="subg" id="' + data[x].Genre_ID + '" name="' + data[x].Genre_ID + '" /><span> All ' + data[x].Name + ' </span></div><div class="menu_head_right_small_line"><div class="level2_rightR"><select class="subg_weight" id="' + data[x].Genre_ID + '_Weight" style="margin-top:5px;" ><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option selected>10</option></select></div><div class="level2_rightL"><p class="genreDescription">An equal mix for all Sub Genres Below</p></div></div><div class="clb"></div></li>';
   					for (var y in data[x].SubGenres) {
   						genreTree += '<li class="' + ((parseInt(x) + parseInt(y)) % 2 == 1 ? 'light' : 'dark') + '_gray"><div class="li_level2"><input type="checkbox" style="margin-left:15px;" class="subg" id="' + data[x].SubGenres[y].Genre_ID + '" isPlaylist="false" name="' + data[x].SubGenres[y].Genre_ID + '" /><span style="cursor:default; height:16px; overflow:hidden; width:110px;" onmouseover="GenreNameScrolling(this);" onmouseout="GenreNameStopScrolling(this);"><span style="position:relative; height:16px; white-space:nowrap; overflow:visible;"> ' + data[x].SubGenres[y].Name + ' </span></span></div><div class="menu_head_right_small_line"><div class="level2_rightR"><select class="subg_weight" id="' + data[x].SubGenres[y].Genre_ID + '_Weight" style="margin-top:5px;"><option>1</option><option>2</option><option>3</option><option>4</option><option selected>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select></div><div class="level2_rightL"><p class="genreDescription"><span style="overflow:visible; width:200px"><span class="currentGenreDescription">' + data[x].SubGenres[y].Description + '</span></span></p></div></div><div class="clb"></div></li>';
   					}
   					genreTree += '</ul></li>';
   				}

   				//                var genrewidth = $("#currentGenreDescription" + data[x].Genre_ID).width();
   				//                alert(genrewidth);
   				//                if (genrewidth > 100) {
   				//                    $("#currentGenreDescription" + data[x].Genre_ID).html("<MARQUEE WIDTH=100% scrollamount=1>" + data[x].Description + "</MARQUEE>");
   				//                }

   			}
   			$.getJSON('/User/Playlists/', function (dataPlaylists) {
   				for (var z in dataPlaylists) {
   					genreTree += '<li class="menu_head ' + ((parseInt(z) + i) % 2 == 1 ? 'dark' : 'light') + '_gray" ><div class="menu_head_left"><input type="checkbox" style="margin-left:27px;" class="subg" id="' + dataPlaylists[z].Playlist_ID + '" isPlaylist="true" name="' + dataPlaylists[z].Playlist_ID + '" /> <span style="cursor:default; overflow:hidden; width:110px;" onmouseover="GenreNameScrolling(this);" onmouseout="GenreNameStopScrolling(this);"><span style="position:relative; white-space:nowrap; overflow:visible;"> ' + dataPlaylists[z].Name + ' </span></span></div><div class="menu_head_right_small_line"><div class="level2_rightR"><select class="subg_weight" id="' + dataPlaylists[z].Playlist_ID + '_Weight" style="margin-top:5px;" ><option>1</option><option>2</option><option>3</option><option>4</option><option selected>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option></select></div><div class="level2_rightL"><p class="genreDescription">Playlist</p></div></div><div class="clb"></div></li>';
   				}
   				$('#pleaseWait').hide().appendTo('body');
   				$('#genreTree').html(genreTree);
   				$('.genreDescription').each(function () {

   					$(this).html("<div class='horizontalartist_scrollerx alabala' onmouseover='StartGenreDescriptionScrollText(this);' onmouseout='StopGenreDescriptionScrollText(this);'  style='white-space:nowrap; float: left; height: 17px; cursor: default; position: relative; overflow:hidden;'><div class='scrollingtext' style='position: relative; height: 17px; white-space:nowrap; overflow:visible; '><span style='overflow:visible;'><span>" + $(this).text() + "</span></span></div></div>");
   				});

   				$(".submenu").hide();
   				$('.subg_weight').attr('disabled', true);
   				var img1 = "/images/item_c_icon.png";
   				var img2 = "/images/item_o_icon.png";
   				$(".menu_expand").click(function () {
   					var id = $(this).attr('id').substring(1);
   					var menuBody = $("#menu_body" + id);
   					var imgIcon = $("#img_menu_icon" + id);
   					if ($(imgIcon).attr('src') == img1) {
   						$(".submenu").slideUp("fast");
   						$(".img_menu_icon").attr('src', img1);
   					}
   					$(menuBody).slideToggle("fast", function () {
   						//   						var vartest1 = $('#genreTree').height();

   						//   						if (vartest1 <= 420) {
   						//   							$('#dragmetoscroll').css({ 'height': '100%', 'top': '0' });
   						//   						}
   						//   						else if (vartest1 > 420) {
   						//   							var diftest = 100 - ((vartest1 - 420) * 0.23);
   						//   							if (diftest > 0) {
   						//   								$('#dragmetoscroll').css('height', diftest + '%');
   						//   								if (($('#dragmetoscroll').position().top + $('#dragmetoscroll').height()) > 388) {
   						//   									$('#dragmetoscroll').css('top', (388 - $('#dragmetoscroll').height()));
   						//   								}
   						//   							}
   						//   							else {
   						//   								$('#dragmetoscroll').css('height', '72px');
   						//   							}
   						//   						}
   					});
   					$(imgIcon).attr('src', imgIcon.attr('src') == img1 ? img2 : img1);
   					return true;
   				});
   				$('.subg').click(function () {
   					$('#' + $(this).attr('id') + '_Weight').attr('disabled', !$(this).attr('checked'));
   				});
   				//   				var vartest1 = $('#genreTree').height();

   				//   				if (vartest1 <= 420) {
   				//   					$('#dragmetoscroll').css('height', '100%');
   				//   				}
   				//   				else if (vartest1 > 420) {
   				//   					var diftest = 100 - ((vartest1 - 420) * 0.23);
   				//   					if (diftest > 0) {
   				//   						$('#dragmetoscroll').css('height', diftest + '%');
   				//   					}
   				//   					else {
   				//   						$('#dragmetoscroll').css('height', '72px');
   				//   					}
   				//   				}
   			});
   		});
   	}
   	//-----------------------------------------------------------------------------------------------------
   	function addGenres() {
   		var stationId = getSelectedStationId();
   		var slot = 0;
   		var max = false;
   		AddGenresFlag = 0;
   		$('.subg:checked', '#genreTree').each(function () {
   			if (max) {
   				return false;
   			}
   			slot++;
   			var genreId = $(this).attr('id');
   			var weight = $('#' + genreId + '_Weight').val();
   			var GenraIsPlaylist = $(this).attr('IsPlaylist');
   			AddGenresFlag++;
   			$.getJSON('/Station/NewStationSlider/' + stationId + '?genreId=' + genreId + '&weight=' + weight + '&slot=' + slot + "&IsPlaylist=" + GenraIsPlaylist, function (data) {
   				if (data.Added) {
   					AddGenresFlag--;
   				} else if (!max) {
   					AddGenresFlag = 0;
   					ShowAlert('13 is unlucky! 12 Genres per station is the maximum for Free Users. Try using the EDIT button to switch your least favorite Genre.');
   					max = true;
   				}
   			});
   		});
   		PopulateSliders();
   		popupHide();
   	}
   	//-----------------------------------------------------------------------------------------------------
   	function PopulateSliders() {
   		if (AddGenresFlag == 0) {
   			clearTimeout(AddGenresTimer);

   			getAllSliders(true); //from V.0.3.Player.js
   			$('#PlayStation').hide();
   			$('#PlayPlaylist').hide();
   			$('#playSong').show();
   			if (playerPaused) {
   				$('#nextSong').hide();
   				$('#nextSongDisabled').show();
   			}
   			else {
   				$('#nextSong').show();
   				$('#nextSongDisabled').hide();
   			}
   			if (CurrentPS == -1 || CurrentPS == null) {
   				CurrentPS = $('#myStationsSelect').val();
   				CurrentPSIsPlaylist = false;
   				$.get("/Song/ChangeStation/" + CurrentPS, { 'IsPlaylist': CurrentPSIsPlaylist, 'Skip': true, 'PlayerInstance': PlayerInstance }, function (json) {
   					if (typeof json.ValidInstance != 'undefined' && !json.ValidInstance) {
   						ShowInvalidPlayerInstance();
   						return false;
   					}
   					if (typeof json.Error != 'undefined') {
   						ShowAlert(json.Error);
   					} else {
   						listenToFriendsStream(json.Stream, false);
   					}
   				}, 'json');
   			}
   		}
   		else {
   			AddGenresTimer = setTimeout(PopulateSliders, 1000);
   		}
   	}

   	//-----------------------------------------------------------------------------------------------------
   	$(window).resize(function () {

   		if ($('#dialog-overlay').is(':visible')) {
   			$('#dialog-overlay').hide().css({ height: $(document).height(), width: $(document).width() }).show();
   			offset = $('#tabb').offset();
   			$('#dialog-popup').css({ left: offset.left, top: offset.top }).topZIndex();
   		}
   		if ($('#dialog-overlay2').is(':visible')) {
   			$('#dialog-overlay2').hide().css({ height: $(document).height(), width: $(document).width() }).show();
   			var location = $('#tabb').offset();
   			$('#PopUpWrap').css({ left: location.left, top: location.top }).topZIndex();
   		}
   	});
   	//-----------------------------------------------------------------------------------------------------
   	$('#buttonAdd').live('click', function () {
   		if (IsFree || IsGuest) {
   			ShowBigArtWork();
   		} else {
   			tmpSongId = currentSongId || -1;
   			$('#AddToPlaylistSelect').html('<option value="-1">Loading...</option>');
   			popupShow($('#AddToPlaylistPopup').show(), offset.left, offset.top);
   			$.post("/User/Playlists", function (data) {
   				if (data.length > 0) {
   					$('#AddToPlaylistSelect').html('');
   					for (var i in data) {
   						$('#AddToPlaylistSelect').append('<option value="' + data[i].Playlist_ID + '">' + data[i].Name + '</option>');
   					}
   				} else {
   					$('#AddToPlaylistSelect').html('<option value="-1">No playlist!</option>');
   				}
   				$('#AddToPlaylistSelect').resetSS();
   			}, 'json');
   		}
   	});
   	//-----------------------------------------------------------------------------------------------------



   	$('#AddToPlaylistBtn').click(function () {
   		var tmpPlaylistId = $('#AddToPlaylistSelect').val() || -1;
   		if (tmpPlaylistId != -1 && tmpSongId != -1) {
   			$.post("/Playlist/AddPlaylistSong/" + tmpPlaylistId, { "songId": tmpSongId }, function (data) {
   				if (data) {
   					RenderNewPlaylist();
   					$('#buttonAdd').attr('src', '/images/button_add_yellow.png');
   				}
   			}, 'json');
   		} else {
   			ShowAlert('Invalid song id (' + tmpSongId + ')/playlist id (' + tmpPlaylistId + ')!');
   		}
   		popupHide();
   	});
   	//-----------------------------------------------------------------------------------------------------
   	$('#CloseAddToPlaylistPopup').click(function () {
   		popupHide();
   	});
   	//-----------------------------------------------------------------------------------------------------
   	$('#create_station_btn_span').click(function () {
   		createStationShowPopUp(false);
   	});
   	//-----------------------------------------------------------------------------------------------------
   	$('#newStation').click(function () {
   		if (!IsGuest) {
   			createStationShowPopUp(true);
   		}
   		else {
   			PopupDialog('', '<span>You need an account to access many features or save settings. Would you like to create an account now?</span><br/><br/><input class="green_btnPM pointer" id="guest_yes" type="button" value="YES" style="margin-left:80px;" /><input class="green_btnPM pointer" id="guest_no" type="button" value="NO" style="margin-left:60px;" />', null, null);
   			$('#PopUpOk').hide();
   			$('#guest_no').show().unbind('click').bind('click', function () {
   				closePopUp();
   				//closeFunc();
   			});
   		}

   	});
   	//-----------------------------------------------------------------------------------------------------
   	$('#createStation_close_btn').click(function () {
   		popupHide();
   	});
   	//-----------------------------------------------------------------------------------------------------

   	$('#StationNameText').bind('keypress', function (e) {
   		if ((e.keyCode ? e.keyCode : e.which) == 13)
   			$('#create_station_btn_save').trigger('click');
   	});

   	$('#create_station_btn_save').click(function () {
   		var name = $('#StationNameText').val();
   		if (name.replace(/^\s*|\s*$/g, '') != '') {
   			$.post("/Station/NewUserStation/" + getActiveUserId(), { "name": name }, function (data) {
   				var option = "<option value=" + data.Station.Station_ID + ">" + data.Station.Name + "</option>";
   				$("select#myStationsSelect").append(option);
   				$("select#myStationsSelect").val(data.Station.Station_ID); //set as selected value
   				$('#playSong').hide();
   				$('#PlayPlaylist').hide();
   				$('#PlayStation').show();
   				$('#nextSong').hide();
   				$('#nextSongDisabled').show();
   				//   				$('#equalizer').empty();
   				$('#station_sortable_list').empty();
   				//$('#PlayStation').show();
   				//$('#PlayStationDisabled').hide();
   				$('#StationNameText').val('');
   				if (data.rookie) {
   					$('#genre_selection').css('height', '645px');
   					$('#genrePopupToChange').css({ 'height': '554px', 'background-image': 'url(/images/popup_body1.png)' });
   					$('#genrequoteVar').html("Choose your favorite music Genres, up to 12 at a time for Free Users. Assign each one a Value of 1(like it) to 10(love it!). Master Genres include an even blend of all Sub-Genres, or chose specific Sub-Genres for maximum control. And DON'T WORRY you can change your Genres and Values easily at any time!");
   				}
   				else {
   					$('#genre_selection').css('height', '620px');
   					$('#genrePopupToChange').css({ 'height': '529px', 'background-image': 'url(/images/popup_body.png)' });
   					$('#genrequoteVar').html("The ADD function will add a new slider with the GENRE of your choosing below to the bottom of your actual STATION.");
   				}
   				IsNewUser = false;
   				popupHide();
   				PopupDialog('Add sliders to your station by ...', '<input class="green_btnPM pointer" id="AddByArtist" type="button" value="Artist" style="margin-left:80px;" /><input class="green_btnPM pointer" id="AddByGenres" type="button" value="Genres" style="margin-left:60px;" />', null, null);
   				$('#PopUpOk').hide();

   			}, 'json');
   		}
   		else {
   			$('#StationNameText').val('Invalid station name!');
   		}
   	});
   	//-----------------------------------------------------------------------------------------------------
   	$('#AddByArtist').live('click', function () {
   		closePopUp();
   		var offset = $('#tabb').offset();
   		$('#AddBtnPlace').hide();
   		IsSearchingArtist = false;
   		popupShow($('#ArtistPopUp').show(), offset.left, offset.top);
   	});
   	//-----------------------------------------------------------------------------------------------------
   	$('li', '#ArtistUl').live('click', function () {
   		var aid = $(this).attr('aid');
   		if (aid != '') {
   			$('#TxtArtistName').val($(this).html());
   			$('#TxtArtistName').attr('aid', aid);
   			$('#ArtistUl').html('');
   			$('#AddBtnPlace').show();
   		}
   	});
   	//-----------------------------------------------------------------------------------------------------
   	$('#TxtArtistName').bind('keyup', function (event) {
   		var keycode = (event.which ? event.which : event.keyCode);
   		if (keycode == 8 || keycode == 13 || keycode == 46 || keycode == 32 || (keycode >= 48 && keycode <= 57) || (keycode >= 65 && keycode <= 90) || (keycode >= 96 && keycode <= 111) || (keycode >= 186 && keycode <= 222)) {
   			SearchArtist();
   		}
   	});

   	///----------- Playlist Artist Search Dropdown---------------------------------------------------------
   	$('li', '#PlaylistArtistUl').live('click', function () {
   		$('#Text1').val($(this).html());
   		$('#Text1').focus();
   		$('#PlaylistArtistUl').html('');
   		$('#PlaylistArtistUl').hide();
   		return false;
   	});


   	$('#Text1').bind('keyup', function (event) {
   		$('#PlaylistSongUl').hide();
   		var keycode = (event.which ? event.which : event.keyCode);
   		if (keycode == 8 || keycode == 46 || keycode == 32 || (keycode >= 48 && keycode <= 57) || (keycode >= 65 && keycode <= 90) || (keycode >= 96 && keycode <= 111) || (keycode >= 186 && keycode <= 222)) {
   			PlaylistSearchArtist();
   		} else if (keycode == 38) {

   			if (ulindex > 0) {
   				ulindex--;
   			}

   			$('li', '#PlaylistArtistUl').each(function () {
   				$('li', '#PlaylistArtistUl').removeClass('selected');
   			});
   			$('li.pos_' + ulindex).addClass('selected');
   			//$('li.pos_' + ulindex).css('color', 'red');
   			$('#Text1').val($('li.pos_' + ulindex).html());
   			return false;
   		} else if (keycode == 40) {

   			if (ulindex <= 8) {
   				ulindex++;
   			}

   			$('li', '#PlaylistArtistUl').each(function () {
   				$('li', '#PlaylistArtistUl').removeClass('selected');
   			});
   			$('li.pos_' + ulindex).addClass('selected');
   			$('#Text1').val($('li.pos_' + ulindex).html());
   			return false;
   		} else {
   			$('#PlaylistArtistUl').html('');
   			$('#PlaylistArtistUl').hide();
   		}
   	});

   	function PlaylistSearchArtist() {
   		if ($('#Text1').val().length > 0) {
   			if (PlaylistIsSearchingArtist) {
   				ArtistModified = true;
   			} else {
   				PlaylistIsSearchingArtist = true;
   				ArtistModified = false;
   				$.get('/Playlist/PlaylistSelectArtist', { 'ArtistName': $('#Text1').val() }, function (data) {
   					PlaylistIsSearchingArtist = false;
   					if (ArtistModified) {
   						PlaylistSearchArtist();
   					}
   					var cnt = 0;
   					var firstName = null;
   					var selectedName = null;
   					var lis = '';
   					for (var name in data.Artists) {
   						$('#PlaylistArtistUl').show();
   						if (cnt == 0) {
   							firstName = name;
   						}
   						if (data.Artists[name] == $('#Text1').val()) {
   							selectedName = name;
   							lis += '<li class="selected">' + data.Artists[name] + '</li>';
   						} else {
   							lis += '<li class="pos_' + name + '">' + data.Artists[name] + '</li>';
   						}
   						cnt++;
   					}
   					if (cnt == 0) {
   						lis = '<li class="selected">No data found!</li>';
   					}
   					$('#PlaylistArtistUl').html(lis);
   				}, 'json');
   			}
   		}
   	}

   	///----------- Playlist Song Search Dropdown-----------------------------------------------------------

   	$('li', '#PlaylistSongUl').live('click', function () {

   		$('#Text2').val($(this).html());
   		$('#Text2').focus();
   		$('#PlaylistSongUl').html('');
   		$('#PlaylistSongUl').hide();
   		return false;

   	});

   	$('#Text2').bind('keyup', function (event) {
   		$('#PlaylistArtistUl').hide();
   		var keycode = (event.which ? event.which : event.keyCode);
   		if (keycode == 8 || keycode == 13 || keycode == 46 || keycode == 32 || (keycode >= 48 && keycode <= 57) || (keycode >= 65 && keycode <= 90) || (keycode >= 96 && keycode <= 111) || (keycode >= 186 && keycode <= 222)) {
   			PlaylistSearchSong();
   		}
   		else if (keycode == 38) {
   			if (ulllindex > 0) {
   				ulllindex--;
   			}
   			$('li', '#PlaylistSongUl').each(function () {
   				$('li', '#PlaylistSongUl').removeClass('selected');
   			});
   			$('li.poss_' + ulllindex).addClass('selected');

   			$('#Text2').val($('li.poss_' + ulllindex).html());
   			return false;
   		}
   		else if (keycode == 40) {
   			if (ulllindex <= 8) {
   				ulllindex++;
   			}

   			$('li', '#PlaylistSongUl').each(function () {
   				$('li', '#PlaylistSongUl').removeClass('selected');
   			});
   			$('li.poss_' + ulllindex).addClass('selected');
   			$('#Text2').val($('li.poss_' + ulllindex).html());
   			return false;

   		}
   		else {
   			$('#PlaylistSongUl').html('');
   			$('#PlaylistSongUl').hide();
   		}
   	});

   	function PlaylistSearchSong() {
   		if ($('#Text2').val().length > 0) {
   			if (PlaylistIsSearchingSong) {
   				SongModified = true;
   			} else {
   				PlaylistIsSearchingSong = true;
   				SongModified = false;
   				$.get('/Playlist/PlaylistSelectSong', { 'SongName': $('#Text2').val() }, function (data) {
   					PlaylistIsSearchingSong = false;
   					if (SongModified) {
   						PlaylistSearchArtist();
   					}
   					var cnt = 0;
   					var firstName = null;
   					var selectedName = null;
   					var lis = '';
   					for (var name in data.SongNames) {
   						$('#PlaylistSongUl').show();
   						if (cnt == 0) {
   							firstName = name;
   						}
   						if (data.SongNames[name] == $('#Text1').val()) {
   							selectedName = name;
   							lis += '<li class="selected">' + data.SongNames[name] + '</li>';
   						} else {
   							lis += '<li class="poss_' + name + '">' + data.SongNames[name] + '</li>';
   						}
   						cnt++;
   					}
   					if (cnt == 0) {
   						lis = '<li class="selected">No data found!</li>';
   					}
   					$('#PlaylistSongUl').html(lis);
   				}, 'json');
   			}
   		}
   	}
   	///----------------------------------------------------------------------------------------------------

   	//-----------------------------------------------------------------------------------------------------
   	$('#BtnAddSliders').click(function () {
   		var aid = parseInt($('#TxtArtistName').attr('aid'));
   		var ssid = parseInt($('#myStationsSelect').val());
   		popupHide();
   		if (aid != NaN && ssid != NaN) {
   			$.post('/Station/' + ssid + '/AddSlidersByArtist/' + aid, null, function (data) {
   				currentStationSliders = data.length;
   				if (data.length) {
   					//   					$('#equalizer').empty();
   					$('#station_sortable_list').empty();
   					maxSlot = 0;
   					var singleSliderItemMarkup = "";
   					var sliderListHTML = "";
   					for (var i = 0; i < data.length; i++) {
   						singleSliderItemMarkup = sliderItemMarkup;
   						singleSliderItemMarkup = singleSliderItemMarkup.replace(/GenreID/g, data[i].GenreId).replace(/IsPlaylist/g, 'false');
   						singleSliderItemMarkup = singleSliderItemMarkup.replace(/GenreName/g, data[i].GenreName);
   						singleSliderItemMarkup = singleSliderItemMarkup.replace(/Slider_ID/g, data[i].Slider_ID);
   						singleSliderItemMarkup = singleSliderItemMarkup.replace(/Slider_Value/g, data[i].Weight);
   						singleSliderItemMarkup = singleSliderItemMarkup.replace(/Slider_LED/g, getSliderLEDImg(currentGenreId == data[i].GenreId ? 1 : (data[i].Weight > 0 ? 0 : -1)));

   						if (maxSlot < data[i].Slot) maxSlot = data[i].Slot;
   						sliderListHTML += singleSliderItemMarkup;
   					}
   					//sliderListHTML = '<aside id="equalizer">' + sliderListHTML + '</aside>';
   					//   					$(sliderListHTML).appendTo('#equalizer');
   					$(sliderListHTML).appendTo('#station_sortable_list');
   					// init sliders
   					slider_onMove = function (genreid, value, IsPlaylist) {
   						if (sliderUpdateTimer != null) window.clearTimeout(sliderUpdateTimer);
   						sliderUpdateTimer = window.setTimeout("updateSlider(" + genreid + "," + value + "," + IsPlaylist + ")", 1000);
   						setPreviewButton(1);
   					}
   					carpeInit();
   					//carpeAddLoadEvent(carpeInit);
   					//$('#PlayPlaylist').show();
   					//$('#PlayPlaylistDisabled').hide();
   					$('#PlayStation').hide();
   					$('#PlayPlaylist').hide();
   					$('#playSong').show();
   					if (playerPaused) {
   						$('#nextSong').hide();
   						$('#nextSongDisabled').show();
   					}
   					else {
   						$('#nextSong').show();
   						$('#nextSongDisabled').hide();
   					}
   					//$('#PlayStationDisabled').show();
   					CurrentPS = $('#myStationsSelect').val();
   					CurrentPSIsPlaylist = false;
   					$.get("/Song/ChangeStation/" + CurrentPS, { 'IsPlaylist': CurrentPSIsPlaylist, 'Skip': true, 'PlayerInstance': PlayerInstance }, function (json) {
   						if (typeof json.ValidInstance != 'undefined' && !json.ValidInstance) {
   							ShowInvalidPlayerInstance();
   							return false;
   						}
   						if (typeof json.Error != 'undefined') {
   							ShowAlert(json.Error);
   						} else {
   							listenToFriendsStream(json.Stream, false);
   						}
   					}, 'json');
   				}

   			}, 'json');

   		}
   	});
   	//-----------------------------------------------------------------------------------------------------
   	function SearchArtist() {
   		$('#AddBtnPlace').hide();
   		if ($('#TxtArtistName').val().length > 0) {
   			if (IsSearchingArtist) {
   				modified = true;
   			} else {
   				IsSearchingArtist = true;
   				modified = false;
   				$.get('/Station/SelectArtist', { 'ArtistName': $('#TxtArtistName').val() }, function (data) {
   					IsSearchingArtist = false;
   					if (modified) {
   						SearchArtist();
   					}
   					var cnt = 0;
   					var fisrtName = null;
   					var selectedName = null;
   					var lis = '';
   					for (var name in data) {
   						if (cnt == 0) {
   							fisrtName = name;
   						}
   						if (data[name] == $('#TxtArtistName').attr('aid')) {
   							selectedName = name;
   							lis += '<li class="selected" aid="' + data[name] + '">' + name + '</li>';
   						} else {
   							lis += '<li aid="' + data[name] + '">' + name + '</li>';
   						}
   						cnt++;
   					}
   					if (cnt == 0) {
   						lis = '<li aid="" class="selected">No data found!</li>';
   					} //else if (cnt == 1) {
   					//	$('#TxtArtistName').attr('aid', data[fisrtName]);
   					//	$('#TxtArtistName').val(fisrtName);
   					//	$('#AddBtnPlace').show();
   					//	lis = '';
   					//}
   					$('#ArtistUl').html(lis);
   				}, 'json');
   			}
   		}
   	}
   	//-----------------------------------------------------------------------------------------------------

   	//-----------------------------------------------------------------------------------------------------
   	$('#AddByGenres').live('click', function () {
   		closePopUp();
   		SelectGenresNewStation();
   		//SelectGenres();
   	});
   	//-----------------------------------------------------------------------------------------------------
   	$('#addGenres').click(function () {
   		addGenres();
   	});
   	//-----------------------------------------------------------------------------------------------------
   	$('#add_genre_btn').click(function () {
   		if (getSelectedStationId() != -1) {
   			if (currentStationSliders == 0) {
   				SelectGenresNewStation();
   			}
   			else if (currentStationSliders < 12) {
   				SelectGenres();
   			}
   			else {
   				ShowAlert('13 is unlucky! 12 Genres per station is the maximum for Free Users. Try using the EDIT button to switch your least favorite Genre.');
   			}
   		}
   		else {
   			createStationShowPopUp(true);
   		}
   	});
   	//-----------------------------------------------------------------------------------------------------
   	$('#close_btn').click(function () {
   		popupHide();
   	});
   	//-----------------------------------------------------------------------------------------------------
   	$('#CloseSwap').click(function () {
   		popupHide();
   	});
   	//-------------------------------------- IF NOT LOGGED IN ---------------------------------------------------------------

   	$('.inputs_login').bind('keypress', function (e) {
   		if ((e.keyCode ? e.keyCode : e.which) == 13)
   			$('#tryLogin').trigger('click');
   	});

   	if ($('#login_box').exists()) {
   		$('.login_btn').click(function () {
   			popupShow($('#login').show(), offset.left, offset.top);
   		});



   		$('#tryLogin').click(function () {
   			LogIn($("#loginForm").serialize());
   		});

   		$('#ResetCaptcha').click(function () {
   			resetCaptcha();
   		});

   		$("#createAccountForm").ajaxForm({
   			iframe: "true",
   			type: 'POST',
   			dataType: 'json',
   			beforeSubmit: function () {
   				$("#createAccountForm").css({ opacity: 0.2 });
   				$('input[type=submit]', "#createAccountForm").attr('disabled', 'disabled');
   			},
   			success: function (response) {
   				$("#createAccountForm").css({ opacity: 1 });
   				$('input[type=submit]', "#createAccountForm").removeAttr('disabled');
   				var errors = {
   					1: { 'message': 'Invalid User Name', 'id': 'UserNameError' },
   					2: { 'message': 'Invalid Password', 'id': 'PasswordError' },
   					3: { 'message': 'Invalid Question', 'id': 'errorMessage' },
   					4: { 'message': 'Invalid Answer', 'id': 'errorMessage' },
   					5: { 'message': 'Invalid e-mail', 'id': 'EmailError' },
   					6: { 'message': 'Username already exists', 'id': 'EmailError' },
   					7: { 'message': 'E-mail already exists', 'id': 'EmailError' },
   					8: { 'message': 'User Rejected', 'id': 'errorMessage' },
   					9: { 'message': 'Invalid Provider User Key', 'id': 'errorMessage' },
   					10: { 'message': 'Duplicate Provider User Key', 'id': 'errorMessage' },
   					11: { 'message': 'Provider Error', 'id': 'errorMessage' },
   					12: { 'message': 'Invalid zip code', 'id': 'ZipCodeError' },
   					13: { 'message': 'Invalid Birth date', 'id': 'BirthDateError' },
   					14: { 'message': 'Passwords do not match', 'id': 'PasswordError' },
   					15: { 'message': 'Password required', 'id': 'PasswordError' },
   					16: { 'message': 'E-mail required', 'id': 'EmailError' },
   					17: { 'message': 'Last name required', 'id': 'LastNameError' },
   					18: { 'message': 'First name required', 'id': 'FirstNameError' },
   					19: { 'message': 'Accept terms and conditions', 'id': 'termsUseError' },
   					20: { 'message': 'Invalid check string', 'id': 'invalidCaptcha' },
   					21: { 'message': 'Email already exists', 'id': 'EmailError' },
   					22: { 'message': 'Password must be at least 6 characters long', 'id': 'PasswordError' },
   					23: { 'message': 'User Name required', 'id': 'UserNameError' },
   					24: { 'message': 'DNN error!', 'id': 'errorMessage' },
   					25: { 'message': 'Invalid invitation code!', 'id': 'InvitationCodeError' }
   				};
   				for (key in errors) {
   					$('#' + errors[key].id).hide();
   				}
   				if ($.isArray(response)) {
   					if (response.length == 0) {
   						popupHide();
   						//popupShow($('#account_created').show(), offset.left, offset.top);
   						//						$("#account_created").dialog({
   						//							modal: true,
   						//							position: 'center',
   						//							close: function () { popupShow($('#login_box').show(), offset.left, offset.top); }
   						//						});
   						PopupDialog('', '<div class="middle" ><label> Your account was created successfully.</label><label> A message was sent to your e-mail address.</label><label> Please check your Inbox (or Junk or Spam) and confirm your account to begin using Radical.</label></div>', function () { popupShow($('#login_box').show(), offset.left, offset.top); }, function () { popupShow($('#login_box').show(), offset.left, offset.top); });
   					}
   					else {
   						resetCaptcha();
   						$.each(response, function () {
   							if (errors[this] != null) {
   								$('#' + errors[this].id).html(errors[this].message).show();
   							}
   							else {
   								$('#errorMessage').html('Unknown error! (' + this + ')').show();
   							}
   						});
   					}
   				} else {
   					resetCaptcha();
   					$('#errorMessage').html('Unknown error!').show();
   				}
   			}
   		});

   		offset = $('#tabb').offset();


   		//		popupShow($('#login_box').show(), offset.left, offset.top);



   		$('.create_acc_btn').click(function () {
   			resetCaptcha();
   			popupShow($('#create_acc_box').show(), offset.left, offset.top);
   		});

   		$('#ForgotPassword').click(function () {
   			popupShow($('#ForgotPassPopup').show(), offset.left, offset.top);
   		});

   		$('#sign_in').click(function () {
   			popupHide();

   		});
   	}
   	else {
   		if ($('#volume').exists()) {
   			//   			$('#LogOutButton').show();
   			//   			$('#LogOutButton').click(LogOut);
   		}
   	}
   	//-------------------------------------- ENDIF NOT LOGGED IN ---------------------------------------------------------------
   });



  

//-----------------------------------------------------------------------------------------------------
function popupHide() {
	$('#dialog-overlay').hide().css({ "z-index": 0 });
	$('#dialog-popup').children().hide().appendTo('body');
	$('#dialog-popup').hide().css({ "z-index": 0 });
}
//-----------------------------------------------------------------------------------------------------
function popupShow(h, l, t) {
	popupHide();
	$('#dialog-overlay').css({ height: $(document).height(), width: $(document).width() }).topZIndex().show();
	$('#dialog-popup').append(h).css({ left: l, top: t }).topZIndex().show();
	$(window).resize();
}
//-----------------------------------------------------------------------------------------------------
function LogOut() {
	$('body').html('Logging out...');
	$.ajax({
		url: '/dnn/AjaxMembership.asmx/LogOut',
		type: 'POST',
		cache: false,
		success: function (xml) {
			window.location.href = "/Account/LogOff?PlayerInstance=" + PlayerInstance;
		},
		error: function () {
			window.location.href = "/Account/LogOff?PlayerInstance=" + PlayerInstance;
		}
	});
};
//-----------------------------------------------------------------------------------------------------
function resetCaptcha() {
	$("#captchaImage").attr('src', '/Images/cloading.gif');
	var d = new Date();
	$("#captchaImage").attr("src", "/Captcha/Show?" + d.getTime());
	$('#CaptchaValue').val('');
}
//-----------------------------------------------------------------------------------------------------
function ShowInvalidPlayerInstance() {
	playerPaused = true;
	setPlayPauseButton();
	player.sendEvent("STOP");
	PopupDialog("Error:", "You can only open your Player from one location at a time!<br/><br/> <h2 style='font-weight:bold;' >Do you want to reload the page to reconnect?</h2>", function () { window.location.reload(); }, function () { window.location = '/dnn/FAQ.aspx'; })
}

