


// fixit plan for loaders on things that require them (which is, like, most of these?)
	// post comment
	// post to thread


function like(id){
	// type: comment, pic, forum post, news story?, video,
	$.post("/ajax/like/",{id:id},function(data){

		var dat;

		if (data == 'like'){
			dat = '<img src="/media/img/ui_favorite.png" class="scon" width="24" height="24" alt="like" />';
		}else{
			dat = '<img src="/media/img/ui_unfavorite.png" class="scon" width="24" height="24" alt="don\'t like" />';
		}

		$("#like-"+id).html(dat);
	});
}





function flag(id){
	// type: comment, pic, forum post, news story?, video,
	$.post("/ajax/flag/",{id:id},function(data){
		$("#flag-"+id).html(data);
	});
}


function unflag(id){
	// type: comment, pic, forum post, news story?, video,
	$.post("/ajax/unflag/",{id:id},function(data){
		window.location.reload();
//		$("#flag-"+id).html(data);
	});
}



function audioPlayer(){

	var w = 360;
	var h = 460;

	var win = window.open ("/audio/","audioplayer",'status=no,resizable=no,scrollbars=no,personalbar=no,directories=no,location=no,toolbar=no,menubar=no,' +
                    'width='+w+',height='+h+',left=0,top=0');
 			win.resizeTo(w, h);
			win.focus();
}



function del(type,id,admin){
	// type: comment, pic, forum post, news story?, video, message

	apprise("Are you sure you want to delete this "+type+"?", {'verify':true}, function(r){ 
		if(r){ 
		$.post("/ajax/del/",{ type:type, id:id},function(data){
			if (type == 'post'){
				window.location.reload();
			}else{
				if (data != ''){
					window.location = data;
				}else{
					window.location.reload();
				}
			}

		});	
		}
	});
}

function post_update(id){
	var body = $("#post-descr-"+id).val();
	$.post("/ajax/postupdate/",{ id:id, body:body },function(data){
			window.location.reload();
	});	
}



function save(type,id){

	var form = $("#edit-form-"+id).serialize();
	$.post("/ajax/save/",{ type:type, id:id, form:form},function(data){
		if (data == 'success'){
			response = 'Changes Saved';
		}else{
			response = data;
		}
		$("#save-response-"+id).html(response); // fixit fadeout after 10 seconds, formatting, maybe close the fancybox after a few seconds instead?
	});

}

function saveMedia(type,id){
	var form = $("#edit-form-"+id).serialize();
	$.post("/ajax/save/",{ type:type, id:id, form:form},function(data){
		window.location.reload();
	});
}


function addMedia(){
	var form = $("#add-media").serialize();
	var ctype = $("#ctype").val();
	$.post("/ajax/addmedia/",{ ctype:ctype, form:form},function(data){
 		window.location = data;
	});

}


function getPassword(){
// fuck bitches, get money
	var email = $("#forgotemail").val();
	$.post("/ajax/getpassword/",{ email:email },function(data){	
		if (data){
			res = 'OK. Now, check your email.';
		}else{
			res = 'That email isn\'t registered with us. Are you sure that\'s the right address?';
		}
		humane(res); // fixit fancy modal response
		$.fancybox.close();
	});
}



// temp media player - subject to change [this is only on the the history section, but but need to be different depending on how we do the audio player)

function play(id){
	// fixit play song where id
	// if playing, show the pause button, if paused show the playing button
}





// post comments

function postComment(id,user){
	var txt = $("textarea[name=cm-txt]").val();
	$.post("/ajax/comment/",{ txt:txt, id:id, user:user },function(data){
		
		var data = eval('(' + data + ')'); // OUCH
		var cmid = data.id;
		var avatarpath = data.avatar;
		var username = data.username;
		var commentformat = txt;
		var cmdate = data.date;

		// on success append this comment's content to the list
			// ugh i hate writing markup w/ js...so messy
//		$("#comment-end").before('<div class="comment" id="comment-'+cmid+'"><a href="javascript:del(\'comment\','+cmid+');"><img src="" width="" height="" class="del" /></a><div class="comment-left"><a href="/people/'+username+'/"><img src="'+avatarpath+'" width="66" height="66" /></a><a href="/people/'+username+'/">'+username+'</a></div><div class="comment-right"><p>'+commentformat+'</p><div class="txt-r">'+cmdate+'<a href="javascript:like(\'comment\','+cmid+');"><img src="" width="" height="" class="like" /></a><a href="javascript:flag(\'comment\','+cmid+');"><img src="" width="" height="" class="flag" /></a></div></div><div class="clear"></div></div>');
		window.location.reload();				
		// reset form
		$("textarea[name=cm-txt]").val('');
	});

}




