$(function() {
	
	
	   PEPS.rollover.init();
	
	var windowSizeArray = [ "width=800,height=460", "width=800,height=400,scrollbars=no" ];
	
	$('.ExternalPlayer').click(function (event){

	                    var url = $(this).attr("href");
	                    var windowName = "popUp";
	                    var windowSize = windowSizeArray[$(this).attr("rel")];

	                    window.open(url, windowName, windowSize);
						$('#ThePlayerDivHolder').html('<br />');

	                    event.preventDefault();

	                });
	
	
	
    $('#slideshow').cycle({
    	speed:  '3000', 
    	timeout: 7000,
        pager:      '#nav',
        pagerEvent: 'click',
    	next:   '#next2', 
    	prev:   '#prev2', 
        cleartype: true,
        cleartypeNoBg: true
    });



	
     	 $('#NKCDCsubscribeform').ajaxForm(function(data) {
			$('#NKCDCsubscribeform').html('');
			$('#NKCDCsubscribeform').html(data);
        	});
	
	
     	 $('#NKCDCvolunteerform').ajaxForm(function(data) {
			$('#NKCDCvolunteerform').html('');
			$('#NKCDCvolunteerform').html(data);
        	});


     	 $('#pegorder').ajaxForm(function(data) {
	
			if (data == 1) {
				
				window.location='/customer-portal';
				
			} else {
				
				alert('ERROR: ' + data);
			}
			
        	});
	

	$( "#accordion" ).accordion({
		autoHeight: false,
		fillSpace: true
	});
	
	$( "#accordionshared" ).accordion({
		autoHeight: false,
		fillSpace: true
	});
	
	SetupContactForms();
	ValidatorSetup();
	
	JButtons();
	RunTheLogin();	
	CreateAccountSetup();
	
	NewListNamer();
	
	TheTrackButtons();
	
	FancyBoxes();
	
	SetupClickSortFilesLongLi(0);
	
	LoadTheLikeButton();
	
	RunIForgot();
  
	
	if ((GetPageName()) == 'u-playlists') {
		SetupJScrollStyler();
		
		FixUpAdminWindows();
			
		$(window).resize(function() {
			SetupJScrollStyler();
			
			FixUpAdminWindows();
		
			});
	}	
		  
	
	if ((GetPageName()) == 'u-photos') {
		
		FixUpAdminWindows();
			
		$(window).resize(function() {
			FixUpAdminWindows();
		
			});
	}
	
	if ((GetPageName()) == 'downloadz') {
		
		FixUpAdminWindows();
			
		$(window).resize(function() {
		    // do something here
			FixUpAdminWindows();
		
			});
	}	
	
	if ((GetPageName()) == 'mycontacts') {
		
		
		FixUpAdminWindows();
			
		$(window).resize(function() {
			FixUpAdminWindows();
		
			});
		
	}
	
		$(window).scroll(function () { 
	      $("#ModalDiv").dialog("option","position",['right',0]);
		  $("#AppearanceModalDiv").dialog("option","position",['right',0]);

	    });
			$("#AdminNoScroll").css("height", ($(window).height() - 95) + "px");

			
			$('#SiteDesigner')
				.click(function() {

					SiteDesignerFunk();
					return false;
				});
			
			$('#CloseMobileFilePlayer')
				.click(function() {

					$('#MobileFilePlayerHolder').hide("slide", { direction: "horizontal" }, 1000);
					
					
					return false;
				});

				$('.pegorderaction')
					.click(function() {
												
						window.location=this.id;
						
						return false;
					});			
			
		
	//$('#PrevImgThumbDivToScroll').jScrollPane();
	
	//$("select, input[type=checkbox]").uniform();
	
						


		var name = $("#name"),
			email = $("#email"),
			password = $("#password"),
			AlbumName = $("#AlbumName"),
			excerpt = $("#excerpt"),
			allFields = $([]).add(name).add(email).add(password),
			tips = $("#validateTips");


SelectAllContacts();

// Toggle divs as needed

	$('#UploadButton').click(function(){ 
     	   $('#settings-upload').show(); 
	       $('#settings-widgets').hide(); 
	       $('#settings-options').hide(); 
     	   $('#settings-delete').hide(); 

	}); 

	$('#SettingsButton').click(function(){ 
     	   $('#settings-options').show();
     	   $('#settings-upload').hide();  
	       $('#settings-widgets').hide(); 
     	   $('#settings-delete').hide(); 

	}); 

	$('#WidgetButton').click(function(){ 
     	   $('#settings-widgets').show(); 
     	   $('#settings-upload').hide();  
	       $('#settings-options').hide(); 
     	   $('#settings-delete').hide(); 
	}); 

	$('#DeleteButton').click(function(){ 
     	   $('#settings-delete').show(); 
	       $('#settings-widgets').hide(); 
     	   $('#settings-upload').hide();  
	       $('#settings-options').hide(); 
	}); 



	$('#AccessAccount').click(function(){ 
	 	  	window.location=(GetSiteRoot())+'/account/';
	});

	$('#NewsletterPrefsLink').click(function(){ 
     	   $('#NewsletterPrefs').show(); 

	}); 
	
	
	$('.AddToCart').click(function(){ 
		
		var TheClickedEntryID = this.id;
				
		$.post("/codebase/cart/", { ID: TheClickedEntryID  }, function(newdata){

			LaunchCart();
			
		 });
		
	});
	
	$('#choosenewdevice')
		.click(function() {
			
			$('.tecspot-computers-mobile').css('display', 'block');
			$('.tecspot-devices-mobile').css('display', 'block');
			$('.tecspot-computers-mobile').css('float', 'left');
			$('.tecspot-devices-mobile').css('float', 'left');
			$('.tecspotcheckboxD').removeAttr('checked');			
			$('#choosenewdevice').css('display', 'none');
			
				return false;
		});
	
	
	$('.tecspot-devices-mobile')
		.click(function() {
			var TheClickedEntryID = this.id;
			
			$('#UPL1NKContactFormWrap').css('display', 'block');
			$('.devices-mobile-labels').css('display', 'block');
			
			$('#choosenewdevice').css('display', 'block');
			
			$('.tecspot-computers-mobile').css('display', 'none');
			$('.tecspot-devices-mobile').css('display', 'none');
			$('#' + TheClickedEntryID).css('display', 'block');
			
			var RawProdID = TheClickedEntryID.replace('tecspot-devices-', '');
			
			$('#Device-' + RawProdID).attr('checked','checked')			
									
				return false;
		});
		

	$('.tecspot-computers-mobile')
		.click(function() {
			var TheClickedEntryID = this.id;

			$('#UPL1NKContactFormWrap').css('display', 'block');
			$('.devices-comp-labels').css('display', 'block');
			
			$('#choosenewdevice').css('display', 'block');
			
			$('.tecspot-computers-mobile').css('display', 'none');
			$('.tecspot-devices-mobile').css('display', 'none');
			$('#' + TheClickedEntryID).css('display', 'block');
			
			var RawProdID = TheClickedEntryID.replace('tecspot-computers-', '');
			
			$('#Device-' + RawProdID).attr('checked','checked')			
			
				return false;
		});		
	
	$('.ListLoader')
		.click(function() {

			var TheClickedEntryID = this.id;
			
			ListLoaderFunk(TheClickedEntryID);

				return false;
		});		
	
	$('.ScrollSliderDiv')
		.click(function() {
			
				var WhichWay = this.id;

				ScrollSliderDiv(WhichWay);

				return false;
		});	
		


		GoGetTheFile();


	
		$( "#searchcontactsval" ).autocomplete({
			source: "/codebase/contact/ajaxcontactsearch.asp",
			minLength: 2
		});

		

		$('.HistoryMore')
			.click(function() {

					var WhichTrackIDRaw = this.id;
					
					var WhichTrackID = WhichTrackIDRaw.replace('buttonmore_', '');

					
					SwapHistoryFile(WhichTrackID);

					return false;
			});


		


	$('#PlaylistSource').change(function(){ 
    	if ($(this).val() == '5') 
		{
     	   $('#dtserverinfodiv').show(); 
	        $('#directoryurlinfodiv').hide(); 

		}
	    else if ($(this).val() == '15') 
		{
     	   $('#directoryurlinfodiv').show(); 
	        $('#dtserverinfodiv').hide(); 

		}
	    else if ($(this).val() == '6') 
		{
     	   $('#directoryurlinfodiv').show(); 
	        $('#dtserverinfodiv').hide(); 

		}
	    else if ($(this).val() == '17') 
		{
     	   $('#directoryurlinfodiv').show(); 
	        $('#dtserverinfodiv').hide(); 

		}
	    else 
		{
	        $('#directoryurlinfodiv').hide(); 
	        $('#dtserverinfodiv').hide(); 
		}
	}); 


	$('#PlaylistSelector').change(function(){ 
            window.location=$(this).val();
	});


	

	$(".PriceShower").fancybox({
		'modal' : true,
		'width' : '800',
		'scrolling' : 'no',
		'padding' : '15'
	});
  
	
	
	$('#topnavlink').click(function(){ 
     	   $('#topnav').toggle('blind'); 
		
			return false;
	});
	
	
	$('#topnav-account-toggle').hover(function(){ 
     	   $('#topnav-account').toggle('blind'); 
		
			return false;
	});
	
	$('#topnav-tools-toggle').hover(function(){ 
     	   $('#topnav-tools').toggle('blind'); 
		
			return false;
	});
	
	
	$('#topnav-page-toggle').hover(function(){ 
     	   $('#topnav-page').toggle('blind'); 
		
			return false;
	});
	
	var timeout    = 500;
	var closetimer = 0;
	var ddmenuitem = 0;

	function topnavlinks_open()
	{  topnavlinks_canceltimer();
	   topnavlinks_close();
	   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

	function topnavlinks_close()
	{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

	function topnavlinks_timer()
	{  closetimer = window.setTimeout(topnavlinks_close, timeout);}

	function topnavlinks_canceltimer()
	{  if(closetimer)
	   {  window.clearTimeout(closetimer);
	      closetimer = null;}}





 	   $('#topnavlinks > li').bind('mouseover', topnavlinks_open);
	   $('#topnavlinks > li').bind('mouseout',  topnavlinks_timer);
	
	
	if ((GetUserName()) == "trinityframing" || (GetUserName()) == "nkcdc" || (GetUserName()) == "pegbandwidth" || (GetUserName()) == "tashan" || (GetUserName()) == "worshiprecs") {
		
		
		function usernavlinks_open()
		{  usernavlinks_canceltimer();
		   usernavlinks_close();
		   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

		function usernavlinks_close()
		{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

		function usernavlinks_timer()
		{  closetimer = window.setTimeout(usernavlinks_close, timeout);}

		function usernavlinks_canceltimer()
		{  if(closetimer)
		   {  window.clearTimeout(closetimer);
		      closetimer = null;}}

	 	   $('#usernav > li').bind('mouseover', usernavlinks_open);
		   $('#usernav > li').bind('mouseout',  usernavlinks_timer);
		
	}
	
	

	document.onclick = topnavlinks_close;		
			
			
		
	$("#AppearanceModalDiv").dialog({
		autoOpen: false,
		height: ($(window).height() - 20),
		width: 710,
        title:"APPEARANCE",
        show:"blind",
        hide: "blind",
        position: ['right',0],
		modal: true,
		resizable: false,
		draggable: false,
        open: function() {
		
        },
        beforeclose:
               function(){
					if ($('#MCEcontentID').length != 0) {
                   tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID');
					}
					if ($('#MCEcontentID2').length != 0) {
				tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID2');
					}
					if ($('#MCEcontentID3').length != 0) {
				tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID3');
					}
					if ($('#MCEcontentID4').length != 0) {
				tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID4');
					}
					if ($('#MCEcontentID5').length != 0) {
				tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID5');
					}
					if ($('#MCEcontentID6').length != 0) {
				tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID6');
					}
					if ($('#MCEcontentID7').length != 0) {
				tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID7');
					}
            },
		buttons: {
			'SAVE': function() {
				if ($('#MCEcontentID').length != 0) {
					var OriginalContent1 = tinyMCE.get('MCEcontentID').getContent();
					$('#MCEcontentID').val(OriginalContent1);
				}
			
				if ($('#MCEcontentID2').length != 0) {
					var OriginalContent2 = tinyMCE.get('MCEcontentID2').getContent();
					$('#MCEcontentID2').val(OriginalContent2);
				  }
				
				if ($('#MCEcontentID3').length != 0) {
					var OriginalContent3 = tinyMCE.get('MCEcontentID3').getContent();
					$('#MCEcontentID3').val(OriginalContent3);
				  }
				
				if ($('#MCEcontentID4').length != 0) {
					var OriginalContent4 = tinyMCE.get('MCEcontentID4').getContent();
					$('#MCEcontentID4').val(OriginalContent4);
				  }
				
				if ($('#MCEcontentID5').length != 0) {
					var OriginalContent5 = tinyMCE.get('MCEcontentID5').getContent();
					$('#MCEcontentID5').val(OriginalContent5);
				  }
				
				if ($('#MCEcontentID6').length != 0) {
					var OriginalContent6 = tinyMCE.get('MCEcontentID6').getContent();
					$('#MCEcontentID6').val(OriginalContent6);
				  }
				
				if ($('#MCEcontentID7').length != 0) {
					var OriginalContent7 = tinyMCE.get('MCEcontentID7').getContent();
					$('#MCEcontentID7').val(OriginalContent7);
				  }
				
				$('#AjaxForm').ajaxSubmit(function(formdata) {
					$('#AppearanceModalDiv').html('<div class="loaderanim8"></div>');
			    	if (formdata==1){
						$(this).dialog('close');
						location.reload();
			    	}
			    	else {
						alert('sorry: ' + formdata);
			    	}
				});
    	      
			},
			CANCEL: function() {
				$(this).dialog('close');
			}	
		}
	});	
			
			
			
			
			
		var ModalDivWidth = "";	
			
		if ((GetPlayerType()) == 1) {
			ModalDivWidth = '100%';
		} else {
			ModalDivWidth = 710;
		}	
			
			
			
		$("#ModalDiv").dialog({
			autoOpen: false,
			height: ($(window).height() - 20),
			width: ModalDivWidth,
            title:"EDIT",
            show:"blind",
            hide: "blind",
            position: ['right',0],
			modal: true,
			resizable: false,
			draggable: false,
            open: function() {
			
            },
            beforeclose:
                function(){
						if ($('#MCEcontentID').length != 0) {
                    tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID');
						}
						if ($('#MCEcontentID2').length != 0) {
					tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID2');
						}
						if ($('#MCEcontentID3').length != 0) {
					tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID3');
						}
						if ($('#MCEcontentID4').length != 0) {
					tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID4');
						}
						if ($('#MCEcontentID5').length != 0) {
					tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID5');
						}
						if ($('#MCEcontentID6').length != 0) {
					tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID6');
						}
						if ($('#MCEcontentID7').length != 0) {
					tinyMCE.execCommand('mceRemoveControl',false,'MCEcontentID7');
						}
             },
			buttons: {
				'SAVE': function() {
					if ($('#MCEcontentID').length != 0) {
						var OriginalContent1 = tinyMCE.get('MCEcontentID').getContent();
						$('#MCEcontentID').val(OriginalContent1);
					}
				
					if ($('#MCEcontentID2').length != 0) {
						var OriginalContent2 = tinyMCE.get('MCEcontentID2').getContent();
						$('#MCEcontentID2').val(OriginalContent2);
					  }
					
					if ($('#MCEcontentID3').length != 0) {
						var OriginalContent3 = tinyMCE.get('MCEcontentID3').getContent();
						$('#MCEcontentID3').val(OriginalContent3);
					  }
					
					if ($('#MCEcontentID4').length != 0) {
						var OriginalContent4 = tinyMCE.get('MCEcontentID4').getContent();
						$('#MCEcontentID4').val(OriginalContent4);
					  }
					
					if ($('#MCEcontentID5').length != 0) {
						var OriginalContent5 = tinyMCE.get('MCEcontentID5').getContent();
						$('#MCEcontentID5').val(OriginalContent5);
					  }
					
					if ($('#MCEcontentID6').length != 0) {
						var OriginalContent6 = tinyMCE.get('MCEcontentID6').getContent();
						$('#MCEcontentID6').val(OriginalContent6);
					  }
					
					if ($('#MCEcontentID7').length != 0) {
						var OriginalContent7 = tinyMCE.get('MCEcontentID7').getContent();
						$('#MCEcontentID7').val(OriginalContent7);
					  }
					
					$('#AjaxForm').ajaxSubmit(function(formdata) {
						$('#ModalDiv').html('<div class="loaderanim8"></div>');
				    	if (formdata==1){
							$(this).dialog('close');
							location.reload();
				    	}
				    	else {
							alert('sorry: ' + formdata);
				    	}
					});
	    	      
				},
				CANCEL: function() {
					$(this).dialog('close');
				}	
			}
		});
		
		
		
		LoadLoginButton();
		
		
		LoadEditFileButton();
			
		$('.EditButton')
			.click(function() {
				var TheClickedEntryID = this.id;
				var TheUrl = (GetSiteRoot()) + '/'+ (GetPageName()) +'/edit-' + TheClickedEntryID + ' #ContentEditor';
				$('#ModalDiv').html('<div class="loaderanim8"></div>');
				$("#ModalDiv").load(TheUrl, function(){ 
					addEditTabs();
										
					setTimeout('addButtonsEditor()',100);
					setTimeout('addMCE()',100);
					
					LoadTheseThumbs();
					SetupUploader();
					
					if ((GetUserName()) == "gametraining") {

						SetupGameUploader();

					}
					
					WhichItemType();
					ApplyLabels();
					FormatPriceFields();
					
			  		$('#AddPlugin').ajaxForm(function(data) {

							var VarPluginID = data.split('**-**');

								var VarPluginType = VarPluginID[0];
								var VarThePluginIDRef = VarPluginID[1];
								var VarThisID = VarPluginID[2];
								var VarThisUserName = VarPluginID[3];
								var VarThisPageName = VarPluginID[4];
								var VarThisPostName = VarPluginID[5];

								var VarTheLIID = '#plugincontent_'+ VarThisID;
								var TheUrl = (GetSiteRoot()) + '/' + VarThisPageName + '/' + VarThisPostName + '/ '  + VarTheLIID;

				                $('#PluginHolder').append('<li id="plugin_'+ VarThisID +'" class=" ui-widget-content"> <div  onclick="DeleteThePlugin(\'' + VarThisID + '\');" style="width: 50px; float: right;">DELETE</div><p style="clear: both;"></p><div id="plugincontent_'+ VarThisID +'"></div></li>');

			            if (VarPluginType>=1){

						 	$('#plugincontent_'+ VarThisID).load(TheUrl, function(){
							});
							   $('#PlaylistPlugin').hide(); 
						       $('#PhotoAlbumPlugin').hide();
							   $('#UpcomingEventsPlugin').hide();

			            }
			            else{
			                $('#PluginHolder').append('<li>Nopes!</li>');
						 	   $('#PlaylistPlugin').hide(); 
						       $('#PhotoAlbumPlugin').hide();
							   $('#UpcomingEventsPlugin').hide();

			            }
			        });
			
					$('#PluginType').change(function(){ 
						if ($(this).val() == '1') 
						{
					 	   $('#PlaylistPlugin').show(); 
					       $('#PhotoAlbumPlugin').hide();
						   $('#UpcomingEventsPlugin').hide();

						}
					    else if ($(this).val() == '2') 
						{
					 	   $('#PlaylistPlugin').hide(); 
					       $('#PhotoAlbumPlugin').show();
						   $('#UpcomingEventsPlugin').hide();

						}
					    else if ($(this).val() == '3') 
						{
					 	   $('#PlaylistPlugin').hide(); 
					       $('#PhotoAlbumPlugin').hide();
						   $('#UpcomingEventsPlugin').show();
						}

					    else 
						{
					 	   $('#PlaylistPlugin').hide(); 
					       $('#PhotoAlbumPlugin').hide();
						   $('#UpcomingEventsPlugin').hide();
						}
					});

					
				}).dialog('open');
				
					return false;
			});
		
			$('#AddAlbum')
				.click(function() {
					var TheUrl = (GetSiteRoot()) + '/u-photos/addalbum #ContentEditor';
					$('#ModalDiv').html('<div class="loaderanim8"></div>');
					$("#ModalDiv").load(TheUrl, function(){ 
							addButtonsDefault();
							setTimeout('addMCE()',100);
						}).dialog('open');

						return false;
				});


				$('#AddContact')
					.click(function() {
						var TheUrl = (GetSiteRoot()) + '/mycontacts/addcontact #ContentEditor';
						$('#ModalDiv').html('<div class="loaderanim8"></div>');
						$("#ModalDiv").load(TheUrl, function(){ 
								addButtonsDefault();
							}).dialog('open');

							return false;
					});


					$('#AddContactList')
						.click(function() {
							var TheUrl = (GetSiteRoot()) + '/mycontacts/addcontactlist #ContentEditor';
							$('#ModalDiv').html('<div class="loaderanim8"></div>');
							$("#ModalDiv").load(TheUrl, function(){ 
									addButtonsDefault();
								}).dialog('open');

								return false;
						});

			$('.EditPlaylist')
				.click(function() {
					var TheClickedEntryID = this.id;
					var TheUrl = (GetSiteRoot()) + '/'+ (GetPageName()) +'/editplaylist-' + TheClickedEntryID + ' #ContentEditor';
						$('#ModalDiv').html('<div class="loaderanim8"></div>');
						$("#ModalDiv").load(TheUrl, function(){ 
								addEditTabs();
								setTimeout('addButtonsEditor()',100);
								setTimeout('addMCE()',100);
								

								$('#PlaylistSource').change(function(){ 
							    	if ($(this).val() == '5') 
									{
							     	   $('#dtserverinfodiv').show(); 
								        $('#directoryurlinfodiv').hide(); 

									}
								    else if ($(this).val() == '15') 
									{
							     	   $('#directoryurlinfodiv').show(); 
								        $('#dtserverinfodiv').hide(); 

									}
								    else if ($(this).val() == '6') 
									{
							     	   $('#directoryurlinfodiv').show(); 
								        $('#dtserverinfodiv').hide(); 

									}
								    else if ($(this).val() == '17') 
									{
							     	   $('#directoryurlinfodiv').show(); 
								        $('#dtserverinfodiv').hide(); 

									}
								    else 
									{
								        $('#directoryurlinfodiv').hide(); 
								        $('#dtserverinfodiv').hide(); 
									}
								}); 

								
							}).dialog('open');

							return false;
					});
									
											
								
		$('.RSS-Update')
			.click(function() {
				var TheClickedEntryID = this.id;
				
				UpdateRSS(TheClickedEntryID);

					return false;
			});
									
									
			$('.DT-UpdatePlaylist')
				.click(function() {
					var TheClickedEntryID = this.id;
					var PLID = GetPLID();
					
					
					DTUpdateRSS(TheClickedEntryID,PLID);

						return false;
				});
			
			$('#DT-LoadPlaylists')
				.click(function() {
					
						DTLoadPlaylistsRSS(GetUserID());
						return false;
				});
				
				
				
				
									
			$('.EditAlbum')
				.click(function() {
					var TheClickedEntryID = this.id;
					var TheUrl = (GetSiteRoot()) + '/'+ (GetPageName()) +'/editalbum-' + TheClickedEntryID + ' #ContentEditor';
					$('#ModalDiv').html('<div class="loaderanim8"></div>');
					$("#ModalDiv").load(TheUrl, function(){ 
						addEditTabs();
						setTimeout('addButtonsEditor()',100);
						setTimeout('addMCE()',100);
					}).dialog('open');

						return false;
				});


				$('.EditPhoto')
					.click(function() {
						var TheClickedEntryID = this.id;
						var TheUrl = (GetSiteRoot()) + '/'+ (GetPageName()) +'/edit-' + TheClickedEntryID + ' #ContentEditor';
						$('#ModalDiv').html('<div class="loaderanim8"></div>');
						$("#ModalDiv").load(TheUrl, function(){ 
							addEditTabs();
							setTimeout('addButtonsEditor()',100);
							setTimeout('addMCE()',100);
						}).dialog('open');

							return false;
					});
			
				$('.EditDownload')
					.click(function() {
						var TheClickedEntryID = this.id;
						var TheUrl = (GetSiteRoot()) + '/'+ (GetPageName()) +'/edit-' + TheClickedEntryID + ' #ContentEditor';
						$('#ModalDiv').html('<div class="loaderanim8"></div>');
						$("#ModalDiv").load(TheUrl, function(){ 
							addEditTabs();
							setTimeout('addButtonsEditor()',100);
							setTimeout('addMCE()',100);
							WhichItemType();
							ApplyLabels();
							FormatPriceFields();
							CheckTheItemType($('#ItemType').val());
						}).dialog('open');

							return false;
					});					
						
						
		
		
				$('#PageOptions')
					.click(function() {

						var TheUrl = (GetSiteRoot()) + '/' + (GetPageName()) + '/page-settings #PageOptionsControls';
						$('#ModalDiv').html('<div class="loaderanim8"></div>');
						$("#ModalDiv").load(TheUrl, function(){ 
								addButtonsEditPage();
								addEditPageTabs();							
								CSSSwapper();
								setTimeout('addMCE()',100);
								
								

								$('#AdvancedOptionsLink').click(function(){ 
							     	   $('#AdvancedOptionsDiv').toggle('blind'); 

										return false;
								});

								$('#AdvancedImagesLink').click(function(){ 
							     	   $('#AdvancedImagesDiv').toggle('blind'); 

										return false;
								});


								
							}).dialog('open');

							return false;
					});		
		
		
		
		
			
		$('#SiteContactInfoNav')
			.click(function() {
				var TheUrl = (GetSiteRoot()) + '/admin/contact #ContentEditor';
				$('#ModalDiv').html('<div class="loaderanim8"></div>');
				$("#ModalDiv").load(TheUrl, function(){ 
						addButtonsDefault();
							JButtons();
						GoGetTheFile();
							
					 }).dialog('open');
		
					return false;
			});			
			
			
			
		
			
		$('#FilePlayerAjaxLoadPL')
			.click(function() {
				
					RunThePlaylistLoad();
		
					return false;
			});
			
		$('#FilePlayerAjaxLoadYouTubePL')
			.click(function() {
				RunTheAjaxPlaylistLoad();
			});
				
			
			
		$('#LoadDT')
			.click(function() {
				var TheUrl = (GetSiteRoot()) + '/codebase/convertrss/dottunes-rss-playlists.asp';
				$('#ModalDiv').html('<div class="loaderanim8"></div>');
				$("#ModalDiv").load(TheUrl, function(){ 
						addButtonsDefault();
					 }).dialog('open');
		
					return false;
			});
			
		$('#LoadDTFilePlayer')
			.click(function() {
				
				LoadDTAjax();
				
			});
	
	$('#PageOptionsAdvanced').click(function(){ 
     	   $('#PageOptionsAdvancedControls').toggle('blind'); 
		
			return false;
	});
	
	$('input#Calendar').click(function() { 
  	   if($(this).attr("checked")) { 
     	   $('#addtocalendardiv').show('blind'); 
 	    } else { 
	        $('#addtocalendardiv').hide('blind'); 
 	    }   
	});     
	
	
	
	
	
	$("#AdvancedSettingsDiv").tabs();
	$("#TabsSettingsDiv").tabs();
	
	$('#contenttabs').tabs();
	
	$('#whyscanphotostabs').tabs();

	$(".ui-dialog-titlebar").hide();


		$('a.lightbox').lightBox(); 


		$("#datepicker").datepicker({ dateFormat: 'yy-mm-dd' });
		$("#DatePosted").datepicker({ dateFormat: 'yy-mm-dd' });
		$("#ContactEventDate").datepicker({ dateFormat: 'yy-mm-dd' });
		$("#ContactBirthday").datepicker({ dateFormat: 'yy-mm-dd' });

  		$('#EditPrefsAccountInfo').ajaxForm(function(data) {
            if (data==1){
                $.growlUI("Settings Saved!"); 
            }
            else if (data==2){
				$.growlUI("Error"); 
            }
        });

  		$('#EditPrefsContactInfo').ajaxForm(function(data) {
            if (data==1){
                $.growlUI("Settings Saved!"); 
            }
            else if (data==2){
				$.growlUI("Error"); 
            }
        });

  		$('#EditPrefsPaymentInfo').ajaxForm(function(data) {
            if (data==1){
                $.growlUI("Settings Saved!"); 
            }
            else if (data==2){
				$.growlUI("Error"); 
            }
        });

  		$('#EditPrefsSiteSettings').ajaxForm(function(data) {
            if (data==1){
                $.growlUI("Settings Saved!"); 
            }
            else if (data==2){
				$.growlUI("Error"); 
            }
        });

  		$('#EditPrefsSiteLayout').ajaxForm(function(data) {
            if (data==1){
                $.growlUI("Settings Saved!"); 
            }
            else if (data==2){
				$.growlUI("Error"); 
            }
        });

  		$('#EditPrefsSiteCustomHeaderFooter').ajaxForm(function(data) {
            if (data==1){
                $.growlUI("Settings Saved!"); 
            }
            else if (data==2){
				$.growlUI("Error"); 
            }
        });



  		$('#EditPrefsWeb20Sync').ajaxForm(function(data) {
            if (data==1){
                $.growlUI("Settings Saved!"); 
            }
            else if (data==2){
				$.growlUI("Error"); 
            }
        });
				
  		$('#EditPrefsChangeUsername').ajaxForm(function(data) {
            if (data==1){
                $.growlUI("Username was changed!"); 
            }
            else if (data==2){
				$.growlUI("Error"); 
            }
        });
		

		$('#ChangePassword').ajaxForm(function(data) {
		    if (data==1){
		        $.growlUI("Your Password was changed!"); 
				$('#ChangePassword')[0].reset();
		    }
		    else if (data==2){
				$.growlUI("Your Passwords do not match!"); 
		    }
		});

			
		




  		$('#AddPluginPage').ajaxForm(function(data) {

				var VarPluginID = data.split('**-**');
			
					var VarPluginType = VarPluginID[0];
					var VarThePluginIDRef = VarPluginID[1];
					var VarThisID = VarPluginID[2];
					var VarThisUserName = VarPluginID[3];
					var VarThisPageName = VarPluginID[4];
					
					var VarTheLIID = '#plugincontent_'+ VarThisID;
					
					
					
					var TheUrl = (GetSiteRoot()) + '/' + VarThisPageName  + '/ '  + VarTheLIID;
	               
	 				$('#PluginHolder').append('<li id="plugin_'+ VarThisID +'" class=" ui-widget-content"> <div  onclick="DeleteThePlugin(\'' + VarThisID + '\');" style="width: 50px; float: right;">DELETE</div><p style="clear: both;"></p><div id="plugincontent_'+ VarThisID +'"></div></li>');
	
					
            if (VarPluginType>=1){
			 	   
			 	$('#plugincontent_'+ VarThisID).load(TheUrl, function(){
				});
				   $('#PlaylistPlugin').hide(); 
			       $('#PhotoAlbumPlugin').hide();
	 			
            }
            else{
                $('#PluginHolder').append('<li>Nopes!</li>');
			 	   $('#PlaylistPlugin').hide(); 
			       $('#PhotoAlbumPlugin').hide();
		
            }
        });

	    var options = { 
	        target:        '#sortableinfo',   // target element(s) to be updated with server response 
	        beforeSubmit:  showRequest,  // pre-submit callback 
	        success:       showResponse  // post-submit callback 
	    }; 

	    $('#FileMover').ajaxForm(options);
	
	
	ContactMoverFunk();




	});


	
	
		// pre-submit callback 
		function showRequest(formData, jqForm, options) { 			
						
			var selectedItems = new Array();
			$("input[@name='FileID[]']:checked").each(function() {selectedItems.push($(this).val());});

		    if (selectedItems.length==0){
		    	alert('nothing selected');
			    return false; 
			} else if ($('#FileSelector').val()=='addnew'){
				return true;
			} else if ($('#FileSelector').val()>=1){
				return true;
			} else if ($('#FileSelector').val()=='choose'){
				alert('please choose an action');
				return false;
		    } else if ($('#FileSelector').val()=='delete') {
				
				input_box=confirm('are you sure you want to delete these items?');
				if (input_box==true)
				{ 
					return true;
				}

				else
				{
			    	return false; 
				}
				
			}
		
		} 

		// post-submit callback 
		function showResponse(responseText, statusText, xhr, $form)  { 

			var VarSlicePrefix = responseText.slice(0,7);
			//alert(VarSlicePrefix);

		    if (VarSlicePrefix=='add2pl-'){
			
				var VarSliceData = responseText.slice(7,responseText.length);
				
				
				if ((GetPageName()) == 'mycontacts') {
				
					ListLoaderFunk(VarSliceData);
				
				
				} else {
					
					window.location=(GetSiteRoot())+'/u-playlists/'+VarSliceData;
		            
				}
				
				

		    }
		    else if (responseText==2){
		    	alert('add a new playlist!');
			}
		    else if (VarSlicePrefix=='delete-'){
				var VarSliceData = responseText.slice(7,responseText.length);
				var VarSliceArray = VarSliceData.split(",");
				for ( var i=0, len=VarSliceArray.length; i<len; ++i ){
						//alert('delete: '+VarSliceArray[i]);
						$('#listItem_'+VarSliceArray[i]).remove();
						$('#PlaylistUpdate').html('0 items selected');
						
				}
				
			}			
		    else {
				alert(VarSlicePrefix);
		    	alert(data);
			}
			
		}
	
	

					function updateTips(t) {
						tips.text(t).effect("highlight",{},1500);
					}



					function checkLength(o,n,min,max) {

						if ( o.val().length > max || o.val().length < min ) {
							o.addClass('ui-state-error');
							updateTips(n + " name must be between "+min+" and "+max+" characters.");
							return false;
						} else {
							return true;
						}

					}

					function checkRegexp(o,regexp,n) {

						if ( !( regexp.test( o.val() ) ) ) {
							o.addClass('ui-state-error');
							updateTips(n);
							return false;
						} else {
							return true;
						}

					}


// Highlight and select embed input field


function highlight(field) {
       field.focus();
       field.select();
}

function JSTest(Var1,Var2) {
	alert(Var2);

}

function AccountLogin(data){
	var LoginUrl = 'http://upl1nk.com/'+data;
	alert(LoginUrl);
	window.location(LoginUrl);
}


    function DeleteThePlugin(data){
		$.post("/codebase/edit/pages/deleteplugin.asp", { ID: data } , function(newdata){

				$('#plugin_' + newdata ).remove();
		 });
	};




// Manage Comments

function ApproveComment(data){
	
	
	var answer = confirm('Are you sure you want to Approve this comment?')
		if (answer){
			$.post("/codebase/edit/comments/contacts-comment-approve.asp", { ID: data } , function(newdata){
						$('#CommentApprove_' + newdata ).remove();
			 });
		}
		
};

function DeleteComment(data){
	var answer = confirm('Are you sure you want to Delete this comment?')
		if (answer){
			$.post("/codebase/edit/comments/deletecomment.asp", { ID: data } , function(newdata){
					$('#Comment_' + newdata ).remove();
			 });
		}
};

function DeletePhoto(data){
	var answer = confirm('Are you sure you want to Delete this image?')
		if (answer){
			$.post("/codebase/edit/deletephoto.asp", { ID: data } , function(newdata){
	            window.location= (GetSiteRoot()) + "/u-photos";
			 });
		}
};


function DeleteDownload(data){
	var answer = confirm('Are you sure you want to Delete this item?')
		if (answer){
			$.post("/codebase/edit/downloads/deletedownload.asp", { ID: data } , function(newdata){
	            window.location= (GetSiteRoot()) + "/downloads";
			 });
		}
};

// Count the checkboxes


function CheckedFiles(data){
	var selectedItems = new Array();
	$("input[@name='FileID[]']:checked").each(function() {selectedItems.push($(this).val());});
				
	$('#AllFiles').val(selectedItems);
	$('#PlaylistUpdate').html(selectedItems.length + ' items selected');
};

function CheckedContacts(data){
	var selectedItems = new Array();
	$("input[@name='FileID[]']:checked").each(function() {selectedItems.push($(this).val());});
				
	$('#AllFiles').val(selectedItems);
	$('#PlaylistUpdate').html(selectedItems.length + ' items selected');
};



// Swap Photos Ajax

    function SwapThePhoto(data){

		var TheUrl = (GetSiteRoot())+'/u-photos/view-'+(data) + ' #thisphoto';

		$('#main').load(TheUrl, function(){
			$('#main').hide();
			$('#main').fadeIn(1000);
		});

    };


	// Swap HISTORY FILE

	    function SwapHistoryFile(data){

			var TheUrl = (GetSiteRoot())+'/u-playlists/playhistory-' + data + ' #songData';

			$('.infomore').html('');

	  		$('#infomore_' + data).html('<div class="loaderanim8"></div>');

			$('#infomore_' + data ).load(TheUrl, function(){
				$("button, input:submit", "body").button();

			});

	    };


		function SetupClickSortFilesLongLi(data) {
			
				$('#SortFilesLong li').unbind("click");
			
				$('#SortFilesLong li').click(function() {
					
					var TheClickedEntryID = this.id;
					
					var TheClickedEntryIDAry = TheClickedEntryID.split("_");
					
					var SourceTrackID = TheClickedEntryIDAry[1];
					var PlayTrackID = TheClickedEntryIDAry[2];
					
						if (SourceTrackID == 'YT') {
							
							//youtube id might have had an _ so get it fresh
							
							PlayTrackID = TheClickedEntryID.replace("listItem_YT_","");
							
							WhichPlayTrackID = ('yt-' + PlayTrackID);
						
						} else if (SourceTrackID == 'DT') {
						
							WhichPlayTrackID = ('dt-' + PlayTrackID);
						} else {
							
							WhichPlayTrackID = ('u-' + PlayTrackID);
						}
						
					
					//figure out if they want a playlist or track
					//call PlayTheFile or FilePlayerPlaylist

						if (data == 1) {

							FilePlayerPlaylist(WhichPlayTrackID);

						} else {

							PlayTheFile(WhichPlayTrackID);
						}
				});
				
			
		};



		// Play FILE

		    function PlayTheFile(TrackID){
			
				
				var VarTRArray = TrackID.split("-");
				
				var PlayTrackSourceID = VarTRArray[0];
				var PlayTrackID = VarTRArray[1];
				
					if (PlayTrackSourceID == 'yt') {
						
						//youtube id might have had an _ so get it fresh
						
						PlayTrackID = TrackID.replace("yt-","");
						
						var data = ('yt-' + PlayTrackID);
					
					} else if (PlayTrackSourceID == 'dt') {
					
						var data = ('dt-' + PlayTrackID);
						
					} else {
						
						var data = (PlayTrackID);
					}
					
					
					
					//check to see if the user is on a mobile device or not in order to know what div to load the player into
					
					if ((GetPlayerType()) == 1) {
						
						
				      
						
						//$('#MobileFilePlayerNav').show('blind');
						//$('#MobileFilePlayer').show('blind');
											
						var TheDivToLoadInto = '#MobileFilePlayer';
						
						//close any other open drawers
						//$('.FileInfoDrawer').html('');
												
					} else {
						
						var TheDivToLoadInto = '#TheFilePlayer';
					}
				

				var TheUrl = (GetSiteRoot()) + '/u-playlists/player-' + data  + ' #songData';
				
		  		$(TheDivToLoadInto).html('<div class="loaderanim8"></div>');

				$(TheDivToLoadInto).load(TheUrl, function(){
					$("button, input:submit", "body").button();
					SetupContactForms();
					ValidatorSetup();
					$(".pltoolbar").buttonset();
					FancyBoxes();
					LoadLoginButton();
					ApplyLabels();
					
					if ((GetPlayerType()) != 1) {
						TheTrackButtons();
					
					} else {
						
						$('#MobileFilePlayerHolder').show("slide", { direction: "horizontal" }, 1000);
						
						$('html, body').animate({ scrollTop: 0 }, 0);
					}

				});
				
				window.location.hash = data;
				LoadTheLikeButton();
		    };

			// LoadThePlaylistintoAjax 

			    function FilePlayerPlaylist(PLID){
				
				
					//Split data into array and check which type of ID
					var VarPLArray = PLID.split("-");
					
					var data = VarPLArray[1];
					
					
					if (VarPLArray[0] == 'yt') {
						
						
						var TheUrl = (GetSiteRoot()) + '/u-playlists/plutube-' + data  + ' #FileContainer';

				  		$('#SortFilesLong').html('<div class="loaderanim8"></div>');

						// need to lookup the name from passing the ID
						// load the playlist name into FilePlayerAjaxPLNAME

						$.post("/codebase/convertrss/plname-rss-youtube.asp", { ID: data } , function(PLName){
								$("#FilePlayerAjaxPLNAME").html(" / " + PLName);
					 	});

						$('#SortFilesLong').load(TheUrl, function(){
							SetupJScrollStyler();
							SetupClickSortFilesLongLi(0);
						});

						
					} else if (VarPLArray[0] == 'dt') {
						
						

						if ((GetPageName()) == 'u-playlists') {

							// load playlist into main area
					  		$('#SortFiles').html('<div class="loaderanim8"></div>');
							
							$.post("/codebase/convertrss/dottunes-rss-all-info.asp", { PLID: data, TheUserID: (GetUserID())  } , function(DTPlaylistResponse){

									$("#SortFiles").html(DTPlaylistResponse);
									JButtons();
									SetupJScrollStyler();
									FixUpAdminWindows();
									SetupClickSortFilesLongLi(0);
									
						 	});

						} else {

							var TheUrl = (GetSiteRoot()) + '/u-playlists/plloaddt-' + data  + ' #FileContainer';

								// need to lookup the name from passing the ID
								// load the playlist name into FilePlayerAjaxPLNAME
								
								$('#SortFilesLong').html('<div class="loaderanim8"></div>');

								$.post("/codebase/convertrss/dottunes-rss-playlistnamefromid.asp", { ID: data, TheUserID: (GetUserID()) } , function(PLName){
										$("#FilePlayerAjaxPLNAME").html(" / " + PLName);
							 	});

								$('#SortFilesLong').load(TheUrl, function(){
									SetupJScrollStyler();
									SetupClickSortFilesLongLi(0);
								});
								
						}

					} else if (VarPLArray[0] == 'u') {
												
						// check to see if on playlists page

						if ((GetPageName()) == 'u-playlists') {

							// load playlist into main area
							var TheUrl = (GetSiteRoot()) + '/u-playlists/loadplaylist-' + data  + ' #SortFiles';
							var TheDivToLoadInto = '#AdminScroll';

						} else {

							var TheUrl = (GetSiteRoot()) + '/u-playlists/plloadajx-' + data  + ' #FileContainer';
							var TheDivToLoadInto = '#SortFilesLong';

						}


				  		$(TheDivToLoadInto).html('<div class="loaderanim8"></div>');

						$(TheDivToLoadInto).load(TheUrl, function(){
							LoadEditFileButton();
							JButtons();
							SetupJScrollStyler();
							FixUpAdminWindows();
							SetupClickSortFilesLongLi(0);
						});
						

					}
					

					
			    };
		
		
			// LoadTheYoutubePlaylistintoAjax 

			    function FilePlayerYoutube(data){

					var TheUrl = (GetSiteRoot()) + '/u-playlists/plutube-' + data  + ' #FileContainer';

			  		$('#SortFilesLong').html('<div class="loaderanim8"></div>');
			
					// need to lookup the name from passing the ID
					// load the playlist name into FilePlayerAjaxPLNAME
					
					$.post("/codebase/convertrss/plname-rss-youtube.asp", { ID: data } , function(PLName){
							$("#FilePlayerAjaxPLNAME").html(" / " + PLName);
				 	});

					$('#SortFilesLong').load(TheUrl, function(){
						SetupJScrollStyler();
					});

			    };


			
				// LoadTheDTPlaylistintoAjax 

				    function FilePlayerPlaylistDT(data){

						// check to see if on playlists page
						
						VarUserID =  (GetUserID());
						

						if ((GetPageName()) == 'u-playlists') {

							// load playlist into main area
					  		$('#SortFiles').html('<div class="loaderanim8"></div>');
							
							$.post("/codebase/convertrss/dottunes-rss-all-info.asp", { PLID: data, TheUserID: VarUserID  } , function(DTPlaylistResponse){

									$("#SortFiles").html(DTPlaylistResponse);
									JButtons();
									SetupJScrollStyler();
									FixUpAdminWindows();
									
						 	});

						} else {

							var TheUrl = (GetSiteRoot()) + '/u-playlists/plloaddt-' + data  + ' #FileContainer';

								// need to lookup the name from passing the ID
								// load the playlist name into FilePlayerAjaxPLNAME
								
								$('#SortFilesLong').html('<div class="loaderanim8"></div>');

								$.post("/codebase/convertrss/dottunes-rss-playlistnamefromid.asp", { ID: data, TheUserID: VarUserID } , function(PLName){
										$("#FilePlayerAjaxPLNAME").html(" / " + PLName);
							 	});

								$('#SortFilesLong').load(TheUrl, function(){
									SetupJScrollStyler();
								});
								

						}

				    };

		
// Swap FILE

    function SwapTheFile(data){

		var TheUrl = data + ' #songData';

  		$('#TheFilePlayer').html('<div class="loaderanim8"></div>');

		$('#TheFilePlayer').load(TheUrl, function(){
			$("button, input:submit", "body").button();
			$(".pltoolbar").buttonset();
			
			TheTrackButtons();
			SetupContactForms();
			
		});

    };

	
	
	
	
// EDIT item

	
    function EditThisItem(data){
		window.location=(GetSiteRoot())+'/downloads/edit-'+(data); 
	};
	

// Edit FILE

    function EditThisFile(data){
		
		var TheUrl = (GetSiteRoot()) + '/'+ (GetPageName()) +'/edit-' + data + ' #FileEditor';
			$('#TrackEditDiv').html('<div class="loaderanim8"></div>');
			$("#TrackEditDiv").load(TheUrl, function(){ tinyMCE.execCommand('mceAddControl',false,'ContentDiv_'+data); }).dialog({
				autoOpen: false,
				height: $(window).height(),
				width: 650,
	            show:"blind",
	            hide: "blind",
	            position: ['right','top'],
				modal: true,
				buttons: {
					'SAVE': function() {
						var OriginalContent = tinyMCE.activeEditor.getContent();
						$('#ContentDiv_'+data).val(OriginalContent);
						$('#EditFileForm_'+data).ajaxSubmit(function(formdata) {
					    	if (formdata==1){
									

						 		$('#listItem_'+data).html('<div class="loaderanim8"></div>');

								var TheDivUrl = (GetSiteRoot()) + '/'+ (GetPageName()) +'/ #listItemDiv_'+data;

								$('#listItem_'+data).load(TheDivUrl, function(){
									$("button, input:submit", "body").button();
									//	$(".check").button();
									$(".pltoolbar").buttonset();
								});
								$('#TrackEditDiv').dialog('close');
								
					    	}
					    	else {
								alert('sorry');
					    	}
							tinyMCE.execCommand('mceRemoveControl',false,'ContentDiv_'+data);
						});
						
					    return false;
					},
					CANCEL: function() {
						tinyMCE.execCommand('mceRemoveControl',false,'ContentDiv_'+data);
						$(this).dialog('close');
					}	
				},
				close: function() {
					tinyMCE.execCommand('mceRemoveControl',false,'ContentDiv_'+data);
				    return false;
				}
			});
			$('#TrackEditDiv').dialog('open');
			
			$(".ui-dialog-titlebar").hide();

    };



		
		

	PEPS = {};

	PEPS.rollover = 
	{
	   init: function()
	   {
	      this.preload();

	      $(".ro").hover(
	         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); }, 
	         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
	      );
	   },

	   preload: function()
	   {
	      $(window).bind('load', function() {
	         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
	      });
	   },

	   newimage: function( src )
	   { 
	      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0]; 
	   },

	   oldimage: function( src )
	   { 
	      return src.replace(/_o\./, '.'); 
	   }
	};
	
	
	
	
	// Swap images for thumbnails

	function change(what) {
	    var value = what.options[what.selectedIndex].id;
	    if (value != '')
	        if (document.images)
	            document.images['myImage'].src = value;
	}

	function change_thumb(what) {
	    var value = what.options[what.selectedIndex].id;
	    if (value != '')

		//strip id value off of beginning of filename?

	        if (document.images)
	            document.images['myImage'].src = value;
	}

	function changeBGimg(what) {
	    var value = what.options[what.selectedIndex].id;
	    if (value != '')
			$('body').css('background-image', 'url(' + value +')');
			$('body').css('background-repeat', 'repeat');

	}


	function changeBGimgAlign(what) {
	    var value = what.options[what.selectedIndex].id;
	    if (value != '')
			$('body').css('background-position', value);
	}
	function changeBGimgRepeat(what) {
	    var value = what.options[what.selectedIndex].id;
	    if (value != '')

			$('body').css('background-repeat', value);
	}
	function changeBGColor(what) {
			$('body').css('background-color', what);
	}

	function changeSiteFormatOptions(what) {
	    var value = what.options[what.selectedIndex].id;	
	    if (value == '3')  		
			$('#main').css('float', 'left');
			$('#sidebar').css('float', 'right');
			$('#main').css('margin-left', '5px');
			$('#main').css('margin-right', '10px');
			$('#sidebar').css('margin-left', '10px');
			$('#sidebar').css('margin-right', '0px');
	    if (value == '1')  		
			$('#main').css('float', 'right');
			$('#sidebar').css('float', 'left');
			$('#main').css('margin-left', '0px');
			$('#main').css('margin-right', '5px');
			$('#sidebar').css('margin-left', '5px');
			$('#sidebar').css('margin-right', '0px');

	}
	function changeBGtopwrapper(what) {
	    var value = what.options[what.selectedIndex].id;
	    if (value != '')

			$('#topwrapper').css('background-image', 'url(' + value +')');
			$('#topwrapper').css('background-position', 'top');
			$('#topwrapper').css('background-repeat', 'repeat');
	}


	function changeTheme(what) {
	    var value = what.options[what.selectedIndex].id;
	    var themes = ['start', 'cupertino', 'south-street', 'overcast', 'vader', 'eggplant', 'mint-choc', 'blitzer', 'le-frog', 'upl1nk-light', 'upl1nk-dark'];
	    if (value != '' && value < 12)  		
	      var VarTheme = themes[value - 1];
	    else if (value >= 12)
	      var VarTheme = 'upl1nk-light';

			document.getElementById('ThemeCSS').href = '/js/themes/' + VarTheme + '/jquery-ui-1.7.2.custom.css'; 

	}


	
	
	function addMCE()
	    {
	        tinyMCE.execCommand('mceAddControl',false,'MCEcontentID');
		    tinyMCE.execCommand('mceAddControl',false,'MCEcontentID2');
			tinyMCE.execCommand('mceAddControl',false,'MCEcontentID3');
			tinyMCE.execCommand('mceAddControl',false,'MCEcontentID4');
			tinyMCE.execCommand('mceAddControl',false,'MCEcontentID5');
			tinyMCE.execCommand('mceAddControl',false,'MCEcontentID6');
			tinyMCE.execCommand('mceAddControl',false,'MCEcontentID7');
	    }			
	
	function addMCEpg()
		{
		     tinyMCE.execCommand('mceAddControl',false,'MCEpgcontentID');
			 tinyMCE.execCommand('mceAddControl',false,'MCEpgcontentID2');
		     tinyMCE.execCommand('mceAddControl',false,'MCEpgcontentID3');
		}			
	
			function addButtonsEditPage()
				{
						$("#ModalDiv").dialog( "option", "buttons", { 
							'SAVE': function() {
									if ($('#MCEcontentID').length != 0) {
										var OriginalContent1 = tinyMCE.get('MCEcontentID').getContent();
										$('#MCEcontentID').val(OriginalContent1);
									}

									if ($('#MCEcontentID2').length != 0) {
										var OriginalContent2 = tinyMCE.get('MCEcontentID2').getContent();
										$('#MCEcontentID2').val(OriginalContent2);
									  }

									if ($('#MCEcontentID3').length != 0) {
										var OriginalContent3 = tinyMCE.get('MCEcontentID3').getContent();
										$('#MCEcontentID3').val(OriginalContent3);
									  }

								$('#AjaxForm').ajaxSubmit(function(formdata) {
									$('#ModalDiv').html('<div class="loaderanim8"></div>');
							    	if (formdata==1){
										$("#ModalDiv").dialog('close');
										location.reload();
							    	}
							    	else {
										alert('sorry: ' + formdata);
							    	}
								});

							},
							CANCEL: function() {
								// reset buttons to defaults
								//$("#ModalDiv").dialog( "option", "buttons", {});
								$('#ModalDiv').dialog('close');
							},
							"DELETE": function() { 
								input_box=confirm('Are you sure you want to delete this entire page and all its contents??');
								if (input_box==true)
								{ 
									$('#DeletePage').submit(); 
									return true;
								}

								else
								{
							    	return false; 
								}



								}
						});
				}

	
		function addButtonsEditor()
			{

					$("#ModalDiv").dialog( "option", "buttons", { 
						'SAVE': function() {
								var OriginalContent1 = tinyMCE.get('MCEcontentID').getContent();
								$('#MCEcontentID').val(OriginalContent1);

							$('#AjaxForm').ajaxSubmit(function(formdata) {
								$('#ModalDiv').html('<div class="loaderanim8"></div>');
						    	if (formdata==1){
									$("#ModalDiv").dialog('close');
									location.reload();
						    	}
						    	else {
									alert('sorry: ' + formdata);
						    	}
							});

						},
						CANCEL: function() {
							// reset buttons to defaults
							//$("#ModalDiv").dialog( "option", "buttons", {});
							$('#ModalDiv').dialog('close');
						},
						"DELETE": function() { 
							input_box=confirm('Are you sure you want to delete this content?');
							if (input_box==true)
							{ 
								
								var DeletePhotoID = $("input[name='DeletePhotoID']").attr("value");
																								
								if (DeletePhotoID >= 1) {
									
									$.post("/codebase/edit/photos/deletephoto.asp", { ID: DeletePhotoID } , function(newdata){
										$('#listItem_'+DeletePhotoID).remove();
										$('#ModalDiv').dialog('close');
										
									 });

									
								} else {
									
									$('#DeleteEntry').submit();
								}
																	 

								return true;
							}

							else
							{
						    	return false; 
							}
							
							
							
							}
					});
			}

		function addButtonsDefault()
				{

					    $("#EditTabsSettingsDiv").tabs();
						$("#ModalDiv").dialog( "option", "buttons", { 
							'SAVE': function() {
									if ($('#MCEcontentID').length != 0) {
										var OriginalContent1 = tinyMCE.get('MCEcontentID').getContent();
										$('#MCEcontentID').val(OriginalContent1);
									}

									if ($('#MCEcontentID2').length != 0) {
										var OriginalContent2 = tinyMCE.get('MCEcontentID2').getContent();
										$('#MCEcontentID2').val(OriginalContent2);
									  }

									if ($('#MCEcontentID3').length != 0) {
										var OriginalContent3 = tinyMCE.get('MCEcontentID3').getContent();
										$('#MCEcontentID3').val(OriginalContent3);
									  }
									

									if ($('#MCEcontentID4').length != 0) {
										var OriginalContent4 = tinyMCE.get('MCEcontentID4').getContent();
										$('#MCEcontentID4').val(OriginalContent4);
									  }
									

									if ($('#MCEcontentID5').length != 0) {
										var OriginalContent5 = tinyMCE.get('MCEcontentID5').getContent();
										$('#MCEcontentID5').val(OriginalContent5);
									  }
									
									if ($('#MCEcontentID6').length != 0) {
										var OriginalContent6 = tinyMCE.get('MCEcontentID6').getContent();
										$('#MCEcontentID6').val(OriginalContent6);
									  }
									
									if ($('#MCEcontentID7').length != 0) {
										var OriginalContent7 = tinyMCE.get('MCEcontentID7').getContent();
										$('#MCEcontentID7').val(OriginalContent7);
									  }
									
									$('#AjaxForm').ajaxSubmit(function(formdata) {
										$('#ModalDiv').html('<div class="loaderanim8"></div>');
								    	if (formdata==1){
											$("#ModalDiv").dialog('close');
											location.reload();
								    	}
								    	else {
											alert('sorry: ' + formdata);
								    	}
									});


							},
							CANCEL: function() {
								$('#ModalDiv').dialog('close');
							}
						});
				}


			
							
	function addEditTabs()
		{
		     $("#AdvancedSettingsDiv").tabs();
				$("#datepicker").datepicker({ dateFormat: 'yy-mm-dd' });
				$("#datepicker3").datepicker({ dateFormat: 'yy-mm-dd' });
				$("#datepicker4").datepicker({ dateFormat: 'yy-mm-dd' });
				
				$("#DatePosted").datepicker({ dateFormat: 'yy-mm-dd' });
								
				var ThisWindowHeightMinusStuff = ($(window).height() - 235);
				var ThisWindowHeightMinusStuffpx = ThisWindowHeightMinusStuff + 'px';
				var ThisWindowHeightMinusStuffpx44 = (ThisWindowHeightMinusStuff - 84) + 'px';

				$('#MCEcontentID_tbl').css('height', ThisWindowHeightMinusStuffpx);
				$('#MCEcontentID_ifr').css('height', ThisWindowHeightMinusStuffpx44);
								
					
		}			
		
		function addEditPageTabs()
			{
			     $("#EditTabsSettingsDiv").tabs();

			}		
		
		function addDesignerTabs()
			{
			     $("#DesignerTabsSettingsDiv").tabs();
			

			}
		
		function CheckPlaylistSync() {
			
			
				var VarPLID = (GetPLID());
				var order = $('#SortFiles').sortable('serialize');
					
				$.post("/codebase/convertrss/dottunes-rss-all.asp", { ID: VarPLID } , function(RawDTID){
				
				if (order == RawDTID) {
					
					alert('They Match');
					
				} else {
					var theURL = "/codebase/edit/sorting/process-sortable-files.asp?PLID="+VarPLID+"&"+RawDTID

					$("#sortableinfo").load(theURL, function(response) {
					  if (response != "") {
						$.growlUI("Update Complete!");
					  }
					});
					
				}
				
			 	});
			
		}
		
		function DTLoadPlaylistsRSS(VarUserID) 
		{
			
			
			$.post("/codebase/convertrss/dottunes-rss-playlists.asp", {TheUserID: VarUserID} , function(DTPlaylistResponse){
				$('#DTPlaylistsHolder').html('<div style="height: 200px;"><p>Connecting to server<br /><img src="http://upl1nk.com/images/loadingAnimation.gif" style="width: 100%;" /></p></div>');

				var VarExclaimArray = DTPlaylistResponse.split("!");

				if (VarExclaimArray[0] == "Connected"){
					$("#DTPlaylistsHolder").html(DTPlaylistResponse);
					
					SetupJScrollStyler();
														
					FixUpAdminWindows();
					
					$('.DTPlaylists')
					.click(function() {
						var TheClickedEntryID = this.id;
						var TheCleanPLTitle = TheClickedEntryID.replace("%20", " ");
						$('#PlaylistOptions').html('Playlist Title Here');
				  		
				  		$('#SortFiles').html('<li><p>Retrieving Playlist...<br /><img src="http://upl1nk.com/images/loadingAnimation.gif" style="width: 100%;" /></p></li>');

							$.post("/codebase/convertrss/dottunes-rss-all-info.asp", { PLID: TheClickedEntryID, TheUserID: VarUserID  } , function(DTPlaylistResponse){

									$("#SortFiles").html(DTPlaylistResponse);
									
									JButtons();
									
									SetupJScrollStyler();
																		
									FixUpAdminWindows();
									
									
						 	});
							return false;
					});
				} 
				else 
				{
					$("#DTPlaylistsHolder").html('unable to connect. please check to see your DOT.TUNES server is online.');
				}
		 	});
		
			
		}
		
		
		
			function DTUpdateTrack(DTID,PLID,TheTrackPos)
		    	{
				
					var DTIDLI = '#'+DTID;
					
			  		$('#SortFiles').prepend('<li id="'+DTID+'"><p>Downloading files... please wait<br /><img src="http://upl1nk.com/images/loadingAnimation.gif" style="width: 100%;" /></p></li>');
					$.post("/codebase/convertrss/dottunes-import-files.asp", { PID: DTID, PLID: PLID, Position: TheTrackPos } , function(PID){
						$.growlUI("Added Track!"); 
						//do ajax call to page but just get that div
						//make a common function
						$(DTIDLI).html('<li>added track!</li>');
		                DTUpdateRSS(DTID,PLID);
				 	});
				}
	
			function DTUpdateRSS(TheClickedEntryID,PLID)
				{
					
					
					$.growlUI("Updating Playlist - Please be patient!"); 
	                			
					$.post("/codebase/convertrss/dottunes-rss.asp", { PLID: PLID } , function(RawDTID){

						if (RawDTID == "completed"){
							CheckPlaylistSync();
						} 
						else 
						{
						var DTIDAry = RawDTID.split('-');
						var DTID = DTIDAry[0];
						var TheTrackPos = DTIDAry[1];

						DTUpdateTrack(DTID,PLID,TheTrackPos);
						}
				 	});
				
				}
		
		

			function UpdateRSS(TheClickedEntryID)
				{
					$.growlUI("Updating Playlist - Please be patient!"); 

					$.post("/codebase/convertrss/import-rss.asp", { ID: TheClickedEntryID } , function(RawDTID){

						if (RawDTID == "completed"){
							$.growlUI("Update Complete!"); 

						} 
						else 
						{
						var DTIDAry = RawDTID.split('-');
						var DTID = DTIDAry[0];
						var TheTrackPos = DTIDAry[1];
						alert(RawDTID);
						//DTUpdateTrack(DTID,PLID,TheTrackPos);
						}
				 	});

				}
		
		
		
		function FixUpAdminWindows() {
			
		//	$("#AdminScroll").css("height", ($(window).height() - 95) + "px");
			
				$("#accordion div").css("height", "270px");
				
				$("#accordionshared").css("height", "265px");
				$("#accordionshared div").css("height", "150px");
				
				
				$("#SortFilesLong").css("height", "auto");
				$("#SortPhotosLong").css("height", "auto");
				$("#AdminScroll").css("height", "auto");
				$(".jScrollPaneContainer").css("height", ($(window).height() - 70) + "px");
				$(".jScrollPaneTrack").css("height", ($(window).height() - 85) + "px");
				$("#outerwrapper").css("height", ($(window).height()) + "px");
			
			
		}
		
		
		function SetupJScrollStyler() {
			
			
			$('#AdminScroll, #SortFilesLong, #SortPlaylist, #twitterwidget, #PrevImgThumbDivToScroll, #viewalbumajax')
				.jScrollPane(
					{
						showArrows:true
						}
					);
					
		}
		
		
		function DeleteThisPostEntry() {
			confirm('Are you sure you want to delete this content?');
			$('#DeleteEntry').submit();
		}
		
	// JWPlayer callbacks

		function JWCallbackUPL1NK(obj) {
			//alert('state: ' + obj.state + ' file: ' + obj.file);
			alert('FOO');
		}

		function FileChosen(TheUserName, FileName)
		{
			var TheTotalURL = 'http://images.upl1nk.com/' + TheUserName + '/' + FileName;
		// fill the path - textbox and show a preview of the image
			 document.images['myImage'].src = TheTotalURL;
        	 document.AjaxForm.elements['ImageName'].value=FileName;		
		}
		
		
		function getWidthAndHeight() {

			var InsertPicWidth = this.width;
			
			var InsertPicWidthVar = InsertPicWidth + 'px';

			if (InsertPicWidth > 600){
					InsertPicWidthVar = '100%';
				};


			var FinalImageHTML = '<p style=\"text-align: center;\"><img  src=\"' + this.name + '\" style=\"width: ' + InsertPicWidthVar + ';\"></p>';
			var OriginalHTML = tinyMCE.activeEditor.getContent();
			tinyMCE.activeEditor.setContent(FinalImageHTML + OriginalHTML);


			return true;

		}
		
		
		
		function JButtons() {
				
			$("button, input:submit", "body").button();
			//	$(".check").button();
			$(".pltoolbar").buttonset();

		}
		
		function CSSSwapper() {
			
			$('#Mobile2Css').click(function() { 
					$('#TheMobileCSS').hide('blind'); 
					$('#TheCustomCSS').show('blind');

					return false;
			});
			
			$('#Css2Mobile').click(function() { 
					$('#TheCustomCSS').hide('blind');
					$('#TheMobileCSS').show('blind'); 

					return false;
			});
			
			
			
			
			$('.Header2Custom').click(function() { 
					$('#TheCustomHeader').show('blind');
					$('#TheMobileHeader').hide('blind');
					$('#TheEmailsHeader').hide('blind');

					return false;
			});
			
			$('.Header2Mobile').click(function() { 
					$('#TheCustomHeader').hide('blind');
					$('#TheMobileHeader').show('blind');
					$('#TheEmailsHeader').hide('blind');

					return false;
			});
			
			
			$('.Headers2Email').click(function() { 
					$('#TheCustomHeader').hide('blind');
					$('#TheMobileHeader').hide('blind');
					$('#TheEmailsHeader').show('blind');

					return false;
			});
			
			
			
			
			$('#Footer2Custom').click(function() { 
					$('#TheCustomFooter').show('blind');
					$('#TheEmailFooter').hide('blind'); 

					return false;
			});
			
			$('#Footer2Email').click(function() { 
					$('#TheCustomFooter').hide('blind');
					$('#TheEmailFooter').show('blind'); 

					return false;
			});
			
			
		}
		
		function TheTrackButtons() {
			
			$('#TheTrackInfoButton').click(function() { 
					$('#TheTrackInfo').show('fade');
					$('#TheTrackComments').hide('fade');
					$('#TheTrackRelated').hide('fade');

					return false;
			});
			
			$('#TheTrackCommentsButton').click(function() { 
					$('#TheTrackInfo').hide('fade');
					$('#TheTrackComments').show('fade');
					$('#TheTrackRelated').hide('fade');

					return false;
			});
			
			$('#TheTrackRelatedButton').click(function() { 
					$('#TheTrackInfo').hide('fade');
					$('#TheTrackComments').hide('fade');
					$('#TheTrackRelated').show('fade');

					return false;
			});
			
			
		}
		

		
	  function LoadWhatsPlaying() {
		var WhatsPlayingTimer = setInterval( WhatsPlaying, 5000);
		
			//disable whats playing when playlists are loaded
			$('#FilePlayerAjaxLoadPL')
				.click(function() {

						clearInterval(WhatsPlayingTimer);

						return false;
				});
		
	  }
		
	  function WhatsPlaying() {
		
		var WhichDB = (GetWhichDB());
				
		
		
		if (WhichDB == 3) {
			
			var TheUrl = '/codebase/convertrss/dottunes-history.asp?TheUserID=' + (GetUserID());
			
		} else if (WhichDB == 0) {
			
			var TheUrl = '/codebase/convertrss/dottunes-whatsplayingnow.asp?TheUserID=' + (GetUserID());
			
		}
		
		
		var WhatsPlayingDivIDVar = $('#WhatsPlayingDivID').html();

			$("#WhatsPlayingDivHelper").load(TheUrl, function(DTWPResponse){ 
				
				//alert(DTWPResponse + ' - ' + WhatsPlayingDivIDVar);

				var DTWPResponsePrefix = DTWPResponse.slice(0,6);
				

				if (DTWPResponsePrefix != 'msxml3') {

					if (WhatsPlayingDivIDVar != DTWPResponse) {

						if (DTWPResponse != "") {

							var OldID = $('#WhatsPlayingDivUPL1NKID').val();

							$('#WhatsPlayingDivID').html(DTWPResponse);
							
							var VarSyncingToggle = '1';
														
							$('#AreWeSyncing').html(VarSyncingToggle);
																					
							$.post("/codebase/convertrss/dottunes-sync-files.asp", { PID: DTWPResponse, WhichDB: WhichDB, TheUserID: (GetUserID()) } , function(UPL1NKID){

									if (OldID != "") {

										//DisplayTrackHistory(OldID);
										//update CSS style instead
									}

								$('#WhatsPlayingDivUPL1NKID').html(UPL1NKID);

								
								var TargetLocation = 'WhatsPlayingDiv';
								
								// double check to make sure this item isnt already there
								var FirstLIid = $('ul#SortFilesLong li:first').attr('id');
								var VarThisUPL1NKid = 'listItem_U_'+UPL1NKID;
																
								if (FirstLIid != VarThisUPL1NKid) {
									DisplayTrack(UPL1NKID,TargetLocation);
								}


						 	});

						}


					};
					
				};
					

				 });
		
	  }
	
	  function DisplayTrackOLD(UPL1NKID,TargetLocation) {
			var TheUrl = (GetSiteRoot()) + '/u-playlists/preview-'+UPL1NKID+' #trackData';
			
			$("#"+TargetLocation).load(TheUrl, function(DTWPResponse){});
			
	  }
	
	  function DisplayTrack(UPL1NKID,TargetLocation) {

			var TheUrl = (GetSiteRoot()) + '/u-playlists/previewsmall-'+UPL1NKID+' #trackData';

	  		$('#SortFilesLong').prepend('<li id="listItem_U_'+UPL1NKID+'"><p>Updating... please wait<br /><img src="http://upl1nk.com/images/loadingAnimation.gif" style="width: 100%;" /></p></li>');

			$('#listItem_U_'+UPL1NKID).load(TheUrl, function(DTWPResponse){

				SetupClickSortFilesLongLi(0);
				
				
			});

	  }
	
	  function DisplayTrackHistory(UPL1NKID) {
			var TheUrl = (GetSiteRoot()) + '/u-playlists/previewsmall-'+UPL1NKID+' #trackData';
			
	  		$('#SortFilesLong').prepend('<li id="listItem_'+UPL1NKID+'"><p>Updating... please wait<br /><img src="http://upl1nk.com/images/loadingAnimation.gif" style="width: 100%;" /></p></li>');

			$('#listItem_'+UPL1NKID).load(TheUrl, function(DTWPResponse){});

	  }
	
	
	
		var tinyMCEmode = true;
	
	  function toggleEditorMode(editor, link) { 

	      if(tinyMCEmode) { 
	        tinyMCE.execCommand( 'mceRemoveControl', false, editor );
	        tinyMCEmode = false; 
	        link.innerHTML = 'Back to PREVIEW';

	      } else { 
	        tinyMCE.execCommand( 'mceAddControl', true, editor );
	        tinyMCEmode = true; 
	        link.innerHTML = 'Edit HTML';

	      } 
			return false;

	  }
	
	var newwindow;
	
	function poptastic(url)
	{
		newwindow=window.open(url,'name','height=10,width=10,resizable=no,scrollbars=no,toolbar=no,status=no');
	}
	
	
	
	   function RunTheLogin() {
		
		
			$('#TheLoginForm').ajaxForm(function(data) {
			    if (data==1){
					$('#LoginMessages').html("Error. Please try again"); 
					
			    }
			    else{
					$('#LoginMessages').html("Logging in..."); 
					//poptastic('/login/cookieauth/crosslogin');
					
					location.reload();
					//window.location=(GetSiteRoot())+(data); 
			    }
			});
		
		
		
		}
		
		function RemindPassword() {
			
			
			$('#ResetPassword').ajaxForm(function(data) {
			    if (data==1){

					$('#LoginMessages').html("Your Password has been reset.  Please check your email."); 
			
					RunConfirmModal(3);
			    }
			    else if (data==2){
				
					$('#LoginMessages').html("Please check your username and try again"); 
					
			    }
			});
			
		}
		
		
		function RunConfirmModal(TheModeVar) {
			
			var TheUrl = '/login/confirm #ContentEditor';
			var TheDivToLoadInto = '';
			if (TheModeVar == 1) {
				
				TheDivToLoadInto = '#UPL1NKContactForm';
				
			} else {
				
				TheDivToLoadInto = '#ThisLoginForm';
				
				$.blockUI({ 
					message: $(TheDivToLoadInto), 
					css: { 
				            top: '100px',
							width: '400px',
						    border: '3px',
				            padding: '15px', 
				            backgroundColor: '#fff', 
				            '-webkit-border-radius': '10px', 
				            '-moz-border-radius': '10px', 
				            opacity: 1.0, 
				            color: '#000' 
				        }
				});
			}
			
			
			$(TheDivToLoadInto).html('<div class="loaderanim8"></div>');
			$(TheDivToLoadInto).load(TheUrl, function(){
				
				JButtons();
				RunTheConfirmation(TheModeVar);				
				
					$('#LoginCancelButton').click(function(){
						if (TheModeVar == 3) { $.unblockUI(); }
						$(TheDivToLoadInto).html('');
					});
				
			});
			
			
			
		}
		
		
		function RunLoginModal(LoginMethod) {
			
			var TheUrl = '/login/form/ #ContentEditor';
			
			
			$('#ThisLoginForm').html('<div class="loaderanim8"></div>');
			
			
			$("#ThisLoginForm").load(TheUrl, function(){
				
				
				
				if (LoginMethod==2) {
					$('#LoginMessages').html("Your email address has already been activated.<br />Please Sign In to post this comment.<br /><br />"); 	
				}
				
				JButtons();
				RunTheLogin();
				
				CreateAccountSetup();
				RunIForgot();
						
		        
					$('#LoginCancelButton').click(function(){
						$.unblockUI();
						$('#ThisLoginForm').html('');
					});
					
				
			});
			
			$.blockUI({ 
				message: $('#ThisLoginForm'), 
				css: { 
			            top: '100px',
						width: '400px',
					    border: '3px',
			            padding: '15px', 
			            backgroundColor: '#fff', 
			            '-webkit-border-radius': '10px', 
			            '-moz-border-radius': '10px', 
			            opacity: 1.0, 
			            color: '#000' 
			        }
			});
			
			
		}
		
		function RunForgotLogin() {
			
			var TheUrl = '/login/forgot #ContentEditor';
			
			$.blockUI({ 
				message: $('#ThisLoginForm'), 
				css: { 
			            top: '100px',
			            width: '400px',
			            border: '3px', 
			            padding: '15px', 
			            backgroundColor: '#fff', 
			            '-webkit-border-radius': '10px', 
			            '-moz-border-radius': '10px', 
			            opacity: 1.0, 
			            color: '#000' 
			        }
			}); 
			$('#ThisLoginForm').html('<div class="loaderanim8"></div>');
			$("#ThisLoginForm").load(TheUrl, function(){
				
				JButtons();
				RemindPassword();
				
		        
					$('#LoginCancelButton').click(function(){
						$.unblockUI();
						$('#ThisLoginForm').html('');
					});
				
			});
			
			
			
		}
		
		function RunCreateAccount() {
			
			var TheUrl = '/login/signup #ContentEditor';
			
			$.blockUI({ 
				message: $('#ThisLoginForm'), 
				css: { 
			            top: '100px',
			            width: '400px',
			            border: '3px', 
			            padding: '15px', 
			            backgroundColor: '#fff', 
			            '-webkit-border-radius': '10px', 
			            '-moz-border-radius': '10px', 
			            opacity: 1.0, 
			            color: '#000' 
			        }
			}); 
			$('#ThisLoginForm').html('<div class="loaderanim8"></div>');
			$("#ThisLoginForm").load(TheUrl, function(){
				
				JButtons();
				RunTheCreate();
						   
					$('#LoginCancelButton').click(function(){
						$.unblockUI();
						$('#ThisLoginForm').html('');
					});
				
			});
			
			
			
		}
		
		function CreateAccountSetup() {
			
			
			$('#CreateAccountPages').click(function(){ 
						RunCreateAccount();
						return false;
				});
				
			$('#CreateAccount').click(function(){ 
						RunCreateAccount();
						return false;
				});
				
			$('#ConfirmAccount').click(function(){ 
						RunConfirmModal(3);
						return false;
				});
		}
		
		function RunTheCreate() {
			
			
	  		$('#CreateUserAccount').ajaxForm(function(data) {
		
	            if (data==77){
	                window.location=(GetSiteRoot()) + "?from=REDIRECTiMPulse";
	            }
	            else if (data==2){
					$('#LoginMessages').html("Username is taken. Choose another"); 
	            }
				
	            else if (data==3){
					$('#LoginMessages').html("Please enter an email address!"); 
	            }
				
	            else if (data==4){
					$('#LoginMessages').html("Email address needs to be formatted properly!");
	            }
				
	            else if (data==5){
					$('#LoginMessages').html("Passwords do not match!");
	            }
				
	            else if (data==6){
					$('#LoginMessages').html("Your email address is already in use! Please login.");
	            }
	
	            else if (data==7){
					$('#LoginMessages').html("You need to have at least 5 characters in your username."); 
	            }
				else {
					
					RunConfirmModal(3);
					
	            }
	        });
			
		}
		
		
		function RunTheConfirmation(TheMode) {
			
			
	  		$('#AuthConfirm').ajaxForm(function(data) {
		
	            if (data==1){
					$('#LoginMessages').html("Invalid authentication code.  Check the email and try again."); 

	            }
	            else if (data==2){
					$('#LoginMessages').html("Your account has been authenticated. Logging you in..."); 
					
					//redirect to user home if new account or content they were trying to access
					if (TheMode==1){
						$.unblockUI();
						
						$('#ThisLoginForm').html('');
						
						$('#UPL1NKContactForm')[0].reset();
						$('#UPL1NKContactForm').html('');

						if ((GetUserName())=='tecspot') {
														
							// first we need to get the ids from the system that have been created.		
							
							$('#UPL1NKContactForm').html('<strong>Thank you for your inquiry. A Tecspot Professional will respond soon!</strong>');
							
					
						} else {
							
							$('#UPL1NKContactForm').html('<strong>Your comment was recieved. It will be approved manually before appearing on the site.</strong>');
							
						}
						
		            } else {
			
						// if gametraining subscription then do a paypal form post subscription
						
						if ((GetUserName())=='gametraining') {
														
							// first we need to get the ids from the system that have been created.		
							
							GetNewContactIDString();					
							
					
						} else {
							
							location.reload();
							
						}
				
					}
					
	            }
				
	            else if (data==3){
					$('#LoginMessages').html("Your new password is now active.  Logging you in..."); 
					
					
					location.reload();
	            }
				
				
				else {
					
					$('#LoginMessages').html(data); 
					
	            }
	        });
			
		}
		
		
		function callIframe(ThisiFrameDomain, ThisiFrameRefDomain) {
			
			var ThisiFrameURL = "/login/cookieauth/?ref=" + ThisiFrameRefDomain;
						
			//var ThisiFrameURL = "/login/cookieauth/load/";
						
						
		    $('body').append('<iframe id="UPL1NKauth" style="display:none;"></iframe>');

		    $('#UPL1NKauth').attr('src', ThisiFrameURL);

		    $('#UPL1NKauth').load(function() 
		    {
                CheckFrameAuth();
			
		    });
		}
		
		function CheckFrameAuth() {
			
			var AuthCookie = $('#UPL1NKauth').contents().find('#loaded').html();
			
				if (AuthCookie=="authorized") {
					location.reload();
				}
			
		}
		
		
		
		function SelectAllContacts() {
			
			$('#SelectAllContacts').click(function(){ 
		     	   $('.checkselector').attr('checked', true);

			});
			
		}
		
		function NewListNamer() {
			
			
			$('#FileSelector').change(function(){ 

				if ($(this).val() == 'addnew') 
				{
			 	   $('#NewPlaylistNameDiv').show(); 
				}
			    else 
				{
			 	   $('#NewPlaylistNameDiv').hide(); 
				}

			});
		}
		
		function ContactMoverFunk() {
			
			
		    var options = { 
		        target:        '#sortableinfo',   // target element(s) to be updated with server response 
		        beforeSubmit:  showRequest,  // pre-submit callback 
		        success:       showResponse  // post-submit callback 
		    }; 

		    $('#ContactMover').ajaxForm(options);
			
			
		}
		
		function ListLoaderFunk(TheClickedEntryID) {
			
				var TheUrl = (GetSiteRoot()) + '/mycontacts/list-' + TheClickedEntryID + ' #ContactsWrapContent';
				$('#ContactsWrapHolder').html('<div class="loaderanim8"></div>');
				$("#ContactsWrapHolder").load(TheUrl, function(){ 
							JButtons();
							SelectAllContacts();
							NewListNamer();	
							ContactMoverFunk();			

					});
			
		}
		
		function ScrollSliderDiv(WhichWay) {
			
			var OldScrollPos = $('#scrollpos').val();
			
			OldScrollPos = parseInt(OldScrollPos);
			
			var NewScrollPos = 1;
			
			if (WhichWay == 'P') {
				
				NewScrollPos = (OldScrollPos - 1);
				
					if (NewScrollPos < 1) 
						{
							NewScrollPos = 1;
						}
				
			} else {
				
				NewScrollPos = (OldScrollPos + 1);
				
			}
			
			var VarScrollToDiv = "#slider-" + NewScrollPos;
			
			
			$("#viewalbumslider").scrollTo(VarScrollToDiv,800);
			
			
			$('#scrollpos').val(NewScrollPos);
			
			
		}
		
		function GetTheFile(thisfilename) {
			var TheUrl = "/codebase/downloads/process/?q=1&u=" + (GetUserName()) + "&file=" + thisfilename;
			
			window.location=TheUrl;
			
			
		}
		
		
		function CheckTheCouponCodeGT(data) {
			
			
				$.post("/codebase/contact/contact-checkcouponcode.asp", { ID: data } , function(newdata){
												
						if (newdata==3){
							
							$('#GTCouponError').html('Invalid Coupon ID!');
							$('#GTCouponButton').css('display', 'none');
							
						} else {
							
							$('#GTCouponError').html('');
							$('#GTCouponButton').css('display', 'block');
							
						}
						
				 });
			
		}
		
		function CheckThisUserEmail(data) {
			
			
				$.post("/codebase/contact/contact-checkusername.asp", { ID: data } , function(newdata){
												
						if (newdata>=10){
							$('.commtoggle').toggle('blind'); 
							$('#commloginuser').val(3);
							
						}
						
				 });
			
		}
		
		function SetupContactForms() {
			
			
			$(".commextra").attr("disabled", "disabled");

			// validate signup form on keyup and submit
			$("#UPL1NKContactForm").validate({

				success: function() {
					$(".commextra").removeAttr("disabled");
					
						var commloginuser = $('#commloginuser').val();

						if (commloginuser==1) {
							var TheContactEmail = $('#UContactEmail').val();

							CheckThisUserEmail(TheContactEmail);	
						}		
				},

				rules: {
					ContactEmail: {
						required: true,
						email: true
					}
				},
				messages: {
					ContactEmail: "Please enter a valid email address"
				}
			});
			
			
			
			// validate gametraining download form on keyup and submit
			$("#UPL1NKGTForm").validate({

				success: function() {
					
						var couponidvar = $('#couponid').val();

						if (couponidvar != '') {
							
							CheckTheCouponCodeGT(couponidvar);	
							
						}			
						
				},

				rules: {
					email: {
						required: true,
						email: true
					},
					
					couponid: {
						required: true
					}
				},
				messages: {
					email: "Please enter a valid email address",
					couponid: "Please enter a coupon code"
				}
			});
			
		}
		
		function RunIForgot() {
			
			
			$('#IForgot').click(function(){ 
						RunForgotLogin();
						return false;
				});
			
		}
		
		function ValidatorSetup() {
			
				
				$.validator.setDefaults({
					submitHandler: function(form) { 



						UPL1NKContactFormFunk();



						 }
				});
			
		}
		
		
		$.validator.setDefaults({
			submitHandler: function(form) { 



				UPL1NKContactFormFunk();
				UPL1NKGTFormFunk();


				 }
		});
		
		
		
		
		function UPL1NKContactFormFunk() {
			
			
	  		$('#UPL1NKContactForm').ajaxSubmit(function(data) {
		
		

	            if (data>=10){
					$('#UPL1NKContactForm')[0].reset();
					$('#UPL1NKContactForm').html('');

					$('#UPL1NKContactForm').html('<strong>Your comment was recieved. It will be approved manually before appearing on the site.</strong>');

	            }	
			    else if (data==1) {
							RunConfirmModal(1);
			            }
			    else if (data==2) {

					//toggle login options
					//$('.commtoggle').toggle('blind'); 


			            }
			    else if (data==3) {
							$.growlUI("Please enter an email address"); 

			            }
			    else if (data==4) {
							$.growlUI("Please enter a valid email address"); 
			            }
			    else if (data==5) {
							$.growlUI("HTML is not allowed in comments. Please edit your comment and try again."); 
			            }

			    else if (data==7) {
							$('#compassmsgs').html('Invalid Password please try again');

			            }
	            else {
					$.growlUI(data); 

	            }
	        });


			
		}
		
		
		
		function UPL1NKGTFormFunk() {
			
			
	  		$('#UPL1NKGTForm').ajaxSubmit(function(data) {
		
		
					$('#UPL1NKGTForm')[0].reset();
					$('#UPL1NKGTForm').html('');

					$('#UPL1NKGTForm').html('<strong>Check your email for the download link!</strong>');


	        });


			
		}
		
		function LoadTheseThumbs() {

			$('#ThumbLoader')
				.click(function() {

					var TheUrl = (GetSiteRoot()) + '/u-photos/allthumbs #thumbsholder';
					$('#PrevImgThumbDivToScroll').html('<div class="loaderanim8"></div>');
					$("#PrevImgThumbDivToScroll").load(TheUrl, function(){ 

					});


						return false;
				});		

			
		}
		
		function LoadDTAjax() {
			
			
				var TheUrl = (GetSiteRoot()) + '/codebase/convertrss/dottunes-rss-playlists-fileplayer.asp?TheUserID=' + (GetUserID());
				$('#SortFilesLong').html('<div class="loaderanim8"></div>');
				$('#FilePlayerAjaxPLNAME').html('');
				$("#SortFilesLong").load(TheUrl, function(){ 
					SetupJScrollStyler();

					 });
		
					return false;
					
		}
		
		function AddPageMainFunk() {
						
			$('#SiteAddPageNav')
				.click(function() {

					var TheUrl = (GetSiteRoot()) + '/addpage #ContentEditor';
					$('#AppearanceModalDiv').html('<div class="loaderanim8"></div>');
					$("#AppearanceModalDiv").load(TheUrl, function(){ 
							addButtonsDefault();
						 }).dialog('open');

						return false;
				});
					
		}
		
		
		function SiteDesignerFunk() {
			
					var TheUrl = (GetSiteRoot()) + '/admin/appearance #ContentEditor';
					$('#AppearanceModalDiv').html('<div class="loaderanim8"></div>');
					$("#AppearanceModalDiv").load(TheUrl, function(){ 
							addDesignerTabs();
							AddPageMainFunk();
							
							setTimeout('addMCE()',100);

							CSSSwapper();
							PEPS.rollover.init();
							
								$('#picker').farbtastic('body, #color');


								$('#picker-titlefontcolor').farbtastic(function(color){
								   $('h3').css('color', color);
								   $('#titlefontexample').css('color', color);
								   $('#titlefontcolor').val(color);

								});


								$('#titlefont').change(function(){ 
									$('h3').css('font-family', $(this).val());
								});

								$('#titlefontsize').change(function(){ 
									var VarTheFontSize = $(this).val()+"px";
									$('h3').css('font-size', VarTheFontSize);
								});

								$('#titlefontcolor').change(function(){ 
									$('h3').css('color', $(this).val());
								});

								$('#h2font').change(function(){ 
									$('h2').css('font-family', $(this).val());
								});

								$('#h2fontsize').change(function(){ 
									var VarTheFontSize = $(this).val()+"px";
									$('h2').css('font-size', VarTheFontSize);
								});

								$('#h2fontcolor').change(function(){ 
									$('h2').css('color', $(this).val());
								});

								$('#bodyfont').change(function(){ 
									$('body').css('font-family', $(this).val());
									$('p').css('font-family', $(this).val());
								});

								$('#bodyfontsize').change(function(){ 
									var VarTheFontSize = $(this).val()+"px";
									$('body').css('font-size', VarTheFontSize);
									$('p').css('font-size', VarTheFontSize);
								});

								$('#bodyfontcolor').change(function(){ 
									$('body').css('color', $(this).val());
									$('p').css('color', $(this).val());
								});
								
								$('#usernavfont').change(function(){ 
									$('#usernav li a').css('font-family', $(this).val());
								});

								$('#usernavfontsize').change(function(){ 
									var VarTheFontSize = $(this).val()+"px";
									$('#usernav li a').css('font-size', VarTheFontSize);
								});

								$('#usernavfontcolor').change(function(){ 
									$('#usernav li a').css('color', $(this).val());
								});
							
								$('#usernavfontweight').change(function(){ 
									
									var VarTheFontWeightChecked = $(this).val();
									
									var VarTheFontWeightCheckedVal = "";
									
									if ($('#usernavfontweight').is(':checked')) {
										VarTheFontWeightCheckedVal = "bold";
									} else {
										VarTheFontWeightCheckedVal = "normal";
									}
									
									$('#usernav li a').css('font-weight', VarTheFontWeightCheckedVal);
								});
							
							
						 }).dialog('open');

					
		}
		
		function LoadEditFileButton() {
			
			$('.EditFileButton')
				.click(function() {
					var TheClickedEntryID = this.id;
					var TheUrl = (GetSiteRoot()) + '/'+ (GetPageName()) +'/edit-' + TheClickedEntryID + ' #ContentEditor';
					$('#ModalDiv').html('<div class="loaderanim8"></div>');
					$("#ModalDiv").load(TheUrl, function(){ 
						addEditTabs();
						setTimeout('addButtonsEditor()',100);
						setTimeout('addMCE()',100);
					}).dialog('open');

						return false;
				});
		}
		
		function RunThePlaylistLoad(data) {
			
			
			if (data == 1) {
				
				var TheUrl = (GetSiteRoot()) + '/u-playlists/plajxlib #FileContainer';
				
			} else {
				
				var TheUrl = (GetSiteRoot()) + '/u-playlists/plajx #FileContainer';
				
			}
			
			
			
			$('#SortFilesLong').html('<div class="loaderanim8"></div>');
			$('#FilePlayerAjaxPLNAME').html('');
			$("#SortFilesLong").load(TheUrl, function(){ 
				
				//append dt playlists 
				
				SetupClickSortFilesLongLi(1);
				
				
				if ((GetUserID()) != 59145) {
				
				var TheUrl3 = '/codebase/convertrss/dottunes-rss-playlists-fileplayer.asp?TheUserID=' + (GetUserID()) + ' #FileContainer';
				$("#SortFilesInnerDT").load(TheUrl3, function(){
					
						SetupJScrollStyler();
						
							if ((GetPageName()) == 'u-playlists') {

								FixUpAdminWindows();

							}
					
							SetupClickSortFilesLongLi(1);
				});
				
		    	}
				
				
					$('#WhatsPlayingLoader').click(function(){ 
						$('#SortFilesLong').html('<div class="loaderanim8"></div>');
						$('#FilePlayerAjaxPLNAME').html('/ Whats Playing');
						var TheUrl3 = '/codebase/convertrss/displayhistory.asp?UserID=' + (GetUserID()) + '&username=' + (GetUserName()) + ' #SortFilesInner';
						$("#SortFilesLong").load(TheUrl3, function(){});
					 
				     	   LoadWhatsPlaying();
				
							if ((GetPageName()) == 'u-playlists') {

								FixUpAdminWindows();

							}

							SetupClickSortFilesLongLi(0);
							return false;
					});
					
					

				$('#LibraryLoader')
					.click(function() {

							RunTheLibraryLoad();

							return false;
					});
					
					

				 });
		}
		
		
		
		function RunTheLibraryLoad() {
			

				var TheUrl = (GetSiteRoot()) + '/u-playlists #AdminScrollContent';
				
				var TheDivToLoadInto = '#AdminScroll';


	  		$(TheDivToLoadInto).html('<div class="loaderanim8"></div>');

			$(TheDivToLoadInto).load(TheUrl, function(){

				LoadEditFileButton();
				
				
				JButtons();
				
				SetupJScrollStyler();
													
				FixUpAdminWindows();
				
				SetupUploader();
				
			});
		}
		
		function SetupGameUploader() {

				var TheButtnImg = '/images/upload-tracks-sm.png';
				var TheButtnTxt = 'Upload Your Game';
				var TheFileDesc = 'Unity Files';
				var TheFileExtn = '*.unity3d;';
				var TheFinish = (GetSiteRoot()) + '/arcade/';
				var TheMultiOpt = 'false';
				var TheScriptDt = (GetUserName()) + '87secret78LIBRARY87secret78' + (GetUserID());
				var TheButtonW = '93';
				var TheButtonH = '20';


			$('#uploadifier-gtgames').fileUpload({
				'uploader':'/plugins/uploadify/uploader.swf',
				'script':'/codebase/upload/',
				'cancelImg':'/images/cancel.png',
				'buttonText':TheButtnTxt,
				'scriptData': {'session_name': TheScriptDt},
				'buttonImg':TheButtnImg,
				'width':TheButtonW,
				'height':TheButtonH,
				'rollover':true,
				'wmode':'transparent',
				'fileDesc': TheFileDesc,
				'fileExt': TheFileExtn, 
				'multi':TheMultiOpt,
				'queueID': 'fileQueue',
				'auto':true,
				'onComplete': function(event, queueID, fileObj, response, data) {

					var NewFileName = fileObj.name;
				
					var NewFileNameReplaced = NewFileName.replace(/ /g,'-');
					var NewFileNameReplaced = NewFileNameReplaced.replace(/'/g,'');
					

					document.AjaxForm.elements['GameFileName'].value=NewFileNameReplaced;		

						
					}
			});

		}
		
		function SetupUploader() {

			if ((GetPageName()) == 'u-playlists') {

				var TheButtnImg = '/images/upload-tracks-sm.png';
				var TheButtnTxt = 'Upload Files';
				var TheFileDesc = 'Media Files';
				var TheFileExtn = '*.mp3;*.mp4;*.flv;';
				var TheFinish = (GetSiteRoot()) + '/u-playlists/';
				var TheMultiOpt = 'false';
				var TheScriptDt = (GetUserName()) + '87secret78LIBRARY87secret78' + (GetUserID());
				var TheButtonW = '93';
				var TheButtonH = '20';

			}  else if ((GetPageName()) == 'u-items') {

				var TheButtnImg = '/images/upload-tracks-sm.png';
				var TheButtnTxt = 'Upload Zip Files';
				var TheFileDesc = 'Zip Files';
				var TheFileExtn = '*.zip';
				var TheFinish = (GetSiteRoot()) + '/downloads/';
				var TheMultiOpt = 'false';
				var TheScriptDt = (GetUserName()) + '87secret78DOWNLOADS87secret78' + (GetUserID());
				var TheButtonW = '93';
				var TheButtonH = '20';

			}  else if ((GetPageName()) == 'customer-portal') {

				var TheButtnImg = '/images/upload-tracks-sm.png';
				var TheButtnTxt = 'Upload Your File';
				var TheFileDesc = 'Document Files';
				var TheFileExtn = '*.xls;*.xlsx;*.docx;*.doc;*.pdf;*.zip;';
				var TheMultiOpt = 'false';
				var TheScriptDt = (GetUserName()) + '87secret78DOWNLOADS87secret78' + (GetUserID());
				var TheButtonW = '93';
				var TheButtonH = '20';

			}  else if ((GetPageName()) == 'downloads') {

				var TheButtnImg = '/images/upload-tracks-sm.png';
				var TheButtnTxt = 'Upload Zip Files';
				var TheFileDesc = 'Zip Files';
				var TheFileExtn = '*.zip';
				var TheFinish = (GetSiteRoot()) + '/downloads/';
				var TheMultiOpt = 'false';
				var TheScriptDt = (GetUserName()) + '87secret78DOWNLOADS87secret78' + (GetUserID());
				var TheButtonW = '93';
				var TheButtonH = '20';

			} else if ((GetPageName()) == 'u-photos') {

				var TheButtnImg = '/images/upload-tracks-sm.png';
				var TheButtnTxt = 'Upload Photos';
				var TheFileDesc = 'Image Files';
				var TheFileExtn = '*.jpg;*.png;';
				var TheFinish = (GetSiteRoot()) + '/u-photos/' + (GetThisVarEntryName());
				var TheMultiOpt = 'true';
				var TheScriptDt = (GetUserName()) + '87secret78' + (GetThisAlbumID()) + '87secret78' + (GetUserID());
				var TheButtonW = '93';
				var TheButtonH = '20';
				
			} else 	 {

				var TheButtnImg = '/images/upload-tracks-sm.png';
				var TheButtnTxt = 'Upload Photos';
				var TheFileDesc = 'Image Files';
				var TheFileExtn = '*.jpg;*.png;';
				var TheMultiOpt = 'false';
				var TheScriptDt = (GetUserName()) + '87secret78' + (GetPageImagesID()) + '87secret78' + (GetUserID());
				var TheButtonW = '93';
				var TheButtonH = '20';
			}



			$('#uploadifier').fileUpload({
				'uploader':'/plugins/uploadify/uploader.swf',
				'script':'/codebase/upload/',
				'cancelImg':'/images/cancel.png',
				'buttonText':TheButtnTxt,
				'scriptData': {'session_name': TheScriptDt},
				'buttonImg':TheButtnImg,
				'width':TheButtonW,
				'height':TheButtonH,
				'rollover':true,
				'wmode':'transparent',
				'fileDesc': TheFileDesc,
				'fileExt': TheFileExtn, 
				'multi':TheMultiOpt,
				'queueID': 'fileQueue',
				'auto':true,
				'onComplete': function(event, queueID, fileObj, response, data) {
					
								var NewFileName = fileObj.name;
							
								var NewFileNameReplaced = NewFileName.replace(/ /g,'-');
								var NewFileNameReplaced = NewFileNameReplaced.replace(/'/g,'');
								
								var VarImagePath = 'http://images.upl1nk.com/' + (GetUserName()) + '/' + NewFileNameReplaced;
								var VarThumbPath = '/media/images/' + (GetUserName()) + '/sm_' + NewFileNameReplaced;
								
								
							if ((GetPageName()) == 'u-playlists') {
							    RunTheLibraryLoad();
							} else if ((GetPageName()) == 'u-photos') {
																
								$('#SortPhotos').prepend('<li id="listItem_'+NewFileName+'"><img src="'+VarThumbPath+'"></li>');
						  		
								//window.location=TheFinish;
							  	
							} else if ((GetPageName()) == 'customer-portal') {
								$('#FileNameUploader').html(NewFileNameReplaced);
								$("#attachment_name").val(NewFileNameReplaced);
								
								
							} else if ((GetPageName()) == 'downloads') {
								window.location=TheFinish;
								
							} else {
													
							


								document.images['myImage'].src = VarThumbPath;

								document.AjaxForm.elements['ImageName'].value=NewFileNameReplaced;		

								if ((GetPageName()) == 'arcade') {

								} else {
										
									var myImage = new Image();
									myImage.name = VarImagePath;
									myImage.onload = getWidthAndHeight;

									myImage.src = VarImagePath;
								}
							}
					
							
					
					}
			});

		}

		
		
		function CreateThisPlayer(VarAutoStart,VarFileName,VarMediaHeight) {
		
		    jwplayer("playercontainer").setup({
	        	autostart: VarAutoStart,
		        flashplayer: "/mediaplayer-5.7/player.swf",
		        file: VarFileName,
		        height: VarMediaHeight,
		        width: '100%',
				controlbar: "bottom"
		    });
		
		}
		
		function CheckTheTrackHash() {
			
				var hash = window.location.hash;
				
				if (hash.length > 2) {
					
					var TrackHash = hash.replace('#','');
					
					var VarTRArray = TrackHash.split("-");

					var PlayTrackSourceID = VarTRArray[0];
					
					if (PlayTrackSourceID == 'yt') {
						
					} else if (PlayTrackSourceID == 'dt') {
						
					} else {
						
						TrackHash = 'u-' + TrackHash;
						
					}
					
					PlayTheFile(TrackHash);
				
				
				}
				
		}
		
		function ShareYouTube(VarSearchText) {
			
			
			var TheSharerURL = "http://www.youtube.com/results?search_query=" + VarSearchText;
			
  		    newwindow=window.open(TheSharerURL);
			
			
		}
		
		function ShareItunes(VarSearchText) {
			
			var TheSharerURL = "itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/search?WOURLEncoding=ISO8859_1&lang=1&output=lm&country=US&term=" + VarSearchText;
			
  		    newwindow=window.open(TheSharerURL);
			
			
		}
		
		function ShareBeatport(VarSearchText) {
			
			var TheSharerURL = "http://www.beatport.com/search?query=" + VarSearchText;
			
  		    newwindow=window.open(TheSharerURL);
			
			
		}
		
		
		
		function ShareTweet(data,tweetdescription) {
			
			
			var SharePageName = (GetPageName());
			
			if (SharePageName == "home") {
				
				SharePageName = "";
			}
			
			var TheUrl = "http%3A%2F%2F" + window.location.hostname +  (GetSiteRoot()) + '%2F'+ SharePageName  + data;
			
			var TheSharerURL = "http://twitter.com/home?status=" + tweetdescription + " " +  TheUrl;
			
			var features = "height=300,width=700,scrollTo,resizable=1,scrollbars=1,location=1";
  		    newwindow=window.open(TheSharerURL, 'Popup', features);
			
			
		}
		
		function ShareFB(data,fbdescription) {
			
			var SharePageName = (GetPageName());
			
			if (SharePageName == "home") {
				
				SharePageName = "";
			}
			
			var TheUrl = "p%5Burl%5D=http%3A%2F%2F" + window.location.hostname + (GetSiteRoot()) + '%2F'+ SharePageName + data + fbdescription;
			
			var TheSharerURL = "http://www.facebook.com/sharer/sharer.php?s=100&" + TheUrl;
			
			var features = "height=400,width=700,scrollTo,resizable=1,scrollbars=1,location=1";
  		    newwindow=window.open(TheSharerURL, 'Popup', features);
			
		}
		
		function FancyBoxes() {
			
			
							$("a[rel=fancybox]").fancybox({

									'width'				: '95%',
									'height'			: '95%',
									'padding'			: 0,
									'margin'			: 0,
								'transitionIn'		: 'none',
								'transitionOut'		: 'none',
								'titlePosition' 	: 'inside',
								'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
									return '<span>' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
								}
							});


							$("a[rel=fancyframe]").fancybox({
								'width'				: '95%',
								'height'			: '95%',
								'autoScale'			: false,
								'transitionIn'		: 'none',
								'transitionOut'		: 'none',
								'showNavArrows'		: false,
								'type'				: 'iframe'
							});

							$("a[rel=fancyframefull]").fancybox({
								'onComplete' : function() {$("#fancybox-wrap").unbind('mousewheel.fb');} ,
								'width'				: '95%',
								'height'			: '95%',
								'padding'			: 0,
								'margin'			: 0,
								'showCloseButton'	: false,
								'autoScale'			: false,
								'transitionIn'		: 'elastic',
								'transitionOut'		: 'elastic',
								'showNavArrows'		: false,
								'centerOnScroll'	: true,

								'type'				: 'iframe'
							});
							

							$("a[rel=gtarcades]").fancybox({
								'onComplete' : function() {$("#fancybox-wrap").unbind('mousewheel.fb');} ,
								'width'				: 980,
								'height'			: 620,
								'padding'			: 0,
								'margin'			: 0,
								'showCloseButton'	: false,
								'autoScale'			: false,
								'transitionIn'		: 'elastic',
								'transitionOut'		: 'elastic',
								'showNavArrows'		: false,
								'centerOnScroll'	: true,

								'type'				: 'iframe'
							});
			
							$("#LaunchEmailShare").fancybox({
								'onComplete' : function() {
									$("#fancybox-wrap").unbind('mousewheel.fb');
									SetupEmailShareForm();
									} ,
									
								'padding'			: 10,
								'margin'			: 0,
								'showCloseButton'	: false,
								'autoScale'			: false,
								'transitionIn'		: 'elastic',
								'transitionOut'		: 'elastic',
								'showNavArrows'		: false,
								'centerOnScroll'	: true								
							});
							
							
					
							
							

		}
		
		function LaunchCart() {
			
					$.fancybox({
						'onComplete' : function() {
							$("#fancybox-wrap").unbind('mousewheel.fb');
							} ,
						'width'				: 500,
						'height'			: 300,
						'padding'			: 10,
						'margin'			: 0,
						'showCloseButton'	: false,
						'autoScale'			: false,
						'transitionIn'		: 'elastic',
						'transitionOut'		: 'elastic',
						'showNavArrows'		: false,
						'centerOnScroll'	: true,
						'type'				: 'iframe',
						'href'				: '/admin/checkout'

					});
			
		}
		
		
		
		function SetupEmailShareForm() {
			
			
			$('#EmailTrigger').click(function(){ 
				
				$('#ShareByEmailMsg').html('Preparing to send your list, please wait!<br /><div class="loaderanim8"></div>');


				var VarThisEntryID = $("#TheEmailShareID").val();
				var VarThisGoingTo = $("#fgoingto").val();
				var VarThisSendEmail = $("#SendEmail").val();
								
				$('#ShareByEmailForm').css("display","none");
				$('#EmailTriggerDiv').css("display","none");

				$.post("/codebase/edit/pages/sendentry-action.asp", { ID: VarThisEntryID,fgoingto: VarThisGoingTo,SendEmail: VarThisSendEmail} , function(newdata){
						$('#ShareByEmailMsg').html(newdata);

				 });
			});
			

		}
		
		function GoGetTheFile() {
			
			
			$('#GetThisFile')
				.click(function() {

					var thisfilename = $('#TheDownloadFilename').val();
					GetTheFile(thisfilename);

						return false;
				});		

			
		}
		
		
		function WhichItemType() {

				$('#ItemType').change(function(){ 
					CheckTheItemType($(this).val());
				});

		}
		
		function CheckTheItemType(data) {
			
		    	if (data == '4') 
				{
		     	   $('#subscriptionlevel').show();
				   $('#downloadfilelist').hide();
				   $('#invoicedate').hide();
				   $('#productfieldlist').hide();
				}
				else if (data == '1') 
				{
		     	   $('#subscriptionlevel').hide();
				   $('#downloadfilelist').show();
				   $('#invoicedate').hide();
				   $('#productfieldlist').hide();
				}
				else if (data == '2') 
				{
		     	   $('#subscriptionlevel').hide();
				   $('#downloadfilelist').hide();
				   $('#invoicedate').hide();
				   $('#productfieldlist').show();
				}
			    else 
				{
			       $('#subscriptionlevel').hide(); 
				   $('#downloadfilelist').hide();
				   $('#invoicedate').show();
				   $('#productfieldlist').hide();
				}
		}
		
		function LoadLoginButton() {
			
			
			$('#LoginButton').click(function() {
					var LoginMethod = 1;
						RunLoginModal(LoginMethod);
						return false;
				});
		}
		
		function LoadTheLikeButton() {
			
			(function(d, s, id) {
			  var js, fjs = d.getElementsByTagName(s)[0];
			  if (d.getElementById(id)) {return;}
			  js = d.createElement(s); js.id = id;
			  js.src = "//connect.facebook.net/en_US/all.js#appId=162778013748821&xfbml=1";
			  fjs.parentNode.insertBefore(js, fjs);
			}(document, 'script', 'facebook-jssdk'));
			
		}
		
		function ApplyLabels() {
			
			$("label").inFieldLabels({ fadeOpacity:.2 });
			
		}
		
		function FormatPriceFields() {
			$('#Price').priceFormat({
			    prefix: '',
			    thousandsSeparator: ','
			});
		}
		
		function RunTheAjaxPlaylistLoad() {
			
			var TheUrl = (GetSiteRoot()) + '/u-playlists/plallutube #FileContainer';
			$('#SortFilesLong').html('<div class="loaderanim8"></div>');
			$('#FilePlayerAjaxPLNAME').html('');
			$("#SortFilesLong").load(TheUrl, function(){ 
				SetupJScrollStyler();
				SetupClickSortFilesLongLi(1);
				 });
	
				return false;
			
		}
		
		function GetNewContactIDString() {
						
				$.post("/codebase/contact/lookupcontactids.asp", { } , function(newdata){

					 $('input[name=custom]').val(newdata);
						
				 });
					
				var TheCustomVal = $('input[name=custom]').val();

			
			
			jQuery.unparam = function (value) {
			    var
			    // Object that holds names => values.
			    params = {},
			    // Get query string pieces (separated by &)
			    pieces = value.split('&'),
			    // Temporary variables used in loop.
			    pair, i, l;

			    // Loop through query string pieces and assign params.
			    for (i = 0, l = pieces.length; i < l; i++) {
			        pair = pieces[i].split('=', 2);
			        // Repeated parameters with the same name are overwritten. Parameters
			        // with no value get set to boolean true.
			        params[decodeURIComponent(pair[0])] = (pair.length == 2 ?
			            decodeURIComponent(pair[1].replace(/\+/g, ' ')) : true);
			    }

			    return params;
			};
			
			$.extend({
			        getGo: function(url, params) {
			            document.location = url + '?' + $.param(params);
			        },
			        postGo: function(url, params) {
			            var $form = $("<form>")
			                .attr("method", "post")
			                .attr("action", url);
			            $.each(params, function(name, value) {
			                $("<input type='hidden'>")
			                    .attr("name", name)
			                    .attr("value", value)
			                    .appendTo($form);
			            });
			            $form.appendTo("body");
			            $form.submit();
			        }
			    });
			
				$.postGo('https://www.paypal.com/cgi-bin/webscr', jQuery.unparam($('#paypalsubscriptions').serialize()));
				
			
			
		}
		
