$(document).ready(function(){
$("#accordion div.h3:first").addClass("active");
$("#accordion div.results:not(:first)").hide();
$("#accordion div.h3").click(function(){
		$(this).next("div.results").slideToggle("fast")
		.siblings("div.results:visible").slideUp("fast");
		$(this).toggleClass("active");
		$(this).siblings("div.h3").removeClass("active");
});
$("#news_accordion div.h3:first").addClass("active");
$("#news_accordion div.results:not(:first)").hide();
$("#news_accordion div.h3").click(function(){
		$(this).next("div.results").slideToggle("fast")
		.siblings("div.results:visible").slideUp("fast");
		$(this).toggleClass("active");
		$(this).siblings("div.h3").removeClass("active");
});





setTimeout(function() {  var Gheight = $("#body_text").height(); if (Gheight < 600) { Gheight = 600; } else { Gheight = $("#body_text").height(); } $("#leftnav_af").height(Gheight); }, 5000);

$("div.srlist2").click(function() {
  var link = $(this).find("a").attr("href");
  if (link!=undefined) { window.location=$(this).find("a").attr("href"); } return false;
});

$(".login").colorbox({innerWidth:300,innerHeight:120,iframe:true});
$(".logout").colorbox({innerWidth:300,innerHeight:120,iframe:true});
$(".profile").colorbox({innerWidth:400,innerHeight:280,iframe:true});
$(".register").colorbox({innerWidth:420,innerHeight:550,iframe:true});
$(".whyregister").colorbox({innerWidth:400,innerHeight:400,iframe:true});
$(".lyrics").colorbox({innerWidth:765,innerHeight:600,iframe:true});
$(".comment_guidelines").colorbox({width:"60%", inline:true, href:"#comment_guidelines"});
});

$(function() {
  $('.error').hide();
  $('#comment').val("Enter your comment here...");
  $('#comment').css({backgroundColor:"#FFFFFF"});

  $('#comment').focus(function(){
  $(this).css({backgroundColor:"#E1EBF7"});
  var temp_com = $("#comment").val();
  if (temp_com == "Enter your comment here...") { $(this).val(""); }
  });

  $('#comment').blur(function(){
  $(this).css({backgroundColor:"#FFFFFF"});
  var temp_com = $("#comment").val();
  if (temp_com == "") { $(this).val("Enter your comment here..."); }
  });


  $(".comments_but").click(function() {
    $('.error').hide();
	  var comment = $("#comment").val();
	  var fid = $("#fid").val();
	  var songart = $("#songart").val();
	  if (comment == "") {
      $("#comment").css({backgroundColor:"#F59271"});
      return false;
    } else if (comment == "Enter your comment here...") {
	  $("#comment").css({backgroundColor:"#F59271"});
      return false;
	}
		var dataString = "com="+ encodeURIComponent(comment) + "&fid="+ fid + "&songart=" + encodeURIComponent(songart);
    
		$.ajax({
      type: "POST",
      url: "/comment_process_af.php",
      data: dataString,
      success: function(data) {
      alert(data);
	  window.location.reload(true);
	  return false;
      }
     });
    return false;
	});
});

$(function() {
$('.error').hide();

$('#sffsub').val("Enter your fact here..."); $('#sffsub').css({backgroundColor:"#FFFFFF"});
$('#artnm').val("Enter Artist Name here..."); $('#artnm').css({backgroundColor:"#FFFFFF"});
$('#resnm').val("Where did you hear/read about this..."); $('#resnm').css({backgroundColor:"#FFFFFF"});

$('#sffsub').focus(function(){$(this).css({backgroundColor:"#DCE6F2"});var temp_fact = $("#sffsub").val();if (temp_fact == "Enter your fact here...") { $(this).val(""); }});
$('#sffsub').blur(function(){$(this).css({backgroundColor:"#FFFFFF"});var temp_fact = $("#sffsub").val();if (temp_fact == "") { $(this).val("Enter your fact here..."); }});

$('#artnm').focus(function(){$(this).css({backgroundColor:"#DCE6F2"});var temp_artnm = $("#artnm").val();if (temp_artnm == "Enter Artist Name here...") { $(this).val(""); }});
$('#artnm').blur(function(){$(this).css({backgroundColor:"#FFFFFF"});var temp_artnm = $("#artnm").val();if (temp_artnm == "") { $(this).val("Enter Artist Name here..."); }});

$('#resnm').focus(function(){$(this).css({backgroundColor:"#DCE6F2"});var temp_resnm = $("#resnm").val();if (temp_resnm == "Where did you hear/read about this...") { $(this).val(""); }});
$('#resnm').blur(function(){$(this).css({backgroundColor:"#FFFFFF"});var temp_resnm = $("#resnm").val();if (temp_resnm == "") { $(this).val("Where did you hear/read about this..."); }});



$(".sffsub_but").click(function() {
$('.error').hide();

var artistname = $("#artnm").val();
var resource = $("#resnm").val();
var facttext = $("#sffsub").val();
var uid = $("#uid").val();

if (artistname == "") { $("#artnm").css({backgroundColor:"#F59271"}); return false; } else if (artistname == "Enter Artist Name here...") { $("#artnm").css({backgroundColor:"#F59271"}); return false;	}
if (resource == "") { $("#resnm").css({backgroundColor:"#F59271"}); return false; } else if (resource == "Where did you hear/read about this...") { $("#resnm").css({backgroundColor:"#F59271"}); return false;	}
if (facttext == "") { $("#sffsub").css({backgroundColor:"#F59271"}); return false; } else if (facttext == "Enter your fact here...") { $("#sffsub").css({backgroundColor:"#F59271"}); return false;	}
    return true;
	});
});

function openHelp() {
    url="help.html"
	helpWin=window.open(url, 'helpWin', 'personalbar=no,toolbar=no,status=no,scrollbars=yes,location=no,resizable=no,menubar=no,width=400,height=400');
	if(window.focus)
		helpWin.focus();
}

function lyricsWindow(url)
{
lyricsWin=window.open(url, 'lyricsWin','personalbar=no,toolbar=no,status=no,scrollbars=yes,location=no,resizable=yes,menubar=no,width=760,height=700');
if(window.focus)
lyricsWin.focus();
}

function profileWindow(url)
{
profileWin=window.open(url, 'profileWin','personalbar=no,toolbar=no,status=no,scrollbars=yes,location=no,resizable=yes,menubar=no,width=600,height=600');
if(window.focus)
profileWin.focus();
}

function urlencode(str) {
return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

function goSearch(){
var target;
var filt = document.getElementById('filter').value;
var query = document.getElementById('string').value;
query = urlencode(query);
if (filt == 'q') target='search.php?'+filt+'='+query;
else if (filt == 'title') target='http://www.songfacts.com/search_fact.php?'+filt+'='+query; 
else if (filt == 'lyrics') target='http://www.songfacts.com/search_lyrics.php?title='+query; 
else target='/search_fact.php?'+filt+'='+query;
window.location.href = target;
}

function handleEnter(inField, e) {
    var charCode;
    if(e && e.which){
        charCode = e.which;
    }else if(window.event){
        e = window.event;
        charCode = e.keyCode;
    }
    if(charCode == 13) { goSearch(); }
}


