/*JQUERY FUNCTIONS
*/
function movebannerleft(){ jQuery('#bannerslider').animate({'left':'-1800px'},50000,'linear',function(){ movebannerright(); }); }
function movebannerright(){ jQuery('#bannerslider').animate({'left':'0px'},50000,'linear',function(){ movebannerleft(); }); }

/*MOOTOOLS REQUIRED
function movebannerleft(){
 var fx_banner = new Fx.Morph($('bannerslider'), {duration: 50000, link:'cancel', transition:Fx.Transitions.Sine.easeOut });
 fx_banner.onComplete = function(){ movebannerright(); }
 fx_banner.start({ 'left':-1800 });
 }
function movebannerright(){
 var fx_banner = new Fx.Morph($('bannerslider'), {duration: 50000, link:'cancel', transition:Fx.Transitions.Sine.easeOut });
 fx_banner.onComplete = function(){ movebannerleft(); }
 fx_banner.start({ 'left':0 });
 }
//END MOOTOOLS REQUIRED*/

function popupplayer(url){
 var newwindow = window.open('mp3.php?id='+url,'otisriddimplayer','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=452,height=350');
 //if(window.focus){newwindow.focus();}
 //newwindow.play('mp3.php?path='+url);
 //return false;
 }


function error(txt){
 //closepopup();
 getElem('error').innerHTML = txt;
 setStyles(['error'],{'display':'block','opacity':1,'visibility':'visible'});
 }
function error2(txt){
 //closepopup();
 setStyles(['error'],{'opacity':0,'visibility':'hidden'});
 getElem('error').innerHTML = txt;
 setTimeout(function(){ fadein('error',500); },10);
 
 setTimeout(function(){ fadeout('error',200); },1500);
 setTimeout(function(){
  getElem('error').innerHTML = ''
+'<a onclick="item_add_new();" class="sm-button" style="float:left;" href="javascript:;">'
+'<div class="btn-lhs">CREATE NEW</div>'
+'<div class="btn-rhs"></div>'
+'</a><br/>';
  fadein('error',200);
  },1710);
 }


function item_add_new(){ ajaxeval(docname(true),'add=&new='); }
function item_insert(id,after){
 var n = document.createElement('form');
 n.id = 'item_'+id;
 n.className = 'item';
 n.method = 'POST';
 n.enctype = 'multipart/form-data';
 insertAfter(n,getElem('error'));
 refresh_item_info(id);
 }
function item_cancel_edit(id){
 openpopup('getting data...please wait..');
 refresh_item_info(id);
 }
function refresh_item_info(id){
 var fn = function(){
  if(isIE()){
   $$('.edit_text'+id).add('keydown',function(event){ this.style.height=this.scrollHeight+'px'; });
   $$('.edit_text'+id).add('keyup',function(event){ this.style.height=this.scrollHeight+'px'; });
   }
  else{
   $$('.edit_text'+id).add('keydown',function(event){ this.style.height=0+'px'; this.style.height=this.scrollHeight+'px'; });
   $$('.edit_text'+id).add('keyup',function(event){ this.style.height=0+'px'; this.style.height=this.scrollHeight+'px'; });
   }
  getElem('input-text-title'+id).style.height = getElem('input-text-title'+id).scrollHeight+'px';
  getElem('input-text-normal'+id).style.height = getElem('input-text-normal'+id).scrollHeight+'px';
  closepopup_delay();
  }
 ajaxload(docname(false),'get_item='+id, 'item_'+id, fn);
 }
function closepopup_delay(t){ var t = t||50; setTimeout(function(){ closepopup(); },t); }

function item_delete(id){
 if(confirm('Are you sure you wish to DELETE this item?\r\nAll info and files associated with this entry will also be deleted.\r\nWould you like to proceed?')){
  ajaxeval(docname(true),'delete='+id);
  }
 }

function delete_file(id,param){
 if(confirm('Are you sure you wish to DELETE this file?\r\nAny text changes will be cancelled.')){
  ajaxeval(docname(true),'deletefile='+id+'&param='+param);
  openpopup('deleting file...please wait.');
  }
 }
function update_filename(e){
 if(name = input_get_filename(e)){
  var btn = '<a href="javascript:;" class="sm-button" style="float:left;"'
  +' onclick="reset_file_input(\''+e.id+'\');"'
  +' >'
  +'<div class="btn-lhs">CLEAR FILE</div><div class="btn-rhs"></div>'
  +'</a>';
  e.parentNode.parentNode.style.display = 'none';
  nextSib(e.parentNode.parentNode).innerHTML = btn + '<span style="margin:2px 0px 0px 8px;">' + e.name +' : '+ name + '</span>';
  }
 }
