// JavaScript Document


//vote script
function n8FlashVote(form,btn){
	var f_options = {
    target: 	'#vote',
    dataType: 	'xml',
    success: 	processVote
  };
  $(form).ajaxSubmit(f_options);
  $(btn).attr('disabled', true);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

//Process vote
function processVote(responseXML) {
	var type 	= $('message_type',responseXML).text();
	var poll 	= $('poll',responseXML).text();
	var m	 	= $('message',responseXML).text();
	var targ 	= $('targ',responseXML).text();
	var row 	= $('row',responseXML).text();
	var wrap 	= $('wrap',responseXML).text();
	var show 	= $('show',responseXML).text();
	if (show == 'yes') {
		n8FlashLoad('#' + row,jamroom_url + '/ranking.php?mode=n8FlashPoll&poll_id=' + poll + '&row_template=poll_response.tpl&cache_time=0', '#' + wrap);
	}	
	$('#'+targ).text(m);	
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

//Enable vote button
function enableVote(id) {
	$(id).attr('disabled',false);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

//Show rules
function infoSlide(div) {
	$(div).slideToggle();
}


///////////////////////////////////////////////////////////////////////////////////////////////////////

//Show Battle Widget
function n8FlashBattleWidget(wrap,div,id,type,but) {
	//Check height
	var h = $(wrap).height();
    if (h < 150) {
		//Set height
		$(wrap).height(270);
		//Slide Open
		$(wrap).slideDown(500,function() {
			//Load Proper Player
			if(type == 'song') {
				n8FlashLoad(div,jamroom_url + '/ranking.php?mode=song&song_id=' + id + '&row_template=battle_widget.tpl&show=1',wrap)
			}
			else if (type == 'video') {
				n8FlashLoad(div,jamroom_url + '/ranking.php?mode=video&video_id=' + id + '&row_template=battle_widget.tpl&show=1',wrap)
			}
			else {
				n8FlashLoad(div,jamroom_url + '/ranking.php?mode=photo&photo_id=' + id + '&row_template=battle_widget.tpl&show=1',wrap)
			}				
		});
		//Change the button text
		$(but).attr('value','Close');	
	}	
	else {
		//Close the div
		$(wrap).slideUp(500,function() {
			//Delete Player
			$(div).empty();
			//Set div height
			$(wrap).height(0);
		});
		//Change the button text
		if(type == 'song') {
			$(but).attr('value','Listen');
		}
		else if (type == 'video') {
			$(but).attr('value','Watch');
		}
		else {
			$(but).attr('value','Preview');
		}
	}	
}

///////////////////////////////////////////////////////////////////////////////////////////////////////

function n8FlashLoad(id,url,parent) {	
	$(parent).addClass('poll_loading');	
	var h = $(parent).height();
	$(parent).height(h);
	$(id).fadeOut(50, function(){
		$(id).load(url,0, function() {			
			$(id).fadeIn(250, function(){		   
				$(parent).removeClass('poll_loading');
				$(parent).height('100%');
		   });			
		});	
	});	
}

///////////////////////////////////////////////////////////////////////////////////////////////////////