// going to the show?

function tourGoing(going,id){
// going: yes/no/maybe

		$(".btn").removeClass('btn-highlight');
		$("#going-"+going).addClass('btn-highlight');	
	$.post("/ajax/tourgoing/",{ going:going, id:id },function(data){			
		window.location.reload();
	});
}



function goingRest(){
	$("#going-rest").slideToggle();

// fixit check visibility and return text accordingly
	$("#going-rest-button").text('see less...or something i don\'t know');
}




// messages
function readMsg(id){
	// fixit show div containing this message
	// pretty sure it's just a fancybox call
	$.post("/ajax/readmsg/",{ id:id });
}





function sendMsg(action, id){
	// action: reply, new

	var recip = $("#recip-"+id).val();
	var subject = $("#subject-"+id).val();
	var msgtext = $("#msgtext-"+id).val();

	$.post("/ajax/sendmsg/",{ id:id, recip:recip, subject:subject, msgtext:msgtext },function(data){			

		humane('message sent'); // fixit fancy modal response
		$.fancybox.close();
		$("#msgtext-"+id).val("");
		if (action == "new"){
			$("#subject-"+id).val("")
		}
	});

}





// add to friends

function addFriend(uid){

	$.post("/ajax/friendrequest/",{ uid:uid },function(data){			
		$("#request-friend").html("<small><i>friendship awaiting approval</i></small>");
	});
	
}

function removeFriend(uid){

	if (confirm("are you sure?")){
		$.post("/ajax/friendremove/",{ uid:uid },function(data){			
	alert(data);
//			window.location.reload();
		});
	}
	
}


function frequest(approve,uid,h5){
	$.post("/ajax/frequest/",{ approve:approve, uid:uid },function(data){			
		$('#h5-'+h5).slideUp();
	});
}





function writeMsg(){ // compose
	// fixit show div w/ subject, msg fields
	// pretty sure it's just a fancybox call
}






// message board

function closeThread(id){
	apprise("Are you sure you want to close this thread?", {'verify':true}, function(r){ 
		if(r){ 
			$.post("/ajax/closethread/",{ id:id },function(data){			
				$("#close-thread").html("This thread is now closed");
				$("#thread-reply").remove();
			});
		}
	});
}

function deleteThread(id){
	apprise("Are you sure you want to delete this thread?", {'verify':true}, function(r){ 
		if(r){ 
			$.post("/ajax/deletethread/",{ id:id },function(data){			
				window.location = '/board';
			});
		}
	});
}






function postThread(id){

	var txt = $("textarea[name=cm-txt]").val(); // fixit text formatting
	var catid = $("input[name=cat_id]").val();
//	humane(catid)
	var filename = $("input[name=filename]").val();
	var addblog = $("input[name=add_blog]").val();
	$.post("/ajax/postthread/",{ txt:txt, id:id, filename:filename,catid:catid,addblog:addblog },function(data){
		
		var data = eval('(' + data + ')'); // OUCH
		var postid = data.id;
		var avatarpath = data.avatar;
		var username = data.username;
		var commentformat = txt;
		var cmdate = data.date;
		var postimgpathlarge = data.imglarge;
		var postimgpath = data.img;
		
		var postimg = '';
		
		if (postimgpath){
			postimg = '<a href="'+postimgpathlarge+'" rel=""><img src="'+postimgpath+'" width="" height="" /></a>';
		}
// fixit newline shit	
	// also, why is this writing markup? is there a better way to do this?
//		$("#thread-reply").before('<div class="posts" id="post-'+postid+'"><a href="javascript:del(\'post\','+postid+');"><img src="" width="" height="" class="del" /></a><div class="posts-l">	<a href="/people/'+username+'/"><img src="'+avatarpath+'" width="40" height="40" /></a>	<a href="/people/'+username+'/">'+username+'</a></div><div class="posts-r">	<p>		'+commentformat+'	</p>	'+postimg+'	<h6>'+cmdate+'		<a href="javascript:like(\'post\','+postid+');"><img src="" width="" height="" class="like" /></a>		<a href="javascript:flag(\'post\','+postid+');"><img src="" width="" height="" class="flag" /></a>	</h6></div><div class="clear"></div></div>');		
		window.location.reload();
		// reset form
		$("textarea[name=cm-txt]").val('');
	});



}




