(function($){$(function(){	
	$('.button').button();
	$('.mapit').button();
	$.localScroll({duration:400});
	
	//Hide remember me until bug is fixed
	$('#remember_me, .remember_me').hide();
	
	$('a.jt').cluetip({
	  cluetipClass: 'jtip',
	  arrows: true,
	  dropShadow: false,
	  hoverIntent: false,
	  sticky: true,
	  ajaxCache:  true,
	  mouseOutClose: true,
	  closePosition: 'title',
	  positionBy: 'mouse',
	  leftOffset:-5,
	  topOffset: -5,
	  closeText: '<img src="/addons/shared_addons/themes/iotm/img/cross.png" alt="close" />',
	  ajaxSettings: {
	  	dataType: 'html'
	  }
	});
	
	$('.welcomepage').click(function(e){
		e.preventDefault();
		$.colorbox({'href':'/welcome'});
	});

	$('a.logintofollow').click(function(e){
		e.preventDefault();
		$(".signin").click();
	});
	$('a.clicktofollow').click(function(e){
		//e.preventDefault();
		$this = $(this);
		$.ajax({
			type: 'POST',
			url: '/following/follow',
			data: {type: $(this).attr('data-type') ,type_id: $(this).attr('data-id')},
			success: function(msg){
				$this.replaceWith(msg);
			}
		});
		return false;
	});
	
	$('.banddetails').click(function(e){
		e.preventDefault();
		$(this).closest('tr').nextAll('tr.hidden').eq(0).slideToggle();
	});
	
	$(".mediabox").colorbox({
		width:"485", 
		height:"75%", 
		iframe:false,
		scrolling: false,
		onComplete: function(){
			$.colorbox.resize();
		}
	});
	
	$("a[rel='videobox']").colorbox({
		width:"485", 
		height:"75%", 
		iframe:false,
		scrolling: false,
		current: "video {current} of {total}",
		onComplete: function(){
			$.colorbox.resize();
		}
	});
	
	$("a[rel='songbox']").colorbox({
		width:"485", 
		height:"75%", 
		iframe:false,
		scrolling: false,
		current: "song {current} of {total}",
		onComplete: function(){
			$.colorbox.resize();
		}
	});
	
	$("a[rel='photobox']").colorbox({
		width:"485", 
		height:"60%", 
		iframe:false,
		scrolling: false,
		onComplete: function(){
			setTimeout(resizecolorbox, 100);
		}
	});
	
	function resizecolorbox(){
		$.colorbox.resize();
	}
	
	$("#setloco").button();
	$("input[name='btnLogin']").button();
	
	//$("#spinner").spin(spinner_opts);
	
	$("#setloco").click(function(){
		$("#setloco").button( "option", "disabled", true );
		$("#spinner").spin(spinner_opts);
		
		$.ajax({
			type: "POST",
			url: "/radius/set",
			data: {'state': $("#state").val(), 'city': $("#city").val(), 'range':  $("#range").val(), 'zip': $("#zip").val() },
			success: function(msg){
				//Remove Set Location
				$("#spinner").spin(false);
				$("#setloco").fadeOut();
				//window.location.reload();
			}
		});
		
		return false;
	});
	
	jQuery("#state,#city,#range,#zip").change(function() {
		$("#setloco").button( "option", "disabled", false );
		$("#setloco").fadeIn();
	});
	
	
	var alert = $('.success-box, .notice-box, .error-box');
	if (alert.length > 0) {
		alert.show().animate({
			height: alert.outerHeight()
		}, 200);

		window.setTimeout(function() {
			alert.slideUp();
		}, 3000);
	}
	
	$('.collapsable').next('div').hide();
	$('.collapsable').bind('click', function() {
			$(this).next('div').slideToggle();
	});
		// Login
	$(".signin").click(function(e) {
		e.preventDefault();
	    $("#signin_menu").fadeIn('slow');
	});

	$("#signin_menu").mouseup(function() {
	    return false
	});
	
	$(document).mouseup(function(e) {
		if($(e.target).parent("a.signin").length==0) {
	        $("#signin_menu").fadeOut('slow');
	   	}
	});
	
	// Drop Menu
	$("#menu ul ul").css({display: "none"});

	$("#menu ul li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(400);
	},function(){
		$(this).find('ul:first').css({visibility: "visible"}).slideUp(400);
	});
	


	
});})(jQuery);
