/*
 * 
 * bigadgig.js
 * 
 * provides encapsulation for the bigadgig html and data
 *
 */

window.Atmosphere = {};

Atmosphere.BigAdGig = function(stage){
	
	if(typeof( stage ) == "undefined"){ stage = 'signin'; }
	if(typeof( previous_stage ) == "undefined"){ previous_stage = ''; }
	if(typeof( email ) == "undefined"){ email = ''; }
	if(typeof( file_extension ) == "undefined"){ file_extension = ''; }
	if(typeof( html ) == "undefind"){ html = ''; }
	if(typeof( hasPerm ) == "undefind"){ hasPerm = false; }
	if(typeof( allowed_file_types ) == "undefined"){ 
		allowed_file_types = []; 
		allowed_file_types[0] = 'pdf';
		allowed_file_types[1] = 'rtf';
		allowed_file_types[2] = 'txt';	
	}

	this.stage = stage,
	this.previous_stage = previous_stage,
	this.setStage = function(value){
		this.previous_stage = this.stage;
		this.stage = value;
	},
	this.email = email,
	this.file_extension = file_extension,
	this.allowed_file_types = allowed_file_types,
	this.html = '',
	this.hasPerm,
	this.getFBPerm = function(){
		if( this.hasPerm == "undefined" )
			this.hasPerm = false;
		return this.hasPerm;
	},
	this.file_type_is_valid = function( ext )
	{
		if(this.file_extension = '')
			this.file_extension = ext;
		
		for(var i=0; i<allowed_file_types.length; i++)
		{
			if( allowed_file_types[i] == this.file_extension )
				return true;	
		}
		return false;
	},
	this.getHtml = function()
	{
		switch( this.stage )
		{
			case 'signin':
				var directionalCopy =	'We use your email address as your registration ' +
										'number, so make sure you use the same address ' +
										'any time you need to log back in.';
				
												
								
				this.html =	'<table width="800px" height="" border="0" cellspacing="0" cellpadding="0" summary="">' +
								'<tr height="100px">' +
									'<td colspan="1" align="left" style="vertical-align:bottom;">' +
										'<img class="page-title" src="images/title_entry1_email.gif" alt="Start by entering your email address." />' +
									'</td>' +	
								'</tr>' +
								'<tr height="10px">' +
									'<td colspan="1" align="left">' +
										'<img src="images/page_rule_gradient.gif" style="margin-bottom:25px;" />' +
									'</td>' +
								'</tr>' +
								'<tr>' +
									'<td>' +
										'<p class="section-text" id="directionRow">'+ directionalCopy +'</p>' + 
										'<form class="cmxform" id="form1" method="post" action="">' +
											'<label for="email" style="margin-top:30px;">Your email address:</label>' +
											'<p>' +
												'<input style="font-size:15px;" type="text" id="email" name="email" size="30" class="required email" maxlength="225" />' +
											'</p>' +
											'<div id="response" style="margin-top:40px;">' +
												'<p id="response-title">Message from The Big Ad Gig</p>' +
												'<p id="response-text"></p>' +
											'</div>' +
											'<p class="submit-holder" style="margin-top:40px;">' +
												'<input class="rollover_gradient" type="image" src="images/button_submit.gif" value="Next" alt="Next" />' +
												'<span id="status-loader">' +
													'<img src="images/circle_loader.gif" />' +
												'</span>' +
											'</p>' +
										'</form>' +
									'</td>' +
								'</tr>' +
							'</table>';
				break;
				
			case 'signup':
				
				var directionalCopy =	"If this is the first time you're registering, you've come to " +
										"the right place. If you've already registered and reached " +
										"this screen, odds are you've put in a different email " +
										"address than the last time &mdash; refresh the page " +
										"and try again.";
				
				var tempHtml = '';						
				tempHtml +=	'<table width="800px" height="" border="0" cellspacing="0" cellpadding="0" summary="">' +
								'<tr height="100px">' +
									'<td colspan="1" align="left" style="vertical-align:bottom;">' +
										'<img class="page-title" src="images/title_entry2_info.gif" alt="Now enter the rest of your info." />' +
									'</td>' +	
								'</tr>' +
								'<tr height="10px">' +
									'<td colspan="1" align="left">' +
										'<img src="images/page_rule_gradient.gif" style="margin-bottom:25px;" />' +
									'</td>' +
								'</tr>' +
								'<tr>' +
									'<td>' +
										'<p class="section-text" id="directionRow">'+ directionalCopy +'</p>' + 
										'<form class="cmxform" id="form1" method="post" action="php/upload.php"  enctype="multipart/form-data" target="upload_target">' +
											'<label for="email" style="margin-top:40px;">Your email address:</label>' +
											'<p class="section-text">' +
												'<span id="email">'+ this.email +'</span>' +
											'</p>' +
											'<label for="fname" style="margin-top:20px;">Your first name:</label>' +
											'<p class="section-text">' +
												'<input type="text" id="fname" name="fname" size="30" class="required" maxlength="100" />' +
											'</p>' +
											'<label for="lname" style="margin-top:20px;">Your last name:</label>' +
											'<p class="section-text">' +
												'<input type="text" id="lname" name="lname" size="30" class="required" maxlength="225" />' +
											'</p>' +
											'<label for="portfolio" style="margin-top:20px;">Your portfolio URL:</label>' +
											'<p class="section-text">' +
												'<input type="text" id="portfolio" name="portfolio" size="30" class="required url" />' +
											'</p>' +
											'<label for="resume" style="margin-top:20px;">Upload your resume: (under 2MB)</label>' +
											'<p class="section-text">' +
												'<input type="file" id="resume" name="resume" size="30" class="required" accept="pdf|rtf|txt" />' +
											'</p>' +
											'<p class="label_checkbox">' +
												'<input type="checkbox" id="agree" name="agree" />' +
												'<label id="agree-label" for="agree">I agree to the <a class="text-link" href="#">Terms &amp; Conditions</a></label>' +
											'</p>' +
											'<p id="agree-error" class="error">You must agree to the Terms and Conditions.</p>'; 
											
							if( !this.getFBPerm() ) 
							{
								tempHtml +=	'<p style="margin-top:25px;">' +
												'<i><span class="notes">Keep up to date with the competition and declare your entry to the world.<span></i>' +
											'</p>' +
											'<a href="#" onclick="checkLoginPermissions(); return false;" >' +
				   								'<img style="margin-top:5px;" id="fb_login_image" src="http://static.ak.fbcdn.net/images/fbconnect/login-buttons/connect_light_medium_long.gif" border="0" alt="Connect"/>' + 
				   			 				'</a>';
							}	
				
							tempHtml +=		'<p class="submit-holder" style="margin-top:40px;">' +
												'<input class="rollover_gradient" type="image" src="images/button_submit.gif" value="Submit" />' +
												'<span id="status-loader">' +
													'<img src="images/circle_loader.gif" />' +
												'</span>' +
											'</p>' +
										'</form>' +
										'<iframe id="upload_target" name="upload_target" src="#"></iframe>' +
										'<div id="response"></div>' +
									'</td>' +
								'</tr>' +
							'</table>';
				
				this.html = tempHtml;
				return this.html;
				break;
				
			case 'video_update':
				
				var directionalCopy = 	"Shot your video? Uploaded it to your YouTube account? Then " +
										"just paste in the URL below. If not, make sure you do so " +
										"before the entry deadline on 09/07/09. Then log in again " +
										"to return to this page.";
										
				var tempHtml = '';					
				tempHtml +=	'<table width="800px" height="" border="0" cellspacing="0" cellpadding="0" summary="">' +
								'<tr height="100px">' +
									'<td colspan="1" align="left" style="vertical-align:bottom;">' +
										'<img class="page-title" src="images/title_entry3_now_enter_link.gif" alt="Now enter the link to your video declaration." />' +
									'</td>' +	
								'</tr>' +
								'<tr height="10px">' +
									'<td colspan="1" align="left">' +
										'<img src="images/page_rule_gradient.gif" style="margin-bottom:25px;" />' +
									'</td>' +
								'</tr>' +
								'<tr>' +
									'<td>' +
										'<p id="directionRow" style="line-height:150%; font-family:verdana; font-size:15px; font-color:#65645f;">'+ directionalCopy +'</p>' + 
										'<form class="cmxform" id="form1" method="post" action="">' +
											'<label for="email" style="margin-top:40px;">Your email address:</label>' +
											'<p>' +
												'<span id="email">'+ this.email +'</span>' +
											'</p>' +
											'<label for="video" style="margin-top:20px;">Video URL</label>' +
											'<p>' +
												'<input style="font-size:15px;" type="text" id="video" name="video" size="30" class="required url" />' +
											'</p>';
			
							if(this.previous_stage != 'signup') {
								tempHtml +=	'<label class="code" for="token" style="margin-top:20px;">Confirmation Code ( request a <span id="new_token"><a href="#" style="color:#00bfe2">new confirmation code</a></span> )</label>' +
											'<p>' +
												'<input style="font-size:15px;" type="text" id="token" name="token" size="30" class="required"/>' +
											'</p>';
							}
							else if(this.previous_stage == 'signup') {
								tempHtml +=	'<input type="hidden" id="token" name="token"/>';
							}
							
							if( !this.getFBPerm() ) 
							{
								tempHtml +=	'<p style="margin-top:25px;">' +
												'<i><span class="notes">Keep up to date with the competition and declare your entry to the world.<span></i>' +
											'</p>' +
											'<a href="#" onclick="checkLoginPermissions(); return false;" >' +
				   								'<img style="margin-top:5px;" id="fb_login_image" src="http://static.ak.fbcdn.net/images/fbconnect/login-buttons/connect_light_medium_long.gif" border="0" alt="Connect"/>' + 
				   			  				'</a>';
							}
							tempHtml +=		'<div id="response">' +
												'<p id="response-title">Message from The Big Ad Gig</p>' +
												'<p id="response-text"></p>' +
											'</div>' +
											'<p class="submit-holder" style="margin-top:40px;">' +
												'<input class="rollover_gradient" type="image" src="images/button_submit.gif" value="Submit"/>' +
												'<span id="status-loader">' +
													'<img src="images/circle_loader.gif" />' +
												'</span>' +
											'</p>' +
										'</form>' +
									'</td>' +
								'</tr>' +
							'</table>';										
				
				this.html = tempHtml;
				return this.html;
				break;
			
			case 'all_done':
			
				var directionalCopy = 	"Don't forget to check out your video on our YouTube Channel &mdash; " +
										"and to find out if you make the cut when the field narrows on 9/11/09.";
										
				this.html =	'<table width="800px" height="" border="0" cellspacing="0" cellpadding="0" summary="">' +
								'<tr height="100px">' +
									'<td colspan="1" align="left" style="vertical-align:bottom;">' +
										'<img class="page-title" src="images/title_thanks_submission.gif" alt="Thanks for completing your submission." />' +
									'</td>' +	
								'</tr>' +
								'<tr height="10px">' +
									'<td colspan="1" align="left">' +
										'<img src="images/page_rule_gradient.gif" style="margin-bottom:25px;" />' +
									'</td>' +
								'</tr>' +
								'<tr>' +
									'<td>' +
										'<p id="directionRow" style="line-height:150%; font-family:verdana; font-size:15px; font-color:#65645f;">'+ directionalCopy +'</p>' + 
										'<p class="submit-holder" style="margin-top:40px;">' +
											'<a href="judges.phtml">' +
												'<img class="rollover_gradient" src="images/button_meet_judges.gif" />' +
											'</a>' +
										'</p>' +
									'</td>' +
								'</tr>' +
							'</table>';
				break;
				
		}
		return this.html
	},
	this.applyEventHandlers = function( page, include_top_nav )
	{	
	
		var link_privacy = $('.privacy-link').bind('click', function(e){
				e.preventDefault();
				window.open('privacy.html','Privacy_Policy', 'width=600,height=600,left=0,top=0,menubar=no,status=no,location=no,toolbar=no,scrollbars=no');
			});
	
		switch( page )
		{
			case 'home':
			
				var nav_details = $('#top-nav-details')
					.mouseover( function(e) { nav_details.find('img').attr('src', 'images/header_02_rollover.gif'); })
					.mouseout( function(e) { nav_details.find('img').attr('src', 'images/header_02.gif'); });
		
				var nav_judges = $('#top-nav-judges')
					.mouseover( function(e) { nav_judges.find('img').attr('src', 'images/header_04_rollover.gif'); })
					.mouseout( function(e) { nav_judges.find('img').attr('src', 'images/header_04.gif'); });
		
				var nav_partners = $('#top-nav-partners')
					.mouseover( function(e) { nav_partners.find('img').attr('src', 'images/header_06_rollover.gif'); })
					.mouseout( function(e) { nav_partners.find('img').attr('src', 'images/header_06.gif'); });

				var nav_entries = $('#top-nav-entries')
					.mouseover( function(e) { nav_entries.find('img').attr('src', 'images/header_08_rollover.gif'); })
					.mouseout( function(e) { nav_entries.find('img').attr('src', 'images/header_08.gif'); });

				break;
			
			case 'details':
				
				$('#top-nav-details').find('img').attr('src', 'images/header_02_rollover.gif');
		
				var nav_judges = $('#top-nav-judges')
					.mouseover( function(e) { nav_judges.find('img').attr('src', 'images/header_04_rollover.gif'); })
					.mouseout( function(e) { nav_judges.find('img').attr('src', 'images/header_04.gif'); });
		
				var nav_partners = $('#top-nav-partners')
					.mouseover( function(e) { nav_partners.find('img').attr('src', 'images/header_06_rollover.gif'); })
					.mouseout( function(e) { nav_partners.find('img').attr('src', 'images/header_06.gif'); });

				var nav_entries = $('#top-nav-entries')
					.mouseover( function(e) { nav_entries.find('img').attr('src', 'images/header_08_rollover.gif'); })
					.mouseout( function(e) { nav_entries.find('img').attr('src', 'images/header_08.gif'); });

				break;

				
			case 'judges':

				var nav_details = $('#top-nav-details')
					.mouseover( function(e) { nav_details.find('img').attr('src', 'images/header_02_rollover.gif'); })
					.mouseout( function(e) { nav_details.find('img').attr('src', 'images/header_02.gif'); });
		
				$('#top-nav-judges').find('img').attr('src', 'images/header_04_rollover.gif');
		
				var nav_partners = $('#top-nav-partners')
					.mouseover( function(e) { nav_partners.find('img').attr('src', 'images/header_06_rollover.gif'); })
					.mouseout( function(e) { nav_partners.find('img').attr('src', 'images/header_06.gif'); });

				var nav_entries = $('#top-nav-entries')
					.mouseover( function(e) { nav_entries.find('img').attr('src', 'images/header_08_rollover.gif'); })
					.mouseout( function(e) { nav_entries.find('img').attr('src', 'images/header_08.gif'); });

				break;
			
			case 'partners':
			
				var nav_details = $('#top-nav-details')
					.mouseover( function(e) { nav_details.find('img').attr('src', 'images/header_02_rollover.gif'); })
					.mouseout( function(e) { nav_details.find('img').attr('src', 'images/header_02.gif'); });
		
				var nav_judges = $('#top-nav-judges')
					.mouseover( function(e) { nav_judges.find('img').attr('src', 'images/header_04_rollover.gif'); })
					.mouseout( function(e) { nav_judges.find('img').attr('src', 'images/header_04.gif'); });
		
				$('#top-nav-partners').find('img').attr('src', 'images/header_06_rollover.gif');

				var nav_entries = $('#top-nav-entries')
					.mouseover( function(e) { nav_entries.find('img').attr('src', 'images/header_08_rollover.gif'); })
					.mouseout( function(e) { nav_entries.find('img').attr('src', 'images/header_08.gif'); });

				break;

			default:
				break;
		}
	}
}