// news filter
function showNews(what){
	$.post("/ajax/shownews/",{ what:what },function(data){			
		window.location.reload();
	});
}


function newCat(){
	var title = $("#new-title").val();
	var descr = $("#new-catdescr").val();
	$.post("/ajax/newcat/",{ title:title, descr:descr },function(data){	
		window.location = data;
	});
}


function editCat(cat){
	var title = $("#edit-title").val();
	var descr = $("#edit-catdescr").val();
	$.post("/ajax/editcat/",{ title:title, descr:descr, id:cat },function(data){	
		window.location.reload();
	});
}


function deleteCat(cat){

	apprise("Are you sure you want to delete this category?", {'verify':true}, function(r){ 
		if(r){ 
		$.post("/ajax/deletecat/",{ id:cat },function(data){	
			window.location = '/board/';
		});
		}
	});
}



function addVideoPlaylist(id){
	$.post("/ajax/addVideoPlaylist/",{ id:id },function(data){	
		if (data == 'success'){
			$("#playlist-btn-"+id).html('<small><i>added to front page</i></small>');
		}
	});
}


// function closeThread(id){
// 	$.post("/ajax/closethread/",{ id:id },function(data){	
// 		window.location.reload();
// 	});
// }


function openThread(id){
	$.post("/ajax/openthread/",{ id:id },function(data){	
		window.location.reload();
	});
}


function stickyThread(id){
	var stick = $("#stick").val();
	$.post("/ajax/stickythread/",{ id:id, stick:stick },function(data){	
		window.location.reload();
	});
}



function move_thread(id){
	var catid = $("#moveThread").val();
	$.post("/ajax/movethread/",{ id:id, catid:catid },function(data){	
		window.location.href = '/board/'+data+'/'+id+'/';
	});
}



function rverify(field){
	var val = $("#r-"+field).val();
	$.post("/ajax/rverify/",{ field:field, val:val },function(data){
		if (data == 'ok'){
			$('#ok-'+field).val('y');
			$('#v-'+field).html('');
		}else{
			$('#ok-'+field).val('');
			$('#v-'+field).html(data);
		}
	});
}


function addVersions(id){ // lame pffsh whatever
	$("#versions-stop-"+id).before('<div class="f-left mr15"><label class="txt c7">Label</label> <br /><input type="text" class="txt txt-small" name="version_title[]" /><br /><br /></div><div class="f-left"><label class="txt c7">URL</label><br /><input type="text" class="txt txt-small" name="version_url[]" /><br /><br /></div><div class="clear"></div>');
}



function shopPrimary(id){
	$.post("/ajax/shopPrimary/",{ id:id },function(data){	
		window.location.href='/admin/shop_promo/';
	});
}

function shopDelete(id){

	apprise("Are you sure you want to delete this shop promo?", {'verify':true}, function(r){ 
		if(r){ 
		$.post("/ajax/shopDelete/",{ id:id },function(data){	
			window.location.href='/admin/shop_promo/';
		});
		}
	});
}



function addToCart(sku){
	var newsku = $("#size").val();
	
	if (newsku){
		var sku = newsku;
	}
	
	window.location.href='http://warnerbrosrecordsstore.com/store/buy.asp?sys=WBR&L=LIP&R=http://flaminglips.com/store&upc='+sku;
}


// THANKS FOR THE PERFORMANCE HIT, IE. FUCK YOU. FUCK YOU HARD.

/*
* Placeholder plugin for jQuery
* ---
* Copyright 2010, Daniel Stocks (http://webcloud.se)
* Released under the MIT, BSD, and GPL Licenses.
*/