function input_get_filename(elem){
 var val = elem.value;
 var i = val.lastIndexOf('\\');
 val = val.substr(i+1);
 if(val!=''){ return val; }
 else{ return false; }
 }
function reset_file_input(e){
 if(typeof(e)=='string') e = getElem(e);
 
 e.parentNode.parentNode.style.display = 'block';
 
 var id = e.id;
 var name = e.name;
 var className = e.className;

 var p = e.parentNode;
 p.removeChild(e);
 p.innerHTML += '<input type="file" name="'+name+'" class="'+className+'" id="'+id+'" />';
 
 getElem(id).onchange = function(){ update_filename(this); }
 nextSib(p.parentNode).innerHTML = '';
 
 return true;
 }

/**/
function o_delete_file(filename,id,param){
 if(confirm('Are you sure you wish to DELETE this file?\r\nOther changes will be cancelled.')){
  ajaxeval(filename,'deletefile='+id+'&param='+param);
  }
 }
/*
CUSTOMISED CMS ACTIONS FOR ARTISTS/ALBUMS/TRACKS
AJAX ADD
DYN HTML INSERT
POPUP EDIT FORM
SUBMIT/SAVE EDITS
CANCEL/UNDO/REFRESH EDIT
AJAX DELETE WITH JS EVAL CALLBACK
EDIT FORM FILE SELECT/ONCHANGE ACTION = indicates filename loaded into custom file input form field
*/
//ARTISTS CMS FUNCTIONS
function o_add_artist(){
 //openpopup('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="../gfx/loading.gif" /></div>');
 ajaxeval('artists_cms.php','add=&new=');
 }
function o_insert_artist(id){
 n = document.createElement('div');
 n.id = 'artist-holder-'+id;
 n.className = 'artist-holder';
 n.style.margin = '10px 0px';
 n.innerHTML = '<div class="artist" id="artist-'+id+'"></div><div class="break0" id="new-album-marker-'+id+'"></div>';
 insertAfter(n,getElem('new-artist-marker'));
 ajaxload('get_info.php?artist_id='+id,false,'artist-'+id,false);
 o_edit_artist(id);
 }
function o_edit_artist(id){
 openpopup('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="../gfx/loading.gif" /></div>',768);
 
 oncomplete = function(){
 getElem('popupmsg').style.height = 'auto';
 $$(document.forms['artist_item_'+id].name)
 .add('blur',function(event){ if(this.value==''){ jQuery(this).addClass('textarea-autosize-empty'); this.value='TYPE ARTIST NAME HERE'; }; })
 .add('focus',function(event){ jQuery(this).removeClass('textarea-autosize-empty'); if(this.value=='TYPE ARTIST NAME HERE'){ this.value=''; }; }); 
 /*
 $$(document.forms['artist_item_'+id].bio)
 .add('blur',function(event){ if(this.value==''){ jQuery(this).addClass('textarea-autosize-empty'); this.value='TYPE ARTIST BIO HERE'; }; })
 .add('focus',function(event){ jQuery(this).removeClass('textarea-autosize-empty'); if(this.value=='TYPE ARTIST BIO HERE'){ this.value=''; }; });
 */
 if(isIE()){
  $$('.textarea-autosize-group-'+id)
  .add('keydown',function(event){ this.style.height=this.scrollHeight+'px'; })
  .add('keyup',function(event){ this.style.height=this.scrollHeight+'px'; }); 
  }
 else{
  $$('.textarea-autosize-group-'+id)
  .add('keydown',function(event){ this.style.height=(this.offsetHeight-15)+'px';this.style.height=this.scrollHeight+'px'; })
  .add('keyup',function(event){ this.style.height=(this.offsetHeight-15)+'px'; this.style.height=this.scrollHeight+'px'; });
  }
 document.forms['artist_item_'+id].name.style.height = document.forms['artist_item_'+id].name.scrollHeight+'px';
 //document.forms['artist_item_'+id].bio.style.height = document.forms['artist_item_'+id].bio.scrollHeight+'px';
 checkbox_ify('checkbox-track-attr');
  }
 
 ajaxload('artists_cms.php?id='+id,false,'popupmsg',oncomplete);
 }
function o_save_artist(id){
 if(document.forms['artist_item_'+id].name.value=='TYPE ARTIST NAME HERE'){ document.forms['artist_item_'+id].name.value=''; }
 if(document.forms['artist_item_'+id].bio.value=='TYPE ARTIST BIO HERE'){ document.forms['artist_item_'+id].bio.value=''; }
 jQuery('#popupmsg').prepend('<div id="loading-gif" style="float:right;"><img src="../gfx/loading2.gif" /></div>');
 ajax_formpost(document.forms['artist_item_'+id]);
 }
