/*

TODO
====
* Create degradable youtube guide link
* Create degradable inline content terms and conditions area for any terms and conditions page - ajax or grab inline content from page?
* Fancy up elements of sign up form
* Fancy up profile setup form for both band and musician
* Allow for degradable form submit link, remove submit button and replace with a tag or use button?
* Create jquery base for allowing more files to be uploaded from same page using profile setup form
* Check tables that are missing zebra class for alternating rows

*/

//standard delete confirmation dialog
function deleteGig(url) {
	if ( confirm('Are you sure you want to delete this gig?') ) {
		window.location=url;
	}
}
function deleteAudition(url) {
	if ( confirm('Are you sure you want to delete this audition?') ) {
		window.location=url;
	}
}
function deleteMail(url) {
	if ( confirm('Are you sure you want to delete this message?') ) {
		window.location=url;
	}
}
function deleteForSale(url) {
	if ( confirm('Are you sure you want to delete this for sale item?') ) {
		window.location=url;
	}
}
function deleteBandMember(url) {
	if ( confirm('Are you sure you want to delete this band member?') ) {
		window.location=url;
	}
}
function deleteHistory(url) {
	if ( confirm('Are you sure you want to delete this bit of history?') ) {
		window.location=url;
	}
}
function deleteVideo(url) {
	if ( confirm('Are you sure you want to delete video link?') ) {
		window.location=url;
	}
}
function deleteAudio(url) {
	if ( confirm('Are you sure you want to delete this audio file?') ) {
		window.location=url;
	}
}
function deleteFriend(url) {
	if ( confirm('Are you sure you want to delete this member from your friend list?') ) {
		window.location=url;
	}
}
function deleteMessage(url) {
	if ( confirm('Are you sure you want to delete this message from your message board?') ) {
		window.location=url;
	}
}
function blockPoster(url,poster) {
	if ( confirm('Are you sure you want to block ' + poster + ' from posting on your message board?') ) {
		window.location=url;
	}
}
function unblockPoster(url,poster) {
	if ( confirm('Are you sure you want to unblock ' + poster + ' so they can post on your message board?') ) {
		window.location=url;
	}
}
function deleteProfile(url) {
	if ( confirm('Are you sure you would like to delete your entire ozjam profile? (this will not delete your membership)') ) {
		window.location=url;
	}
}