(function(b){function d(a){this.input=a;a.attr("type")=="password"&&this.handlePassword();b(a[0].form).submit(function(){if(a.hasClass("placeholder")&&a[0].value==a.attr("placeholder"))a[0].value=""})}d.prototype={show:function(a){if(this.input[0].value===""||a&&this.valueIsPlaceholder()){if(this.isPassword)try{this.input[0].setAttribute("type","text")}catch(b){this.input.before(this.fakePassword.show()).hide()}this.input.addClass("placeholder");this.input[0].value=this.input.attr("placeholder")}},
hide:function(){if(this.valueIsPlaceholder()&&this.input.hasClass("placeholder")&&(this.input.removeClass("placeholder"),this.input[0].value="",this.isPassword)){try{this.input[0].setAttribute("type","password")}catch(a){}this.input.show();this.input[0].focus()}},valueIsPlaceholder:function(){return this.input[0].value==this.input.attr("placeholder")},handlePassword:function(){var a=this.input;a.attr("realType","password");this.isPassword=!0;if(b.browser.msie&&a[0].outerHTML){var c=b(a[0].outerHTML.replace(/type=(['"])?password\1/gi,
"type=$1text$1"));this.fakePassword=c.val(a.attr("placeholder")).addClass("placeholder").focus(function(){a.trigger("focus");b(this).hide()});b(a[0].form).submit(function(){c.remove();a.show()})}}};var e=!!("placeholder"in document.createElement("input"));b.fn.placeholder=function(){return e?this:this.each(function(){var a=b(this),c=new d(a);c.show(!0);a.focus(function(){c.hide()});a.blur(function(){c.show(!1)});b.browser.msie&&(b(window).load(function(){a.val()&&a.removeClass("placeholder");c.show(!0)}),
a.focus(function(){if(this.value==""){var a=this.createTextRange();a.collapse(!0);a.moveStart("character",0);a.select()}}))})}})(jQuery);



$(function(){

	$("a[rel='fbox']").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'scrolling'		:	'no',
		'showNavArrows'	:	false
	});

	$("a[rel=modal]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'showNavArrows'	:	false
	});
	
	$("a.editmodal").click(function(){
		$(".video-player").css('visibility','hidden');
	});



	$("a#msg").fancybox({
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});

	$("input.utitle").blur(function(){
		var title = $(this).val();
		
		var urltitle = '#url' + $(this).attr('id');
		
		var ctype = $("#ctype").val();
		
		if (!ctype){
			ctype = false;
		}

		$.post("/ajax/urltitle/",{ title:title, ctype:ctype},function(data){

			$(urltitle).val(data);
		});

	});

	if (window.location.hash == '#authError'){
		humane('login incorrect');
	}

	if (window.location.hash == '#updated'){
		humane('your account has been updated');
	}

	
	$('input[placeholder], textarea[placeholder]').placeholder();
});




// fancy alert boxes...that's cool
function apprise(string,args,callback)
{var default_args={'confirm':false,'verify':false,'input':false,'animate':false,'textOk':'Ok','textCancel':'Cancel','textYes':'Yes','textNo':'No'}
if(args)
{for(var index in default_args)
{if(typeof args[index]=="undefined")args[index]=default_args[index];}}
var aHeight=$(document).height();var aWidth=$(document).width();$('body').append('<div class="appriseOverlay" id="aOverlay"></div>');$('.appriseOverlay').css('height',aHeight).css('width',aWidth).fadeIn(100);$('body').append('<div class="appriseOuter"></div>');$('.appriseOuter').append('<div class="appriseInner"></div>');$('.appriseInner').append(string);$('.appriseOuter').css("left",($(window).width()-$('.appriseOuter').width())/2+$(window).scrollLeft()+"px");if(args)
{if(args['animate'])
{var aniSpeed=args['animate'];if(isNaN(aniSpeed)){aniSpeed=400;}
$('.appriseOuter').css('top','-200px').show().animate({top:"100px"},aniSpeed);}
else
{$('.appriseOuter').css('top','100px').fadeIn(200);}}
else
{$('.appriseOuter').css('top','100px').fadeIn(200);}
if(args)
{if(args['input'])
{if(typeof(args['input'])=='string')
{$('.appriseInner').append('<div class="aInput"><input type="text" class="aTextbox" t="aTextbox" value="'+args['input']+'" /></div>');}
else
{$('.appriseInner').append('<div class="aInput"><input type="text" class="aTextbox" t="aTextbox" /></div>');}
$('.aTextbox').focus();}}
$('.appriseInner').append('<div class="aButtons"></div>');if(args)
{if(args['confirm']||args['input'])
{$('.aButtons').append('<button value="ok">'+args['textOk']+'</button>');$('.aButtons').append('<button value="cancel">'+args['textCancel']+'</button>');}
else if(args['verify'])
{$('.aButtons').append('<button value="ok">'+args['textYes']+'</button>');$('.aButtons').append('<button value="cancel">'+args['textNo']+'</button>');}
else
{$('.aButtons').append('<button value="ok">'+args['textOk']+'</button>');}}
else
{$('.aButtons').append('<button value="ok">Ok</button>');}
$(document).keydown(function(e)
{if($('.appriseOverlay').is(':visible'))
{if(e.keyCode==13)
{$('.aButtons > button[value="ok"]').click();}
if(e.keyCode==27)
{$('.aButtons > button[value="cancel"]').click();}}});var aText=$('.aTextbox').val();if(!aText){aText=false;}
$('.aTextbox').keyup(function()
{aText=$(this).val();});$('.aButtons > button').click(function()
{$('.appriseOverlay').remove();$('.appriseOuter').remove();if(callback)
{var wButton=$(this).attr("value");if(wButton=='ok')
{if(args)
{if(args['input'])
{callback(aText);}
else
{callback(true);}}
else
{callback(true);}}
else if(wButton=='cancel')
{callback(false);}}});}







