$().ready( function(){

});

function addToGamePlan( src, business_id){
	
	$.getJSON('/ajax.php', {action:'getbusiness',business_id:business_id}, function(data) {
			
			business_name = data[1];
			
			$('<li style="display:none;" id="droppedcoaster_'+business_id+'" class="droppedcoaster"><a class="gpb_delete" href="#" onclick="deleteFromGamePlan(\''+business_id+'\');return false;">&nbsp;</a><img src="'+src+'"><div class="name">'+business_name+'</span></li>').insertBefore('#dropzone').show('scale');
			
			$("#dropzone").removeClass("default").addClass("coaster");
			
			saveGamePlan();
	 });
	
}

function saveGamePlan(){

	var business_ids = Array();
	
	$.each( $('.droppedcoaster'), function( i, val ){
		
		business_ids.push( val.id.substr(15) );
	
	});
	
	$.ajax({
	   type: "POST",
	   url: '/ajax.php',
	   data: 'action=savegameplan&business_ids=' + business_ids.join(',')
	 });

}

function deleteFromGamePlan( business_id ){
	
	$('#droppedcoaster_' + business_id).remove();
	
	saveGamePlan();
	
	if( $('.droppedcoaster').size() == 0 ){
		$("#dropzone").removeClass("coaster").addClass("default");
	}

}

function launchGamePlan( gameplan_id ){

	if( gameplan_id != null ){
	
		$.fancybox({href:'/pop_gameplanedit.php?gameplan_id='+gameplan_id,type:'iframe', width:550, height:400, centerOnScroll:true});
	
	}else{
	
		if( $('.droppedcoaster').size() < 1 ){
		
			popDialog( 'Gamplan', 'You must first drag some businesses into your gameplan!', 150 );	
			
		}else{
		
			$.fancybox({href:'/pop_gameplan.php',type:'iframe', width:550, height:400, centerOnScroll:true});
		
		}
		
	}

}