$(document).ready(function(){
	//$("select[@name=iCategoryID]").each(findSubCat)

	$("select[@name=iCategoryID]").change(findSubCat)
  
	//finds subcats and fills a drop down menu of them
	function findSubCat() {
		iSubCategoryID	= $("select[@name=iSubCategoryID]").val()
		iParentID		= $(this).val()
		iLevels			= 2

		$("select[@name=iSubCategoryID]").attr("disabled", "disabled")

		//ajax to grab sub cats
		$.getJSON("_ajax-grabForSaleCategories.asp",{iLevels: iLevels, iParentID: iParentID, iSubCategoryID: iSubCategoryID}, function(aCategory){
			var options = '';
			var selected = '';

			for (var i = 0; i < aCategory.length; i++) {

					if ( aCategory[i].Selected == 1 ) {
						selected = ' selected=""selected""';
					} else {
						selected = '';
					}
					options += "<option value=" + aCategory[i].CategoryID + selected +">" + aCategory[i].CategoryName + "</option>"
			}
			//add options to sub category
			$("select[@name=iSubCategoryID]").html(options);
		});

		$("select[@name=iSubCategoryID]").attr("disabled", "")
	};

  // 1 Month Free Trial reflection link fix
  $("#header #user-login-signup h4 a").hover(function(){
    // add class to parent h4
    $(this).parents("h4:first").addClass("hover");
  },function(){    
    // remove the class from parent h4
    $(this).parents("h4:first").removeClass("hover");
  });
  
  // Welcome to Ozjam scroller
  $(".site-feature-container#welcome-to-ozjam .scroll").css("height","230px");
  $(".site-feature-container#welcome-to-ozjam .scroll").jScrollPane({scrollbarWidth: 6});
  
  // Friends list scroller
  $("div#friends-list-container div.scrollable").scrollable({
    vertical: true,
    moveAmount: 4,
    clickable: false,
    size: 4,
    navi: '.scroller-links'
  });
  
  $("div#message_board-container div.scrollable").scrollable({
    vertical: true,
    moveAmount: 1,
    clickable: false,
    size: 1,
    navi: '.scroller-links'
  });

  //validate post a message
  $("#post_message_form").validate();
  
  // Alternating color rows for ul and ol with zebra class present
  $(".site-feature-container ul.zebra" || ".site-feature-container ol.zebra").each(function(){
    $(this).find("li:even").addClass("alt");
  });
  
  // Alternating table rows if zebra class is present
  $("#main table.zebra").each(function(){
    $(this).find("tr:even").addClass("alt");
  });

  // Media list alternating rows
  $("ul.media-list").each(function(){
    $(this).find("li:even").addClass("alt");
  });



  // Alternate mini calendar row color for gig guide
  $("#p-gig_guide #main table").each(function() {
    $(this).find("tr:even:has(td)").addClass("alt");
  })
  
  // Alternate main calendar gig guide colors
  $("#p-gig_guide table#week_gig_calendar ul").find("li:even").addClass("alt");

  // Alternate mini calendar row color for auditions guide
  $("#p-auditions #main table").each(function() {
    $(this).find("tr:even:has(td)").addClass("alt");
  })
  
  // Alternate mini calendar row color for gig guide
  $("#popup-calendar").each(function() {
    $(this).find("tr:even:has(td)").addClass("alt");
  })

  // Alternate main calendar auditions colors
  $("#p-auditions table#week_gig_calendar ul").find("li:even").addClass("alt");

  // Alternate how to links list background colors
  $("ul.how_to_list").find("li:even").addClass("alt");

  // Alternate for sale navigation list background colors
  $("ul#for-sale-navigation").find("li:even").addClass("alt");

  // Alternate myads list background colors
  $("ul#my-ads").find("li:even").addClass("alt");

  // Alternate search results list background colors
  $("div#advanced-search-results").find("div:odd").addClass("alt");

  // Sign up form
  $(".band_or_musician_fieldset").hide();
  
  // Inbox Tool tips
  
  $(function() {
 	  $('#inbox *').tooltip({
		track: true, 
		delay: 0, 
		showURL: false,
		opacity: 0.85
	  });
  });

  // Band form link click
  $(".band_form_link").click(function() {
    if($(".band_or_musician_fieldset:visible").length != 0) {
      $("#musician_fieldset").fadeOut("slow",function(){
        $("#band_fieldset").fadeIn("slow");
      })
    } else {
      $("#band_fieldset").slideDown("slow");
    }

    return false;
  });
  
  // Musician form link click
  $(".musician_form_link").click(function() {
    if($(".band_or_musician_fieldset:visible").length != 0) {
      $("#band_fieldset").fadeOut("slow",function(){
        $("#musician_fieldset").fadeIn("slow");
      })
    } else {
      $("#musician_fieldset").slideDown("slow");
    }

    return false;
  });
  
  // Profile media links
  $("#profile-media .media-links").css('display','block');
  $(".media-container").hide();
  $(".media-container h2").remove();
  $(".media-links a.selected").each(selectMediaBox);
  
  //grab the selected media box from load
  $(".media-links a").click(selectMediaBox)
  
	function selectMediaBox() {
		$('.media-links a').removeClass('active');
		$(this).addClass('active');
		var rel = $(this).attr('rel');
		$(".media-container").hide();
		$("#" + rel).show();
		return false;
	};

  //Hover on my ads in wanted/for sale section
	$('#my-ads li').hover(function() {
	  $(this).addClass('hover');
	}, function() {
	  $(this).removeClass('hover');
	});  
  
  // Profile information
  $("ul.profile-information").each(function(){
	$(this).find("li:odd").addClass("alt");
  });
  
  // Full interview content
  $("ol.full_interview li:odd").addClass("alt");
  
  // Links
  $("ul.link_list li:even").addClass("alt");
  
  // Post a gig calendar
  $("input#TheDate, input.TheDate").datepicker({ dateFormat: 'dd/mm/y'})
;

  $("a.back-button").click(goBack);
  function goBack() {
	history.go(-1);
  }

  // Post a gig free event checkboxing
  $("li.entry_price").hide();
  $("#FreeEvent").click(entryPrice)
	  
	function entryPrice() {
		if($(this).attr("checked")) {
			$(this).parent("li").next("li.entry_price").children("input").val("");
			$(this).parent("li").next("li.entry_price").hide("slow");
		} else {
			$(this).parent("li").next("li.entry_price").show("slow");
		}
	};
  
})