function o_cancel_artist(id){ getElem('popupmsg').style.height = ''+(getElem('popupmsg').offsetHeight-34)+'px'; o_edit_artist(id); }
function o_delete_artist(id){ ajaxeval('artists_cms.php?delete='+id); }
function o_filename_artist(e){ if(name=input_get_filename(e)){ nextSib(e.parentNode.parentNode).innerHTML = name; } }

//ALBUMS CMS FUNCTIONS
function o_add_album(id){
 //openpopup('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="../gfx/loading.gif" /></div>');
 ajaxeval('albums_cms.php','add=&new=&artist_id='+id);
 }
function o_insert_album(id,artist_id){
 n = document.createElement('div');
 n.id = 'album-holder-'+id;
 n.className = 'album-holder';
 n.style.padding = '10px 16px';
 n.innerHTML = '<div class="album" id="album-'+id+'"></div><div class="break0" id="new-track-marker-'+id+'"></div>';
 insertAfter(n,getElem('new-album-marker-'+artist_id));
 ajaxload('get_info.php?album_id='+id,false,'album-'+id,false);
 o_edit_album(id);
 }
function o_edit_album(id){
 openpopup('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="../gfx/loading.gif" /></div>');
 
 oncomplete = function(){
 if(getElem('popupmsg')) getElem('popupmsg').style.height = 'auto';
 $$(document.forms['album_item_'+id].name)
 .add('blur',function(event){ if(this.value==''){ jQuery(this).addClass('textarea-autosize-empty'); this.value='TYPE ALBUM TITLE HERE'; }; })
 .add('focus',function(event){ jQuery(this).removeClass('textarea-autosize-empty'); if(this.value=='TYPE ALBUM TITLE HERE'){ this.value=''; }; }); 
 $$(document.forms['album_item_'+id].description)
 .add('blur',function(event){ if(this.value==''){ jQuery(this).addClass('textarea-autosize-empty'); this.value='TYPE TEXT DESCRIPTION HERE'; }; })
 .add('focus',function(event){ jQuery(this).removeClass('textarea-autosize-empty'); if(this.value=='TYPE TEXT DESCRIPTION HERE'){ this.value=''; }; });
 if(isIE()){
  $$('.textarea-autosize-group-'+id)
  .add('keydown',function(event){ this.style.height=this.scrollHeight+'px'; })
  .add('keyup',function(event){ this.style.height=this.scrollHeight+'px'; }); 
  }
 else{
  $$('.textarea-autosize-group-'+id)
  .add('keydown',function(event){ this.style.height=(this.offsetHeight-15)+'px';this.style.height=this.scrollHeight+'px'; })
  .add('keyup',function(event){ alert(keycode(event)); this.style.height=(this.offsetHeight-15)+'px'; this.style.height=this.scrollHeight+'px'; });
  }
 document.forms['album_item_'+id].name.style.height = document.forms['album_item_'+id].name.scrollHeight+'px';
 document.forms['album_item_'+id].description.style.height = document.forms['album_item_'+id].description.scrollHeight+'px';
  }
 
 ajaxload('albums_cms.php?id='+id,false,'popupmsg',oncomplete);
 }
function o_imagefilename_album(e){
 if(name = input_get_filename(e)){
  nextSib(e.parentNode.parentNode).innerHTML = '<span style="margin:2px 0px 0px 8px;">' + e.name +' : '+ name + '</span>';
  }
 }
function o_save_album(id){
 if(document.forms['album_item_'+id].name.value=='TYPE ALBUM TITLE HERE'){ document.forms['album_item_'+id].name.value=''; }
 if(document.forms['album_item_'+id].description.value=='TYPE TEXT DESCRIPTION HERE'){ document.forms['album_item_'+id].description.value=''; }
 jQuery('#popupmsg').prepend('<div id="loading-gif" style="float:right;"><img src="../gfx/loading2.gif" /></div>');
 ajax_formpost(document.forms['album_item_'+id]);
 }
function o_cancel_album(id){ getElem('popupmsg').style.height = (getElem('popupmsg').offsetHeight-34)+'px'; o_edit_album(id); }
function o_delete_album(id){ ajaxeval('albums_cms.php?delete='+id); }
function o_filename_album(e){  }

//TRACKS CMS FUNCTIONS
function o_add_track(id){
 //openpopup('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="../gfx/loading.gif" /></div>');
 ajaxeval('tracks_cms.php','add=&new=&albumid='+id);
 }
function o_insert_track(id,album_id){
 n = document.createElement('div');
 n.id = 'track-'+id;
 n.className = 'track';
 insertBefore(n,getElem('new-track-marker-'+album_id));
 ajaxload('get_info.php?track_id='+id,false,'track-'+id,false);
 ajaxload('get_info.php?album_id='+album_id,false,'album-'+album_id,false);
 o_edit_track(id);
 }
