// Initialize global variables
var songSource = '';
var controller;
var action;
var base;
var baseurl;
var songs = new Array($(".songmp3").length);
var comboShareVideoEvent;
var songPlayError = 0;

$(document).ready(function()
{
	// Controller and Action
	controller = $("#sp_ref1").html();
	action = $("#sp_action").html();
	baseurl = $("#sp_base").html();
	// Main tabs
	var tab = controller;
	if(tab == 'index' || tab === '') {
		$("#index").attr("src",'http://d382womoc7z666.cloudfront.net/static/nav01_on.gif');
	} else if (tab == "artist" || tab == "album" || tab == "music" || tab == "playlist") {
		$("#music").attr("src",'http://d382womoc7z666.cloudfront.net/static/nav02_on.gif');
	} else if(tab =="manage") {
		$("#manage").attr("src",'http://d382womoc7z666.cloudfront.net/static/nav06_on.gif');
	} else if(tab =="friends") {
		$("#friends").attr("src",'http://d382womoc7z666.cloudfront.net/static/nav03_on.gif');
	} else if(tab =="download") {
		$("#download").attr("src",'http://d382womoc7z666.cloudfront.net/static/nav04_on.gif');
	} else if(tab =="myprofile") {
		$("#myprofile").attr("src",'http://d382womoc7z666.cloudfront.net/static/nav05_on.gif');
	}
	// Sub tabs
	if($("#tab_"+action).length > 0) {
		$("#tab_"+action).attr("class", "current");
	}
	// Labelify
	$("input").each(function() {
		$obj = $(this);
		if($obj.attr("title").length > 0) {
			$obj.labelify();
		}
	});
	$("textarea").each(function() {
		$obj = $(this);
		if($obj.attr("title").length > 0) {
			$obj.labelify();
		}
	});
	// Playlist Sorting
	$("#plsongs").sortable({
		scroll: true ,
		stop: function(ev, ui){
			plSort();
		}
	});
	// Playlist Change
	$("#plrhs").change(function () {
      	$("#plrhs option:selected").each(function () {
        	plChange($(this).attr("id"));
        });
    })
	// Play
    songPlay();
	// Combo
	if(controller == "myprofile") {
		if(action == "index") {
			comboswitch('playlist', 0);
		}
	} else if(controller == "user") {
		if(action == "index") {
			comboswitch('scrap', 0);
		}
	} else if(controller == "playlist") {
		if(action == "list") {
			comboswitch('playlistaddsongs', 0);
		} else if(action == "onenl") {
			comboswitch('playlistaddsongs', 0);
		}
	}

	// Header Width Adjust
	var headerwidth = $("#mainheaderlhs").width();
	if($("#mainheadernull").html()) {
		var headernullwidth = $("#mainheadernull").width();
		headerwidth = headerwidth - headernullwidth;
	}
	if(headerwidth > 0) {
		$("#mainheaderrhs").css({'padding-right': ''+headerwidth+'px'});
	}
	// Status Update Input
	if($("#status").length > 0 ) {
		$("#status").blur(function () {
			tstatusblur();
		});
	}
	// Status
	$("form#statusupdate").find("button").each(function(){
		$(this).click(function () {
	      statusUpdate();
	    });
	});
	// Default Prevent
	pDefault('songmp3link');
	//
	loadPlayer();
	// Overlib
	$("span.overlib").overlib();
	// PL extend
	//$("div#plsongsrhsdiv").plExtend();
	$("#plPlayAll").bind("click", function() {
		sunohfmmp3toggle(0, 1);
		return false;
	});
	// Video
	$(".videowidgetDiv").each(function(){videoWidget($(this));})
	//
	$(".select_input").bind("click", function() {
		select_input($(this))
	});
	$(".toggle").bind("click", function() {
		var name = $(this).attr("name");
		$("#"+name).toggle();
	});
	// Textarea expand
	$(".texpando").bind("focus", function() {
		$(this).css('height', '50px');
	});
	// Round
	settings = {
	  tl: { radius: 5 },
	  tr: { radius: 5 },
	  bl: { radius: 5 },
	  br: { radius: 5 },
	  antiAlias: true,
	  autoPad: false,
	  validTags: ["div"]
	}
	settingsTop = {
	  tl: { radius: 3 },
	  tr: { radius: 3 },
	  bl: false,
	  br: false,
	  antiAlias: true,
	  autoPad: false,
	  validTags: ["div", "table"]
	}
    newCornersObj = new curvyCorners(settings, 'rounded');
    newCornersTopObj = new curvyCorners(settingsTop, 'roundedTop');
    newCornersObj.applyCornersToAll();
    newCornersTopObj.applyCornersToAll();
    // Song Details
	songMore();
	// Friend Invites
	friendInvites();
	// Quick Search
	$(".quicksearch").each( function(){
		var a = $(this).attr("name");
		var oSuggest = $(this).autocomplete(
			baseurl+'/ajax/'+a,
			{onItemSelect:acSelected,
			 selectFirst: true,
			 inputClass: a
			}
		);
	});
	// Change
	$(".changesearch").each( function(){
		$(this).bind("keyup", function(e){
			var ar = $(this).attr("name");
			var key = $(this).val();
			var len = key.length;
			if(len > 3) {
				notice('Searching...', '');
				$.php(baseurl+'/ajax/artistsongsearch/keyword/'+key+'/artist/'+ar,{});
			} else if(len == 0) {
				$.php(baseurl+'/ajax/artistsongsearch/showall/1/artist/'+ar,{});
			}
		});
	});
	//
	if($.browser.msie || $.browser.opera){
		$(".buttonfavdiv").show();
		$(".buttonfav").jFav();
	}

});


function acSelected(li)
{
	noticeC();
	if( li == null ) {
		return false;
	}
	if( !!li.extra ) {
		var sValue = li.extra[0];
	} else {
		var sValue = li.selectValue;
	}
	var c = $(".quicksearch").attr("class");
	var cparts = c.split(" ");
	if(cparts[1] == "acalbums") {
		$.php(baseurl+'/ajax/albums/title/'+sValue,{});
	} else if(cparts[1] == "acartists") {
		var url = 'http://sunoh.fm/artist/index/id/'+sValue;
		//suRedirect(url);
		window.location = url;
	}
}


