var dumdum = 'a';

$(document).ready(function() {
  //alert('sss');
  //alert($('div').length());
  
  $("span.edit").editable('/user/edit', {
    cssclass    : 'inherit',
    event       : 'dblclick',
    placeholder : 'Double Click to Edit',
    callback    : function() {
      $('span#profile_tip').html('<b>{</b>Done!<b>}</b>');
      $('span#profile_tip').css('background', '#FFF');
      $('span#profile_tip').css('color', '#FC3204');
    }
  });
  $("span.edittxt").editable("/user/edit", {
    cssclass    : 'inherit',
    type        : 'textarea',
    cancel      : 'Cancel',
    submit      : 'OK',
    indicator   : 'Saving...',
    tooltip     : 'Double click to edit...',
    event       : 'dblclick',
    placeholder : 'Double Click to Edit',
    callback    : function() {
      $('span#profile_tip').html('<b>{</b>Done!<b>}</b>');
      $('span#profile_tip').css('background', '#FFF');
      $('span#profile_tip').css('color', '#FC3204');
    }
  });
  
  $('.list_hover').hover(function() {
    $(this).addClass('list_hover_hover');
  }, function() {
    $(this).removeClass('list_hover_hover');
  });
  $('.user_list').click(function() {
    var url = $(this).find('a.lnk').attr('href');
    window.location = url;
  });
  $('.wall_rec').click(function() {
    var url = $(this).find('a.lnk').attr('href');
    window.location = url;
  });
  $('.gss').click(function() {
    var url = $(this).find('a.lnk').attr('href');
    window.location = url;
  });
  //test();
  $('.slide-box-small').click(function() {
    var url = $(this).find('a.lnk').attr('href');
    window.location = url;
  });
  $('.homephoto').hover(function() {
    $(this).addClass('list_hover_hover');
  }, function() {
    $(this).removeClass('list_hover_hover');
  });
  $('.homephoto').click(function() {
    var url = $(this).find('a.lnk').attr('href');
    window.location = url;
  });
})

function trace(str) {
	if (typeof(console) == 'object') {
		console.log(str);
	}	
}

// animate # links
jQuery.smoothHashLinks = function(){
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});
};


function GetLyrics(id){
	//alert(id);
	$.get("/music/edit/lyrics/"+id, function(data){
	   //alert("Data Loaded: " + data);
		 //arr = data.split.('{=}');
		 //div_val = "<div><input type='text' name='lname' value='"+arr[0]+"'></div><div><textarea name='blurb' >"+arr[0]+"</textarea></div>";
		 document.getElementById('updateLyrics').innerHTML = data;
		 document.getElementById('updateLyrics').style.display = ''; 
	});
}

function editLyrics(id){
	lname  = document.getElementById('lname').value; 
	blurb = document.getElementById('blurb').value; 
	$.post("/music/edit/lyrics/"+id, {  lyricsid: id, name: lname, blurb: blurb },
   function(data){
     //alert("Data Loaded: " + data);
   });
	//$.post("/music/edit/lyrics/"+id, { lyricsid: id,name: name, blurb: blurb } );
	closeLyrics()
}

function closeLyrics(){
	document.getElementById('updateLyrics').style.display = 'none'; 
}

function AddCategory(){
	$(document).ready(function() {
		$('<span><a href="#add_gossip" onClick="addNewCategory()" class="btn" title="click here to add new categor!" id="catlink">+</a></span>').insertAfter('select#gdcatid');
	});
}

function addNewCategory(){
	$(document).ready(function() {
		$('<span><input type="text" name="newcatg" id="newcatg"></span>').insertAfter('select#gdcatid');
		$('select#gdcatid').remove('#gdcatid');
		$('a#catlink').remove('#catlink');
	});
}

var bio_row = 0;
function AddCelebBiocell(rowid){
	//alert(rowid);
	if(bio_row == 0)
		bio_row = rowid;
	else 
		bio_row++;
	
	$(document).ready(function() {
		$('<tr id="rw'+bio_row+'"><td><input type="hidden" name="infoid['+bio_row+']" size="6"	value=""><b></b></td><td><input type="text" disabled="true" name="name['+bio_row+']" 	value=""></td><td><input type="text" name="thead['+bio_row+']" size="20" value=""></td><td><input type="text" name="tinfo['+bio_row+']" size="50" value=""></td></tr>').insertBefore('tr#info_submit');
	});

}

var contentRow = 1;
function NewContent(cid){
contentRow++;
//alert(cid);
	$(document).ready(function() {
		$('<tr><td ><strong>Title</strong></td><td><input class="cms" type="text" name="title['+cid+']" value="" size="105"></td></tr><tr style="border-bottom:1px solid #cccccc;margin-left:20px;"><td style="margin-right:18px;"><strong>Blurb</strong></td><td><textarea name="blurb['+cid+']" class="wysiwyg" rel-chars="4000" style="width:650px;height:195px"></textarea></td></tr>').insertBefore('tr#addCMS');
	});
}

var albumRow = 1;
function NewAlbum(cid){
//alert(cid);
	$(document).ready(function() {
		$('<tr style="margin-left:20px;margin-bottom:5px;"><td style="width:100px;margin-right:20px;"><strong>Album Title '+(albumRow+1)+'</strong></td><td><input class="cms" type="text" name="title['+cid+']" value=""></td></tr>').insertBefore('tr#addALBUM');
	});
	albumRow++;
}

$.fn.manyFields = function () {
  return this.each( function() {
    var $this = $(this);
    $this.wrap('<div class="manyFielsContainer"></div>');
    $this.after('<span class="error" style="display:none;">Press enter a valid email address</span>');
    $this.after('&nbsp;<a href="#"><img src="/asset/icon/add.png" alt="Add" /></a>');
    var name = $this.attr('name');
    $this.attr('name', name+"[]");
    var atag = $this.parent().children('a');
    trace(atag.attr('href'));
    atag.click(function() {
      var $this = $(this);
      var input = $this.parent().children('input.manyFields');
      trace(input.val());
      var value = input.val();
      if(value != "" && value.match("@") != null) {
        $('<span class="manyFields">' + value + '<input type="hidden" name="' + name + '[]" value="' + value + '" /></span>').insertBefore(input);
      } else {
        $this.parent().children('span.error').fadeIn(500).fadeTo(2000, 1).fadeOut(500);
      }
      input.val("");
      return false;
    });
    return false;
  });
}

 //$("#updateLyrics").scrollable("next", 200);
function showVideo(val){
// youtube video
document.getElementById("ytube").src = "http://www.youtube.com/v/"+val+"&hl=en&fs=1";
}
function formatItem(row) {
		return row[0];
}