function o_edit_track(id){
 openpopup('<div id="loading-gif" style="text-align:center;padding:50px 0px 80px;"><img src="../gfx/loading.gif" /></div>');
 
 oncomplete = function(){
 getElem('popupmsg').style.height = 'auto';
 $$(document.forms['track_item_'+id].artist)
 .add('blur',function(event){ if(this.value==''){ jQuery(this).addClass('textarea-autosize-empty'); this.value='TYPE ARTIST NAME HERE'; }; })
 .add('focus',function(event){ jQuery(this).removeClass('textarea-autosize-empty'); if(this.value=='TYPE ARTIST NAME HERE'){ this.value=''; }; }); 
 $$(document.forms['track_item_'+id].name)
 .add('blur',function(event){ if(this.value==''){ jQuery(this).addClass('textarea-autosize-empty'); this.value='TYPE TRACK TITLE HERE'; }; })
 .add('focus',function(event){ jQuery(this).removeClass('textarea-autosize-empty'); if(this.value=='TYPE TRACK TITLE HERE'){ this.value=''; }; }); 
 $$(document.forms['track_item_'+id].description)
 .add('blur',function(event){ if(this.value==''){ jQuery(this).addClass('textarea-autosize-empty'); this.value='TYPE TRACK DESCRIPTION HERE'; }; })
 .add('focus',function(event){ jQuery(this).removeClass('textarea-autosize-empty'); if(this.value=='TYPE TRACK DESCRIPTION HERE'){ this.value=''; }; });
 if(isIE()){
  $$('.textarea-autosize')
  .add('keydown',function(event){ this.style.height=this.scrollHeight+'px'; })
  .add('keyup',function(event){ this.style.height=this.scrollHeight+'px'; }); 
  }
 else{
  $$('.textarea-autosize')
  .add('keydown',function(event){ this.style.height=(this.offsetHeight-15)+'px';this.style.height=this.scrollHeight+'px'; })
  .add('keyup',function(event){ alert(keycode(event)); this.style.height=(this.offsetHeight-15)+'px'; this.style.height=this.scrollHeight+'px'; });
  }
 document.forms['track_item_'+id].artist.style.height = document.forms['track_item_'+id].artist.scrollHeight+'px';
 document.forms['track_item_'+id].name.style.height = document.forms['track_item_'+id].name.scrollHeight+'px';
 document.forms['track_item_'+id].description.style.height = document.forms['track_item_'+id].description.scrollHeight+'px';
 checkbox_ify('checkbox-track-attr');
  }
 
 ajaxload('tracks_cms.php?id='+id,false,'popupmsg',oncomplete);
 }
function o_save_track(id){
 if(document.forms['track_item_'+id].name.value=='TYPE TRACK TITLE HERE'){ document.forms['track_item_'+id].name.value=''; }
 if(document.forms['track_item_'+id].description.value=='TYPE TRACK DESCRIPTION HERE'){ document.forms['track_item_'+id].description.value=''; }
 jQuery('#popupmsg').prepend('<div id="loading-gif" style="float:right;"><img src="../gfx/loading2.gif" /></div>');
 ajax_formpost(document.forms['track_item_'+id]);
 }
function o_cancel_track(id){ getElem('popupmsg').style.height = (getElem('popupmsg').offsetHeight-34)+'px'; o_edit_track(id); }
function o_delete_track(id,albumid){ if(confirm("Are you sure you wish to delete this TRACK?")) ajaxeval('tracks_cms.php','delete='+id+'&albumid='+albumid); }
function o_filename_track(e){  }

/*END CUSTOMISED CMS ACTIONS FOR ARTISTS/ALBUMS/TRACKS*/




/**/
function form_defaults(form,name_text_array){
 for(var name in name_text_array){
 
 $$(form[name])
 .add('blur',function(event){ if(this.value==''){ jQuery(this).addClass('textarea-autosize-empty'); this.value=name_text_array[name]; }; })
 .add('focus',function(event){ jQuery(this).removeClass('textarea-autosize-empty'); if(this.value==name_text_array[name]){ this.value=''; }; }); 
 if(isIE()){
  $$(form[name])
  .add('keydown',function(event){ this.style.height=this.scrollHeight+'px'; })
  .add('keyup',function(event){ this.style.height=this.scrollHeight+'px'; }); 
  }
 else{
  $$(form[name])
  .add('keydown',function(event){ this.style.height=(this.offsetHeight-15)+'px';this.style.height=this.scrollHeight+'px'; })
  .add('keyup',function(event){ this.style.height=(this.offsetHeight-15)+'px'; this.style.height=this.scrollHeight+'px'; });
  }  
 form[name].style.height = form[name].scrollHeight+'px';
 form[name].style.height = form[name].scrollHeight+'px';
  }
 }