function songMore()
{
	var i = 0;
	$(".songmore").each(function() {
		var idf, id;
		idf = $(this).attr("name").split('_');
		id = idf[1];
		$p = $(this).parent().next().next();
		$p.attr("id", "songmore_"+id+"_"+i);

		$p.find("div.songmorecontent").each(function(){
			$(this).attr("id", "songmorecontent_"+id+"_"+i);
		});

		$(this).bind("click", function() {
			$obj = $(this);
			$p = $obj.parent().next().next();
			showMoreHide($p.attr("id"));
			var dis = $p.css("display");
			$(".songmoreimg").each(function(){
				$(this).attr("src", "http://d382womoc7z666.cloudfront.net/static/bullet_arrow_bottom.png");
			});
			if(dis == "none") {
				if($.browser.msie){
					$p.css("display", "inline");
				} else {
					$p.css("display", "table-row");
				}
				$p.find(".songmorelink:first").trigger('click');
				$obj.children("img").each(function(){
					$(this).attr("src", "http://d382womoc7z666.cloudfront.net/static/bullet_arrow_top.png");
				});
				statsSD(id);
			} else {
				$p.css("display", "none");
			}
		});

		$p.find(".songmorelink").each(function(){
			var type = $(this).text().toLowerCase();
			$(this).bind("click", function() {
				var contentid = $p.find(".songmorecontent").attr("id");
				$("#"+contentid ).html('Loading...');
				$.php(baseurl+'/ajax/song'+type+'/song/'+id+'/display/'+contentid,{});
				$p.find(".songmorelink").each(function(){
					$(this).removeClass("active");
				});
				$(this).addClass("active");
				return false;
			});
		});

		i++;
	});
}

function showMoreHide(id)
{
	$(".songmorebox").each(function() {
		if($(this).attr("id") != id) {
			$(this).hide();
		}
	});
}

function friendInvites()
{
	$(".submitadd").each(function(){
		$(this).bind("click", function() {
			notice('Updating...', '');
			$form = $(this).parents(".friendadd");
			var url = baseurl+'/inbox/friendadd';
			$.php(url, $form.formToArray(true));
		});
	});
	$(".submitignore").each(function(){
		$(this).bind("click", function() {
			notice('Updating...', '');
			$form = $(this).parents(".friendignore");
			var url = baseurl+'/inbox/friendignore';
			$.php(url, $form.formToArray(true));
		});
	});
}

function suToggle(ids)
{
	var id = ids.split(',');
	jQuery.each(id, function(i, val) {
		$('#'+val).toggle();
	});
}