/**
 * HumaneJS
 * Humanized Messages for Notifications
 * @author Marc Harter (@wavded)
 * @contributers
 *   Alexander (@bga_)
 *   Jose (@joseanpg)
 * @example
 *  humane('hello world');
 */

;(function(win,doc){var eventOn,eventOff;if(win.addEventListener){eventOn=function(obj,type,fn){obj.addEventListener(type,fn,false)};eventOff=function(obj,type,fn){obj.removeEventListener(type,fn,false)}}else{eventOn=function(obj,type,fn){obj.attachEvent('on'+type,fn)};eventOff=function(obj,type,fn){obj.detachEvent('on'+type,fn)}}var eventing=false,animationInProgress=false,humaneEl=null,timeout=null,useFilter=/msie [678]/i.test(navigator.userAgent),isSetup=false,queue=[];eventOn(win,'load',function(){var transitionSupported=(function(style){var prefixes=['MozT','WebkitT','OT','msT','KhtmlT','t'];for(var i=0,prefix;prefix=prefixes[i];i++){if(prefix+'ransition'in style)return true}return false}(doc.body.style));if(!transitionSupported)animate=jsAnimateOpacity;setup();run()});function setup(){humaneEl=doc.createElement('div');humaneEl.id='humane';humaneEl.className='humane';doc.body.appendChild(humaneEl);if(useFilter)humaneEl.filters.item('DXImageTransform.Microsoft.Alpha').Opacity=0;isSetup=true}function remove(){eventOff(doc.body,'mousemove',remove);eventOff(doc.body,'click',remove);eventOff(doc.body,'keypress',remove);eventOff(doc.body,'touchstart',remove);eventing=false;if(animationInProgress)animate(0)}function run(){if(animationInProgress&&!win.humane.forceNew)return;if(!queue.length){remove();return}animationInProgress=true;if(timeout){clearTimeout(timeout);timeout=null}timeout=setTimeout(function(){if(!eventing){eventOn(doc.body,'mousemove',remove);eventOn(doc.body,'click',remove);eventOn(doc.body,'keypress',remove);eventOn(doc.body,'touchstart',remove);eventing=true;if(!win.humane.waitForMove)remove()}},win.humane.timeout);humaneEl.innerHTML=queue.shift();animate(1)}function animate(level){if(level===1){humaneEl.className="humane humane-show"}else{humaneEl.className="humane";end()}}function end(){animationInProgress=false;setTimeout(run,500)}var setOpacity=(function(){if(useFilter){return function(opacity){humaneEl.filters.item('DXImageTransform.Microsoft.Alpha').Opacity=opacity*100}}else{return function(opacity){humaneEl.style.opacity=String(opacity)}}}());function jsAnimateOpacity(level,callback){var interval;var opacity;if(level===1){opacity=0;if(win.humane.forceNew){opacity=useFilter?humaneEl.filters.item('DXImageTransform.Microsoft.Alpha').Opacity/100|0:humaneEl.style.opacity|0}humaneEl.style.visibility="visible";interval=setInterval(function(){if(opacity<1){opacity+=0.1;if(opacity>1)opacity=1;setOpacity(opacity)}else{clearInterval(interval)}},500/20)}else{opacity=1;interval=setInterval(function(){if(opacity>0){opacity-=0.1;if(opacity<0)opacity=0;setOpacity(opacity)}else{clearInterval(interval);humaneEl.style.visibility="hidden";end()}},500/20)}}function notify(message){queue.push(message);if(isSetup)run()}win.humane=notify;win.humane.timeout=2000;win.humane.waitForMove=true;win.humane.forceNew=false}(window,document));
