// Custom jQuery actions by Zarino Zappia
		
$(document).ready(
	function(){
	
		var homelink = $('#nav ul li:first a').attr('href');
		var hometitle = $('#nav ul li:first a').attr('title');
		$('#nav ul li:first').before('<li class="logo"><a href="' + homelink + '" title="' + hometitle + '"></a></li>');
		
		$('a.mail_link').each(
			function(){
				var email = $(this).attr('rel') + '@wiredradio.co.uk';
				$(this).text(email).attr('href', 'mailto:' + email).attr('title', 'Email the Wired team');
			}
		);
		
		
		//		LISTEN		//
		

		$('body.listen').ready(
			function(){
			
				$('a#bigplaybutton').click(
					function(){
					var player = $(this).attr("href");
					window.open(
						player,
						'player',
						'width=620,height=400,toolbar=no,directories=no,location=no,menubar=no,personalbar=no'
					);
					return false;
					}
				);

				$('#mini-downloads li:even').addClass('even');
				
				$('#mini-calendar li:odd').addClass('odd');

				$('a#help-button').toggle(
					function(){
						$(this).next().slideDown(500, function(){
							$(this).css("minHeight", 400);
						});
						return false;
					}, function(){
						$(this).next().css("minHeight", 0).slideUp(500);
						return false;
					}
				).next().hide();
				
				$(".copyme").click(
					function(){
						$(this).focus().select();
					}
				);
				
				$('#help-div li a').hover(function(){
					tab = $(this).attr("href");
					$(this).parents("#help-div").children("div").hide().filter(tab).show().parents("help-div");
					$(this).addClass("selected").parent().siblings("li").children().removeClass("selected");
					return false;
				}).click(function(){
					return false;
				}).filter(":first").addClass("selected");

				
			}
		);
		
		
		
		//		POP OUT PLAYER		//
		
		
		$('body.player-old div.downloadlinks p').not('.selected').hide();
		
		$('body.player-old ul.downloadtabs a').click(
			function(){
				var requested_box = $(this).attr('href');
				$(this).parent().siblings('.selected').removeClass('selected');
				$(this).parent().addClass('selected');
				$('body.player div.downloadlinks p').not(requested_box).hide();
				$('body.player div.downloadlinks p').filter(requested_box).show();
				return false;
			}
		);
		
		$('body.player #nowandnext').ready(
			function(){
				setInterval(
					function(){
						$(this).empty().load("nowandnext.php");
					}, 300000
					//	refreshes the now and next section every 5 minutes
				);
			}
		);
		
		$('body.player #listenonline a.alternative').live("click", function(){
			alt = $(this).attr("href");
			$('#listenonline>div').empty().load(alt);
			return false;
		});
		
		$('body.player #listenonyourcomputer li a').hover(function(){
			tab = $(this).attr("href");
			$(this).parents("#listenonyourcomputer").children("div").hide().filter(tab).show();
			$(this).addClass("selected").parent().siblings("li").children().removeClass("selected");
			return false;
		}).click(function(){
			return false;
		}).filter(":first").addClass("selected");
		
		
		


		//		EVENTS CALENDAR		//
		
		
		$('body.events .eventscalendar td a').hover(
			function(){
				var event_id = $(this).attr('rel');
				$.get("/see/minidetails.php", {id: event_id}, function(data){
  					$(".eventscalendar a[rel='" + event_id + "']").append("<span class='minidetails'><span class='arrow'></span><span class='minidetailsinner'></span></span>").children('.minidetails').hide().children('.minidetailsinner').html(data).parent('.minidetails').fadeIn(250);
				});	
			}, function(){
				$(this).children(".minidetails").fadeOut(250, function(){
					$(this).remove();
				});
			}
		)
		
		$('body.events .eventscalendar td a').click(
			function(){
				$(this).children(".minidetails").fadeOut(150, function(){
					$(this).remove();
				});
				return true;
			}
		)
		
		
		
		//			ABOUT		//
		
		$('body.about a.listen').click(
					function(){
					window.open(
						'../player.php',
						'player',
						'width=620,height=500,toolbar=no,directories=no,location=no,status=no,menubar=no,personalbar=no'
					);
					return false;
					}
				);
		

		
		//		CONTACT US		//
		
		
		$('#mapinfo+a, #person a#map').hover(
			function(){
				$(this).children().fadeOut('slow');
			}, function(){
				$(this).children().fadeIn('slow');
			}
		);
		
		$("body.contact div.dependent.hidden").hide();
		
		$("body.contact div.team.hidden textarea").hide();
		
		$("body.contact #why").change(
			function(){
				var type = $(this).val();
				
				if (type == 'feedback') {
					$("div.show:visible, div.involved:visible").slideUp(250);
					$("div.comments:hidden").slideDown(250);
				} else if (type == 'show') {
					$("div.comments:visible, div.involved:visible").slideUp(250);
					$("div.show:hidden").slideDown(250);
				} else if (type == 'involved') {
					$("div.comments:visible, div.show:visible").slideUp(250);
					$("div.involved:hidden").slideDown(250);
				} else if (type == 'unselected') {
					$("div.dependent:visible").slideUp(250);
				}
			}
		);
		
		$("body.contact div.music_type :checkbox").click(
			function(){
				var box_id = $(this).attr("id");
				if (box_id == 'no_music') {
					$("body.contact div.music_type").unCheckCheckboxes(":not(#no_music)");
				} else {
					$("body.contact div.music_type").unCheckCheckboxes("#no_music");
				}
			}
		);
		
		$("body.contact div.ratio input").keyup(
			function(){
				var this_box = $(this).attr("id");
				var other_box = $("div.ratio input").not("#" + this_box).attr("id");
				var this_box_value = $(this).val();
				if(this_box_value >= 0 && this_box_value <= 100) {
					var other_box_new_value = 100 - this_box_value;
				} else {
					var other_box_new_value = '!?';
				}
				$("div.ratio #" + other_box).val(other_box_new_value);
			}
		);
		
		$("body.contact div.team :radio").change(
			function(){
				var this_radio = $(this).attr("id");
				if(this_radio == 'alone') {
					$('div.team textarea:visible').slideUp(250);				
				} else if (this_radio == 'notalone') {
					$('div.team textarea:hidden').slideDown(250);
				}
			}
		);		
		
		
		
		

		//		BACKEND: LOGIN			//
		
		
		
		$('body.backroom-login h3').toggle(
			function(){
				$(this).next('fieldset').slideDown(250);
			}, function() {
				$(this).next('fieldset').slideUp(250);
			}		
		).next('fieldset').hide();
		
		
		
	}
);