/***********************************
PRELOAD LOADING IMAGES
***********************************/
if (document.images) {

var smallLoading=new Image(16,16);
smallLoading.src="images/loading.gif";

var largeLoading=new Image(32,32);
smallLoading.src="images/loading_large.gif";

}

/***********************************
GENERAL FUNCTIONS
***********************************/

function checkNameInput(inputObj) {
	if (inputObj.value=="Enter your name") { inputObj.value=''; }
}

function resetNameInput(inputObj) {
	if (inputObj.value=='') { inputObj.value="Enter your name"; }
}

function checkInput(inputObj) {
	if (inputObj.value=="Enter your email") { inputObj.value=''; }
}

function resetInput(inputObj) {
	if (inputObj.value=='') { inputObj.value="Enter your email"; }
}



// when the pop backdrop is clicked it should always
// close itself and any open popups
function fadePop() {
	$('#popMask, .popWindow').fadeOut();
	renderFlappr();
	
	if($('#popExperience').length != 0) {
		var popExp = document.getElementById('popExperience');
		popExp.parentNode.removeChild(popExp);
	}
	
}

function fadePopSmall() {
	$('#popMask, .popWindowSmall').fadeOut();
	renderFlappr();
	
	if($('#popExperience').length != 0) {
		var popExp = document.getElementById('popExperience');
		popExp.parentNode.removeChild(popExp);
	}
	
}

function createMask() {
	if($('#popMask').length == 0) {
		$('<div id="popMask"><div class="mask" style="height: '+$(document).height()+'px;" onclick="fadePop();"></div><img id="loadingPop" src="images/loading_pop.gif" alt="Loading..." /></div>').appendTo('body').fadeIn();
	} else {
		$('#popMask').fadeIn();
	}
	document.getElementById('flappr').innerHTML='';
}

function createMaskSmall() {
	if($('#popMask').length == 0) {
		$('<div id="popMask"><div class="mask" style="height: '+$(document).height()+'px;" onclick="fadePopSmall();"></div><img id="loadingPop" src="images/loading_pop.gif" alt="Loading..." /></div>').appendTo('body').fadeIn();
	} else {
		$('#popMask').fadeIn();
	}
	document.getElementById('flappr').innerHTML='';
}
/************************************
FLASH FUNCTIONS
************************************/
function renderFlappr() {
	var fo = new FlashObject("http://www.frappr.com/ajax/yvmap.swf", "flappr", "275", "300", "9", "#FFFFFF");
	fo.addParam("quality", "high");
	fo.addParam("scale", "noscale");
	fo.addParam("wmode", "opaque");
	fo.addParam("salign", "l");
	fo.addParam("align", "middle");
	fo.addParam("flashvars", "host=http://www.frappr.com/&origin=myspace&lo=1&mvid=137440604335");
	fo.write("flappr");
}

/************************************
AJAX FUNCTIONS
************************************/
// brings up news pop. currently set to any 'more' link
function switchNews(thisObj) {
	document.getElementById('newsContent').innerHTML="<img id='loadingLarge' src='images/loading_large.gif' />";
		$.ajax({
			type: 'POST',
			url: 'ajax/news.php?ajax=true&section='+thisObj.getAttribute('title')+'&nocache='+Math.random(),
			success: function(response) {
				document.getElementById("popSos").innerHTML=response;
			}
		});
	
	return false;
};

function showExperienceLoad() {
	$('#experienceLoading').show();
}

function hideExperienceLoad() {
	$('#experienceLoading').hide();
}

function generalFade(id,action) {
	if(action == 'show') { 
	$(id).fadeIn();	
	} else { 
	$(id).hide();	
	}
	
}

function submitExperience() {
		$('#experienceLoading').show();
		var name = $('#storyName').fieldValue();
		var email = $('#storyEmail').fieldValue();
		var story = $('#storyStory').fieldValue();
		var age = $('#storyAge').fieldValue();
		var image = $('#picture').fieldValue();
		$.ajax({
			type: 'POST',
			url: 'ajax/process_experience.php?ajax=true&name='+name+'&email='+email+'&age='+age+'&story='+story+'&nocache='+Math.random(),
			success: function(response) {
				eval(response);
			}
		});

		return false;
	}

/************************************
JQUERY 'ONLOAD' ATTACHMENTS
************************************/	
$(document).ready(function() {

renderFlappr();


	// brings up news pop. currently set to any 'more' link
	$('#submitExperience').click(function() {
		if($('#popExperience').length == 0) {
			createMask();
			$.ajax({
				type: 'POST',
				url: 'ajax/submitYourStory.php?ajax=true&nocache='+Math.random(),
				success: function(response) {
					$('<div class="popWindow" id="popExperience">'+response+'</div>').appendTo('body').fadeIn();
				}
			});
		
		return false;
	} else {
		$('#popMask, #popExperience').fadeIn();
	}
	});


	// brings up news pop. currently set to any 'more' link
	$('.sosMore').click(function() {
		if($('#popSos').length == 0) {
			createMask();
			$.ajax({
				type: 'POST',
				url: 'ajax/news.php?ajax=true&section='+this.getAttribute('title')+'&nocache='+Math.random(),
				success: function(response) {
					$('<div class="popWindow" id="popSos">'+response+'</div>').appendTo('body').fadeIn();
				}
			});
		
		return false;
	} else {
		$('#popMask, #popSos').fadeIn();
	}
	});
		
	// trouper popup creation / content adding 
	// click event & function
	$('#readTrouper').click(function() {
		if($('#popTrouper').length == 0) {
			createMask();
			$.ajax({
				type: 'POST',
				url: 'ajax/superTrouper.php?ajax=true&nocache='+Math.random(),
				success: function(response) {
					$('<div class="popWindow" id="popTrouper">'+response+'</div>').appendTo('body').fadeIn();
				}
			});
		} else {
			$('#popMask, #popTrouper').fadeIn();
			document.getElementById('flappr').innerHTML='';
		}
		
		return false;
	});
	
	//contest popover
	$('#contestLink').click(function() {
		if($('#popContest').length == 0) {
			createMaskSmall();
			$.ajax({
				type: 'POST',
				url: 'ajax/contest.php?ajax=true&nocache='+Math.random(),
				success: function(response) {
					$('<div class="popWindowSmall" id="popContest">'+response+'</div>').appendTo('body').fadeIn();
				}
			});
		} else {
			$('#popMask, #popContest').fadeIn();
			document.getElementById('flappr').innerHTML='';
		}
		
		return false;
	});
	
	// trouper popup creation / content adding 
	// click event & function
	$('#readFan').click(function() {
		if($('#popFan').length == 0) {
			createMask();
			$.ajax({
				type: 'POST',
				url: 'ajax/fanOfTheMonth.php?ajax=true&nocache='+Math.random(),
				success: function(response) {
					$('<div class="popWindow" id="popFan">'+response+'</div>').appendTo('body').fadeIn();
				}
			});
		} else {
			$('#popMask, #popFan').fadeIn();
			document.getElementById('flappr').innerHTML='';
		}
		
		return false;
	});
	

	
	// Fan club signup
	// click event & function
	// $('#signUpForm').submit(function() {
		// $('#signUpLoading').show();
		// var email = $('#clubEmail').fieldValue();
		// $.ajax({
			// type: 'POST',
			// url: 'ajax/signUp.php?ajax=true&email='+email+'&nocache='+Math.random(),
			// success: function(response) {
				// eval(response);
			// }
		// });

		// return false;
	// });
	
});

//AWESOME DREAMWEAVER CODE!
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