/* Plugin Detect */
var swfobject=function(){var b="undefined",Q="object",n="Shockwave Flash",p="ShockwaveFlash.ShockwaveFlash",P="application/x-shockwave-flash",m="SWFObjectExprInst",j=window,K=document,T=navigator,o=[],N=[],i=[],d=[],J,Z=null,M=null,l=null,e=false,A=false;var h=function(){var v=typeof K.getElementById!=b&&typeof K.getElementsByTagName!=b&&typeof K.createElement!=b,AC=[0,0,0],x=null;if(typeof T.plugins!=b&&typeof T.plugins[n]==Q){x=T.plugins[n].description;if(x&&!(typeof T.mimeTypes!=b&&T.mimeTypes[P]&&!T.mimeTypes[P].enabledPlugin)){x=x.replace(/^.*\s+(\S+\s+\S+$)/,"$1");AC[0]=parseInt(x.replace(/^(.*)\..*$/,"$1"),10);AC[1]=parseInt(x.replace(/^.*\.(.*)\s.*$/,"$1"),10);AC[2]=/r/.test(x)?parseInt(x.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof j.ActiveXObject!=b){var y=null,AB=false;try{y=new ActiveXObject(p+".7")}catch(t){try{y=new ActiveXObject(p+".6");AC=[6,0,21];y.AllowScriptAccess="always"}catch(t){if(AC[0]==6){AB=true}}if(!AB){try{y=new ActiveXObject(p)}catch(t){}}}if(!AB&&y){try{x=y.GetVariable("$version");if(x){x=x.split(" ")[1].split(",");AC=[parseInt(x[0],10),parseInt(x[1],10),parseInt(x[2],10)]}}catch(t){}}}}var AD=T.userAgent.toLowerCase(),r=T.platform.toLowerCase(),AA=/webkit/.test(AD)?parseFloat(AD.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,q=false,z=r?/win/.test(r):/win/.test(AD),w=r?/mac/.test(r):/mac/.test(AD);/*@cc_on q=true;@if(@_win32)z=true;@elif(@_mac)w=true;@end@*/return{w3cdom:v,pv:AC,webkit:AA,ie:q,win:z,mac:w}}();var L=function(){if(!h.w3cdom){return }f(H);if(h.ie&&h.win){try{K.write("<script id=__ie_ondomload defer=true src=//:><\/script>");J=C("__ie_ondomload");if(J){I(J,"onreadystatechange",S)}}catch(q){}}if(h.webkit&&typeof K.readyState!=b){Z=setInterval(function(){if(/loaded|complete/.test(K.readyState)){E()}},10)}if(typeof K.addEventListener!=b){K.addEventListener("DOMContentLoaded",E,null)}R(E)}();function S(){if(J.readyState=="complete"){J.parentNode.removeChild(J);E()}}function E(){if(e){return }if(h.ie&&h.win){var v=a("span");try{var u=K.getElementsByTagName("body")[0].appendChild(v);u.parentNode.removeChild(u)}catch(w){return }}e=true;if(Z){clearInterval(Z);Z=null}var q=o.length;for(var r=0;r<q;r++){o[r]()}}function f(q){if(e){q()}else{o[o.length]=q}}function R(r){if(typeof j.addEventListener!=b){j.addEventListener("load",r,false)}else{if(typeof K.addEventListener!=b){K.addEventListener("load",r,false)}else{if(typeof j.attachEvent!=b){I(j,"onload",r)}else{if(typeof j.onload=="function"){var q=j.onload;j.onload=function(){q();r()}}else{j.onload=r}}}}}function H(){var t=N.length;for(var q=0;q<t;q++){var u=N[q].id;if(h.pv[0]>0){var r=C(u);if(r){N[q].width=r.getAttribute("width")?r.getAttribute("width"):"0";N[q].height=r.getAttribute("height")?r.getAttribute("height"):"0";if(c(N[q].swfVersion)){if(h.webkit&&h.webkit<312){Y(r)}W(u,true)}else{if(N[q].expressInstall&&!A&&c("6.0.65")&&(h.win||h.mac)){k(N[q])}else{O(r)}}}}else{W(u,true)}}}function Y(t){var q=t.getElementsByTagName(Q)[0];if(q){var w=a("embed"),y=q.attributes;if(y){var v=y.length;for(var u=0;u<v;u++){if(y[u].nodeName=="DATA"){w.setAttribute("src",y[u].nodeValue)}else{w.setAttribute(y[u].nodeName,y[u].nodeValue)}}}var x=q.childNodes;if(x){var z=x.length;for(var r=0;r<z;r++){if(x[r].nodeType==1&&x[r].nodeName=="PARAM"){w.setAttribute(x[r].getAttribute("name"),x[r].getAttribute("value"))}}}t.parentNode.replaceChild(w,t)}}function k(w){A=true;var u=C(w.id);if(u){if(w.altContentId){var y=C(w.altContentId);if(y){M=y;l=w.altContentId}}else{M=G(u)}if(!(/%$/.test(w.width))&&parseInt(w.width,10)<310){w.width="310"}if(!(/%$/.test(w.height))&&parseInt(w.height,10)<137){w.height="137"}K.title=K.title.slice(0,47)+" - Flash Player Installation";var z=h.ie&&h.win?"ActiveX":"PlugIn",q=K.title,r="MMredirectURL="+j.location+"&MMplayerType="+z+"&MMdoctitle="+q,x=w.id;if(h.ie&&h.win&&u.readyState!=4){var t=a("div");x+="SWFObjectNew";t.setAttribute("id",x);u.parentNode.insertBefore(t,u);u.style.display="none";var v=function(){u.parentNode.removeChild(u)};I(j,"onload",v)}U({data:w.expressInstall,id:m,width:w.width,height:w.height},{flashvars:r},x)}}function O(t){if(h.ie&&h.win&&t.readyState!=4){var r=a("div");t.parentNode.insertBefore(r,t);r.parentNode.replaceChild(G(t),r);t.style.display="none";var q=function(){t.parentNode.removeChild(t)};I(j,"onload",q)}else{t.parentNode.replaceChild(G(t),t)}}function G(v){var u=a("div");if(h.win&&h.ie){u.innerHTML=v.innerHTML}else{var r=v.getElementsByTagName(Q)[0];if(r){var w=r.childNodes;if(w){var q=w.length;for(var t=0;t<q;t++){if(!(w[t].nodeType==1&&w[t].nodeName=="PARAM")&&!(w[t].nodeType==8)){u.appendChild(w[t].cloneNode(true))}}}}}return u}function U(AG,AE,t){var q,v=C(t);if(v){if(typeof AG.id==b){AG.id=t}if(h.ie&&h.win){var AF="";for(var AB in AG){if(AG[AB]!=Object.prototype[AB]){if(AB.toLowerCase()=="data"){AE.movie=AG[AB]}else{if(AB.toLowerCase()=="styleclass"){AF+=' class="'+AG[AB]+'"'}else{if(AB.toLowerCase()!="classid"){AF+=" "+AB+'="'+AG[AB]+'"'}}}}}var AD="";for(var AA in AE){if(AE[AA]!=Object.prototype[AA]){AD+='<param name="'+AA+'" value="'+AE[AA]+'" />'}}v.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+AF+">"+AD+"</object>";i[i.length]=AG.id;q=C(AG.id)}else{if(h.webkit&&h.webkit<312){var AC=a("embed");AC.setAttribute("type",P);for(var z in AG){if(AG[z]!=Object.prototype[z]){if(z.toLowerCase()=="data"){AC.setAttribute("src",AG[z])}else{if(z.toLowerCase()=="styleclass"){AC.setAttribute("class",AG[z])}else{if(z.toLowerCase()!="classid"){AC.setAttribute(z,AG[z])}}}}}for(var y in AE){if(AE[y]!=Object.prototype[y]){if(y.toLowerCase()!="movie"){AC.setAttribute(y,AE[y])}}}v.parentNode.replaceChild(AC,v);q=AC}else{var u=a(Q);u.setAttribute("type",P);for(var x in AG){if(AG[x]!=Object.prototype[x]){if(x.toLowerCase()=="styleclass"){u.setAttribute("class",AG[x])}else{if(x.toLowerCase()!="classid"){u.setAttribute(x,AG[x])}}}}for(var w in AE){if(AE[w]!=Object.prototype[w]&&w.toLowerCase()!="movie"){F(u,w,AE[w])}}v.parentNode.replaceChild(u,v);q=u}}}return q}function F(t,q,r){var u=a("param");u.setAttribute("name",q);u.setAttribute("value",r);t.appendChild(u)}function X(r){var q=C(r);if(q&&(q.nodeName=="OBJECT"||q.nodeName=="EMBED")){if(h.ie&&h.win){if(q.readyState==4){B(r)}else{j.attachEvent("onload",function(){B(r)})}}else{q.parentNode.removeChild(q)}}}function B(t){var r=C(t);if(r){for(var q in r){if(typeof r[q]=="function"){r[q]=null}}r.parentNode.removeChild(r)}}function C(t){var q=null;try{q=K.getElementById(t)}catch(r){}return q}function a(q){return K.createElement(q)}function I(t,q,r){t.attachEvent(q,r);d[d.length]=[t,q,r]}function c(t){var r=h.pv,q=t.split(".");q[0]=parseInt(q[0],10);q[1]=parseInt(q[1],10)||0;q[2]=parseInt(q[2],10)||0;return(r[0]>q[0]||(r[0]==q[0]&&r[1]>q[1])||(r[0]==q[0]&&r[1]==q[1]&&r[2]>=q[2]))?true:false}function V(v,r){if(h.ie&&h.mac){return }var u=K.getElementsByTagName("head")[0],t=a("style");t.setAttribute("type","text/css");t.setAttribute("media","screen");if(!(h.ie&&h.win)&&typeof K.createTextNode!=b){t.appendChild(K.createTextNode(v+" {"+r+"}"))}u.appendChild(t);if(h.ie&&h.win&&typeof K.styleSheets!=b&&K.styleSheets.length>0){var q=K.styleSheets[K.styleSheets.length-1];if(typeof q.addRule==Q){q.addRule(v,r)}}}function W(t,q){var r=q?"visible":"hidden";if(e&&C(t)){C(t).style.visibility=r}else{V("#"+t,"visibility:"+r)}}function g(s){var r=/[\\\"<>\.;]/;var q=r.exec(s)!=null;return q?encodeURIComponent(s):s}var D=function(){if(h.ie&&h.win){window.attachEvent("onunload",function(){var w=d.length;for(var v=0;v<w;v++){d[v][0].detachEvent(d[v][1],d[v][2])}var t=i.length;for(var u=0;u<t;u++){X(i[u])}for(var r in h){h[r]=null}h=null;for(var q in swfobject){swfobject[q]=null}swfobject=null})}}();return{registerObject:function(u,q,t){if(!h.w3cdom||!u||!q){return }var r={};r.id=u;r.swfVersion=q;r.expressInstall=t?t:false;N[N.length]=r;W(u,false)},getObjectById:function(v){var q=null;if(h.w3cdom){var t=C(v);if(t){var u=t.getElementsByTagName(Q)[0];if(!u||(u&&typeof t.SetVariable!=b)){q=t}else{if(typeof u.SetVariable!=b){q=u}}}}return q},embedSWF:function(x,AE,AB,AD,q,w,r,z,AC){if(!h.w3cdom||!x||!AE||!AB||!AD||!q){return }AB+="";AD+="";if(c(q)){W(AE,false);var AA={};if(AC&&typeof AC===Q){for(var v in AC){if(AC[v]!=Object.prototype[v]){AA[v]=AC[v]}}}AA.data=x;AA.width=AB;AA.height=AD;var y={};if(z&&typeof z===Q){for(var u in z){if(z[u]!=Object.prototype[u]){y[u]=z[u]}}}if(r&&typeof r===Q){for(var t in r){if(r[t]!=Object.prototype[t]){if(typeof y.flashvars!=b){y.flashvars+="&"+t+"="+r[t]}else{y.flashvars=t+"="+r[t]}}}}f(function(){U(AA,y,AE);if(AA.id==AE){W(AE,true)}})}else{if(w&&!A&&c("6.0.65")&&(h.win||h.mac)){A=true;W(AE,false);f(function(){var AF={};AF.id=AF.altContentId=AE;AF.width=AB;AF.height=AD;AF.expressInstall=w;k(AF)})}}},getFlashPlayerVersion:function(){return{major:h.pv[0],minor:h.pv[1],release:h.pv[2]}},hasFlashPlayerVersion:c,createSWF:function(t,r,q){if(h.w3cdom){return U(t,r,q)}else{return undefined}},removeSWF:function(q){if(h.w3cdom){X(q)}},createCSS:function(r,q){if(h.w3cdom){V(r,q)}},addDomLoadEvent:f,addLoadEvent:R,getQueryParamValue:function(v){var u=K.location.search||K.location.hash;if(v==null){return g(u)}if(u){var t=u.substring(1).split("&");for(var r=0;r<t.length;r++){if(t[r].substring(0,t[r].indexOf("="))==v){return g(t[r].substring((t[r].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(A&&M){var q=C(m);if(q){q.parentNode.replaceChild(M,q);if(l){W(l,true);if(h.ie&&h.win){M.style.display="block"}}M=null;l=null;A=false}}}}}();

function loadPlayer()
{
	var playerVersion = swfobject.getFlashPlayerVersion();
	if(playerVersion.major) {
		$.php(baseurl+'/ajax/statsfv/major/'+playerVersion.major+'/minor/'+playerVersion.minor+'/release/'+playerVersion.release,{});
	}
	if(playerVersion.major < 8 ) {
		$("#noticeTop").css("display", "block");
		$("#container").css("padding-top", "30px");
		$("#flashInstallButton").bind("click", function(){
			url = 'http://www.adobe.com/products/flashplayer/';
			window.location = url;
		});
	}
}

/* Default Action Prevent */
function pDefault(tn)
{
	$("."+tn).each(function(){
		$(this).click(function(event){
			event.preventDefault();
		});
	});
}

function notice(m, t)
{
	$('#noticediv').css({'display' : 'block'});
	$('#notice').html("<span class='notice"+t+"'>"+m+"</span>");
}

function noticeC()
{
	$('#notice').html('');
	$('#noticediv').css({'display' : 'none'});
}


/* End Song Tabs */

/* Sunoh Nav */
function MM_preloadImages() { //v3.0
  	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* Sunoh.js */
function showAnswer(id)
{
    $("#" + id).toggle();
}

function closeTB()
{
    tb_remove();
}

// Status Update Input
function tstatus(name)
{
	var currVal = $("#status").attr("value");
	if(currVal.substr(-29, 29) == "What are you doing right now?") {
		$("#status").attr("value", name+" is ");
		if($.browser.msie) {
			var range = document.getElementById('status').createTextRange();
	    	range.collapse(false);
	    	range.select();
	  	}
	}
}

function tstatusblur()
{
	var currVal = $("#status").attr("value");
	var len = currVal.length;
	if(currVal.substring(len-4, len) == " is ") {
		$("#status").attr("value", "What are you doing right now?");
    }
}

function oc(a)
{
  var o = {};
  for(var i=0;i<a.length;i++) {
    o[a[i]]='';
  }
  return o;
}

function makeCurrent(tab2)
{
	document.getElementById(tab2).id = 'current';
}

function select_input(obj)
{
	var input=eval(obj);
	input.focus();
	input.select();
	if (!document.all) {
		return; // IE only
	}
	r=  input.createTextRange();
	r.execCommand('copy');
}

function slideshow(ids, images, captions, id)
{
	captions = $("#photoCaptions").html();
	var idList =[];
   	idList = ids.split(',');
   	var len = idList.length;
   	var imageList = [];
   	imageList = images.split(',');
   	var captionList = [];
   	captionList = captions.split(',');
   	var oIndex = jQuery.inArray(id, idList);
   	var currIndex, nextIndex, prevIndex;
   	if(oIndex + 1 == len) {
   		currIndex = 0;
   		nextIndex = 0;
   	} else {
		currIndex = oIndex + 1;
		nextIndex = oIndex + 1;
   	}
   	if(oIndex === 0) {
   		prevIndex = len - 1;
   	} else {
   		prevIndex = oIndex - 1;
   	}
	var newId = idList[currIndex];
   	var newImage = imageList[currIndex];
	var newCaption = captionList[currIndex];
	var nextId = idList[nextIndex];
	var prevId = idList[prevIndex];
	$("#sphoto").html("<img id='"+newId+"' src='"+newImage+"' onclick=\"slideshow('"+ids+"', '"+images+"', '"+captions+"', '"+newId+"' );\" class=\"imageBorder\" />");
	$("#scaption").html(newCaption);
	$("#next").html("<span onclick=\"slideshow('"+ids+"', '"+images+"', '"+captions+"', '"+nextId+"' );\"  class=\"linkPointer12\" >Next</span>");
	$("#previous").html("<span onclick=\"slideshow('"+ids+"', '"+images+"', '"+captions+"', '"+prevId+"' );\"  class=\"linkPointer12\" >Previous</span>");
	$("#pno").html(currIndex+1);
}

function rslideshow(id, url)
{
	window.location = url+"/photo/"+id;
}

function videoshow(ids, id)
{
	var idList = [];
   	idList = ids.split(',');
   	for (i=0; i<idList.length; i++) {
		$("#"+idList[i]).css("background","#FFF");
   	}
	$("#svideo").html("<object width=\"210\" height=\"170\"><param name=\"movie\" value=\"http://www.youtube.com/v/"+id+"&hl=en&fs=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><embed src=\"http://www.youtube.com/v/"+id+"&hl=en&fs=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"210\" height=\"170\"></embed></object>");
	currentVideo("v_"+id);
}

function currentVideo(vid)
{
	$("#"+vid).css("background","#CFCFCF");
}

function videoshowDetail(ids, id, song)
{
	var idList = [];
   	idList = ids.split(',');
   	for (i=0; i<idList.length; i++) {
		$("#"+idList[i]).css("background","#FFF");
   	}
	$("#svideo_"+song).html("<object width=\"135\" height=\"110\"><param name=\"movie\" value=\"http://www.youtube.com/v/"+id+"&hl=en&fs=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><embed src=\"http://www.youtube.com/v/"+id+"&hl=en&fs=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"135\" height=\"110\"></embed></object>");
	currentVideo("v_"+song+"_"+id);
}

function share(url)
{
	var popup=[];
	var s1 = url;
	popup.push(s1);
	//popup.push(u)
	w = screen.availWidth;
	h = screen.availHeight;
	var popW = 500;
	var popH = 400;
	var le = (w-popW)/2;
	var to = (h-popH)/2;
	try {
		var win = window.open(popup.join(''),'share', 'width=' + popW + ',height=' + popH + ',top=' + to + ',left=' + le);
		window.focus();
		win.focus();
	}
	catch(e){}
}

function showHidden(id1, id2)
{
	if($("#"+id1).html()) {
		$("#"+id2).show();
	}
}

function scrapSongCheck(id)
{
	var isChecked = $("#scrap_song_search_cb_"+id).attr('checked');
	if(isChecked) {
		var songinfo = $("#scrap_song_info_"+id).html();
		$("input[name='scrap_song']").attr("value", songinfo);
		$(":checkbox").attr('checked', false);
		$("#scrap_song_search_cb_"+id).attr('checked', true);
		$("#song_id").attr("value", id);
	} else {
		$("input[name='scrap_song']").attr("value", '');
		$("#song_id").attr("value", '');
	}
}

function songSearch()
{
	var keyword = $("input[name='scrap_song']").attr("value");
	keyword = jQuery.trim(keyword);
	var len = keyword.length;
	var html;
	$("#song_id").attr("value", '');
	if(len > 3) {
		$("#scrap_song_search").remove();
		html = '<table style="width:437px;" id="scrap_song_search"><tr><td style="width:35px;">&nbsp;</td><td>Loading...</td></tr></table>';
		$("#scrap_link_div").before(html);
		$.php(baseurl+'/ajax/songsearch/s/'+keyword,{});
	} else if(len < 4 & len > 0 ) {
		$("#scrap_song_search").remove();
		html = '<table style="width:437px;" id="scrap_song_search"><tr><td style="width:35px;">&nbsp;</td><td>Please enter a longer keyword</td></tr></table>';
		$("#scrap_link_div").before(html);
	} else {
		$("#scrap_song_search").remove();
		html = '<table style="width:437px;" id="scrap_song_search"><tr><td style="width:35px;">&nbsp;</td><td>Please enter keywords to search for</td></tr></table>';
		$("#scrap_link_div").before(html);
	}
}

function cancelSongSearch()
{
	$("#song_id").attr("value", '');
	$("#scrap_song_search").remove();
}

function fav(base, type, paction, id)
{
	var logged_in = $("#logged_in").html();
	if(logged_in == 1) {
      $.php(baseurl+'/ajax/'+paction+type+'/id/'+id+'/origin/'+action,{});
	} else {
		var url = baseurl+"/auth/login/ref1/"+$("#sp_ref1").html()+"/ref2/"+$("#sp_ref2").html()+"/message/Please login to continue...";
		window.location = url;
	}
}

function statsSD(s, a)
{
	$.php(baseurl+'/ajax/statssd/s/'+s+'/a/'+a+'/c/'+controller+'/ac/'+action,{});
}

function statsVideo(id)
{
	$.php(baseurl+'/ajax/statsvideo/id/'+id+'/c/'+controller+'/ac/'+action,{});
}

function checkAll()
{
	$(':checkbox').each(function(){
        if(this.checked) {
            this.checked = false;
        } else {
            this.checked = true;
        }
    });
    return false;
}

function suRedirect(url)
{
	url = baseurl+"/"+url;
	window.location = url;
}

function comboswitch(tab, initial)
{
	initial = (typeof initial == "undefined")? 1:initial;
	if(initial == 1) {
		noticeC();
	}
	$('.r1select').each(function(){
		$(this).removeClass('r1select');
		$(this).addClass('r1');
	});
	$('.containselect').each(function(){
		$(this).removeClass('containselect');
		$(this).addClass('contain');
	});

	$('.combotabdiv').each(function() {
		$obj = $(this);
		$(this).find("div").each(function() {
			var width = $(this).width();
			$obj.css("width", parseInt(width)+20);
		});
	});

	$('#combodiv'+tab).children().each(function(){
		if($(this).attr("class") == "rblock" || $(this).attr("class") == "rblock2") {
			$(this).children().each(function(){
				$(this).removeClass('r1');
				$(this).addClass('r1select');
			});
		}
		if($(this).attr("class") == 'contain') {
			$(this).removeClass('contain');
			$(this).addClass('containselect');
		}
	});
	$('#comboformdiv').children("div").each(function(){
		$(this).css({'display' : 'none'});
	});

	$('#comboform'+tab).css({'display' : 'block'});
	if (tab == "scrap") {
		$("#scrap").css({'width': '100%'});
	}
	if($.browser.msie) {
		$("#combotabdivpre").css("margin-top", "-12px");
	}
}

function comboShareSearch(skip)
{
	if (typeof(skip) == "undefined") {
		skip = 0;
	}
	comboShareFormReset();
	var keyword = $("input[name='combosharekeyword']").attr("value");
	var title = $("input[name='combosharekeyword']").attr("title");
	keyword = jQuery.trim(keyword);
	var len = keyword.length;
	if(len > 3) {
		if(keyword == title) {
			notice('Please enter keywords to search for', 'Err');
		} else {
			songstop();
			notice('Loading...', '');
			$.php(baseurl+'/ajax/combosharesearch/s/'+keyword+'/skip/'+skip,{});
		}
	} else if(len < 4 & len > 0 ) {
		notice('Please enter a longer keyword', 'Err');
	} else {
		notice('Please enter keywords to search for', 'Err');
	}
}

function comboPostVideoSearch()
{
	var keyword = $("input[name='combopostvideokeyword']").attr("value");
	var title = $("input[name='combopostvideokeyword']").attr("title");
	keyword = jQuery.trim(keyword);
	var len = keyword.length;
	if(len > 3) {
		if(keyword == title) {
			notice('Please enter keywords to search for', 'Err');
		} else {
			notice('Loading...', '');
			$.php(baseurl+'/ajax/combovideosearch/s/'+keyword,{});
		}
	} else if(len < 4 & len > 0 ) {
		notice('Please enter a longer keyword', 'Err');
	} else {
		notice('Please enter keywords to search for', 'Err');
	}
}

function comboShareVideoPlay(event)
{
	var id = event.data.id;
	$(".comboShareVideoPlay").each(function(){
		if("comboShareVideoPlay_"+id != $(this).attr("id")) {
			$(this).children('img').each(function(){
				$(this).attr({
					src : "http://d382womoc7z666.cloudfront.net/static/control_play_blue.png",
					title : "Play",
					alt : "Play"
				});
			});
		}
	});
	$(this).children('img').each(function(){
		var state = $(this).attr("alt");
		if(state == 'Play') {
			$(this).attr({
				src : "http://d382womoc7z666.cloudfront.net/static/control_stop_blue.png",
				title : "Stop",
				alt : "Stop"
			});

			$('#comboShareVideoParam').attr("value", "http://www.youtube.com/v/"+id+"&hl=en&fs=1");
			$('#comboShareVideoEmbed').attr("src", "http://www.youtube.com/v/"+id+"&hl=en&fs=1&autoplay=1");
			$("#comboShareVideoPlayer").css({'display' : 'block'});
			$.scrollTo('#v_'+id, 800);
		} else {
			$(this).attr({
				src : "http://d382womoc7z666.cloudfront.net/static/control_play_blue.png",
				title : "Play",
				alt : "Play"
			});
			$("#comboShareVideoPlayer").css({'display' : 'none'});
			$('#comboShareVideoParam').attr("value", "");
			$('#comboShareVideoEmbed').attr("src", "");
		}
	});
	comboShareVideoEvent = 'pp';
}


function comboShareVideoSelect(event) {
	if(comboShareVideoEvent == 'pp') {
		comboShareVideoEvent = 'select';
	} else {
		var id = event.data.id;
		var type = event.data.type;
		var tdClass = $(this).attr('class'); // = comboShare
		$(this).children().each(function(){
			var divClass = $(this).attr('class'); // = comboshareround
			comboPostVideoClean()
			var isCurrent =  divClass.indexOf("current");
			if(isCurrent > -1) {
				comboShareFormReset(id, type);
			} else {
				$('#'+divClass+"_"+id).addClass("current");
				$('#'+divClass+'_'+id).find('*').each(function(){
					$(this).css({'display' : 'block'});
				});
				comboShareFormSet(id, type);
			}
		});
	}
}


function comboShareSongSelect(event)
{
	var id = event.data.id;
	var type = event.data.type;
	var isChecked = $(this).attr('checked');
	comboShareClean();
	if(isChecked) {
		$(this).attr('checked', true);
		comboShareFormSet(id, type);
	} else {
		comboShareFormReset(id, type);
	}
}

function comboShareClean()
{
	$('#comboShareSong').find(':checkbox').each(function(){
		$(this).attr('checked', false);
	});
}

function comboPostVideoClean()
{
	$('.comboShare').children().each(function(){
		$(this).removeClass("current");
		$('.comboShareVideoAdd').css({'display' : 'none'});
	});
}

function comboShareFormReset(id, type)
{
	if(type == "postvideo") {
		$("#comboPostVideoSubmit").attr({"disabled":"disabled", "class":"buttonDisabled"});
		$('#comboPostVideoSelectId').attr("value", '');
	} else {
		$("#combosharesubmit").attr({"disabled":"disabled", "class":"buttonDisabled"});
		$('#comboShareSelectId').attr("value", '');
		$('#comboShareSelectType').attr("value", '');
	}

}

function comboShareFormSet(id, type)
{
	if(type == "postvideo") {
		$('#comboPostVideoSelectId').attr("value", id);
		$('#comboPostVideoSelectType').attr("value", type);
		$("#comboPostVideoSubmit").removeAttr("disabled");
	 	$("#comboPostVideoSubmit").attr("class", 'buttonLogin');
	} else {
		$('#comboShareSelectId').attr("value", id);
		$('#comboShareSelectType').attr("value", type);
		$("#combosharesubmit").removeAttr("disabled");
	 	$("#combosharesubmit").attr("class", 'buttonLogin');
	}
}

function comboShareFormSubmit()
{
	notice('Working on it...');
	var val = $('#comboShareSelectId').attr("value");
	var type = $('#comboShareSelectType').attr("value");
	if(val!=='' & type!=='') {
		var url = baseurl+"/combo/sharemusic"+controller;
		$.php(url, $('form#comboshareform').formToArray(true));
	} else {
		notice('Please select a song to share', 'Err');
	}
}

function comboPostVideoFormSubmit()
{
	notice('Working on it...', '');
	var val = $('#comboPostVideoSelectId').attr("value");
	if(val!=='') {
		var url = baseurl+"/combo/postvideo";
		$.php(url, $('form#combopostvideoform').formToArray(true));
	} else {
		notice('Please select a video to post', 'Err');
	}
}

function comboSharePlaylist()
{
	notice('Working on it...', '');
	var url = baseurl+'/playlist/share';
	$.php(url, $('form#comboshareplaylistform').formToArray(true));
}

function comboPLCollaborate()
{
	notice('Working on it...', '');
	var url = baseurl+'/playlist/collaborate';
	$.php(url, $('form#plcollaborate').formToArray(true));
}

function plSongSearch(skip)
{
	if (typeof(skip) == "undefined") {
		skip = 0;
	}
	var keyword = $("input[name='keyword']").attr("value");
	var auth = $("input[name='auth']").attr("value");
	var title = $("input[name='keyword']").attr("title");
	keyword = jQuery.trim(keyword);
	var len = keyword.length;
	$('div#plsearchhelper1').attr({style: 'visibility: hidden;'});
	if(len > 2) {
		if(title == keyword) {
			notice('Please enter keywords to search for', 'Err');
		} else {
			songstop();
			noticeC();
			var html = '<table class="plnotify"><tr><td><span class="font14" id="searchnotify"><img src="http://d382womoc7z666.cloudfront.net/static/loadingAnimation.gif" /></span></td></tr></table>';
			$('#songsearchresultspre').slideDown();
			$('#songsearchresults').slideDown();
			$("#songsearchresults").html(html);
			$.php(baseurl+'/playlist/songsearch/s/'+keyword+'/auth/'+auth+'/skip/'+skip,{});
			return false;
		}
	} else if(len < 4 & len > 0 ) {
		notice('Please enter a longer keyword', 'Err');
	} else {
		notice('Please enter keywords to search for', 'Err');
	}
}

function plSongAdd(id)
{
	if(id.length > 0) {
		var pl = $('#sp_playlist').html();
		if(pl > 0) {
			songstop();
			notice('Adding...', '');
			var auth = $("input[name='auth']").attr("value");
			$('#plsearchsong_'+id).css({'background' : '#F0F0F0'});
			$.php(baseurl+'/playlist/songadd/id/'+id+'/pl/'+pl+'/ct/'+controller+'/ac/'+action+'/auth/'+auth+'?ref='+location.href,{});
		} else {
			suRedirect('playlist/create/message/Please create a new Playlist...?ref='+location.href);
		}
	} else {
		notice('Error occured while adding song to Playlist', 'Err');
	}
}

function plSongRemove(id)
{
	if(id.length > 0) {
		var pl = $('#sp_playlist').html();
		if(pl > 0) {
			songstop();
			notice('Removing...', '');
			$('#plsongdata_'+id).css({'background' : '#F0F0F0'});
			var auth = $("input[name='auth']").attr("value");
			$.php(baseurl+'/playlist/songremove/id/'+id+'/pl/'+pl+'/auth/'+auth,{});
			songremove();
		} else {
			suRedirect('playlist/create/message/Please create a new Playlist...?ref='+location.href);
		}
	} else {
		notice('Error occured while removing song from Playlist', 'Err');
	}
}

function plSort()
{
	var pl = $('#sp_playlist').html();
	if(pl > 0) {
		songstop();
		var ids_o;
		var ids = $('#plsongs').sortable('toArray');
		var auth = $("input[name='auth']").attr("value");
		jQuery.each(ids, function(i, val) {
			id = val.split('_');
			if (ids_o) {
				ids_o = ids_o+","+id[1];
			} else {
				ids_o = id[1];
			}
		});
		noticeC();
		$.php(baseurl+'/playlist/sort/ids/'+ids_o+'/pl/'+pl+'/auth/'+auth,{});
		songPlay();
	}
}

function plNameSave()
{
	notice('Updating...');
	var url = baseurl+'/playlist/nameupd';
	$.php(url, $('form#plnameedit').formToArray(true));
}

function plSongSearchToggle()
{
	$('#songsearchresultspre').slideUp();
	$('#songsearchresults').slideUp();
}

function plEditShow()
{
	$('#plnameedit_name').toggle();
	$('#plnameedit_box').toggle();
}

function plCopy()
{
	$("form#plcopy").find("input[type='text']").each(function() {
		var t = $(this).attr("title");
		var v = $(this).val();
		if(v == t) {
			notice('Please enter a name for the new Playlist', 'Err');
		} else {
			notice('Copying...');
			var url = baseurl+'/playlist/copy';
			$.php(url, $('form#plcopy').formToArray(true));
		}
	});

}

function plChange(id)
{
	var pl = id.split('_');
	if(pl[1] == 0) {
		suRedirect('playlist/create?ref='+location.href);
	} else {
		notice('Loading...');
		$('#sp_playlist').html(pl[1]);
		$.php(baseurl+'/playlist/change/pl/'+pl[1],{});
	}
}

function plCreate()
{
	$("form#plcreateform").find("input").each(function() {
		var t = $(this).attr("title");
		var v = $(this).val();
		if(v == t) {
			notice('Please enter a name for the new Playlist', 'Err');
		} else {
			$("#plcreateform").submit();
		}
	});
}

function statusUpdate()
{
	$("form#statusupdate").find("input").each(function() {
		var t = 'What are you doing right now?';
		var v = $(this).val();
		if(v == t) {
			notice('Please enter valid status message', 'Err');
		} else {
			notice('Updating...', '');
			var url = baseurl+'/ajax/statusupdate';
			$.php(url, $('form#statusupdate').formToArray(true));
		}
	});
}

// Script for NiftyPlayer 1.7, by tvst from varal.org
// Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
var sunohfmplayername='sunohfmmp3';
var loadInnerHtml="<img src='http://d382womoc7z666.cloudfront.net/static/control_play_blue.png' class='mp3player' />";
var loadingInnerHtml="<img src='http://d382womoc7z666.cloudfront.net/static/icon_animated_busy.gif' class='mp3player' />";
var playInnerHtml="<img src='http://d382womoc7z666.cloudfront.net/static/control_play_blue.png' class='mp3player' />";
var pauseInnerHtml="<img src='http://d382womoc7z666.cloudfront.net/static/control_pause_blue.png' class='mp3player' />";
var errorInnerHtml="<img src='http://d382womoc7z666.cloudfront.net/static/error.png' class='mp3player' />";
var playingSongNo=-1;
var prevSongNo=-1;
var FlashHelper =
{
	movieIsLoaded : function (theMovie)
	{
		if (typeof(theMovie) != "undefined") return theMovie.PercentLoaded() == 100;
		else return
		false;
  	},
	getMovie : function (movieName)
	{
  		if (window.document[movieName])	{
		  return window.document[movieName];
		}
		if (navigator.appName.indexOf("Microsoft Internet")==-1) {
			if (document.embeds && document.embeds[movieName])
		  		return document.embeds[movieName];
		} else {
			return document.getElementById(movieName);
		}
	}
};


function sunohfmmp3player()
{
	this.obj = FlashHelper.getMovie(sunohfmplayername);
	if (!FlashHelper.movieIsLoaded(this.obj)) return;
	this.play = function () {
		try{
			this.obj.TCallLabel('/','play');			
		} catch(err){
			$.php(baseurl+'/ajax/playerror2/error/'+err,{});			
		}
	};
	this.pause = function () {
		this.obj.TCallLabel('/','pause');
	};
	this.loadNewSong = function (songid,sessionid) {
		this.obj.SetVariable('/:songid', songid);
		this.obj.SetVariable('/:songLoaded', 0);
		this.obj.SetVariable('/:sessionid', sessionid);
		this.play();
	};
	this.stop = function () {
		this.obj.TCallLabel('/','stop');
	};
	return this;
}

function sunohfmmp3toggle(songSeqNo,actionSeqNo)
{
	if(songs.length > 0) {
		switch(actionSeqNo){
			case 1:
				if(prevSongNo!=-1) {
					$("#sfmsongid_"+songs[prevSongNo][0]+"_"+prevSongNo).html(loadInnerHtml);
	        		songClickBind(prevSongNo, songs[prevSongNo][0], 1);
				}
				playingSongNo=prevSongNo=songSeqNo;
	    		$("#sfmsongid_"+songs[playingSongNo][0]+"_"+playingSongNo).html(loadingInnerHtml);
	        	songClickBind(playingSongNo, songs[playingSongNo][0], 1);
	    		sunohfmmp3player().loadNewSong(songs[songSeqNo][0],songs[songSeqNo][1]);
	    		pDefault('songmp3link');
			break;
			case 2:
				sunohfmmp3player().pause();
				$("#sfmsongid_"+songs[playingSongNo][0]+"_"+playingSongNo).html(playInnerHtml);
	        	songClickBind(playingSongNo, songs[playingSongNo][0], 3);
	        	pDefault('songmp3link');
			break;
			case 3:
				sunohfmmp3player().play();
				songloaded();
			break;
		}
	}
}

function songloaded()
{
	$("#sfmsongid_"+songs[playingSongNo][0]+"_"+playingSongNo).html(pauseInnerHtml);
	songClickBind(playingSongNo, songs[playingSongNo][0], 2);
	pDefault('songmp3link');
}

function songfinished()
{
	$p = $("#sfmsongid_"+songs[prevSongNo][0]+"_"+prevSongNo).parents(".songtr").next().next();
	$p.css("display", "none");
	$("#sfmsongid_"+songs[prevSongNo][0]+"_"+prevSongNo).html(loadInnerHtml);
	songClickBind(prevSongNo, songs[prevSongNo][0], 1);
	if(prevSongNo+1 < songs.length) {
		sunohfmmp3toggle(prevSongNo+1, 1);
		$.php(baseurl+'/ajax/play/id/'+songs[prevSongNo][0]+'/val/1',{});
		$obj = $("#sfmsongid_"+songs[prevSongNo][0]+"_"+prevSongNo).parents(".songtr").find(".songmore");
		$obj.trigger("click");
	}
	pDefault('songmp3link');
}

function songloaderror()
{
	$("#sfmsongid_"+songs[playingSongNo][0]+"_"+playingSongNo).html(errorInnerHtml);
	songClickBind(playingSongNo, songs[playingSongNo][0], 2);
	if(songPlayError == 0) {
		var playerVersion = swfobject.getFlashPlayerVersion();
		$.php(baseurl+'/ajax/playerror/id/'+songs[playingSongNo][0]+'/val/1/major/'+playerVersion.major+'/minor/'+playerVersion.minor+'/release/'+playerVersion.release,{});
		songPlayError = 1;
	}
	pDefault('songmp3link');
}

function songstop()
{
	$(".songmp3").find("a").each(function() {
		$(this).html(loadInnerHtml);
	});
	sunohfmmp3player().stop();
}

function songremove()
{
	prevSongNo=-1;
}

function songPlay()
{
	var i = 0;
	songs = [];
	$(".songmp3").each(function() {
		var $obj = $(this);
		var id, fid, us, nid, con, usf;
		$obj.children("a").each(function() {
			fid = $(this).attr("id");
			$("#"+fid).unbind();
			usf = fid.indexOf("_", 0) + 1;
			us = fid.indexOf("_", usf);
			id = fid.substr(usf, fid.length);
			songs[i] = [];
			songs[i][1] = '1';
			if(us == -1) {
				songs[i][0] = id;
				$(this).attr("id", fid+"_"+i);
			} else {
				con = fid.substr(0, usf);
				nid = fid.substr(usf, us-usf);
				fid = con+nid+"_"+i;
				songs[i][0] = nid;
				$(this).attr("id", fid);
			}
		});
		$obj.attr("id", "sfmsong"+i);
		i++;
	});
	jQuery.each(songs, function(i, val) {
		var us = val[0].indexOf("_", 0);
		if(us == -1) {
			var id = val[0];
		} else {
			var id = val[0].substr(0, us);
		}
		if(id > 0) {
			songClickBind(i, id, 1);
		}
	});
}

function songClickBind(i, id, val)
{
	$("#sfmsongid_"+id+"_"+i).unbind();
	$("#sfmsongid_"+id+"_"+i).bind("click", function() {
		noticeC();
		sunohfmmp3toggle(i, val);
		songPlayError = 0;
		$.php(baseurl+'/ajax/play/id/'+id+'/val/'+val,{});
		$obj = $(this).parents(".songtr").find(".songmore");
		$p = $obj.parent().next().next();
		var dis = $p.css("display");
		if((val == 1 || val == 3) & dis == "none") {
			$obj.trigger('click');
		}
		return false;
	});
}

/* Overlib */
jQuery.fn.overlib = function() {
	this.each(function(){
		var $obj = $(this);
		$obj.children().each(function() {
			if($(this).attr("tagName") == "A") {
				$(this).attr({"href":"#", "class":"overlibLink"});
				$(this).click(function(event){
					event.preventDefault();
				});
			}
			if($(this).attr("tagName") == "SPAN") {
				$(this).hide();
				$(this).attr("class", "overlibData");
			}
		});
		$obj.click(function(){
			$obj.children("span").each(function() {
				var cd = $(this).css("display");
				if(cd == "none") {
					var p = $obj.position();
					var finalL = p.left;
					var finalT = p.top + $obj.height() + 2;
					$(this).css({"top":finalT, "left":finalL});
					$(this).show();
				} else {
					$(this).hide();
				}
			});
		});
	});
};

function videoWidget(obj)
{
	var id, fid, fidparts, src, srcparts, video_id;
	var images = [];
	$obj = obj;
	$obj.children("img").each(function(){
		images.push($(this));
		id = $(this).attr("id");
		src = $(this).attr("src");
		srcparts = src.split('/');
		video_id = srcparts[srcparts.length - 2];
	});
	$obj.children("div").each(function(){
		images.push($(this));
	});
	jQuery.each(images, function() {
		this.bind("click", function() {
			$("#videowidgetbox_"+id).toggle();
			statsVideo(video_id, 'youtube');
			videowidgetPP(id, video_id);
		});
	});
}

function videowidgetPP(id, video_id)
{
	var alt, video;
	$obj = $("#videowidgetPP_"+id);
	$obj2 =  $("#videowidgetVideo_"+id);
	alt = $obj.attr("alt");
	if(alt == "Play") {
		$obj.attr({"src":"http://d382womoc7z666.cloudfront.net/static/control_stop_blue.png", "alt":"Stop", "title":"Stop"});
		$obj2.html('<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/'+video_id+'&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/'+video_id+'&hl=en&fs=1&autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>');
	} else {
		$obj.attr({"src":"http://d382womoc7z666.cloudfront.net/static/control_play_blue.png", "alt":"Play", "title":"Play"});
		$obj2.html('');
	}
}

function adAlbumImages()
{
	$(".googleimagebutton").each( function() {
		$(this).bind("click", function() {
			notice('Updating...', '');
			var src;
			$(this).prev().children(".googleimage").each(function(){
				$img = $(this);
				src = $img.attr("src");
			});
			src = encodeURI(src);
			var a = $(this).attr("id");
			$.php(baseurl+'/admin/savealbumimage?src='+src+'&album='+a,{});
		});
	});
}

function adAlbumRD()
{
	$(".albumrd").each( function() {
		$(this).bind("click", function() {
			notice('Updating...', '');
			$form = $(this).parents(".formalbumrd");
			var url = $form.attr("action");
			$.php(url, $form.formToArray(true));
		});
	});

}

function noenter(e)
{
	var evt=window.event || e
	return !(e.keyCode == 13);
}