  $(document).ready(function(){
	 $("#CTVLogo").attr("src","http://www.muchmusic.com/ringtones/images/ctvlogo.gif");
	 //subnav stuff
	 $("#SubSections .SubnavMain").hover(
	  function () {
		$("#SubSections").css("background-position","0 -103px");
	  }, 
	  function () {
		if ($("#SubSections").attr("class")=="ArtistsLanding"){
			$("#SubSections").css("background-position","0 -134px");
		} else if ($("#SubSections").attr("class")=="PlaylistsLanding"){
			$("#SubSections").css("background-position","0 -165px");
		} else if ($("#SubSections").attr("class")=="GenresLanding"){
			$("#SubSections").css("background-position","0 -196px");
		} else if ($("#SubSections").attr("class")=="ImagesLanding"){
			$("#SubSections").css("background-position","0 -227px");
		} else{
			$("#SubSections").css("background-position","0 0");
		}
	  }
	);
	$(".ArtistsShopDrop").hover(
	  function () {
		$("#SubSections").css("background-position","0 -134px");
		$("#ArtistsDropdown").show();
	  }, 
	  function () {
		if ($("#SubSections").attr("class")=="ArtistsLanding"){
			$("#SubSections").css("background-position","0 -134px");
		} else if ($("#SubSections").attr("class")=="PlaylistsLanding"){
			$("#SubSections").css("background-position","0 -165px");
		} else if ($("#SubSections").attr("class")=="GenresLanding"){
			$("#SubSections").css("background-position","0 -196px");
		} else if ($("#SubSections").attr("class")=="ImagesLanding"){
			$("#SubSections").css("background-position","0 -227px");
		} else{
			$("#SubSections").css("background-position","0 0");
		}
		$("#ArtistsDropdown").hide();
	  }
	);
	$(".PlaylistsShopDrop").hover(
	  function () {
		$("#SubSections").css("background-position","0 -165px");
		$("#PlaylistsDropdown").show();
	  }, 
	  function () {
		if ($("#SubSections").attr("class")=="ArtistsLanding"){
			$("#SubSections").css("background-position","0 -134px");
		} else if ($("#SubSections").attr("class")=="PlaylistsLanding"){
			$("#SubSections").css("background-position","0 -165px");
		} else if ($("#SubSections").attr("class")=="GenresLanding"){
			$("#SubSections").css("background-position","0 -196px");
		} else if ($("#SubSections").attr("class")=="ImagesLanding"){
			$("#SubSections").css("background-position","0 -227px");
		} else{
			$("#SubSections").css("background-position","0 0");
		}
		$("#PlaylistsDropdown").hide();
	  }
	);
	$(".GenresShopDrop").hover(
	  function () {
		$("#SubSections").css("background-position","0 -196px");
		$("#GenresDropdown").show();
	  }, 
	  function () {
		if ($("#SubSections").attr("class")=="ArtistsLanding"){
			$("#SubSections").css("background-position","0 -134px");
		} else if ($("#SubSections").attr("class")=="PlaylistsLanding"){
			$("#SubSections").css("background-position","0 -165px");
		} else if ($("#SubSections").attr("class")=="GenresLanding"){
			$("#SubSections").css("background-position","0 -196px");
		} else if ($("#SubSections").attr("class")=="ImagesLanding"){
			$("#SubSections").css("background-position","0 -227px");
		} else{
			$("#SubSections").css("background-position","0 0");
		}
		$("#GenresDropdown").hide();
	  }
	);
	$("#SubSections .SubnavImages").hover(
	  function () {
		$("#SubSections").css("background-position","0 -227px");
	  }, 
	  function () {
		if ($("#SubSections").attr("class")=="ArtistsLanding"){
			$("#SubSections").css("background-position","0 -134px");
		} else if ($("#SubSections").attr("class")=="PlaylistsLanding"){
			$("#SubSections").css("background-position","0 -165px");
		} else if ($("#SubSections").attr("class")=="GenresLanding"){
			$("#SubSections").css("background-position","0 -196px");
		} else if ($("#SubSections").attr("class")=="ImagesLanding"){
			$("#SubSections").css("background-position","0 -227px");
		} else{
			$("#SubSections").css("background-position","0 0");
		}
	  }
	);
	$("#SubSections .SubnavInfo").hover(
	  function () {
		$("#SubSections").css("background-position","0 -258px");
	  }, 
	  function () {
		if ($("#SubSections").attr("class")=="ArtistsLanding"){
			$("#SubSections").css("background-position","0 -134px");
		} else if ($("#SubSections").attr("class")=="PlaylistsLanding"){
			$("#SubSections").css("background-position","0 -165px");
		} else if ($("#SubSections").attr("class")=="GenresLanding"){
			$("#SubSections").css("background-position","0 -196px");
		} else if ($("#SubSections").attr("class")=="ImagesLanding"){
			$("#SubSections").css("background-position","0 -227px");
		} else{
			$("#SubSections").css("background-position","0 0");
		}
	  }
	);

  	
	//playlist scrolling stuff
	$(".SingleNavRight").click(function(){
		//$("this ~ .UpperTones").hide();
		$('.UpperTones', $(this).parentsUntil('#MainContent')).toggle();
		$('.LowerTones', $(this).parentsUntil('#MainContent')).toggle();
		return false;
	});
	$(".SingleNavLeft").click(function(){
		//$("this ~ .UpperTones").hide();
		$('.UpperTones', $(this).parentsUntil('#MainContent')).toggle();
		$('.LowerTones', $(this).parentsUntil('#MainContent')).toggle();
		return false;
	});
    
	//makes artist names clickable
	/*$(".ArtistClick").click(function(){
		var urlgen=$(this).html();
		urlgen=unescapeHTML(urlgen);
		urlgen=escape(urlgen);
		$(this).attr("href","/ringtones/artist/"+urlgen);
	});*/
	//makes artist names clickable
	$(".ArtistClick").click(function(){
		var urlgen=$(this).html();
		//urlgen=urlgen.replace(/ /g,'-')
		//urlgen=unescapeHTML(urlgen);
		//urlgen=escape(urlgen);
		urlgen=slugify(urlgen);
		$(this).attr("href","/ringtones/artist/"+urlgen);
	});
	

	/**
	 * Transform text into a URL slug: spaces turned into dashes, remove non alnum
	 * @param string text
	 */
	function slugify(text) {
		text = text.replace(/[^-a-zA-Z0-9$,&\s]+/ig, '');
		text = text.replace(/-/gi, "--");
		text = text.replace(/\s/gi, "-");
		text = text.replace(/-&[0-9a-z]*-/gi, "-");
		return text;
	}
	
	//search
	$("#RingtoneSearchButton").click(function(){
		ringtonesearch();
	});
	
	//previewlistener();
	
  });
  function checkEnterPress(e){ //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable
	
	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e;
	characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
	e = event;
	characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		ringtonesearch();
	//document.forms[0].submit(); //submit the form
	return false;
	}
	else{
	return true;
	}

  }
  function ringtonesearch(){
  	var searchquery=$("#RingtoneSearchBox").val();
	searchquery=escape(searchquery);
	document.location="/ringtones/search.aspx?query="+searchquery;
  }
  /*function previewlistener(){
  //ringtone preview/get stuff	
	$(".RingtoneThumbnail").hover(
	  function () {
		$('.PlayStop', this).css('left', '0'); 
		$('.GetButton', this).show();
	   }, 
	  function () {
		$('.PlayStop', this).css('left', '-9999px'); 
		$('.GetButton', this).hide() ;
	   });	
  }*/
  function unescapeHTML(html) {
		var htmlNode = document.createElement("DIV");
		htmlNode.innerHTML = html;
		if(htmlNode.innerText)
		return htmlNode.innerText; // IE
		return htmlNode.textContent; // FF
	  }
